Commit 3fc22a69 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Increasing the Coverage

parent 954aa5b8
Pipeline #39006 failed with stages
in 83 minutes and 6 seconds
......@@ -19,7 +19,7 @@ def discrete_equilibrium_from_matching_moments(stencil, moment_constraints,
return GenericDiscreteEquilibrium(stencil, pdfs, zeroth_order_moment_symbol,
first_order_moment_symbols, deviation_only=deviation_only)
except sp.matrices.inverse.NonInvertibleMatrixError as e:
raise Exception("Could not construct equilibrium from given moment constraints.") from e
raise ValueError("Could not construct equilibrium from given moment constraints.") from e
class GenericDiscreteEquilibrium(AbstractEquilibrium):
......
......@@ -2,6 +2,8 @@ import pytest
import sympy as sp
from itertools import chain
from pystencils.sympyextensions import remove_higher_order_terms
from lbmpy.stencils import Stencil, LBStencil
from lbmpy.equilibrium import ContinuousHydrodynamicMaxwellian, DiscreteHydrodynamicMaxwellian
from lbmpy.moments import moments_up_to_component_order, moments_up_to_order
......@@ -73,3 +75,51 @@ def test_continuous_discrete_moment_equivalence(stencil, compressible, deviation
subs = { delta_rho : rho - rho_0 }
assert (cm - dm).subs(subs).expand() == sp.Matrix((0,) * len(moments))
@pytest.mark.parametrize('stencil', [Stencil.D2Q9, Stencil.D3Q15, Stencil.D3Q19, Stencil.D3Q27])
@pytest.mark.parametrize('compressible', [False, True])
@pytest.mark.parametrize('deviation_only', [False, True])
def test_continuous_discrete_central_moment_equivalence(stencil, compressible, deviation_only):
stencil = LBStencil(stencil)
c_s_sq = sp.Rational(1, 3)
moments = tuple(moments_up_to_order(3, dim=stencil.D, include_permutations=False))
cd = ContinuousHydrodynamicMaxwellian(dim=stencil.D, compressible=compressible, deviation_only=deviation_only,
order=2, c_s_sq=c_s_sq)
cm = sp.Matrix(cd.central_moments(moments))
dd = DiscreteHydrodynamicMaxwellian(stencil, compressible=compressible, deviation_only=deviation_only,
order=2, c_s_sq=c_s_sq)
dm = sp.Matrix(dd.central_moments(moments))
dm = sp.Matrix([remove_higher_order_terms(t, dd.velocity, order=2) for t in dm])
rho = cd.density
delta_rho = cd.density_deviation
rho_0 = cd.background_density
subs = { delta_rho : rho - rho_0 }
assert (cm - dm).subs(subs).expand() == sp.Matrix((0,) * len(moments))
@pytest.mark.parametrize('stencil', [Stencil.D2Q9, Stencil.D3Q15, Stencil.D3Q19, Stencil.D3Q27])
def test_continuous_discrete_cumulant_equivalence(stencil):
stencil = LBStencil(stencil)
c_s_sq = sp.Rational(1, 3)
compressible = True
deviation_only = False
moments = tuple(moments_up_to_order(3, dim=stencil.D, include_permutations=False))
cd = ContinuousHydrodynamicMaxwellian(dim=stencil.D, compressible=compressible, deviation_only=deviation_only,
order=2, c_s_sq=c_s_sq)
cm = sp.Matrix(cd.cumulants(moments))
dd = DiscreteHydrodynamicMaxwellian(stencil, compressible=compressible, deviation_only=deviation_only,
order=2, c_s_sq=c_s_sq)
dm = sp.Matrix(dd.cumulants(moments))
dm = sp.Matrix([remove_higher_order_terms(t, dd.velocity, order=2) for t in dm])
rho = cd.density
delta_rho = cd.density_deviation
rho_0 = cd.background_density
subs = { delta_rho : rho - rho_0 }
assert (cm - dm).subs(subs).expand() == sp.Matrix((0,) * len(moments))
......@@ -30,6 +30,7 @@ exclude_lines =
pragma: no cover
def __repr__
def _repr_html_
# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment