I would like to implement a natural boundary conditions (i. e. such that result in right side contributions via boundary integrals) that are different on different parts on the boundary. The whole contribution by the boundary conditions is given by sum like \int_{\Gamma_1} ( \vec f_1, \vec n) \mathrm{d}s + \int_{\Gamma_2} ( \vec f_2, \vec n) \mathrm{d}s
Originally, I used a piece of code like
# Initialize mesh function for boundary domains
boundaries = FacetFunction("size_t", mesh)
boundaries.set_all(0)
left.mark(boundaries, 1)
top.mark(boundaries, 2)
right.mark(boundaries, 3)
bottom.mark(boundaries, 4)
taken from the older fenics example to construct measures corresponding to \Gamma_i. This approach is unfortunately not working in my installation of 2018.1.0 as FacetFunction is no longer available. I would be grateful for any advice on the preffered reimplementation in the current version.
Indeed, FacetFunction is no longer available. You need to use MeshFunction instead, with an additional parameter to specify the topological dimension (mesh.topology().dim()-1 for the facets).
In your code, the two first lines could then be replaced by : boundaries = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 0)
I would like to use CellFunction(‘size_t’, 3Dmesh), but I’m not sure, if this is the correct substitution: MeshFunction("size_t", 3Dmesh, 3Dmesh.topology().dim()-2, 0)
First, it seems that the documentation you have been reading is quite old, I would recommend reading a more recent version.
The last argument (0 in your case), is an optional argument initializing the MeshFunction with the given value.
If I understand correctly, you would like to use the equivalent of CellFunction. Then I think the dimension you give to MeshFunction is not correct. Indeed, 3Dmesh.topology().dim()-2 will create a MeshFunction relative to the edges and not the cells.
The equivalent of CellFunction would be
This is useful information if anyone is trying to run the tutorial ('vol.1") demos and wants to fix demo#10. Line 223 needs to have boundary_markers = FacetFunction('size_t', mesh)
replaced with boundary_markers = MeshFunction('size_t', mesh, mesh.topology().dim()-1, 0)