Commit 19debc8c authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Cleanup

parent afacbe58
Pipeline #33655 failed with stages
in 11 minutes and 42 seconds
......@@ -11,8 +11,7 @@ from lbmpy.stencils import get_stencil
from lbmpy.methods.abstractlbmethod import AbstractLbMethod, LbmCollisionRule, RelaxationInfo
from lbmpy.methods.conservedquantitycomputation import AbstractConservedQuantityComputation
from lbmpy.moments import (exponents_to_polynomial_representations,
moments_up_to_order, get_order,
from lbmpy.moments import (moments_up_to_order, get_order,
monomial_to_polynomial_transformation_matrix,
moment_sort_key, exponent_tuple_sort_key,
exponent_to_polynomial_representation, extract_monomials, MOMENT_SYMBOLS,
......@@ -377,7 +376,8 @@ class CenteredCumulantBasedLbMethod(AbstractLbMethod):
# 3) Get Forward Transformation from PDFs to central moments
pdfs_to_k_transform = self._central_moment_transform_class(
stencil, None, density, velocity, moment_exponents=central_moments, conserved_quantity_equations=cqe)
pdfs_to_k_eqs = cached_forward_transform(pdfs_to_k_transform, f, simplification=pre_simplification, return_monomials=True)
pdfs_to_k_eqs = cached_forward_transform(
pdfs_to_k_transform, f, simplification=pre_simplification, return_monomials=True)
# 4) Add relaxation rules for lower order moments
lower_order_moments = moments_up_to_order(1, dim=self.dim)
......@@ -412,7 +412,8 @@ class CenteredCumulantBasedLbMethod(AbstractLbMethod):
# 6) Get backward transformation from central moments to PDFs
d = self.post_collision_pdf_symbols
k_post_to_pdfs_eqs = cached_backward_transform(pdfs_to_k_transform, d, simplification=pre_simplification, start_from_monomials=True)
k_post_to_pdfs_eqs = cached_backward_transform(
pdfs_to_k_transform, d, simplification=pre_simplification, start_from_monomials=True)
# 7) That's all. Now, put it all together.
all_acs = [] if pdfs_to_k_transform.absorbs_conserved_quantity_equations else [cqe]
......
......@@ -6,17 +6,14 @@ from pystencils.sympyextensions import subs_additive
from lbmpy.methods.abstractlbmethod import AbstractLbMethod, LbmCollisionRule, RelaxationInfo
from lbmpy.methods.conservedquantitycomputation import AbstractConservedQuantityComputation
from lbmpy.moment_transforms import (FastCentralMomentTransform,
PRE_COLLISION_MONOMIAL_CENTRAL_MOMENT, POST_COLLISION_MONOMIAL_CENTRAL_MOMENT)
from lbmpy.moment_transforms import FastCentralMomentTransform
from lbmpy.moments import (MOMENT_SYMBOLS, moment_matrix, set_up_shift_matrix,
statistical_quantity_symbol)
from lbmpy.moments import MOMENT_SYMBOLS, moment_matrix, set_up_shift_matrix
def relax_central_moments(pre_collision_symbols, post_collision_symbols,
relaxation_rates, equilibrium_values,
force_terms,
post_collision_base=POST_COLLISION_MONOMIAL_CENTRAL_MOMENT):
force_terms):
equilibrium_vec = sp.Matrix(equilibrium_values)
moment_vec = sp.Matrix(pre_collision_symbols)
relaxation_matrix = sp.diag(*relaxation_rates)
......@@ -280,7 +277,7 @@ class CentralMomentBasedLbMethod(AbstractLbMethod):
else:
force_model_terms = sp.Matrix([0] * len(stencil))
collision_eqs = relax_central_moments(k_pre, k_post, tuple(relaxation_rates),
collision_eqs = relax_central_moments(k_pre, k_post, tuple(relaxation_rates),
tuple(equilibrium_value), force_terms=force_model_terms)
# 3) Get backward transformation from central moments to PDFs
......
......@@ -21,9 +21,10 @@ POST_COLLISION_MONOMIAL_CENTRAL_MOMENT = 'kappa_post'
PRE_COLLISION_CENTRAL_MOMENT = 'K'
POST_COLLISION_CENTRAL_MOMENT = 'K_post'
class AbstractMomentTransform:
r"""Abstract Base Class for classes providing transformations between moment spaces.
These transformations are bijective maps between two spaces :math:`\mathcal{S}`
and :math:`\mathcal{D}` (i.e. populations and moments, or central moments and cumulants).
The forward map :math:`F : \mathcal{S} \mapsto \mathcal{D}` is given by :func:`forward_transform`,
......@@ -59,7 +60,7 @@ class AbstractMomentTransform:
Both :func:`forward_transform` and :func:`backward_transform` expect a keyword argument ``simplification``
which can be used to direct simplification steps applied during the derivation of the transformation
equations. Possible values are:
- `False` or ``'none'``: No simplification is to be applied
- `True` or ``'default'``: A default simplification strategy specific to the implementation is applied.
The actual simplification steps depend strongly on the nature of the equations. They are defined by
......@@ -79,7 +80,7 @@ class AbstractMomentTransform:
pre_collision_monomial_symbol_base=None,
post_collision_monomial_symbol_base=None):
"""Abstract Base Class constructor.
Args:
stencil: Nested tuple defining the velocity set
equilibrium_density: Symbol of the equilibrium density used in the collision rule
......@@ -91,7 +92,7 @@ class AbstractMomentTransform:
"""
if moment_exponents is not None and moment_polynomials is not None:
raise ValueError("Both moment_exponents and moment_polynomials were given. Pass only one of them!")
self.stencil = stencil
self.dim = len(stencil[0])
self.q = len(stencil)
......@@ -141,7 +142,6 @@ class AbstractMomentTransform:
returned by :func:`backward_transform`."""
return tuple(sq_sym(self.mono_base_post, e) for e in self.moment_exponents)
@abstractmethod
def forward_transform(self, *args, **kwargs):
"""Implemented in a subclass, will return the forward transform equations."""
......
......@@ -61,7 +61,6 @@ class PdfsToCentralMomentsByMatrix(AbstractCentralMomentTransform):
self.forward_matrix = shift_matrix * moment_matrix_without_shift
self.backward_matrix = moment_matrix_without_shift.inv() * shift_matrix.inv()
def forward_transform(self, pdf_symbols, simplification=True, subexpression_base='sub_f_to_k',
return_monomials=False):
simplification = self._get_simp_strategy(simplification)
......@@ -73,7 +72,6 @@ class PdfsToCentralMomentsByMatrix(AbstractCentralMomentTransform):
km = self.forward_matrix
pre_collision_moments = self.pre_collision_symbols
f_to_k_vec = km * sp.Matrix(pdf_symbols)
main_assignments = [Assignment(k, eq) for k, eq in zip(pre_collision_moments, f_to_k_vec)]
......@@ -99,10 +97,10 @@ class PdfsToCentralMomentsByMatrix(AbstractCentralMomentTransform):
m_to_f_vec = km_inv * sp.Matrix(post_collision_moments)
main_assignments = [Assignment(f, eq) for f, eq in zip(pdf_symbols, m_to_f_vec)]
symbol_gen = SymbolGen(subexpression_base)
ac = AssignmentCollection(main_assignments, subexpression_symbol_generator=symbol_gen)
if simplification:
ac = simplification.apply(ac)
return ac
......@@ -188,7 +186,7 @@ class FastCentralMomentTransform(AbstractCentralMomentTransform):
subexpressions += monomial_moment_eqs
moment_eqs = self.mono_to_poly_matrix * sp.Matrix(self.pre_collision_monomial_symbols)
main_assignments = [Assignment(m, v) for m, v in zip(self.pre_collision_symbols, moment_eqs)]
symbol_gen = SymbolGen(subexpression_base)
ac = AssignmentCollection(main_assignments, subexpressions=subexpressions,
subexpression_symbol_generator=symbol_gen)
......
import numpy as np
import sympy as sp
import warnings
from lbmpy.fieldaccess import StreamPullTwoFieldsAccessor
from lbmpy.methods.abstractlbmethod import LbmCollisionRule
from pystencils import Assignment, AssignmentCollection, Field
from pystencils import Assignment, AssignmentCollection
from pystencils.field import create_numpy_array_with_layout, layout_string_to_tuple
from pystencils.simp import add_subexpressions_for_field_reads
from pystencils.sympyextensions import fast_subs
......
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