From b5f5f1f625b2b1b16298bba0e633a07d82327f03 Mon Sep 17 00:00:00 2001 From: Thomas Gibson <gibsonthomas1120@hotmail.com> Date: Thu, 3 Jun 2021 21:05:20 -0500 Subject: [PATCH] Test geometric factors --- test/test_dt_utils.py | 87 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 test/test_dt_utils.py diff --git a/test/test_dt_utils.py b/test/test_dt_utils.py new file mode 100644 index 00000000..124ba598 --- /dev/null +++ b/test/test_dt_utils.py @@ -0,0 +1,87 @@ +__copyright__ = """ +Copyright (C) 2021 University of Illinois Board of Trustees +""" + +__license__ = """ +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +""" + +import numpy as np + +from arraycontext import ( # noqa + pytest_generate_tests_for_pyopencl_array_context + as pytest_generate_tests +) + +from grudge import DiscretizationCollection + +import grudge.op as op + +import pytest + +import logging + + +logger = logging.getLogger(__name__) + + +@pytest.mark.parametrize("name", ["interval", "box2d", "box3d"]) +def test_geometric_factors_regular_refinement(actx_factory, name): + from grudge.dt_utils import dt_geometric_factors + + actx = actx_factory() + + # {{{ cases + + if name == "interval": + from mesh_data import BoxMeshBuilder + builder = BoxMeshBuilder(ambient_dim=1) + elif name == "box2d": + from mesh_data import BoxMeshBuilder + builder = BoxMeshBuilder(ambient_dim=2) + elif name == "box3d": + from mesh_data import BoxMeshBuilder + builder = BoxMeshBuilder(ambient_dim=3) + else: + raise ValueError("unknown geometry name: %s" % name) + + # }}} + + min_factors = [] + for resolution in builder.resolutions: + mesh = builder.get_mesh(resolution, builder.mesh_order) + dcoll = DiscretizationCollection(actx, mesh, order=builder.order) + min_factors.append(op.nodal_min(dcoll, "vol", dt_geometric_factors(dcoll))) + + # Resolution is doubled each refinement, so the ratio of consecutive + # geometric factors should satisfy: gfi+1 / gfi = 2 + min_factors = np.asarray(min_factors) + ratios = min_factors[:-1] / min_factors[1:] + assert np.all(np.isclose(ratios, 2)) + + +# You can test individual routines by typing +# $ python test_grudge.py 'test_routine()' + +if __name__ == "__main__": + import sys + if len(sys.argv) > 1: + exec(sys.argv[1]) + else: + pytest.main([__file__]) -- GitLab