This does not work for me. My test case goes :
- Compute mesh from
gmsh
.geo
file
- Convert
.msh
file to .xdmf
using tutorial snippet
- Requires a pip install inside docker
- I suspect this is where noise is introduced, which shifts some points
- Create a dummy
dolfinx.Function
which is then interpolated to obtain coordinates
- Apply @nate’s
move
- Interpolate again
This gives a code looking like this :
import ufl
import numpy as np
import dolfinx as dfx
from dolfinx.io import XDMFFile
from mpi4py.MPI import COMM_WORLD
import meshio
# Tutorial extract
mesh = meshio.read("mesh.msh")
cells = mesh.get_cells_type("triangle")
cell_data = mesh.get_cell_data("gmsh:physical", "triangle")
mesh = meshio.Mesh(points=mesh.points, cells={"triangle": cells}, cell_data={"name_to_read":[cell_data]})
meshio.write("mesh.xdmf", mesh)
# Reread directly xdmf file
with XDMFFile(COMM_WORLD, "mesh.xdmf", "r") as file:
mesh = file.read_mesh(name="Grid")
# Create Finite Element and test for outliers
def test_outliers():
FE=ufl.FiniteElement("Lagrange",mesh.ufl_cell(),2)
FS=dfx.FunctionSpace(mesh,FE)
fx=dfx.Function(FS)
fx.interpolate(lambda x: x[0])
ux=fx.compute_point_values()
print(np.sum(ux<0))
test_outliers()
# Attempt to nudge outliers into place
x = mesh.geometry.x
x[:,0] -= np.minimum(x[:,0],0)
test_outliers()
On dolfinx-real-mode
, inside the dolfinx
docker container, I obtain 4972 twice.
.geo file :
Mesh.MshFileVersion = 2.0;
r1 = 1/20;
r4 = 2;
r3=(r1+r4)/2;
r2=(r1+r3)/2;
Point(1) = {0, 0, 0, r1};
Point(2) = {50, 0, 0, r1};
Point(3) = {50, 1, 0, r2};
Point(4) = {0, 1, 0, r1};
Point(5) = {0, 5, 0, r3};
Point(6) = {70, 5, 0, r3};
Point(7) = {70, 10, 0, r3};
Point(8) = {0, 10, 0, r3};
Point(9) = {70, 0, 0, r2};
Point(10) = {120, 0, 0, r3};
Point(11) = {120, 60, 0, r4};
Point(12) = {0, 60, 0, r4};
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};
Line(5) = {5, 6};
Line(6) = {6, 7};
Line(7) = {7, 8};
Line(8) = {8, 5};
Line(9) = {4, 5};
Line(10) = {6, 9};
Line(11) = {9, 10};
Line(12) = {10, 11};
Line(13) = {11, 12};
Line(14) = {12, 8};
Line(15) = {2, 9};
Line Loop(1) = {1, 2, 3, 4};
Line Loop(2) = {-15, 10, 5, 9, 3, 2};
Line Loop(3) = {5, 6, 7, 8};
Line Loop(4) = {11, 12, 13, 14, -7, -6, 10};
Plane Surface(1) = {1};
Plane Surface(2) = {2};
Plane Surface(3) = {3};
Plane Surface(4) = {4};
Physical Line(1) = {1,15,11};
Physical Line(2) = {12};
Physical Line(3) = {13};
Physical Line(4) = {14,8,9,4};
Physical Surface(1) = {1,2,3,4};