Refine sphere in boxmesh

7 months ago by
We have a usual Box mesh generated with mshr. Is it possible to define a fitting triangularization for a Sphere lying inside the Box? I tried it combining the tutorial of mshr and the usual CellFunction approach to get a submesh:

import dolfin
from mshr import *

class subdomain_sphere(dolfin.SubDomain):
    def inside(self, x, on_boundary):
        Returns a ball around 0 with radius 0.2.
        return x[0]**2 + x[1]**2 + x[2]**2 <= 0.04

# Define 3D geometry
domain = Box(dolfin.Point(-1, -1, -1), dolfin.Point(1, 1, 1))

# Creating a mesh generator object gives access to parameters of the
# meshing backend
generator = CSGCGALMeshGenerator3D()
generator.parameters["edge_size"] = 0.025
generator.parameters["facet_angle"] = 25.0
generator.parameters["facet_size"] = 0.05

# Invoke the mesh generator
mesh = generator.generate(CSGCGALDomain3D(domain))

Subdomain = subdomain_sphere()
domains = dolfin.CellFunction("size_t", mesh)

Subdomain.mark(domains, 1)

submesh = dolfin.SubMesh(mesh, domains, 1)
dolfin.plot(submesh, interactive = True)​

I know that there is no support for 3d meshes in mshr yet, but maybe theres a workaround for this fairly easy case? Thanks.
Community: FEniCS Project
Please login to add an answer/comment or follow this question.

Similar posts:
Search »