I am solving the classical EM problem; scattering from a conducting sphere, so far i 2D. Assuming the sphere to be a perfect conductor, the problem can be solved on a mesh with a (circular) hole representing the sphere (along with appropriate BCs). This mesh is readily generated in FEniCS.
If a particular material (e.g. silver) is to be considered, the inner region of the hole must be meshed too. The "easy way out" would be to use a simple, rectangular mesh . However, a such mesh does not respect the boundary between the two regions, so the circular shape obtained is very poor.
I can construct a mesh externally, that enforces the boundary, but i was wondering if it is possible to construct the mesh from within FEniCS?
I know how to construct the circular "inner" domain as well as the "outer" domain (as demonstrated), so it seems somehow that the functionality is there.
Sample code for generating figures:
from dolfin import *
from dolfin.cpp.mesh import *
from mshr import *
class LambdaDomain(SubDomain):
def __init__(self, condition):
self.condition = condition
SubDomain.__init__(self)
def inside(self, x, on_boundary):
return self.condition(x, on_boundary)
lx = ly = 10
cx = cy = lx / 2.0
radius = 2.5
res = 25
# Generate mesh with hole.
base = Rectangle(Point(0, 0), Point(lx, ly))
hole = Circle(Point(cx, cy), radius)
plot(generate_mesh(base - hole, res))
# Mark hole in full mesh using mesh function.
mesh = generate_mesh(base, res)
mesh_func = MeshFunction("size_t", mesh, 2)
mesh_func.set_all(0)
LambdaDomain(lambda x, on: ((x[0] - cx) ** 2 + (x[1] - cy) ** 2) ** 0.5 <= radi us).mark(mesh_func, 1)
plot(mesh_func)
interactive()