-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
210f373
commit 765d912
Showing
3 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import pathlib | ||
import tempfile | ||
|
||
import dolfinx | ||
import gmsh | ||
from mpi4py import MPI | ||
|
||
from nos.data.helmholtz.solver import get_mesh | ||
|
||
|
||
def test_get_mesh(): | ||
# create mesh | ||
gmsh.initialize() | ||
gmsh.model.add("test_get_mesh") | ||
|
||
rect = gmsh.model.occ.add_rectangle(0.0, 0.0, 0.0, 1.0, 1.0) | ||
circ = gmsh.model.occ.add_disk(0.0, 0.0, 0.0, 0.5, 0.5) | ||
|
||
objs, _ = gmsh.model.occ.fragment([(2, rect)], [(2, circ)]) | ||
|
||
gmsh.model.occ.synchronize() | ||
|
||
surfs = gmsh.model.occ.get_entities(2) | ||
surfs = [surf[1] for surf in surfs] | ||
lines = gmsh.model.occ.get_entities(1) | ||
lines = [line[1] for line in lines] | ||
|
||
for i, surf in enumerate(surfs): | ||
gmsh.model.add_physical_group(2, [surf], i) | ||
for i, line in enumerate(lines): | ||
gmsh.model.add_physical_group(1, [line], i) | ||
|
||
gmsh.model.occ.synchronize() | ||
gmsh.model.mesh.generate(2) | ||
|
||
with tempfile.TemporaryDirectory() as tmp: | ||
# write file | ||
file_path = pathlib.Path(tmp).joinpath("test_mesh.msh") | ||
gmsh.write(file_path) | ||
gmsh.finalize() | ||
|
||
# load | ||
mesh, cell_tags, boundary_tags = get_mesh(file_path, MPI.COMM_WORLD) | ||
|
||
# test types | ||
assert isinstance(mesh, dolfinx.mesh.Mesh) | ||
assert isinstance(cell_tags, dolfinx.mesh.MeshTags) | ||
assert isinstance(boundary_tags, dolfinx.mesh.MeshTags) | ||
|
||
# test size | ||
assert len(lines) == len(set(boundary_tags.values)) | ||
assert len(surfs) == len(set(cell_tags.values)) |