Creating Mesh Functions

Hello,

I am trying to create a diffusion function on the mesh. I’ve been following the “Tensor-weighted Poisson” tutorial.
https://fenicsproject.org/docs/dolfin/1.3.0/python/demo/documented/tensor-weighted-poisson/python/documentation.html

I have the following questions:
(1) Why does the array of a mesh function have more values than elements/cells on the mesh?
(2) How do you assign values to a Mesh Function?


Here is my problem in more detail:

To initialize the mesh function, I do this:
c00 = MeshFunction(“double”, mesh, 1)

Now I want to set the values of ‘c00’ on each mesh element. As I understand, the values of the function ‘c00’ are stored in c00.array().

However, I find that:
the number of cells on the mesh is not equal to length of c00.array()

That is:

    count = 0
    for x in (cells(mesh)):
        count += 1
    print (count)
    c00 = MeshFunction("double", mesh, 1)

prints 48,000

While

print (len(c00.array())

prints 59,660

I can’t figure out where this 59,660 number comes from. What are the values in c00.array() associated with (if not the mesh elements)?


Also, is there something like an “element_to_dof_map()” (analogous to vertex_to_dof_map()) for mesh functions? The “Tensor-weighted Poisson Tutorial” assigns to c00 like this:

for cell in cells(mesh):
     c00[cell] = 1

But this raised an error.


Thanks for the help,
T

Hi,

I reckon you may have a 2D mesh but have created a MeshFunction on 1D elements. So len(c00) is then the total ammount of facets in your mesh (not cells).

To create a MeshFunction on cells just go :
c00 = MeshFunction("double", mesh, mesh.topology().dim()) for cells
and c001 = MeshFunction("double", mesh, mesh.topology().dim()) - 1 for facets.

You can then assign values to c00 as you did above.
Hope this helps

Rem

1 Like

Ah, yes that worked, thanks.

Also, is it correct to say that doing:

c00[0] = 1

assigns the value 1 to the mesh element mesh.cells()[0].

In other words, is the order of the elements in mesh.cell() the same as the order of the degrees of freedom in c00.array()?

Thanks,
T

Well I wouldn’t be so sure about it. To be safe you should iterate through the mesh the way you did above.