Skip to content

Commit

Permalink
Add unit test for scale and res
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Nov 2, 2024
1 parent 773e0bb commit fb71a64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions UM2N/generator/unstructured_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class UnstructuredMeshGenerator(abc.ABC):

def __init__(self, scale=1.0, mesh_type=2):
"""
:kwarg scale: overall scale factor
:kwarg scale: overall scale factor for the domain size
:type scale: float
:kwarg mesh_type: Gmsh algorithm number
:type mesh_type: int
Expand Down Expand Up @@ -120,7 +120,7 @@ class UnstructuredRandomPolygonalMeshGenerator(UnstructuredMeshGenerator):

def __init__(self, scale=1.0, mesh_type=2):
"""
:kwarg scale: overall scale factor
:kwarg scale: overall scale factor for the domain size
:type scale: float
:kwarg mesh_type: Gmsh algorithm number
:type mesh_type: int
Expand Down
12 changes: 12 additions & 0 deletions tests/test_unstructured_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,15 @@ def test_area_squaremesh(num_elem_bnd, mesh_algorithm, scale):
UnstructuredSquareMeshGenerator, 1, res=1.0 / num_elem_bnd, scale=scale
)
assert np.isclose(assemble(Constant(1.0, domain=mesh) * ufl.dx), scale**2)


def test_num_cells_with_res_and_scale(generator, num_elem_bnd, mesh_algorithm):
"""
Check that doubling or halving the overall resolution doesn't affect the number of
cells for the square mesh, so long as the resolution is changed accordingly.
"""
generator = UnstructuredSquareMeshGenerator
mesh1 = generate_mesh(generator, mesh_algorithm, res=1.0 / num_elem_bnd)
mesh2 = generate_mesh(generator, mesh_algorithm, res=2.0 / num_elem_bnd, scale=2.0)
meshp5 = generate_mesh(generator, mesh_algorithm, res=0.5 / num_elem_bnd, scale=0.5)
assert np.allclose((mesh2.num_cells(), meshp5.num_cells()), mesh1.num_cells())

0 comments on commit fb71a64

Please sign in to comment.