SubMesh from List of Nodes

Hi All,

I would like to create a submesh of an original mesh given a list of specified nodes from the original mesh. Does anyone know how I might do this? So, let’s say I have a mesh created with

mesh = UnitSquareMesh(4, 4, “left”)

which should give me 25 nodes. Then, I want to create a submesh only using say 9 of those nodes. Is this possible? And, if so, how can incorporate evaluating an integral only on that submesh?

Thanks!

Amanda

Maybe something like this:

from dolfin import *
mesh = UnitSquareMesh(4,4)
leave_right_top = CompiledSubDomain("x[0] < 1 && x[1] < 1")
remainingMesh = SubMesh(mesh, leave_right_top)
dxnew = Measure("dx", domain=remainingMesh)
assert abs(assemble(1*dxnew) - 0.75**2) < 1.e-10

as long as you can mark the subdomains which you want to use to construct the SubMesh

1 Like

Thanks @bhaveshshrimali. I think now my question is: What kind of object is CompiledSubDomain(“x[0] < 1 && x[1] < 1”)? Is it just a list of points…(0,0), (.5,.5) … or is there more information contained in that?

The reason for my question is that my SubMesh will not be as simple as identifying nodes in a particular region. I actually need to pull out the coordinates of my mesh, identify certain points on that mesh, then create the SubMesh based on those certain points. Does that make sense?

Thanks again!

Amanda

What kind of object is CompiledSubDomain(“x[0] < 1 && x[1] < 1”)? Is it just a list of points…(0,0), (.5,.5) … or is there more information contained in that?

It’s a SubDomain instance. The methods can be looked up via help(leave_right_top) in this case, much like for any other instance in python.

The reason for my question is that my SubMesh will not be as simple as identifying nodes in a particular region. I actually need to pull out the coordinates of my mesh, identify certain points on that mesh, then create the SubMesh based on those certain points

I see… If you just need to integrate on a portion of your mesh then you might not need SubMesh per se. That could be done simply via a MeshFunction, say marking the first 50 cells of your mesh and integrating over those

from dolfin import *
import numpy as np
mesh = UnitSquareMesh(10, 10)
meshMarks = cpp.mesh.MeshFunctionSizet(mesh, mesh.topology().dim())
meshMarks.array()[np.arange(50)] = 2 
dx = Measure("dx", domain=mesh, subdomain_data=meshMarks)
u = Function(FunctionSpace(mesh, "DG", 0))
u.vector()[:] = 1
assemble(u * dx(2))  # should give 0.25

Now as long as you can identify the cells via some rule then tweaking the above method should work. Just go to the corresponding index (in the same order as the cells) in meshMarks.array() and assign the value of your marker.

But if you have a list of points, then you might have to compute the cells which collide with those points (see this post) and then define the subdomain like in this case. There may be a more efficient approach, but I can’t think of one off the bat.

But if all this can be done in the pre-processing, then simply create a mesh with required markers and load the data into corresponding mesh functions at the beginning.

For marking cells in pre-processing I have done things very similar to : Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio

1 Like

Thanks for all your help, @bhaveshshrimali. I’ll try some of these options and see if I can get it to work.