Sailfish API

Simulation

Base class for all lattice Boltzman simulations in Sailfish.

class lb_base.LBSim(config)

Describes a specific type of a lattice Boltzmann simulation.

update_context(ctx)

Updates the context dicitionary containing variables used for code generation.

grid

Returns a grid object representing the connectivity of the lattice used in the simulation. If the simulation uses more than 1 grid, returns the grid with the highest connectivity.

nonlocality = 0

How many layers of nearest neighbors nodes are required by the model.

Classes for single fluid lattice Boltzmann simulations.

class lb_single.LBFluidSim(config)

Simulates a single phase fluid.

get_compute_kernels(runner, full_output, bulk)

Args: full_output: if True, returns kernels that prepare fields for

visualization or saving into a file
grid

Grid with the highest connectivity (Q).

class lb_single.LBForcedSim(config)

Adds support for body forces.

add_body_force(force, grid=0, accel=True)

Add a constant global force field acting on the fluid.

Multiple calls to this function will add the value of force to any previously set value. Forces and accelerations are processed separately and are never mixed in this addition process.

Parameters:
  • force – n-vector representing the force value
  • grid – grid number on which this force is acting
  • accel – if True, the added field is an acceleration field, otherwise it is an actual force field

Geometry

Classes to specify global LB simulation geometry and its partitions.

class geo.LBGeometry(config)

Describes the high-level geometry of a LB simulation.

class geo.LBGeometry2D(config)

Describes the high-level 2D geometry of a LB simulation.

blocks()

Returns a 1-element list containing a single 2D block covering the whole domain.

class geo.LBGeometry3D(config)

Describes the high-level 3D geometry of a LB simulation.

blocks()

Returns a 1-element list containing a single 3D block covering the whole domain.

Symbolic computation

Helper code for symbolic processing and RTCG.

class sym.TargetDist

TargetDist(var, idx)

idx

Alias for field number 1

var

Alias for field number 0

sym.bb_swap_pairs(grid)

Get a set of indices which have to be swapped for a full bounce-back.

sym.bgk_equilibrium(grid, rho=None, rho0=None)

Get expressions for the BGK equilibrium distribution.

Parameters:grid – the grid class to be used
Return type:list of sympy epxressions representing the equilibrium distribution functions
sym.bgk_external_force(grid, grid_num=0)

Get expressions for the external body force correction in the BGK model.

This implements the external force as in Eq. 20 from PhysRevE 65, 046308.

Parameters:grid – the grid class to be used
Return type:list of sympy expressions (in the same order as the current grid’s basis)
sym.body_force_accel(i, dim, forces, accel=True)
Parameters:
  • i – grid number
  • forces – forces dictionary (see lbm.py)
  • accel – if True, returns an acceleration expression; returns a force expresssion otherwise
sym.cexpr(sim, incompressible, pointers, ex, rho, aliases=True, vectors=False, phi=None)

Convert a SymPy expression into a string containing valid C code.

Parameters:
  • sim – the main simulation class (descendant of LBMSim)
  • incompressible – if True, use the incompressible model
  • pointers – if True, macroscopic variables (density and velocities) will be converted to pointers in the output
  • ex – the sympy expression to convert
  • rho – density symbol (sympy Symbol, string). If None the standard rho symbol for the grid will be used.
Return type:

string representing the C code

sym.equilibrium_expr(eq, eq_vars)

Substitute any additional variables directly into the expressions for the equilibrium distribution.

Equilibrium distributions can use additional local variables, which are stored in the form of sympy equalities in the second element of the equilibrium pair. If the abliity to directly evalute the equilibrium distribution is required, this function will substitute the local variables into the expressions.

sym.ex_rho(grid, distp, incompressible, missing_dir=None)

Express density as a function of the distributions.

Parameters:
  • distp – name of the pointer to the distribution structure
  • incompressible – if True, an expression for the incompressible model will be returned
  • missing_dir – direction number specified if an expression for a node where not all distributions are known is necessary. This parameter identifies the normal vector pointing towards the fluid (i.e. the distributions in this direction are unknown).
Return type:

sympy expression for the density

sym.ex_velocity(grid, distp, comp, momentum=False, missing_dir=None, par_rho=None)

Express velocity as a function of the distributions.

Parameters:
  • distp – name of the pointer to the distribution structure
  • comp – velocity component number: 0, 1 or 2 (for 3D lattices)
  • momentum – if True, an expression for momentum is returned instead of for velocity
  • missing_dir – direction number specified if an expression for a node where not all distributions are known is necessary. This parameter identifies the normal vector pointing towards the fluid (i.e. the distributions in this direction are unknown).
  • par_rho – name of the variable (a string) containing the externally imposed density (e.g. from a boundary condition)
Return type:

sympy expression for the velocity in a given direction

sym.get_interblock_dists(grid, direction, opposite=False)

Computes a list of indices of the distributions that would be transferred to a node pointed to by the vector ‘direction’.

sym.get_prop_dists(grid, dir_, axis=0)

Compute a list of base vectors with a specific value of the X component (dir).

sym.lambdify_equilibrium(sim)

Get a lambdified version of the equilibrium distribution.

Parameters:sim – a lbm.LBMSim instance
Return type:iterable of Q callables, Q being the number of basis vectors for the grid used in sim
sym.orthogonalize(*vectors)

Ortogonalize a set of vectors.

Given a set of vectors orthogonalize them using the GramSchmidt procedure. The vectors are then simplified (common factors are removed to keep their norm small).

Parameters:vectors – a collection of vectors to orthogonalize
Return type:orthogonalized vectors
sym.poly_factorize(poly)

Factorize multivariate polynomials into a sum of products of monomials.

This function can be used to decompose polynomials into a form which minimizes the number of additions and multiplications, and which thus can be evaluated efficently.

sym.shallow_water_equilibrium(grid)

Get expressions for the BGK equilibrium distribution for the shallow water equation.

Table Of Contents

Previous topic

Drag coefficient of a sphere (3D)

Next topic

About

This Page

External links