This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to add edges to a subdomain class after the solution is computed?

0 votes

Suppose I have the unit square (a 2D problem) as my domain and I have a SubDomain class defined on the boundary of the unit square. After I have computed my first solution, I want to add edges to the existing SubDomain by marking it and compute the new solution. How am supposed to achieve that?

Suppose the mesh is defined as:

mesh = UnitSquareMesh(10,10)

My subdomain is defined and marked as follows:

class u0_boundary(SubDomain):
      def inside(self, x, on_boundary):
            return on_boundary and (x[0] < 1e-10)
u0_boundary = u0_boundary()
boundaries = FacetFunction('size_t', mesh)
u0_boundary.mark(boundaries,1)

Suppose I have the index of a point(vertex) in the dofmap after my first computation:

dof_x = CG.dofmap().tabulate_all_coordinates(mesh).reshape((-1,d))

where CG is the name of my FunctionSpace and d is 2.

How do I mark the edge connected to this vertex as u0_boundary (the marker is 1 in this case) ?

Thank you very much!

asked Apr 6, 2016 by Riemannstein FEniCS Novice (210 points)

1 Answer

0 votes

Assuming that you have the index of the vertex, the following marks all connected edges.

vertex = Vertex(mesh, vertex_index)

mesh.init(0,1) # compute connectivity between vertices and edges

for edge in vertex.entities(1):
    boundaries.set_value(edge, 1)
answered Apr 9, 2016 by Magne Nordaas FEniCS Expert (13,820 points)
...