From fb71a640d9e50305b4837e67c2f29092d72f927b Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Sat, 2 Nov 2024 16:46:44 +0000 Subject: [PATCH] Add unit test for scale and res --- UM2N/generator/unstructured_mesh.py | 4 ++-- tests/test_unstructured_mesh.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/UM2N/generator/unstructured_mesh.py b/UM2N/generator/unstructured_mesh.py index 13e4b0d..43b4d56 100644 --- a/UM2N/generator/unstructured_mesh.py +++ b/UM2N/generator/unstructured_mesh.py @@ -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 @@ -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 diff --git a/tests/test_unstructured_mesh.py b/tests/test_unstructured_mesh.py index 1e753b5..6524ff1 100644 --- a/tests/test_unstructured_mesh.py +++ b/tests/test_unstructured_mesh.py @@ -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())