Source code for test_heat_convergence

"""
Module to gather tests for convergence of decoupled stress system.

This file is executed by ``pytest`` to have good CI.
"""

import subprocess
import pytest


[docs]class TestHeatConvergence(object): """ Class to bundle all stress convergence tests. All tests are compared against reference errors. """ working_dir = "tests/2d_heat" solver_path = "fenicsR13"
[docs] def run_solver(self, inputfile): """ Run the solver as subprocess with the given input file. Test fails if subprocess return Exception or error. """ subprocess.check_call([ self.solver_path, inputfile ], cwd=self.working_dir)
[docs] def compare_errors(self, errorsfile, ref_errorsfile): """ Check against reference errors. Compares absolute differences. Absolute Error allowed: ``1E-10`` Return exception if diff returns with !=0 A comparison for complete equalness can be obtained with: .. code-block:: python subprocess.check_call([ "diff", "-u", "--strip-trailing-cr", errorsfile, ref_errorsfile ], cwd=self.working_dir) """ print(subprocess.check_output([ "numdiff", "-s", "\"\n\r ,\"", "-a", "1E-10", errorsfile, ref_errorsfile ], cwd=self.working_dir))
# @pytest.fixture(scope="module", autouse=True)
[docs] @pytest.mark.skip(reason="Not needed because meshes are in repo") def create_meshes(self): """ Create the test meshes. Executed before any test of the class. Often not needed if meshes are in Git through LFS for reproducability. """ subprocess.check_call(["python3", "create_meshes.py"], cwd="tests/mesh")
[docs] def test_heat_01_coeffs_p1p1_gls(self): r""" Execute decoupled heat system test and check with reference errors. ============= ======================= Parameter Value ============= ======================= :math:`Kn` :math:`0.1` Elements :math:`P_1P_1` Stabilization GLS ============= ======================= """ name = "heat_01_coeffs_p1p1_gls" self.run_solver("inputs/" + name + ".yml") errors = name + "/" + "errors.csv" referrors = "referrors/" + name + "/errors.csv" self.compare_errors(errors, referrors)
[docs] def test_heat_01_coeffs_p1p1_stab(self): r""" Execute decoupled heat system test and check with reference errors. ============= ======================= Parameter Value ============= ======================= :math:`Kn` :math:`0.1` Elements :math:`P_1P_1` Stabilization CIP, :math:`\delta_\theta=1` ============= ======================= """ name = "heat_01_coeffs_p1p1_stab" self.run_solver("inputs/" + name + ".yml") errors = name + "/" + "errors.csv" referrors = "referrors/" + name + "/errors.csv" self.compare_errors(errors, referrors)
[docs] def test_heat_10_coeffs_p2p2_stab(self): r""" Execute decoupled heat system test and check with reference errors. ============= ======================= Parameter Value ============= ======================= :math:`Kn` :math:`10.0` Elements :math:`P_2P_2` Stabilization CIP, :math:`\delta_\theta=1` ============= ======================= """ name = "heat_10_coeffs_p2p2_stab" self.run_solver("inputs/" + name + ".yml") errors = name + "/" + "errors.csv" referrors = "referrors/" + name + "/errors.csv" self.compare_errors(errors, referrors)
[docs] def test_heat_01_coeffs_p2p2_stab(self): r""" Execute decoupled heat system test and check with reference errors. ============= ======================= Parameter Value ============= ======================= :math:`Kn` :math:`0.1` Elements :math:`P_2P_2` Stabilization CIP, :math:`\delta_\theta=1` ============= ======================= """ name = "heat_01_coeffs_p2p2_stab" self.run_solver("inputs/" + name + ".yml") errors = name + "/" + "errors.csv" referrors = "referrors/" + name + "/errors.csv" self.compare_errors(errors, referrors)
[docs] def test_heat_01_coeffs_p1p2_nostab(self): r""" Execute decoupled heat system test and check with reference errors. ============= ======================= Parameter Value ============= ======================= :math:`Kn` :math:`0.1` Elements :math:`P_2P_1` Stabilization CIP, :math:`\delta_\theta=1` ============= ======================= """ name = "heat_01_coeffs_p1p2_nostab" self.run_solver("inputs/" + name + ".yml") errors = name + "/" + "errors.csv" referrors = "referrors/" + name + "/errors.csv" self.compare_errors(errors, referrors)