Skip to content

Commit

Permalink
Add unit test for area of square mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Nov 2, 2024
1 parent 4c868a1 commit 773e0bb
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions tests/test_unstructured_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
UnstructuredRandomPolygonalMeshGenerator,
UnstructuredSquareMeshGenerator,
)
from firedrake.assemble import assemble
from firedrake.bcs import DirichletBC
from firedrake.constant import Constant
import numpy as np
import os
import pytest
import ufl


@pytest.fixture(params=[1, 2, 3, 4])
Expand Down Expand Up @@ -37,11 +40,11 @@ def generator(request):
return request.param


def generate_mesh(generator, mesh_algorithm, **kwargs):
def generate_mesh(generator, mesh_algorithm, scale=1.0, **kwargs):
"""
Utility mesh generator function for testing purposes.
"""
mesh_gen = generator(mesh_type=mesh_algorithm)
mesh_gen = generator(mesh_type=mesh_algorithm, scale=scale)
kwargs.setdefault("remove_file", True)
mesh = mesh_gen.generate_mesh(**kwargs)
mesh.init()
Expand Down Expand Up @@ -91,6 +94,11 @@ def test_num_points_boundaries_square(num_elem_bnd, mesh_algorithm):
assert len(dbc.nodes) == num_elem_bnd + 1


# def test_area_squaremesh(num_elem_bnd, mesh_algorithm, scale):
#
# raise NotImplementedError # TODO: Test area as expected with scaling
def test_area_squaremesh(num_elem_bnd, mesh_algorithm, scale):
"""
Check that the area of a square mesh is equal to the scale factor squared.
"""
mesh = generate_mesh(
UnstructuredSquareMeshGenerator, 1, res=1.0 / num_elem_bnd, scale=scale
)
assert np.isclose(assemble(Constant(1.0, domain=mesh) * ufl.dx), scale**2)

0 comments on commit 773e0bb

Please sign in to comment.