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

Redefine mesh for a sign distance function such a level surface

0 votes

I got a 3d tetraedrized space $\Omega$ and a Affine surface over the elements $\psi(x,y,z)=0$

I want to redefine the cuted elements maintaining the hierarchy between old elements and new elements (this is only a 2D example)

Drawing

The idea is add new points $\psi \cap edges(\Omega)$ and in the next step add new edges for build a new elements but without to destroy the "father" elements.

then:

from dolfin import *

def psi(x, y, z):
    #some level function
    return x**2+y**2+z**2-1

omega = BoxMesh(-1, -1, -1, 1, 1, 1, 10, 10, 10)
cell_markers = CellFunction("bool", omega)
cell_markers.set_all(False)
coordinates = omega.coordinates()
for cell in cells(omega):
    # the psi function cut some edge?
    for edge in edges(cell):
        v0 = psi(*coordinates[edge.entities(0)[0]])
        v1 = psi(*coordinates[edge.entities(0)[1]])
        if(v0*v1<0):
            #if level function change the sign between the nodes then has a zero un that element
            cell_markers[cell]=True

new_omega = refine(omega, cell_markers)

omega_file = File("omega.pvd")
omega_file << omega

new_omega_file = File("new_omega.pvd")
new_omega_file << new_omega

but I have not seen the difference between $\Omega$ and $\Omega_{\text{new}}$

asked Nov 6, 2013 by ljofre FEniCS Novice (720 points)
edited Dec 12, 2013 by ljofre

2 Answers

0 votes

You can't use non-simplicial mesh with FEniCS.

answered Nov 9, 2013 by Jan Blechta FEniCS Expert (51,420 points)

but I want to refine a mesh after getting a level surface to calculate some integrals on these surfaces. An example is to get the area on a level surface over the mesh.

Ok, I believe that you need to program this by yourself. You may utilize MeshEditor.

I edited the question a little

There is refine function based on CellFunction marking cells for refinement. Then you can use adapt to transfer you data to new mesh.

I understand your recommendations but still can not get to redefine the mesh, I edited the question a bit for a better understanding

I edited the question a bit again, thanks

+1 vote

I guess you use a level set function to implicitly describe a surface. Typically, this is a sign distance function. So my suggestion is that you should first loop over each cell and mark the cells that you want to refine according to their distances to the interface, then use FEniCS/dolfin refine function. If you want further refine the cells closer to the surface, keep doing the same loop.

XZ

answered Nov 10, 2013 by xzhao99 FEniCS Novice (270 points)

my problem is how to evaluate the nodes of the edges over the psi function now

I did that but i got the same mesh, I edited el question a bit.

...