I am solving an elliptic boundary value problem on a subset of the rectangle [-1,1]x[-1,1]. The domain contains the line segment x=0, however this does not need to be a part of the boundary, so it is not aligned with the facets by default.

I want to compute the flux of a solution function across the line segment x=0. I know from the tutorial how to compute fluxes over boundary elements. However, I am not sure whether making the line a boundary element is necessary in this case. Nor am I sure how to insert it, since simply inserting the line into the mesh will cause degrees of freedom to conflict, as would naively gluing rectangles together. Can you offer any suggestions on how to compute this flux?


Make sure that the mesh is aligned with x = 0. Then mark the facets along that line and compute the flux using an "interior facet integral". You can do this by supplying a facet function markers that (e.g.) marks those facets by 1 and the remaining facets by 0. Then compute the flux by

line_segment = AutoSubDomain(lambda x: near(x[0], 0))
markers = FacetFunction("size_t", mesh)
line_segment.mark(markers, 1)
dS = dS[markers]
flux = assemble(<expression for flux>*dS(1))

If you use a built-in mesh like RectangleMesh, it is easy to make sure that the mesh is aligned with the line segment. If you use an external mesh generator, it should have support for respecting your line segment when meshing.

| cite | improve this answer | |
  • $\begingroup$ Thanks, that is quite helpful! However, at present I am using DOLFIN's CSG for my mesh generation, and my domain is slightly more complicated than just a rectangle, being defined by: Rectangle(-2,-2,2,2)-Ellipse(-1,0,0.12,0.25)-Ellipse(1,0,0.12,0.25) Can I adjust this to get the CSG to respect the line segment, or will I need to use an external mesh generator? $\endgroup$ – Ian Jun 3 '13 at 21:59
  • $\begingroup$ Yes, you can do that with DOLFIN CSG (insert subdomains into your domain which are respected by the meshing). However, this is part of a separate branch which has not yet been merged. I'll ask its author to comment on the status of this feature. $\endgroup$ – Anders Logg Jun 4 '13 at 6:33
  • $\begingroup$ What if the mesh doesn't align with the line segment? Is there a work-around for that scenario? $\endgroup$ – Paul Nov 1 '17 at 20:42

As Anders said, the CSG functionality in Dolfin will be able to handle this soon. If you want to try it out now, get the code here: https://bitbucket.org/benjamik/dolfin and check out the branch called benjamik/csg-2d. Take a look at demo/undocumented/csg/2d/python/demo_csg_2d.py. The functionality is not documented yet except from this demo.

There are a couple of remaining issues that need to be sorted out before merging this into the official dolfin repo, but none of them should affect your case.

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.