Commit d37b073d authored by Frederik Hennig's avatar Frederik Hennig Committed by Markus Holzer
Browse files

Full Support for Zero-Centered Storage

parent 1d166a7a
......@@ -12,6 +12,9 @@ _build
This diff is collapsed.
This diff is collapsed.
......@@ -6,10 +6,10 @@ API Reference
Equilibrium Distributions (lbmpy.equilibrium)
.. automodule:: lbmpy.equilibrium
Abstract Base Class
.. autoclass:: lbmpy.equilibrium.AbstractEquilibrium
:private-members: _monomial_raw_moment, _monomial_central_moment, _monomial_cumulant
Generic Discrete Equilibria
Use the following class for custom discrete equilibria.
.. autoclass:: lbmpy.equilibrium.GenericDiscreteEquilibrium
Maxwellian Equilibria for Hydrodynamics
The following classes represent the continuous and the discrete variant of the Maxwellian equilibrium for
.. autoclass:: lbmpy.equilibrium.ContinuousHydrodynamicMaxwellian
.. autoclass:: lbmpy.equilibrium.DiscreteHydrodynamicMaxwellian
......@@ -188,11 +188,11 @@ keywords = {{Lattice Boltzmann} method, {BGK} collision operator, Steady-state f
abstract = {We derive minimal discrete models of the Boltzmann equation consistent with equilibrium thermodynamics, and which recover correct hydrodynamics in arbitrary dimensions. A new discrete velocity model is proposed for the simulation of the Navier-Stokes-Fourier equation and is tested in the setup of Taylor vortex flow. A simple analytical procedure for constructing the equilibrium for thermal hydrodynamics is established. For the lattice Boltzmann method of isothermal hydrodynamics, the explicit analytical form of the equilibrium distribution is presented. This results in an entropic version of the isothermal lattice Boltzmann method with the simplicity and computational efficiency of the standard lattice Boltzmann model.}
author = {D. D'Humières},
title = {Generalized lattice-{Boltzmann} equations},
journal = {Rarefied gas dynamics },
year = {1992}
author = {D. D'Humières},
journal = {Rarefied gas dynamics},
title = {Generalized lattice-{Boltzmann} equations},
year = {1992},
......@@ -211,4 +211,32 @@ pages = {427-478},
title = {Two-relaxation-time Lattice Boltzmann scheme: about parametrization, velocity, pressure and mixed boundary conditions},
volume = {3},
journal = {Communications in Computational Physics}
\ No newline at end of file
author = {Xiaoyi He and Li-Shi Luo},
journal = {Journal of Statistical Physics},
title = {Lattice Boltzmann Model for the Incompressible Navier{\textendash}Stokes Equation},
year = {1997},
month = {aug},
number = {3/4},
pages = {927--944},
volume = {88},
doi = {10.1023/b:joss.0000015179.12689.e4},
publisher = {Springer Science and Business Media {LLC}},
author = {G. Gruszczy{\'{n}}ski and T. Mitchell and C. Leonardi and {\L}. {\L}aniewski-Wo{\l}{\l}k and T. Barber},
journal = {Computers {\&} Mathematics with Applications},
title = {A cascaded phase-field lattice Boltzmann model for the simulation of incompressible, immiscible fluids with high density contrast},
year = {2020},
month = {feb},
number = {4},
pages = {1049--1071},
volume = {79},
doi = {10.1016/j.camwa.2019.08.018},
publisher = {Elsevier {BV}},
@Comment{jabref-meta: databaseType:bibtex;}
Maxwellian Equilibrium
Maxwellian Equilibrium (Legacy)
.. automodule:: lbmpy.maxwellian_equilibrium
Creating LBM methods
This module is a lower level API to construct methods.
When possible use the high level API.
.. automodule:: lbmpy.methods.creationfunctions
Methods (lbmpy.methods)
Methods and Method Creation (lbmpy.methods)
This module defines the classes defining all types of lattice Boltzmann methods available in *lbmpy*,
together with a set of factory functions used to create their instances. The factory functions are
organized in three levels of abstraction. Objects of the method classes should be created only through
these factory functions, never manually.
LBM Method Interfaces
Methods in *lbmpy* can be distinguished into three categories:
- :ref:`methods_rawmomentbased`, including the classical single relaxation-time (SRT, BGK), two relaxation-time (TRT)
and multiple relaxation-time (MRT) methods, as well as entropic variants of the TRT method.
- :ref:`methods_centralmomentbased`, which are multiple relaxation-time methods using relaxation in central moment space.
- :ref:`methods_cumulantbased`, multiple relaxation-time methods using relaxation in cumulant space.
Abstract LB Method Base Class
.. autoclass:: lbmpy.methods.LbmCollisionRule
......@@ -12,27 +22,35 @@ LBM Method Interfaces
.. autoclass:: lbmpy.methods.AbstractLbMethod
.. autoclass:: lbmpy.methods.AbstractConservedQuantityComputation
Conserved Quantity Computation
The classes of the conserved quantity computation (CQC) submodule define an LB Method's conserved quantities and
the equations to compute them. For hydrodynamic methods, :class:`lbmpy.methods.DensityVelocityComputation` is
the typical choice. For custom methods, however, a custom CQC class might have to be created.
LBM with conserved zeroth and first order
.. autoclass:: lbmpy.methods.AbstractConservedQuantityComputation
.. autoclass:: lbmpy.methods.DensityVelocityComputation
.. _methods_rawmomentbased:
Raw Moment-based methods
Moment-based methods
These methods are represented by instances of :class:`lbmpy.methods.momentbased.MomentBasedLbMethod` and will derive
collision equations either in population space (SRT, TRT, entropic TRT), or in raw moment space (MRT variants).
Creation Functions
The following factory functions create raw moment-based methods using variants of the regular hydrodynamic maxwellian
.. autofunction:: lbmpy.methods.create_srt
.. autofunction:: lbmpy.methods.create_trt
......@@ -41,9 +59,7 @@ Creation Functions
.. autofunction:: lbmpy.methods.create_mrt_orthogonal
.. autofunction:: lbmpy.methods.create_with_continuous_maxwellian_eq_moments
.. autofunction:: lbmpy.methods.create_with_discrete_maxwellian_eq_moments
.. autofunction:: lbmpy.methods.create_trt_kbc
......@@ -53,12 +69,42 @@ Class
.. _methods_centralmomentbased:
Central Moment-based methods
These methods are represented by instances of :class:`lbmpy.methods.momentbased.CentralMomentBasedLbMethod` and will derive
collision equations in central moment space.
Creation Functions
The following factory functions create central moment-based methods using variants of the regular hydrodynamic maxwellian
.. autofunction:: lbmpy.methods.create_central_moment
.. autoclass:: lbmpy.methods.momentbased.CentralMomentBasedLbMethod
.. _methods_cumulantbased:
Cumulant-based methods
These methods are represented by instances of :class:`lbmpy.methods.centeredcumulant.CenteredCumulantBasedLbMethod` and will derive
collision equations in cumulant space.
Creation Functions
The following factory functions create cumulant-based methods using the regular continuous hydrodynamic maxwellian equilibrium.
.. autofunction:: lbmpy.methods.create_with_polynomial_cumulants
.. autofunction:: lbmpy.methods.create_with_monomial_cumulants
......@@ -80,9 +126,48 @@ Class
.. autoclass:: lbmpy.methods.centeredcumulant.CenteredCumulantBasedLbMethod
Default Moment sets
The following functions provide default sets of polynomial raw moments, central moments and cumulants
to be used in MRT-type methods.
.. autofunction:: lbmpy.methods.default_moment_sets.cascaded_moment_sets_literature
.. autofunction:: lbmpy.methods.default_moment_sets.mrt_orthogonal_modes_literature
Low-Level Method Creation Interface
The following classes and factory functions constitute the lower levels of abstraction in method creation.
They are called from the higher-level functions described above, or, in special cases, by the user directly.
Custom method variants in population space, raw and central moment space based on the hydrodynamic Maxwellian
equilibrium may be created using either
:func:`lbmpy.methods.creationfunctions.create_with_discrete_maxwellian_equilibrium` or
Methods may also be created using custom equilibrium distributions using
The desired collision space, and the transform classes defining the manner of transforming populations to that
space and back, are defined using :class:`lbmpy.enums.CollisionSpace` and :class:`lbmpy.methods.CollisionSpaceInfo`.
Collision Space Info
.. autoclass lbmpy.methods.CollisionSpaceInfo
Low-Level Creation Functions
.. autofunction:: lbmpy.methods.creationfunctions.create_with_discrete_maxwellian_equilibrium
.. autofunction:: lbmpy.methods.creationfunctions.create_with_continuous_maxwellian_equilibrium
.. autofunction:: lbmpy.methods.creationfunctions.create_from_equilibrium
from .creationfunctions import create_lb_ast, create_lb_collision_rule, create_lb_function,\
create_lb_method, create_lb_method_from_existing, create_lb_update_rule, LBMConfig, LBMOptimisation
from .enums import Stencil, Method, ForceModel
create_lb_method, create_lb_update_rule, LBMConfig, LBMOptimisation
from .enums import Stencil, Method, ForceModel, CollisionSpace
from .lbstep import LatticeBoltzmannStep
from .macroscopic_value_kernels import pdf_initialization_assignments, macroscopic_values_getter,\
compile_macroscopic_values_getter, compile_macroscopic_values_setter, create_advanced_velocity_setter_collision_rule
......@@ -13,7 +13,7 @@ from .stencils import LBStencil
__all__ = ['create_lb_ast', 'create_lb_collision_rule', 'create_lb_function', 'create_lb_method',
'create_lb_method_from_existing', 'create_lb_update_rule', 'LBMConfig', 'LBMOptimisation',
'Stencil', 'Method', 'ForceModel',
'Stencil', 'Method', 'ForceModel', 'CollisionSpace',
'pdf_initialization_assignments', 'macroscopic_values_getter', 'compile_macroscopic_values_getter',
'compile_macroscopic_values_setter', 'create_advanced_velocity_setter_collision_rule',
......@@ -317,7 +317,7 @@ class UBB(LbBoundary):
cqc = lb_method.conserved_quantity_computation
shifted_vel_eqs = cqc.equilibrium_input_equations_from_init_values(velocity=velocity)
shifted_vel_eqs = shifted_vel_eqs.new_without_subexpressions()
velocity = [eq.rhs for eq in shifted_vel_eqs.new_filtered(cqc.first_order_moment_symbols).main_assignments]
velocity = [eq.rhs for eq in shifted_vel_eqs.new_filtered(cqc.velocity_symbols).main_assignments]
c_s_sq = sp.Rational(1, 3)
weight_info = LbmWeightInfo(lb_method, data_type=self.data_type)
......@@ -328,12 +328,12 @@ class UBB(LbBoundary):
# Better alternative: in conserved value computation
# rename what is currently called density to "virtual_density"
# provide a new quantity density, which is constant in case of incompressible models
if not lb_method.conserved_quantity_computation.zero_centered_pdfs:
if lb_method.conserved_quantity_computation.compressible:
cqc = lb_method.conserved_quantity_computation
density_symbol = sp.Symbol("rho")
pdf_field_accesses = [f_out(i) for i in range(len(lb_method.stencil))]
density_equations = cqc.output_equations_from_pdfs(pdf_field_accesses, {'density': density_symbol})
density_symbol = lb_method.conserved_quantity_computation.defined_symbols()['density']
density_symbol = lb_method.conserved_quantity_computation.density_symbol
result = density_equations.all_assignments
result += [Assignment(f_in(inv_dir[dir_symbol]),
f_out(dir_symbol) - vel_term * density_symbol)]
......@@ -564,7 +564,7 @@ class FixedDensity(LbBoundary):
return assignment_collection.copy(new_main_assignments)
cqc = lb_method.conserved_quantity_computation
velocity = cqc.defined_symbols()['velocity']
velocity = cqc.velocity_symbols
symmetric_eq = remove_asymmetric_part_of_main_assignments(lb_method.get_equilibrium(),
substitutions = {sym: f_out(i) for i, sym in enumerate(lb_method.pre_collision_pdf_symbols)}
......@@ -573,24 +573,26 @@ class FixedDensity(LbBoundary):
simplification = create_simplification_strategy(lb_method)
symmetric_eq = simplification(symmetric_eq)
density_symbol = cqc.defined_symbols()['density']
density = self.density
equilibrium_input = cqc.equilibrium_input_equations_from_init_values(density=density)
equilibrium_input = equilibrium_input.new_without_subexpressions()
density_eq = equilibrium_input.main_assignments[0]
assert density_eq.lhs == density_symbol
transformed_density = density_eq.rhs
equilibrium_input = equilibrium_input.main_assignments_dict
subexpressions_dict = symmetric_eq.subexpressions_dict
subexpressions_dict[cqc.density_symbol] = equilibrium_input[cqc.density_symbol]
subexpressions_dict[cqc.density_deviation_symbol] = equilibrium_input[cqc.density_deviation_symbol]
conditions = [(eq_i.rhs, sp.Equality(dir_symbol, i))
for i, eq_i in enumerate(symmetric_eq.main_assignments)] + [(0, True)]
eq_component = sp.Piecewise(*conditions)
subexpressions = [Assignment(eq.lhs, transformed_density if eq.lhs == density_symbol else eq.rhs)
for eq in symmetric_eq.subexpressions]
main_assignments = [Assignment(f_in(inv_dir[dir_symbol]), 2 * eq_component - f_out(dir_symbol))]
ac = AssignmentCollection(main_assignments, subexpressions=subexpressions_dict)
ac = ac.new_without_unused_subexpressions()
return subexpressions + [Assignment(f_in(inv_dir[dir_symbol]),
2 * eq_component - f_out(dir_symbol))]
return ac
# end class FixedDensity
......@@ -21,8 +21,8 @@ class ChapmanEnskogAnalysis:
cqc = method.conserved_quantity_computation
self._method = method
self._moment_cache = LbMethodEqMoments(method)
self.rho = cqc.defined_symbols(order=0)[1]
self.u = cqc.defined_symbols(order=1)[1]
self.rho = cqc.density_symbol
self.u = cqc.velocity_symbols
self.t = sp.Symbol("t")
self.epsilon = sp.Symbol("epsilon")
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