I'm a beginner user of FEniCS and still struggling with some of the basics. Specifically,
I have some issues doing the tutorials in the Langtangen-Logg book Solving PDEs in Python - The FEniCS Tutorial Volume I. I think some of the problems are due to the different versions of the book and my installation (2019.1.0).
One of the issues is the use of the MeshFunction
or CellFunction
, FacetFunction
, etc.
The example (4.3.2 on page 90) says:
materials = CellFunction(’size_t’, mesh)
which doesn't work for me. After some research I found out that CellFunction
is deprecated since 2017.2.0:
Deprecate VertexFunction, EdgeFunction, FaceFunction, FacetFunction, CellFunction; use MeshFunction instead
I got the example to work with some trial and error (at least it looks like it's working):
materials = MeshFunction('size_t', mesh, 2)
But I do not really understand how and why. Especially after trying the next example that uses FacetFunction
.
The 2017.2.0 doc doesn't say much about how to use MeshFunction
. The descripton for the dim (unsigned int)
argument says:
The topological dimension of the MeshFunction. Optional.
The description for CellFunction
is just:
Create MeshFunction of topological codimension 0 on given mesh.
For FacetFunction
:
Create MeshFunction of topological codimension 1 on given mesh.
It doesn't work with materials = MeshFunction('size_t', mesh, 0)
. I figured that the codimension 0 might mean to use 0
for the dim
argument in the case of "CellFunction".
Therefore, my questions are:
- Is the "codimension" referring to the
dim
argument? - What does "topological dimension" and "topological codimension" mean in this context?
- If I should use
MeshFunction
instead of all those other functions mentioned above, how does using MeshFunction for cells differ from using it for facets, etc.
PS: I am aware of the question Fenics: Meshfunction usage, but it doesn't really answer my question
MeshFunction('size_t',mesh,mesh.topology().dim())
(for cells in 2d, usemesh.topology().dim()-1
for facets andmesh.topology(),dim()-2
for vertices). This is described in this commented demo. Always make sure that what you're looking at (even if it's a book) matches the version you are using (which you didn't specify). $\endgroup$