As a follow up of my recent question, I want to remesh a subdomain and to compute integrals on this new mesh on a subdomain.
If I have a function v
on the actual domain, then interpolate(v, V_sub)
gives the interpolation of v
in the function space V_sub
that relates to the mesh of the subdomain.
Since I want to assemble forms, in particular, I need to interpolate some basis functions of V
in V_sub
.
So the question is, how can I extract the DOFs of the basis functions, that are located within the subdomain?
I have a running example for this based on this answer.
However, this does not work for higher order elements, where the DOFs are also located at the facets. (because of vertex_to_dof_map
does not work for these elements)
from dolfin import *
import numpy as np
def extract_dofs_subdomain(V, subd):
""" extract dofs of subdomain"""
dofs_of_V = V.dofmap().vertex_to_dof_map(V.mesh())
coord_of_dofs = V.mesh().coordinates()
ncords = coord_of_dofs.shape[0]
subd_bools = np.zeros(V.dim())
for inds in dofs_of_V:
subd_bools[inds] = subd.inside(coord_of_dofs[np.mod(inds, ncords)],
False)
return np.arange(V.dim())[subd_bools.astype(bool)]
class ContDomain(dolfin.SubDomain):
"""define a subdomain"""
def __init__(self, ddict):
dolfin.SubDomain.__init__(self)
self.minxy = [ddict['xmin'], ddict['ymin']]
self.maxxy = [ddict['xmax'], ddict['ymax']]
def inside(self, x, on_boundary):
return (dolfin.between(x[0], (self.minxy[0], self.maxxy[0]))
and
dolfin.between(x[1], (self.minxy[1], self.maxxy[1])))
odcoo = dict(xmin=0.45,
xmax=0.55,
ymin=0.6,
ymax=0.8)
mesh = UnitSquareMesh(2, 5)
V = VectorFunctionSpace(mesh, "CG", 1)
odom = ContDomain(odcoo)
ininds = extract_dofs_subdomain(V, odom)
print ininds
How to proceed then? Or is there a better approach to this problem?