Commit b04caa75 authored by Markus Holzer's avatar Markus Holzer Committed by Jan Hönig
Browse files

Dataclasses for method creation

parent 4e47c1eb
*********
Enums
*********
.. automodule:: lbmpy.enums
:members:
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
create_lb_method, create_lb_method_from_existing, create_lb_update_rule, LBMConfig, LBMOptimisation
from .enums import Stencil, Method, ForceModel
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
......@@ -7,11 +8,12 @@ from .maxwellian_equilibrium import get_weights
from .relaxationrates import relaxation_rate_from_lattice_viscosity, lattice_viscosity_from_relaxation_rate,\
relaxation_rate_from_magic_number
from .scenarios import create_lid_driven_cavity, create_fully_periodic_flow
from .stencils import get_stencil
from .stencils import get_stencil, LBStencil
__all__ = ['create_lb_ast', 'create_lb_collision_rule', 'create_lb_function', 'create_lb_method',
'create_lb_method_from_existing', 'create_lb_update_rule',
'create_lb_method_from_existing', 'create_lb_update_rule', 'LBMConfig', 'LBMOptimisation',
'Stencil', 'Method', 'ForceModel',
'LatticeBoltzmannStep',
'pdf_initialization_assignments', 'macroscopic_values_getter', 'compile_macroscopic_values_getter',
'compile_macroscopic_values_setter', 'create_advanced_velocity_setter_collision_rule',
......@@ -19,7 +21,7 @@ __all__ = ['create_lb_ast', 'create_lb_collision_rule', 'create_lb_function', 'c
'relaxation_rate_from_lattice_viscosity', 'lattice_viscosity_from_relaxation_rate',
'relaxation_rate_from_magic_number',
'create_lid_driven_cavity', 'create_fully_periodic_flow',
'get_stencil']
'get_stencil', 'LBStencil']
from ._version import get_versions
......
......@@ -5,6 +5,7 @@ from lbmpy.advanced_streaming.utility import is_inplace, get_accessor, numeric_i
numeric_offsets, Timestep, get_timesteps
from lbmpy.stencils import get_stencil
from pystencils.datahandling import SerialDataHandling
from pystencils.enums import Target
from itertools import chain
......@@ -105,7 +106,7 @@ def get_communication_slices(
def periodic_pdf_copy_kernel(pdf_field, src_slice, dst_slice,
domain_size=None, target='gpu',
domain_size=None, target=Target.GPU,
opencl_queue=None, opencl_ctx=None):
"""Copies a rectangular array slice onto another non-overlapping array slice"""
from pystencils.gpucuda.kernelcreation import create_cuda_kernel
......@@ -134,10 +135,10 @@ def periodic_pdf_copy_kernel(pdf_field, src_slice, dst_slice,
copy_eq = Assignment(pdf_field(pdf_idx), pdf_field[tuple(offset)](pdf_idx))
ast = create_cuda_kernel([copy_eq], iteration_slice=dst_slice, skip_independence_check=True)
if target == 'gpu':
if target == Target.GPU:
from pystencils.gpucuda import make_python_function
return make_python_function(ast)
elif target == 'opencl':
elif target == Target.OPENCL:
from pystencils.opencl import make_python_function
return make_python_function(ast, opencl_queue, opencl_ctx)
else:
......@@ -176,17 +177,17 @@ class LBMPeriodicityHandling:
self.dh = data_handling
target = data_handling.default_target
assert target in ['cpu', 'gpu', 'opencl']
assert target in [Target.CPU, Target.GPU, Target.OPENCL]
self.pdf_field_name = pdf_field_name
self.ghost_layers = ghost_layers
periodicity = data_handling.periodicity
self.inplace_pattern = is_inplace(streaming_pattern)
self.target = target
self.cpu = target == 'cpu'
self.cpu = target == Target.CPU
self.opencl_queue = opencl_queue
self.opencl_ctx = opencl_ctx
self.pycuda_direct_copy = target == 'gpu' and pycuda_direct_copy
self.pycuda_direct_copy = target == Target.GPU and pycuda_direct_copy
def is_copy_direction(direction):
s = 0
......@@ -209,7 +210,7 @@ class LBMPeriodicityHandling:
ghost_layers=ghost_layers)
self.comm_slices.append(list(chain.from_iterable(v for k, v in slices_per_comm_dir.items())))
if target == 'opencl' or (target == 'gpu' and not pycuda_direct_copy):
if target == Target.OPENCL or (target == Target.GPU and not pycuda_direct_copy):
self.device_copy_kernels = []
for timestep in timesteps:
self.device_copy_kernels.append(self._compile_copy_kernels(timestep))
......
......@@ -2,8 +2,9 @@ import numpy as np
import sympy as sp
from lbmpy.advanced_streaming.indexing import BetweenTimestepsIndexing
from lbmpy.advanced_streaming.utility import is_inplace, Timestep, AccessPdfValues
from pystencils import Field, Assignment, TypedSymbol, create_indexed_kernel
from pystencils import Field, Assignment, TypedSymbol, create_kernel
from pystencils.stencil import inverse_direction
from pystencils import Target
from pystencils.boundaries import BoundaryHandling
from pystencils.boundaries.createindexlist import numpy_data_type_for_boundary_object
from pystencils.backends.cbackend import CustomCodeNode
......@@ -17,7 +18,7 @@ class LatticeBoltzmannBoundaryHandling(BoundaryHandling):
"""
def __init__(self, lb_method, data_handling, pdf_field_name, streaming_pattern='pull',
name="boundary_handling", flag_interface=None, target='cpu', openmp=True):
name="boundary_handling", flag_interface=None, target=Target.CPU, openmp=True):
self._lb_method = lb_method
self._streaming_pattern = streaming_pattern
self._inplace = is_inplace(streaming_pattern)
......@@ -175,7 +176,7 @@ class LbmWeightInfo(CustomCodeNode):
def create_lattice_boltzmann_boundary_kernel(pdf_field, index_field, lb_method, boundary_functor,
prev_timestep=Timestep.BOTH, streaming_pattern='pull',
target='cpu', **kernel_creation_args):
target=Target.CPU, **kernel_creation_args):
indexing = BetweenTimestepsIndexing(
pdf_field, lb_method.stencil, prev_timestep, streaming_pattern, np.int64, np.int64)
......@@ -191,7 +192,7 @@ def create_lattice_boltzmann_boundary_kernel(pdf_field, index_field, lb_method,
elements = [Assignment(dir_symbol, index_field[0]('dir'))]
elements += boundary_assignments.all_assignments
kernel = create_indexed_kernel(elements, [index_field], target=target, **kernel_creation_args)
kernel = create_kernel(elements, index_fields=[index_field], target=target, **kernel_creation_args)
# Code Elements ahead of the loop
index_arrs_node = indexing.create_code_node()
......
This diff is collapsed.
from enum import Enum, auto
class Stencil(Enum):
D2Q9 = auto()
D2V17 = auto()
D2V37 = auto()
D3Q15 = auto()
D3Q19 = auto()
D3Q27 = auto()
class Method(Enum):
SRT = auto()
TRT = auto()
MRT = auto()
CENTRAL_MOMENT = auto()
MRT_RAW = auto()
TRT_KBC_N1 = auto()
TRT_KBC_N2 = auto()
TRT_KBC_N3 = auto()
TRT_KBC_N4 = auto()
ENTROPIC_SRT = auto()
CUMULANT = auto()
MONOMIAL_CUMULANT = auto()
class ForceModel(Enum):
SIMPLE = auto()
LUO = auto()
GUO = auto()
BUICK = auto()
SILVA = auto()
EDM = auto()
KUPERSHTOKH = auto()
CUMULANT = auto()
HE = auto()
SHANCHEN = auto()
......@@ -4,13 +4,13 @@ import numpy as np
from lbmpy.boundaries.boundaryhandling import LatticeBoltzmannBoundaryHandling
from lbmpy.creationfunctions import (
create_lb_function, switch_to_symbolic_relaxation_rates_for_omega_adapting_methods,
update_with_default_parameters)
create_lb_function, update_with_default_parameters)
from lbmpy.enums import Stencil
from lbmpy.macroscopic_value_kernels import (
create_advanced_velocity_setter_collision_rule, pdf_initialization_assignments)
from lbmpy.simplificationfactory import create_simplification_strategy
from lbmpy.stencils import get_stencil
from pystencils import create_data_handling, create_kernel, make_slice
from lbmpy.stencils import LBStencil
from pystencils import create_data_handling, create_kernel, make_slice, Target, Backend
from pystencils.slicing import SlicedGetter
from pystencils.timeloop import TimeLoop
......@@ -23,7 +23,8 @@ class LatticeBoltzmannStep:
compute_velocity_in_every_step=False, compute_density_in_every_step=False,
velocity_input_array_name=None, time_step_order='stream_collide', flag_interface=None,
alignment_if_vectorized=64, fixed_loop_sizes=True, fixed_relaxation_rates=True,
timeloop_creation_function=TimeLoop, **method_parameters):
timeloop_creation_function=TimeLoop,
lbm_config=None, lbm_optimisation=None, config=None, **method_parameters):
self._timeloop_creation_function = timeloop_creation_function
......@@ -32,7 +33,11 @@ class LatticeBoltzmannStep:
if domain_size is not None:
raise ValueError("When passing a data_handling, the domain_size parameter can not be specified")
target = optimization.get('target', 'cpu')
if config is not None:
target = config.target
else:
target = optimization.get('target', Target.CPU)
if data_handling is None:
if domain_size is None:
raise ValueError("Specify either domain_size or data_handling")
......@@ -43,17 +48,19 @@ class LatticeBoltzmannStep:
parallel=False)
if 'stencil' not in method_parameters:
method_parameters['stencil'] = 'D2Q9' if data_handling.dim == 2 else 'D3Q27'
method_parameters['stencil'] = LBStencil(Stencil.D2Q9) \
if data_handling.dim == 2 else LBStencil(Stencil.D3Q27)
method_parameters, optimization = update_with_default_parameters(method_parameters, optimization)
field_dtype = np.float64 if optimization['double_precision'] else np.float32
lbm_config, lbm_optimisation, config = update_with_default_parameters(method_parameters, optimization,
lbm_config, lbm_optimisation, config)
del method_parameters['kernel_type']
# the parallel datahandling understands only numpy datatypes. Strings lead to an error.
field_dtype = np.float64 if config.data_type == 'double' else np.float32
if lbm_kernel:
q = len(lbm_kernel.method.stencil)
q = lbm_kernel.method.stencil.Q
else:
q = len(get_stencil(method_parameters['stencil']))
q = lbm_config.stencil.Q
self.name = name
self._data_handling = data_handling
......@@ -62,13 +69,12 @@ class LatticeBoltzmannStep:
self.velocity_data_name = name + "_velocity" if velocity_data_name is None else velocity_data_name
self.density_data_name = name + "_density" if density_data_name is None else density_data_name
self.density_data_index = density_data_index
self._optimization = optimization
self._gpu = target == 'gpu' or target == 'opencl'
layout = optimization['field_layout']
self._gpu = target == Target.GPU or target == Target.OPENCL
layout = lbm_optimisation.field_layout
alignment = False
if optimization['target'] == 'cpu' and optimization['vectorization']:
if config.backend == Backend.C and config.cpu_vectorize_info:
alignment = alignment_if_vectorized
self._data_handling.add_array(self._pdf_arr_name, values_per_cell=q, gpu=self._gpu, layout=layout,
......@@ -86,49 +92,51 @@ class LatticeBoltzmannStep:
layout=layout, latex_name='ρ', dtype=field_dtype, alignment=alignment)
if compute_velocity_in_every_step:
method_parameters['output']['velocity'] = self._data_handling.fields[self.velocity_data_name]
lbm_config.output['velocity'] = self._data_handling.fields[self.velocity_data_name]
if compute_density_in_every_step:
density_field = self._data_handling.fields[self.density_data_name]
if self.density_data_index is not None:
density_field = density_field(density_data_index)
method_parameters['output']['density'] = density_field
lbm_config.output['density'] = density_field
if velocity_input_array_name is not None:
method_parameters['velocity_input'] = self._data_handling.fields[velocity_input_array_name]
if method_parameters['omega_output_field'] and isinstance(method_parameters['omega_output_field'], str):
method_parameters['omega_output_field'] = data_handling.add_array(method_parameters['omega_output_field'],
dtype=field_dtype, alignment=alignment)
lbm_config.velocity_input = self._data_handling.fields[velocity_input_array_name]
if isinstance(lbm_config.omega_output_field, str):
lbm_config.omega_output_field = data_handling.add_array(lbm_config.omega_output_field,
dtype=field_dtype, alignment=alignment)
self.kernel_params = kernel_params.copy()
# --- Kernel creation ---
if lbm_kernel is None:
switch_to_symbolic_relaxation_rates_for_omega_adapting_methods(method_parameters, self.kernel_params,
force=not fixed_relaxation_rates)
if fixed_loop_sizes:
optimization['symbolic_field'] = data_handling.fields[self._pdf_arr_name]
method_parameters['field_name'] = self._pdf_arr_name
method_parameters['temporary_field_name'] = self._tmp_arr_name
lbm_optimisation.symbolic_field = data_handling.fields[self._pdf_arr_name]
lbm_config.field_name = self._pdf_arr_name
lbm_config.temporary_field_name = self._tmp_arr_name
if time_step_order == 'stream_collide':
self._lbmKernels = [create_lb_function(optimization=optimization,
**method_parameters)]
self._lbmKernels = [create_lb_function(lbm_config=lbm_config,
lbm_optimisation=lbm_optimisation,
config=config)]
elif time_step_order == 'collide_stream':
self._lbmKernels = [create_lb_function(optimization=optimization,
kernel_type='collide_only',
**method_parameters),
create_lb_function(optimization=optimization,
kernel_type='stream_pull_only',
** method_parameters)]
self._lbmKernels = [create_lb_function(lbm_config=lbm_config,
lbm_optimisation=lbm_optimisation,
config=config,
kernel_type='collide_only'),
create_lb_function(lbm_config=lbm_config,
lbm_optimisation=lbm_optimisation,
config=config,
kernel_type='stream_pull_only')]
else:
assert self._data_handling.dim == lbm_kernel.method.dim, \
"Error: %dD Kernel for %d dimensional domain" % (lbm_kernel.method.dim, self._data_handling.dim)
f"Error: {lbm_kernel.method.dim}D Kernel for {self._data_handling.dim} dimensional domain"
self._lbmKernels = [lbm_kernel]
self.method = self._lbmKernels[0].method
self.ast = self._lbmKernels[0].ast
# -- Boundary Handling & Synchronization ---
stencil_name = method_parameters['stencil']
stencil_name = lbm_config.stencil.name
self._sync_src = data_handling.synchronization_function([self._pdf_arr_name], stencil_name, target,
stencil_restricted=True)
self._sync_tmp = data_handling.synchronization_function([self._tmp_arr_name], stencil_name, target,
......@@ -137,7 +145,11 @@ class LatticeBoltzmannStep:
self._boundary_handling = LatticeBoltzmannBoundaryHandling(self.method, self._data_handling, self._pdf_arr_name,
name=name + "_boundary_handling",
flag_interface=flag_interface,
target=target, openmp=optimization['openmp'])
target=target, openmp=config.cpu_openmp)
self._lbm_config = lbm_config
self._lbm_optimisation = lbm_optimisation
self._config = config
# -- Macroscopic Value Kernels
self._getterKernel, self._setterKernel = self._compile_macroscopic_setter_and_getter()
......@@ -190,6 +202,21 @@ class LatticeBoltzmannStep:
def pdf_array_name(self):
return self._pdf_arr_name
@property
def lbm_config(self):
"""LBM configuration of the scenario"""
return self._lbm_config
@property
def lbm_optimisation(self):
"""LBM optimisation parameters"""
return self._lbm_optimisation
@property
def config(self):
"""Configutation of pystencils parameters"""
return self.config
def _get_slice(self, data_name, slice_obj, masked):
if slice_obj is None:
slice_obj = make_slice[:, :] if self.dim == 2 else make_slice[:, :, 0.5]
......@@ -343,11 +370,11 @@ class LatticeBoltzmannStep:
collision_rule = create_advanced_velocity_setter_collision_rule(self.method, vel_backup_field,
velocity_relaxation_rate)
optimization = self._optimization.copy()
optimization['symbolic_field'] = dh.fields[self._pdf_arr_name]
self._lbm_optimisation.symbolic_field = dh.fields[self._pdf_arr_name]
kernel = create_lb_function(collision_rule=collision_rule, field_name=self._pdf_arr_name,
temporary_field_name=self._tmp_arr_name, optimization=optimization)
temporary_field_name=self._tmp_arr_name,
lbm_optimisation=self._lbm_optimisation)
self._velocity_init_kernel = kernel
def make_velocity_backup():
......@@ -383,7 +410,7 @@ class LatticeBoltzmannStep:
self._data_handling.all_to_cpu()
self._data_handling.run_kernel(self._getterKernel, **self.kernel_params)
global_residuum = compute_residuum()
print("Initialization iteration {}, residuum {}".format(steps_run, global_residuum))
print(f"Initialization iteration {steps_run}, residuum {global_residuum}")
if np.isnan(global_residuum) or global_residuum < convergence_threshold:
break
......@@ -391,8 +418,8 @@ class LatticeBoltzmannStep:
converged = global_residuum < convergence_threshold
if not converged:
restore_velocity_backup()
raise ValueError("Iterative initialization did not converge after %d steps.\n"
"Current residuum is %s" % (steps_run, global_residuum))
raise ValueError(f"Iterative initialization did not converge after {steps_run} steps.\n"
f"Current residuum is {global_residuum}")
return global_residuum, steps_run
......@@ -406,10 +433,10 @@ class LatticeBoltzmannStep:
getter_eqs = cqc.output_equations_from_pdfs(pdf_field.center_vector,
{'density': rho_field, 'velocity': vel_field})
getter_kernel = create_kernel(getter_eqs, target='cpu', cpu_openmp=self._optimization['openmp']).compile()
getter_kernel = create_kernel(getter_eqs, target=Target.CPU, cpu_openmp=self._config.cpu_openmp).compile()
setter_eqs = pdf_initialization_assignments(lb_method, rho_field,
vel_field.center_vector, pdf_field.center_vector)
setter_eqs = create_simplification_strategy(lb_method)(setter_eqs)
setter_kernel = create_kernel(setter_eqs, target='cpu', cpu_openmp=self._optimization['openmp']).compile()
setter_kernel = create_kernel(setter_eqs, target=Target.CPU, cpu_openmp=self._config.cpu_openmp).compile()
return getter_kernel, setter_kernel
......@@ -2,6 +2,7 @@ import functools
from copy import deepcopy
from lbmpy.simplificationfactory import create_simplification_strategy
from pystencils.field import Field, get_layout_of_array
from pystencils.enums import Target
from lbmpy.advanced_streaming.utility import get_accessor, Timestep
......@@ -51,7 +52,7 @@ macroscopic_values_setter = pdf_initialization_assignments
def compile_macroscopic_values_getter(lb_method, output_quantities, pdf_arr=None,
ghost_layers=1, iteration_slice=None,
field_layout='numpy', target='cpu',
field_layout='numpy', target=Target.CPU,
streaming_pattern='pull', previous_timestep=Timestep.BOTH):
"""
Create kernel to compute macroscopic value(s) from a pdf field (e.g. density or velocity)
......@@ -65,7 +66,7 @@ def compile_macroscopic_values_getter(lb_method, output_quantities, pdf_arr=None
is determined automatically and assumed to be equal for all dimensions.
iteration_slice: if not None, iteration is done only over this slice of the field
field_layout: layout for output field, also used for pdf field if pdf_arr is not given
target: 'cpu' or 'gpu'
target: `Target.CPU` or `Target.GPU`
previous_step_accessor: The accessor used by the streaming pattern of the previous timestep
Returns:
......@@ -116,16 +117,16 @@ def compile_macroscopic_values_getter(lb_method, output_quantities, pdf_arr=None
eqs = cqc.output_equations_from_pdfs(pdf_symbols, output_mapping).all_assignments
if target == 'cpu':
if target == Target.CPU:
import pystencils.cpu as cpu
kernel = cpu.make_python_function(cpu.create_kernel(
eqs, ghost_layers=ghost_layers, iteration_slice=iteration_slice))
elif target == 'gpu':
elif target == Target.GPU:
import pystencils.gpucuda as gpu
kernel = gpu.make_python_function(gpu.create_cuda_kernel(
eqs, ghost_layers=ghost_layers, iteration_slice=iteration_slice))
else:
raise ValueError("Unknown target '%s'. Possible targets are 'cpu' and 'gpu'" % (target,))
raise ValueError("Unknown target '%s'. Possible targets are `Target.CPU` and `Target.GPU`" % (target,))
def getter(pdfs, **kwargs):
if pdf_arr is not None:
......@@ -141,7 +142,7 @@ def compile_macroscopic_values_getter(lb_method, output_quantities, pdf_arr=None
def compile_macroscopic_values_setter(lb_method, quantities_to_set, pdf_arr=None,
ghost_layers=1, iteration_slice=None,
field_layout='numpy', target='cpu',
field_layout='numpy', target=Target.CPU,
streaming_pattern='pull', previous_timestep=Timestep.BOTH):
"""
Creates a function that sets a pdf field to specified macroscopic quantities
......@@ -156,7 +157,7 @@ def compile_macroscopic_values_setter(lb_method, quantities_to_set, pdf_arr=None
is determined automatically and assumed to be equal for all dimensions.
iteration_slice: if not None, iteration is done only over this slice of the field
field_layout: layout of the pdf field if pdf_arr was not given
target: 'cpu' or 'gpu'
target: `Target.CPU` or `Target.GPU`
previous_step_accessor: The accessor used by the streaming pattern of the previous timestep
Returns:
......@@ -201,16 +202,16 @@ def compile_macroscopic_values_setter(lb_method, quantities_to_set, pdf_arr=None
substitutions = {sym: write_accesses[i] for i, sym in enumerate(lb_method.post_collision_pdf_symbols)}
eq = eq.new_with_substitutions(substitutions).all_assignments
if target == 'cpu':
if target == Target.CPU:
import pystencils.cpu as cpu
kernel = cpu.make_python_function(cpu.create_kernel(eq))
kernel = functools.partial(kernel, **fixed_kernel_parameters)
elif target == 'gpu':
elif target == Target.GPU:
import pystencils.gpucuda as gpu
kernel = gpu.make_python_function(gpu.create_cuda_kernel(eq))
kernel = functools.partial(kernel, **fixed_kernel_parameters)
else:
raise ValueError("Unknown target '%s'. Possible targets are 'cpu' and 'gpu'" % (target,))
raise ValueError("Unknown target '%s'. Possible targets are `Target.CPU` and `Target.GPU`" % (target,))
def setter(pdfs, **kwargs):
if pdf_arr is not None:
......
......@@ -86,7 +86,7 @@ class DensityVelocityComputation(AbstractConservedQuantityComputation):
zeroth_order_moment_symbol=sp.Symbol("rho"),
first_order_moment_symbols=sp.symbols("u_:3"),
second_order_moment_symbols=sp.symbols("p_:9")):
dim = len(stencil[0])
dim = stencil.D
self._stencil = stencil
self._compressible = compressible
self._forceModel = force_model
......@@ -97,7 +97,7 @@ class DensityVelocityComputation(AbstractConservedQuantityComputation):
@property
def conserved_quantities(self):
return {'density': 1,
'velocity': len(self._stencil[0])}
'velocity': self._stencil.D}
@property
def compressible(self):
......@@ -134,7 +134,7 @@ class DensityVelocityComputation(AbstractConservedQuantityComputation):
return result
def equilibrium_input_equations_from_pdfs(self, pdfs, force_substitution=True):
dim = len(self._stencil[0])
dim = self._stencil.D
eq_coll = get_equations_for_zeroth_and_first_order_moment(self._stencil, pdfs, self._symbolOrder0,
self._symbolsOrder1[:dim])
if self._compressible:
......@@ -148,7 +148,7 @@ class DensityVelocityComputation(AbstractConservedQuantityComputation):
return eq_coll
def equilibrium_input_equations_from_init_values(self, density=1, velocity=(0, 0, 0), force_substitution=True):
dim = len(self._stencil[0])
dim = self._stencil.D
zeroth_order_moment = density if self._compressible else density - sp.Rational(1, 1)
first_order_moments = velocity[:dim]
vel_offset = [0] * dim
......@@ -172,7 +172,7 @@ class DensityVelocityComputation(AbstractConservedQuantityComputation):
return result
def output_equations_from_pdfs(self, pdfs, output_quantity_names_to_symbols, force_substitution=True):
dim = len(self._stencil[0])
dim = self._stencil.D
ac = get_equations_for_zeroth_and_first_order_moment(self._stencil, pdfs,
self._symbolOrder0, self._symbolsOrder1,
......@@ -284,7 +284,7 @@ def get_equations_for_zeroth_and_first_order_moment(stencil, symbolic_pdfs, symb
result += term
return result
dim = len(stencil[0])
dim = stencil.D
subexpressions = []
pdf_sum = sum(symbolic_pdfs)
......
......@@ -125,8 +125,8 @@ def create_with_continuous_maxwellian_eq_moments(stencil, moment_to_relaxation_r
if isinstance(stencil, str):
stencil = get_stencil(stencil)
mom_to_rr_dict = OrderedDict(moment_to_relaxation_rate_dict)
assert len(mom_to_rr_dict) == len(stencil), "The number of moments has to be equal to the number of stencil entries"
dim = len(stencil[0])
assert len(mom_to_rr_dict) == stencil.Q, "The number of moments has to be equal to the number of stencil entries"
dim = stencil.D
density_velocity_computation = DensityVelocityComputation(stencil, compressible, force_model)
moments = tuple(mom_to_rr_dict.keys())
......@@ -480,9 +480,11 @@ def create_mrt_orthogonal(stencil, relaxation_rate_getter, maxwellian_moments=Fa
moment_to_relaxation_rate_dict[m] = rr
if maxwellian_moments:
return create_with_continuous_maxwellian_eq_moments(stencil, moment_to_relaxation_rate_dict, **kwargs)
return create_with_continuous_maxwellian_eq_moments(stencil,
moment_to_relaxation_rate_dict, **kwargs)
else:
return create_with_discrete_maxwellian_eq_moments(stencil, moment_to_relaxation_rate_dict, **kwargs)
return create_with_discrete_maxwellian_eq_moments(stencil,
moment_to_relaxation_rate_dict, **kwargs)
def mrt_orthogonal_modes_literature(stencil, is_weighted):
......
......@@ -46,9 +46,9 @@ def add_entropy_condition(collision_rule, omega_output_field=None):
q = len(stencil)
f_symbols = collision_rule.method.pre_collision_pdf_symbols
ds_symbols = [sp.Symbol("entropicDs_%d" % (i,)) for i in range(q)]
dh_symbols = [sp.Symbol("entropicDh_%d" % (i,)) for i in range(q)]
feq_symbols = [sp.Symbol("entropicFeq_%d" % (i,)) for i in range(q)]
ds_symbols = [sp.Symbol(f"entropicDs_{i}") for i in range(q)]
dh_symbols = [sp.Symbol(f"entropicDh_{i}") for i in range(q)]
feq_symbols = [sp.Symbol(f"entropicFeq_{i}") for i in range(q)]
subexpressions = [Assignment(a, b) for a, b in zip(ds_symbols, ds)] + \
[Assignment(a, b) for a, b in zip(dh_symbols, dh)] + \
......@@ -125,19 +125,19 @@ def add_iterative_entropy_condition(collision_rule, free_omega=None, newton_iter
# 2) get equilibrium from method and define subexpressions for it
eq_terms = [eq.rhs for eq in collision_rule.method.get_equilibrium().main_assignments]
eq_symbols = sp.symbols("entropicFeq_:%d" % (len(eq_terms, )))
eq_symbols = sp.symbols(f"entropicFeq_:{len(eq_terms)}")