Refine a triangulation of a circle domain

10 weeks ago by

I want to solve a PDE on a circle with initial triangulation
import matplotlib.pyplot as plt
from fenics import *
from mshr import *

dom = Circle(Point(0.,0.),1.0,20)
mesh = generate_mesh(dom,5,'cgal')

Thereafter, I want to refine the mesh = refine(mesh) and project the boundary nodes on the boundary of the circle (to have a "smoother" circle). Can I do this with a built-in function? If not, how can I access the boundary nodes and shift them?

Best regards,
Community: FEniCS Project

1 Answer

10 weeks ago by
I believe that this is what the snap_boundary method is for.  Here's an example.
from fenics import *
from mshr import *
import matplotlib.pyplot as plt

class SnapBdry(SubDomain):
    def snap(self, x):
        r = sqrt(x[0]**2 + x[1]**2)
        x[0] = x[0]/r
        x[1] = x[1]/r
snapbdry = SnapBdry()

domain = Circle(Point(0., 0.), 1.0, segments=20)
mesh = generate_mesh(domain, 5)
mesh = refine(mesh)

Thank you very much for introducing me to fenics.Mesh.snap_boundary.

In case anyone else comes here searching for the same things as me:
- I didn't find any useful documentation except for the source code at .
- I made a Jupyter notebook applying this to a domain which is a general circle cut out of a larger shape:

written 10 weeks ago by Alexander G. Zimmerman  
This works perfect. Thanks a lot!
written 10 weeks ago by Johannes  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »