Skip to content

Commit

Permalink
[test] shapemeshing test use np.isclose
Browse files Browse the repository at this point in the history
  • Loading branch information
FZill committed Sep 6, 2024
1 parent 5fccf2c commit 6b0d1ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
7 changes: 2 additions & 5 deletions docs/examples/howto_prjfile/plot_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@

# %%
# Initialize the ogs6py object:
import tempfile
from pathlib import Path

import ogstools as ogs
from ogstools.definitions import EXAMPLES_DIR

prj = ogs.Project(
output_file=Path(tempfile.mkdtemp) / "prj/simple_mechanics.prj"
)
prj = ogs.Project(output_file=EXAMPLES_DIR / "prj" / "mechanics_new.prj")

# %%
# Define geometry and/or meshes:
Expand Down
36 changes: 18 additions & 18 deletions tests/test_shapefile_meshing.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import subprocess
from tempfile import mkdtemp

import ogstools.meshlib as ml
import numpy as np

from ogstools.examples import circle_shapefile, test_shapefile
from ogstools.meshlib import Mesh, read_shape


def test_cli():
Expand All @@ -15,29 +17,27 @@ def test_cli():

class TestShapeFileMeshing:
def test_default(self):
pyvista_mesh = ml.read_shape(
test_shapefile
) # simplify_false, mesh_generator_triangle
assert pyvista_mesh.n_points > 233000
assert pyvista_mesh.n_points < 234000
assert pyvista_mesh.n_cells > 344000
assert pyvista_mesh.n_points < 345000
# simplify_false, mesh_generator_triangle
pyvista_mesh = read_shape(test_shapefile)

assert np.isclose(pyvista_mesh.n_points, 233465, rtol=0.05)
assert np.isclose(pyvista_mesh.n_cells, 344431, rtol=0.05)

# Same for simplified mesh.
def test_simplify(self):
mesh_simplify = ml.read_shape(test_shapefile, simplify=True)
mesh_orignal = ml.read_shape(test_shapefile, simplify=False)
mesh_simplify = read_shape(test_shapefile, simplify=True)
mesh_orignal = read_shape(test_shapefile, simplify=False)

assert mesh_simplify.n_points > 0
assert mesh_simplify.n_cells > 0

assert mesh_simplify.n_points < mesh_orignal.n_points
assert mesh_simplify.n_cells < mesh_orignal.n_cells

mesh_simplify_finer = ml.read_shape(
mesh_simplify_finer = read_shape(
test_shapefile, simplify=True, cellsize=2000
)
mesh_simplify_coarser = ml.read_shape(
mesh_simplify_coarser = read_shape(
test_shapefile, simplify=True, cellsize=10000
)

Expand All @@ -47,21 +47,21 @@ def test_simplify(self):
assert mesh_simplify_coarser.n_points < mesh_simplify.n_points
assert mesh_simplify.n_points < mesh_simplify_finer.n_points

def test_simpify_gmsh(self):
mesh_simplify = ml.read_shape(
def test_simplify_gmsh(self):
mesh_simplify = read_shape(
circle_shapefile, simplify=True, mesh_generator="gmsh"
)
mesh_original = ml.read_shape(
mesh_original = read_shape(
circle_shapefile, simplify=False, mesh_generator="gmsh"
)

assert mesh_simplify.n_points < mesh_original.n_points
assert mesh_simplify.n_cells < mesh_original.n_cells

def test_meshclass_reading(self):
ogs_mesh = ml.Mesh.read(circle_shapefile)
ogs_mesh_special = ml.Mesh.read_shape(circle_shapefile)
pyvista_mesh = ml.read_shape(circle_shapefile)
ogs_mesh = Mesh.read(circle_shapefile)
ogs_mesh_special = Mesh.read_shape(circle_shapefile)
pyvista_mesh = read_shape(circle_shapefile)
assert pyvista_mesh.n_points == ogs_mesh.n_points
assert pyvista_mesh.n_cells == ogs_mesh.n_cells
assert pyvista_mesh.n_points == ogs_mesh_special.n_points
Expand Down

0 comments on commit 6b0d1ca

Please sign in to comment.