One new vertex per cell
Hi,
I am currently trying to do something with interface identification. I had been hinted towards MMesh which has been helpful.
While I found out how to do what I wanted to do, I also encountered a bug whereby adding two new vertices within a single element via refineEdge
only adds the first.
This can be seen from the relatively minimal code:
from dune.mmesh import mmesh
from dune.fem.view import adaptiveLeafGridView as adaptive
from dune.fem import parameter, adapt
import numpy as np
from ufl import SpatialCoordinate, conditional
parameter.append( { "fem.adaptation.method": "callback" } )
dim = 2
vertices = np.array( [(-1,-1), (1,-1), (1,1), (-1,1),(0,0)] )
triangles = np.array( [(0,1,4), (1,2,4), (2,4,3), (3,4,0)] )
gridView = mmesh({"vertices": vertices, "simplices": triangles}, dim)
gridView = adaptive( gridView )
hgrid = gridView.hierarchicalGrid
from dune.fem.space import lagrange
spaceScalar = lagrange(gridView, order = 1); x = SpatialCoordinate(spaceScalar)
phi = spaceScalar.interpolate(1- x[0]**2 - x[1]**2 ,name = "phi")
for e in gridView.elements:
for k, edge in enumerate(e.subEntities(1)):
hgrid.refineEdge(e, k)
adapt([phi])
We see that not every edge has been bisected here.
For my project, I do not wish to refine every edge, I have some criteria based on phi. My solution is to loop over the edges and adapt twice - perhaps something like that might be of use.
Best,
Philip