Commit f3d5a430 authored by Martin Bauer's avatar Martin Bauer
Browse files

Rest of PEP8 renaming

parent 1efaf4fe
......@@ -20,7 +20,7 @@ class Boundary:
:param pdf_field: pystencils field describing the pdf. The current cell is cell next to the boundary,
which is influenced by the boundary cell i.e. has a link from the boundary cell to
itself.
:param direction_symbol: a sympy symbol that can be used as index to the pdfField. It describes
:param direction_symbol: a sympy symbol that can be used as index to the pdf_field. It describes
the direction pointing from the fluid to the boundary cell
:param lb_method: an instance of the LB method used. Use this to adapt the boundary to the method
(e.g. compressibility)
......@@ -32,8 +32,8 @@ class Boundary:
@property
def additional_data(self):
"""Return a list of (name, type) tuples for additional data items required in this boundary
These data items can either be initialized in separate kernel see additionalDataKernelInit or by
Python callbacks - see additionalDataCallback """
These data items can either be initialized in separate kernel see additional_data_kernel_init or by
Python callbacks - see additional_data_callback """
return []
@property
......@@ -134,7 +134,7 @@ class UBB(Boundary):
for d_i, v_i in zip(neighbor, velocity)]) * weight_of_direction(direction)
# Better alternative: in conserved value computation
# rename what is currently called density to "virtualDensity"
# 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:
cqc = lb_method.conserved_quantity_computation
......
......@@ -261,7 +261,7 @@ class LbMethodEqMoments:
moment_tuple = ce_moment.moment_tuple
moment_symbols = []
for moment, (eqValue, rr) in self._method.relaxation_info_dict.items():
for moment, (eq_value, rr) in self._method.relaxation_info_dict.items():
if isinstance(moment, tuple):
moment_symbols.append(-rr**exponent
* CeMoment(pre_collision_moment_name, moment, ce_moment.superscript))
......@@ -326,8 +326,8 @@ def substitute_collision_operator_moments(expr, lb_moment_computation, collision
pre_collision_moment_name="\\Pi"):
moments_to_replace = [m for m in expr.atoms(CeMoment) if m.name == collision_op_moment_name]
subs_dict = {}
for ceMoment in moments_to_replace:
subs_dict[ceMoment] = lb_moment_computation.get_post_collision_moment(ceMoment, 1, pre_collision_moment_name)
for ce_moment in moments_to_replace:
subs_dict[ce_moment] = lb_moment_computation.get_post_collision_moment(ce_moment, 1, pre_collision_moment_name)
return expr.subs(subs_dict)
......@@ -341,10 +341,10 @@ def take_moments(eqn, pdf_to_moment_name=(('f', '\Pi'), ('\Omega f', '\\Upsilon'
velocity_terms = tuple(expanded_symbol(velocity_name, subscript=i) for i in range(3))
def determine_f_index(factor):
FIndex = namedtuple("FIndex", ['momentName', 'superscript'])
for symbolListId, pdfSymbolsElement in enumerate(pdf_symbols):
FIndex = namedtuple("FIndex", ['moment_name', 'superscript'])
for symbol_list_id, pdf_symbols_element in enumerate(pdf_symbols):
try:
return FIndex(pdf_to_moment_name[symbolListId][1], pdfSymbolsElement.index(factor))
return FIndex(pdf_to_moment_name[symbol_list_id][1], pdf_symbols_element.index(factor))
except ValueError:
pass
return None
......@@ -370,13 +370,13 @@ def take_moments(eqn, pdf_to_moment_name=(('f', '\Pi'), ('\Omega f', '\\Upsilon'
f_index = new_f_index
moment_tuple = [0] * len(velocity_terms)
for cIdx in c_indices:
moment_tuple[cIdx] += 1
for c_idx in c_indices:
moment_tuple[c_idx] += 1
moment_tuple = tuple(moment_tuple)
if use_one_neighborhood_aliasing:
moment_tuple = non_aliased_moment(moment_tuple)
result = CeMoment(f_index.momentName, moment_tuple, f_index.superscript)
result = CeMoment(f_index.moment_name, moment_tuple, f_index.superscript)
if derivative_term is not None:
result = derivative_term.change_arg_recursive(result)
result *= rest
......@@ -510,7 +510,7 @@ def chapman_enskog_ansatz(equation, time_derivative_orders=(1, 3), spatial_deriv
equation: equation to expand
time_derivative_orders: tuple describing range for time derivative to expand
spatial_derivative_orders: tuple describing range for spatial derivatives to expand
pdfs: symbols to expand: sequence of triples (symbolName, startOrder, endOrder)
pdfs: symbols to expand: sequence of triples (symbol_name, start_order, end_order)
commutative: can be set to False to have non-commutative pdf symbols
Returns:
tuple mapping epsilon order to equation
......@@ -533,15 +533,15 @@ def chapman_enskog_ansatz(equation, time_derivative_orders=(1, 3), spatial_deriv
expanded_pdf_symbols = []
max_expansion_order = spatial_derivative_orders[1] if spatial_derivative_orders else 10
for pdf_name, startOrder, stopOrder in pdfs:
for pdf_name, start_order, stop_order in pdfs:
if isinstance(pdf_name, sp.Symbol):
pdf_name = pdf_name.name
expanded_pdf_symbols += [expanded_symbol(pdf_name, superscript=i, commutative=commutative)
for i in range(startOrder, stopOrder)]
for i in range(start_order, stop_order)]
pdf_symbol = sp.Symbol(pdf_name, commutative=commutative)
subs_dict[pdf_symbol] = sum(eps ** i * expanded_symbol(pdf_name, superscript=i, commutative=commutative)
for i in range(startOrder, stopOrder))
max_expansion_order = max(max_expansion_order, stopOrder)
for i in range(start_order, stop_order))
max_expansion_order = max(max_expansion_order, stop_order)
equation = equation.subs(subs_dict)
equation = expand_using_linearity(equation, functions=expanded_pdf_symbols).expand().collect(eps)
result = {eps_order: equation.coeff(eps ** eps_order) for eps_order in range(1, 2*max_expansion_order)}
......@@ -568,7 +568,7 @@ def match_to_navier_stokes(conservation_equations, rho=sp.Symbol("rho"), u=sp.sy
def match_moment_eqs(moment_eqs, is_compressible):
shear_and_pressure_eqs = []
for i, momEq in enumerate(moment_eqs):
for i, mom_eq in enumerate(moment_eqs):
factor = rho if is_compressible else 1
ref = diff_simplify(Diff(factor * u[i], t) + sum(Diff(factor * u[i] * u[j], j) for j in range(dim)))
shear_and_pressure_eqs.append(diff_simplify(moment_eqs[i]) - ref)
......@@ -590,8 +590,8 @@ def match_to_navier_stokes(conservation_equations, rho=sp.Symbol("rho"), u=sp.sy
sigma_ = sp.zeros(dim)
error_terms_ = []
for i, shearAndPressureEq in enumerate(shear_and_pressure_eqs):
eq_without_pressure = shearAndPressureEq - sum(coeff * Diff(arg, i) for coeff, arg in pressure_terms)
for i, shear_and_pressure_eq in enumerate(shear_and_pressure_eqs):
eq_without_pressure = shear_and_pressure_eq - sum(coeff * Diff(arg, i) for coeff, arg in pressure_terms)
for d in eq_without_pressure.atoms(Diff):
eq_without_pressure = eq_without_pressure.collect(d)
sigma_[i, d.target] += eq_without_pressure.coeff(d) * d.arg
......
......@@ -69,17 +69,17 @@ def determine_higher_order_moments(epsilon_hierarchy, relaxation_rates, moment_c
time_diffs = OrderedDict()
non_eq_moms = OrderedDict()
for epsOrder in range(1, order):
eps_eq = epsilon_hierarchy[epsOrder]
for eps_order in range(1, order):
eps_eq = epsilon_hierarchy[eps_order]
for order in range(order+1):
eqs = sp.Matrix([full_expand(tm(eps_eq * m)) for m in poly_moments(order, dim)])
unknown_moments = [m for m in eqs.atoms(CeMoment)
if m.superscript == epsOrder and sum(m.moment_tuple) == order]
if m.superscript == eps_order and sum(m.moment_tuple) == order]
if len(unknown_moments) == 0:
for eq in eqs:
time_diffs_in_expr = [d for d in eq.atoms(Diff) if
(d.target == 't' or d.target == sp.Symbol("t")) and d.superscript == epsOrder]
(d.target == 't' or d.target == sp.Symbol("t")) and d.superscript == eps_order]
if len(time_diffs_in_expr) == 0:
continue
assert len(time_diffs_in_expr) == 1, \
......
......@@ -13,12 +13,12 @@ class SteadyStateChapmanEnskogAnalysis:
self.method = method
self.dim = method.dim
self.order = order
self.physicalVariables = list(sp.Matrix(self.method.moment_equilibrium_values).atoms(sp.Symbol)) # rho, u..
self.physical_variables = list(sp.Matrix(self.method.moment_equilibrium_values).atoms(sp.Symbol)) # rho, u..
self.eps = sp.Symbol("epsilon")
self.f_sym = sp.Symbol("f", commutative=False)
self.f_syms = [expanded_symbol("f", superscript=i, commutative=False) for i in range(order + 1)]
self.collisionOpSym = sp.Symbol("A", commutative=False)
self.collision_op_sym = sp.Symbol("A", commutative=False)
self.force_sym = sp.Symbol("F_q", commutative=False)
self.velocity_syms = sp.Matrix([expanded_symbol("c", subscript=i, commutative=False) for i in range(self.dim)])
......@@ -26,34 +26,34 @@ class SteadyStateChapmanEnskogAnalysis:
self.force_model = None
if force_model_class:
acceleration_symbols = sp.symbols("a_:%d" % (self.dim,), commutative=False)
self.physicalVariables += acceleration_symbols
self.physical_variables += acceleration_symbols
self.force_model = force_model_class(acceleration_symbols)
self.F_q = self.force_model(self.method)
# Perform the analysis
self.tayloredEquation = self._create_taylor_expanded_equation()
inserted_hierarchy, raw_hierarchy = self._create_pdf_hierarchy(self.tayloredEquation)
self.pdfHierarchy = inserted_hierarchy
self.pdfHierarchyRaw = raw_hierarchy
self.recombinedEq = self._recombine_pdfs(self.pdfHierarchy)
self.taylored_equation = self._create_taylor_expanded_equation()
inserted_hierarchy, raw_hierarchy = self._create_pdf_hierarchy(self.taylored_equation)
self.pdf_hierarchy = inserted_hierarchy
self.pdf_hierarchy_raw = raw_hierarchy
self.recombined_eq = self._recombine_pdfs(self.pdf_hierarchy)
symbols_to_values = self._get_symbols_to_values_dict()
self.continuityEquation = self._compute_continuity_equation(self.recombinedEq, symbols_to_values)
self.momentumEquations = [self._compute_momentum_equation(self.recombinedEq, symbols_to_values, h)
for h in range(self.dim)]
self.continuity_equation = self._compute_continuity_equation(self.recombined_eq, symbols_to_values)
self.momentum_equations = [self._compute_momentum_equation(self.recombined_eq, symbols_to_values, h)
for h in range(self.dim)]
def get_pdf_hierarchy(self, order, collision_operator_symbol=sp.Symbol("omega")):
def substitute_non_commuting_symbols(eq):
return eq.subs({a: sp.Symbol(a.name) for a in eq.atoms(sp.Symbol)})
result = self.pdfHierarchy[order].subs(self.collisionOpSym, collision_operator_symbol)
result = self.pdf_hierarchy[order].subs(self.collision_op_sym, collision_operator_symbol)
result = normalize_diff_order(result, functions=(self.f_syms[0], self.force_sym))
return substitute_non_commuting_symbols(result)
def get_continuity_equation(self, only_order=None):
return self._extract_order(self.continuityEquation, only_order)
return self._extract_order(self.continuity_equation, only_order)
def get_momentum_equation(self, only_order=None):
return [self._extract_order(e, only_order) for e in self.momentumEquations]
return [self._extract_order(e, only_order) for e in self.momentum_equations]
def _extract_order(self, eq, order):
if order is None:
......@@ -76,7 +76,7 @@ class SteadyStateChapmanEnskogAnalysis:
taylor_expansion = DiffOperator.apply(differential_operator.expand(), self.f_sym)
f_non_eq = self.f_sym - self.f_syms[0]
return taylor_expansion + self.collisionOpSym * f_non_eq - self.eps * self.force_sym
return taylor_expansion + self.collision_op_sym * f_non_eq - self.eps * self.force_sym
def _create_pdf_hierarchy(self, taylored_equation):
"""
......@@ -90,8 +90,8 @@ class SteadyStateChapmanEnskogAnalysis:
inserted_hierarchy = []
raw_hierarchy = []
substitution_dict = {}
for ceEq, f_i in zip(chapman_enskog_hierarchy, self.f_syms):
new_eq = -1 / self.collisionOpSym * (ceEq - self.collisionOpSym * f_i)
for ce_eq, f_i in zip(chapman_enskog_hierarchy, self.f_syms):
new_eq = -1 / self.collision_op_sym * (ce_eq - self.collision_op_sym * f_i)
raw_hierarchy.append(new_eq)
new_eq = expand_using_linearity(new_eq.subs(substitution_dict), functions=self.f_syms + [self.force_sym])
if new_eq:
......@@ -110,14 +110,14 @@ class SteadyStateChapmanEnskogAnalysis:
eq = sp.expand(self.velocity_syms[coordinate] * recombined_eq)
result = self._compute_moments(eq, symbols_to_values)
if self.force_model and hasattr(self.force_model, 'equilibriumVelocityShift'):
if self.force_model and hasattr(self.force_model, 'equilibrium_velocity_shift'):
compressible = self.method.conserved_quantity_computation.compressible
shift = self.force_model.equilibriumVelocityShift(sp.Symbol("rho") if compressible else 1)
shift = self.force_model.equilibrium_velocity_shift(sp.Symbol("rho") if compressible else 1)
result += shift[coordinate]
return result
def _get_symbols_to_values_dict(self):
result = {1 / self.collisionOpSym: self.method.inverse_collision_matrix,
result = {1 / self.collision_op_sym: self.method.inverse_collision_matrix,
self.force_sym: sp.Matrix(self.force_model(self.method)) if self.force_model else 0,
self.f_syms[0]: self.method.get_equilibrium_terms()}
for i, c_i in enumerate(self.velocity_syms):
......@@ -163,7 +163,7 @@ class SteadyStateChapmanEnskogAnalysis:
new_products.append(new_prod)
return normalize_diff_order(expand_using_linearity(sp.Add(*new_products), functions=self.physicalVariables))
return normalize_diff_order(expand_using_linearity(sp.Add(*new_products), functions=self.physical_variables))
# ----------------------------------------------------------------------------------------------------------------------
......
......@@ -20,7 +20,7 @@ def moment_generating_function(generating_function, symbols, symbols_in_result):
:param generating_function: sympy expression
:param symbols: a sequence of symbols forming the vector x
:param symbols_in_result: a sequence forming the vector t
:return: transformation result F: an expression that depends now on symbolsInResult
:return: transformation result F: an expression that depends now on symbols_in_result
(symbols have been integrated out)
.. note::
......
......@@ -90,11 +90,11 @@ Simplifications / Transformations:
Field size information:
- ``pdfArr=None``: pass a numpy array here to create kernels with fixed size and create the loop nest according to layout
of this array
- ``pdf_arr=None``: pass a numpy array here to create kernels with fixed size and create the loop nest according
to layout of this array
- ``field_size=None``: create kernel for fixed field size
- ``field_layout='c'``: ``'c'`` or ``'numpy'`` for standard numpy layout, ``'reverseNumpy'`` or ``'f'`` for fortran
layout, this does not apply when pdfArr was given, then the same layout as pdfArr is used
- ``field_layout='c'``: ``'c'`` or ``'numpy'`` for standard numpy layout, ``'reverse_numpy'`` or ``'f'`` for fortran
layout, this does not apply when pdf_arr was given, then the same layout as pdf_arr is used
GPU:
......@@ -102,7 +102,7 @@ GPU:
and installed *pycuda* package
- ``gpu_indexing='block'``: determines mapping of CUDA threads to cells. Can be either ``'block'`` or ``'line'``
- ``gpu_indexing_params='block'``: parameters passed to init function of gpu indexing.
For ``'block'`` indexing one can e.g. specify the block size ``{'blockSize' : (128, 4, 1)}``
For ``'block'`` indexing one can e.g. specify the block size ``{'block_size' : (128, 4, 1)}``
Other:
......@@ -173,10 +173,10 @@ from lbmpy.updatekernels import StreamPullTwoFieldsAccessor, PeriodicTwoFieldsAc
def create_lb_function(ast=None, optimization={}, **kwargs):
params, optParams = update_with_default_parameters(kwargs, optimization)
params, opt_params = update_with_default_parameters(kwargs, optimization)
if ast is None:
params['optimization'] = optParams
params['optimization'] = opt_params
ast = create_lb_ast(**params)
res = ast.compile()
......@@ -279,7 +279,7 @@ def create_lb_collision_rule(lb_method=None, optimization={}, **kwargs):
if params['velocity_input'] is not None:
eqs = [Assignment(cqc.zeroth_order_moment_symbol, sum(lb_method.pre_collision_pdf_symbols))]
velocity_field = params['velocity_input']
eqs += [Assignment(uSym, velocity_field(i)) for i, uSym in enumerate(cqc.first_order_moment_symbols)]
eqs += [Assignment(u_sym, velocity_field(i)) for i, u_sym in enumerate(cqc.first_order_moment_symbols)]
eqs = AssignmentCollection(eqs, [])
collision_rule = lb_method.get_collision_rule(conserved_quantity_equations=eqs)
else:
......@@ -366,7 +366,7 @@ def create_lb_method_from_existing(method, modification_function):
Args:
method: old method
modification_function: function receiving (moment, equilibriumValue, relaxation_rate) as arguments,
modification_function: function receiving (moment, equilibrium_value, relaxation_rate) as arguments,
i.e. one row of the relaxation table, returning a modified version
"""
relaxation_table = (modification_function(m, eq, rr)
......@@ -463,7 +463,7 @@ def update_with_default_parameters(params, opt_params=None, fail_on_unknown_para
'split': False,
'field_size': None,
'field_layout': 'fzyx', # can be 'numpy' (='c'), 'reverseNumpy' (='f'), 'fzyx', 'zyxf'
'field_layout': 'fzyx', # can be 'numpy' (='c'), 'reverse_numpy' (='f'), 'fzyx', 'zyxf'
'symbolic_field': None,
'target': 'cpu',
......
......@@ -52,7 +52,7 @@ def __cumulant_raw_moment_transform(index, dependent_var_dict, outer_function, d
index: tuple describing the index of the cumulant/moment to express as function of moments/cumulants
dependent_var_dict: a dictionary from index tuple to moments/cumulants symbols, or None to use default symbols
outer_function: logarithm to transform from moments->cumulants, exp for inverse direction
default_prefix: if dependentVarDict is None, this is used to construct symbols of the form prefix_i_j_k
default_prefix: if dependent_var_dict is None, this is used to construct symbols of the form prefix_i_j_k
centralized: if True the first order moments/cumulants are set to zero
"""
dim = len(index)
......@@ -74,8 +74,8 @@ def __cumulant_raw_moment_transform(index, dependent_var_dict, outer_function, d
# index (2,1,0) means differentiate twice w.r.t to first variable, and once w.r.t to second variable
# this is transformed here into representation [0,0,1] such that each entry is one diff operation
partition_list = []
for i, indexComponent in enumerate(index):
for j in range(indexComponent):
for i, index_component in enumerate(index):
for j in range(index_component):
partition_list.append(i)
if len(partition_list) == 0: # special case for zero index
......
......@@ -68,22 +68,22 @@ class PeriodicTwoFieldsAccessor(PdfFieldAccessor):
for i, d in enumerate(stencil):
pull_direction = inverse_direction(d)
periodic_pull_direction = []
for coordId, dirElement in enumerate(pull_direction):
if not self._periodicity[coordId]:
periodic_pull_direction.append(dirElement)
for coord_id, dir_element in enumerate(pull_direction):
if not self._periodicity[coord_id]:
periodic_pull_direction.append(dir_element)
continue
lower_limit = self._ghostLayers
upper_limit = field.spatial_shape[coordId] - 1 - self._ghostLayers
upper_limit = field.spatial_shape[coord_id] - 1 - self._ghostLayers
limit_diff = upper_limit - lower_limit
loop_counter = LoopOverCoordinate.get_loop_counter_symbol(coordId)
if dirElement == 0:
loop_counter = LoopOverCoordinate.get_loop_counter_symbol(coord_id)
if dir_element == 0:
periodic_pull_direction.append(0)
elif dirElement == 1:
new_dir_element = sp.Piecewise((dirElement, loop_counter < upper_limit), (-limit_diff, True))
elif dir_element == 1:
new_dir_element = sp.Piecewise((dir_element, loop_counter < upper_limit), (-limit_diff, True))
periodic_pull_direction.append(new_dir_element)
elif dirElement == -1:
new_dir_element = sp.Piecewise((dirElement, loop_counter > lower_limit), (limit_diff, True))
elif dir_element == -1:
new_dir_element = sp.Piecewise((dir_element, loop_counter > lower_limit), (limit_diff, True))
periodic_pull_direction.append(new_dir_element)
else:
raise NotImplementedError("This accessor supports only nearest neighbor stencils")
......@@ -127,9 +127,9 @@ def visualize_field_mapping(axes, stencil, field_mapping, color='b'):
from lbmpy.plot2d import LbGrid
grid = LbGrid(3, 3)
grid.fill_with_default_arrows()
for fieldAccess, direction in zip(field_mapping, stencil):
field_position = stencil[fieldAccess.index[0]]
neighbor = fieldAccess.offsets
for field_access, direction in zip(field_mapping, stencil):
field_position = stencil[field_access.index[0]]
neighbor = field_access.offsets
grid.add_arrow((1 + neighbor[0], 1 + neighbor[1]),
arrow_position=field_position, arrow_direction=direction, color=color)
grid.draw(axes)
......
......@@ -110,14 +110,14 @@ class Simple(object):
def __call__(self, lb_method, **kwargs):
assert len(self._force) == lb_method.dim
def scalarProduct(a, b):
def scalar_product(a, b):
return sum(a_i * b_i for a_i, b_i in zip(a, b))
return [3 * w_i * scalarProduct(self._force, direction)
return [3 * w_i * scalar_product(self._force, direction)
for direction, w_i in zip(lb_method.stencil, lb_method.weights)]
def macroscopic_velocity_shift(self, density):
return defaultVelocityShift(density, self._force)
return default_velocity_shift(density, self._force)
class Luo(object):
......@@ -139,7 +139,7 @@ class Luo(object):
return result
def macroscopic_velocity_shift(self, density):
return defaultVelocityShift(density, self._force)
return default_velocity_shift(density, self._force)
class Guo(object):
......@@ -153,15 +153,15 @@ class Guo(object):
def __call__(self, lb_method):
luo = Luo(self._force)
shearRelaxationRate = get_shear_relaxation_rate(lb_method)
correctionFactor = (1 - sp.Rational(1, 2) * shearRelaxationRate)
return [correctionFactor * t for t in luo(lb_method)]
shear_relaxation_rate = get_shear_relaxation_rate(lb_method)
correction_factor = (1 - sp.Rational(1, 2) * shear_relaxation_rate)
return [correction_factor * t for t in luo(lb_method)]
def macroscopic_velocity_shift(self, density):
return defaultVelocityShift(density, self._force)
return default_velocity_shift(density, self._force)
def equilibriumVelocityShift(self, density):
return defaultVelocityShift(density, self._force)
def equilibrium_velocity_shift(self, density):
return default_velocity_shift(density, self._force)
class Buick(object):
......@@ -176,15 +176,15 @@ class Buick(object):
def __call__(self, lb_method, **kwargs):
simple = Simple(self._force)
shearRelaxationRate = get_shear_relaxation_rate(lb_method)
correctionFactor = (1 - sp.Rational(1, 2) * shearRelaxationRate)
return [correctionFactor * t for t in simple(lb_method)]
shear_relaxation_rate = get_shear_relaxation_rate(lb_method)
correction_factor = (1 - sp.Rational(1, 2) * shear_relaxation_rate)
return [correction_factor * t for t in simple(lb_method)]
def macroscopic_velocity_shift(self, density):
return defaultVelocityShift(density, self._force)
return default_velocity_shift(density, self._force)
def equilibriumVelocityShift(self, density):
return defaultVelocityShift(density, self._force)
def equilibrium_velocity_shift(self, density):
return default_velocity_shift(density, self._force)
class EDM(object):
......@@ -198,18 +198,18 @@ class EDM(object):
rho = cqc.zeroth_order_moment_symbol if cqc.compressible else 1
u = cqc.first_order_moment_symbols
shiftedU = (u_i + f_i / rho for u_i, f_i in zip(u, self._force))
eqTerms = lb_method.get_equilibrium_terms()
shiftedEq = eqTerms.subs({u_i: su_i for u_i, su_i in zip(u, shiftedU)})
return shiftedEq - eqTerms
shifted_u = (u_i + f_i / rho for u_i, f_i in zip(u, self._force))
eq_terms = lb_method.get_equilibrium_terms()
shifted_eq = eq_terms.subs({u_i: su_i for u_i, su_i in zip(u, shifted_u)})
return shifted_eq - eq_terms
def macroscopic_velocity_shift(self, density):
return defaultVelocityShift(density, self._force)
return default_velocity_shift(density, self._force)
# -------------------------------- Helper functions ------------------------------------------------------------------
def defaultVelocityShift(density, force):
def default_velocity_shift(density, force):
return [f_i / (2 * density) for f_i in force]
......@@ -87,8 +87,8 @@ def add_pipe(boundary_handling, diameter, boundary=NoSlip()):
:param boundary_handling: boundary handling object, works for serial and parallel versions
:param diameter: pipe diameter, can be either a constant value or a callback function.
the callback function has the signature (xCoordArray, domainShapeInCells) andp has to return
a array of same shape as the received xCoordArray, with the diameter for each x position
the callback function has the signature (x_coord_array, domain_shape_in_cells) and has to return
a array of same shape as the received x_coord_array, with the diameter for each x position
:param boundary: boundary object that is set at the wall, defaults to NoSlip (bounce back)
"""
domain_shape = boundary_handling.shape
......
......@@ -18,7 +18,7 @@ class LatticeBoltzmannStep:
kernel_params=MappingProxyType({}), data_handling=None, name="lbm", optimization=None,
velocity_data_name=None, density_data_name=None, density_data_index=None,
compute_velocity_in_every_step=False, compute_density_in_every_step=False,
velocity_input_array_name=None, time_step_order='streamCollide', flag_interface=None,
velocity_input_array_name=None, time_step_order='stream_collide', flag_interface=None,
**method_parameters):
# --- Parameter normalization ---
......@@ -87,10 +87,10 @@ class LatticeBoltzmannStep:
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
if time_step_order == 'streamCollide':
if time_step_order == 'stream_collide':
self._lbmKernels = [create_lb_function(optimization=optimization,
**method_parameters)]
elif time_step_order == 'collideStream':
elif time_step_order == 'collide_stream':
self._lbmKernels = [create_lb_function(optimization=optimization,
kernel_type='collide_only',
**method_parameters),
......@@ -224,9 +224,9 @@ class LatticeBoltzmannStep:
self._data_handling.to_cpu(self._pdf_arr_name)
self._data_handling.run_kernel(self._getterKernel, **self.kernel_params)
def run(self, timeSteps):
def run(self, time_steps):
self.pre_run()
for i in range(timeSteps):
for i in range(time_steps):
self.time_step()
self.post_run()
......
......@@ -3,57 +3,59 @@ from pystencils.field import Field, get_layout_of_array
from lbmpy.simplificationfactory import create_simplification_strategy
def compileMacroscopicValuesGetter(lb_method, outputQuantities, pdfArr=None, field_layout='numpy', target='cpu'):
def compile_macroscopic_values_getter(lb_method, output_quantities, pdf_arr=None, field_layout='numpy', target='cpu'):
"""
Create kernel to compute macroscopic value(s) from a pdf field (e.g. density or velocity)
:param lb_method: instance of :class:`lbmpy.methods.AbstractLbMethod`
:param outputQuantities: sequence of quantities to compute e.g. ['density', 'velocity']
:param pdfArr: optional numpy array for pdf field - used to get optimal loop structure for kernel
:param field_layout: layout for output field, also used for pdf field if pdfArr is not given
:param output_quantities: sequence of quantities to compute e.g. ['density', 'velocity']
:param pdf_arr: optional numpy array for pdf field - used to get optimal loop structure for kernel
:param field_layout: layout for output field, also used for pdf field if pdf_arr is not given
:param target: 'cpu' or 'gpu'
:return: a function to compute macroscopic values:
- pdf_array
- keyword arguments from name of conserved quantity (as in outputQuantities) to numpy field
- keyword arguments from name of conserved quantity (as in output_quantities) to numpy field
"""
if not (isinstance(outputQuantities, list) or isinstance(outputQuantities, tuple)):
outputQuantities = [outputQuantities]
if not (isinstance(output_quantities, list) or isinstance(output_quantities, tuple)):
output_quantities = [output_quantities]
cqc = lb_method.conserved_quantity_computation
unknownQuantities = [oq for oq in outputQuantities if oq not in cqc.conserved_quantities]
if unknownQuantities:
unknown_quantities = [oq for oq in output_quantities if oq not in cqc.conserved_quantities]
if unknown_quantities:
raise ValueError("No such conserved quantity: %s, conserved quantities are %s" %
(str(unknownQuantities), str(cqc.conserved_quantities.keys())))
(str(unknown_quantities), str(cqc.conserved_quantities.keys())))
if pdfArr is None:
pdfField = Field.create_generic('pdfs', lb_method.dim, index_dimensions=1, layout=field_layout)
if pdf_arr is None:
pdf_field = Field.create_generic('pdfs', lb_method.dim, index_dimensions=1, layout=field_layout)
else:
pdfField = Field.create_from_numpy_array('pdfs', pdfArr, index_dimensions=1)
pdf_field = Field.create_from_numpy_array('pdfs', pdf_arr, index_dimensions=1)
outputMapping = {}
for outputQuantity in outputQuantities: