Commit 1ce2c1d7 authored by Markus Holzer's avatar Markus Holzer
Browse files

Revert central moment transform changes

parent 7bc65dd3
Pipeline #33589 failed with stages
in 10 minutes and 16 seconds
......@@ -10,13 +10,12 @@ from lbmpy.moment_transforms import (FastCentralMomentTransform,
PRE_COLLISION_CENTRAL_MOMENT, POST_COLLISION_CENTRAL_MOMENT)
from lbmpy.moments import (polynomial_to_exponent_representation, MOMENT_SYMBOLS, moment_matrix, set_up_shift_matrix,
statistical_quantity_symbol)
statistical_quantity_symbol, extract_monomials, exponent_tuple_sort_key)
def relax_central_moments(moment_indices, pre_collision_values,
relaxation_rates, equilibrium_values,
post_collision_base=POST_COLLISION_CENTRAL_MOMENT):
post_collision_symbols = [sp.Symbol(f'{post_collision_base}_{"".join(str(i) for i in m)}') for m in moment_indices]
equilibrium_vec = sp.Matrix(equilibrium_values)
moment_vec = sp.Matrix(pre_collision_values)
......@@ -26,6 +25,7 @@ def relax_central_moments(moment_indices, pre_collision_values,
return AssignmentCollection(main_assignments)
# =============================== LB Method Implementation ===========================================================
......@@ -255,11 +255,12 @@ class CentralMomentBasedLbMethod(AbstractLbMethod):
if cqe is None:
cqe = self._conserved_quantity_computation.equilibrium_input_equations_from_pdfs(f)
moment_polynomials = list(self.moments)
moments_as_exponents = list(extract_monomials(list(self.moments), dim=2))
moments_as_exponents = sorted(moments_as_exponents, key=exponent_tuple_sort_key)
# 1) Get Forward Transformation from PDFs to central moments
pdfs_to_k_transform = self.central_moment_transform_class(
stencil, moment_polynomials, density, velocity, conserved_quantity_equations=cqe)
stencil, moments_as_exponents, density, velocity, conserved_quantity_equations=cqe)
pdfs_to_k_eqs = pdfs_to_k_transform.forward_transform(f, simplification=pre_simplification)
moments_as_exponents = pdfs_to_k_transform.moment_exponents
......
......@@ -6,8 +6,7 @@ from pystencils.simp import (
from pystencils.simp.assignment_collection import SymbolGen
from pystencils.sympyextensions import subs_additive, fast_subs
from lbmpy.moments import moment_matrix, set_up_shift_matrix, contained_moments, moments_up_to_order,\
monomial_to_polynomial_transformation_matrix
from lbmpy.moments import moment_matrix, set_up_shift_matrix, contained_moments, moments_up_to_order
from lbmpy.moments import statistical_quantity_symbol as sq_sym
from .abstractmomenttransform import (
......@@ -20,22 +19,22 @@ from .momenttransforms import PdfsToMomentsByChimeraTransform
class PdfsToCentralMomentsByMatrix(AbstractMomentTransform):
def __init__(self, stencil, moment_polynomials,
def __init__(self, stencil, moment_exponents,
equilibrium_density,
equilibrium_velocity,
pre_collision_central_moment_base=PRE_COLLISION_CENTRAL_MOMENT,
post_collision_central_moment_base=POST_COLLISION_CENTRAL_MOMENT,
**kwargs):
assert len(moment_polynomials) == len(stencil), 'Number of moments must match stencil'
assert len(moment_exponents) == len(stencil), 'Number of moments must match stencil'
super(PdfsToCentralMomentsByMatrix, self).__init__(
stencil, equilibrium_density, equilibrium_velocity,
moment_polynomials=moment_polynomials, **kwargs)
moment_exponents=moment_exponents, **kwargs)
moment_matrix_without_shift = moment_matrix(self.moment_polynomials, self.stencil)
shift_matrix = set_up_shift_matrix(self.moment_polynomials, self.stencil, equilibrium_velocity)
moment_matrix_without_shift = moment_matrix(self.moment_exponents, self.stencil)
shift_matrix = set_up_shift_matrix(self.moment_exponents, self.stencil, equilibrium_velocity)
self.forward_matrix = moment_matrix(self.moment_polynomials, self.stencil, equilibrium_velocity)
self.forward_matrix = moment_matrix(self.moment_exponents, self.stencil, equilibrium_velocity)
self.backward_matrix = moment_matrix_without_shift.inv() * shift_matrix.inv()
self.kappa_pre = pre_collision_central_moment_base
......@@ -88,28 +87,25 @@ class PdfsToCentralMomentsByMatrix(AbstractMomentTransform):
class FastCentralMomentTransform(AbstractMomentTransform):
def __init__(self, stencil,
moment_polynomials,
moment_exponents,
equilibrium_density,
equilibrium_velocity,
conserved_quantity_equations=None,
pre_collision_central_moment_base=PRE_COLLISION_CENTRAL_MOMENT,
post_collision_central_moment_base=POST_COLLISION_CENTRAL_MOMENT,
**kwargs):
assert len(moment_polynomials) == len(stencil), 'Number of moments must match stencil'
assert len(moment_exponents) == len(stencil), 'Number of moments must match stencil'
super(FastCentralMomentTransform, self).__init__(
stencil, equilibrium_density, equilibrium_velocity,
conserved_quantity_equations=conserved_quantity_equations,
moment_polynomials=moment_polynomials, **kwargs)
moment_exponents=moment_exponents, **kwargs)
self.kappa_pre = pre_collision_central_moment_base
self.kappa_post = post_collision_central_moment_base
self.mono_to_poly_matrix = monomial_to_polynomial_transformation_matrix(self.moment_exponents,
self.moment_polynomials)
self.mat_transform = PdfsToCentralMomentsByMatrix(
stencil, moment_polynomials, equilibrium_density, equilibrium_velocity,
stencil, moment_exponents, equilibrium_density, equilibrium_velocity,
conserved_quantity_equations=conserved_quantity_equations,
pre_collision_central_moment_base=pre_collision_central_moment_base,
post_collision_central_moment_base=post_collision_central_moment_base,
......@@ -163,7 +159,7 @@ class FastCentralMomentTransform(AbstractMomentTransform):
subexpressions = [Assignment(lhs, rhs) for lhs, rhs in subexpressions_dict.items()]
symbol_gen = SymbolGen(subexpression_base)
ac = AssignmentCollection(moment_eqs, subexpressions=subexpressions,
ac = AssignmentCollection(main_assignments, subexpressions=subexpressions,
subexpression_symbol_generator=symbol_gen)
if simplification:
ac = self._simplify_lower_order_moments(ac, moment_symbol_base)
......@@ -299,29 +295,30 @@ class FastCentralMomentTransform(AbstractMomentTransform):
class PdfsToCentralMomentsByShiftMatrix(AbstractMomentTransform):
def __init__(self, stencil, moment_polynomials,
def __init__(self, stencil, moment_exponents,
equilibrium_density,
equilibrium_velocity,
conserved_quantity_equations=None,
pre_collision_central_moment_base=PRE_COLLISION_CENTRAL_MOMENT,
post_collision_central_moment_base=POST_COLLISION_CENTRAL_MOMENT,
**kwargs):
assert len(moment_polynomials) == len(stencil), 'Number of moments must match stencil'
assert len(moment_exponents) == len(stencil), 'Number of moments must match stencil'
super(PdfsToCentralMomentsByShiftMatrix, self).__init__(
stencil, equilibrium_density, equilibrium_velocity,
conserved_quantity_equations=conserved_quantity_equations,
moment_polynomials=moment_polynomials, **kwargs)
moment_exponents=moment_exponents, **kwargs)
self.raw_moment_transform = PdfsToMomentsByChimeraTransform(
stencil, moment_polynomials, equilibrium_density, equilibrium_velocity,
stencil, None, equilibrium_density, equilibrium_velocity,
conserved_quantity_equations=conserved_quantity_equations,
moment_exponents=moment_exponents,
**kwargs)
self.kappa_pre = pre_collision_central_moment_base
self.kappa_post = post_collision_central_moment_base
self.shift_matrix = set_up_shift_matrix(self.moment_polynomials, self.stencil, self.equilibrium_velocity)
self.shift_matrix = set_up_shift_matrix(self.moment_exponents, self.stencil, self.equilibrium_velocity)
self.inv_shift_matrix = self.shift_matrix.inv()
@property
......@@ -343,7 +340,7 @@ class PdfsToCentralMomentsByShiftMatrix(AbstractMomentTransform):
cq_subs = dict()
if simplification:
from lbmpy.methods.momentbased.momentbasedsimplifications import (
from lbmpy.methods.momentbased.momentbasedsimplifications import (
substitute_moments_in_conserved_quantity_equations)
rm_ac = substitute_moments_in_conserved_quantity_equations(rm_ac)
......
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