API

Simulation

Lattices

Stencils

Streaming

Collision

Observables

Reporters

Force

Equilibrium

Boundary

Flows

Couette

Poiseuille

Taylor-Green

Decaying-Turbulence

Obstacle

Utility

Utility functions.

exception lettuce.util.ExperimentalWarning[source]

Bases: LettuceWarning

class lettuce.util.HDF5Reporter(flow, collision, interval, filebase='./output', metadata=None)[source]

Bases: Reporter

HDF5 _reporter for distribution function f in lettuce containing metadata of the simulation.

Parameters:
  • filebase (string) – Path to the hdf5 file with annotations.

  • metadata (dictionary) – Optional metadata can be saved. The passed values must be of type string. >>> metadata = {“attr_1”: “str_value_1”, “attr_2”: “str_value_2”}

  • interval (integer) – Define the step interval after the _reporter is applied. The _reporter will save f every “interval” step.

Examples

Create a HDF5 _reporter. >>> import lettuce as lt >>> context = Context() >>> flow = lt.TaylorGreenVortex(context, [50, 50], 300, 0.1) >>> _collision = … >>> simulation = … >>> hdf5_reporter = lt.HDF5Reporter( >>> context=context, >>> flow=flow, >>> _collision=_collision, >>> interval= 100, >>> filebase=”./h5_output”) >>> simulation.reporters.append(hdf5_reporter)

exception lettuce.util.InefficientCodeWarning[source]

Bases: LettuceWarning

class lettuce.util.LettuceDataset(filebase, transform=None, target=False, skip_idx_to_target=1)[source]

Bases: Dataset

Custom dataset for HDF5 files in lettuce that can be used by torch’s

dataloader.

Parameters:
  • filebase (string) – Path to the hdf5 file with annotations.

  • transform (class object) – Optional transform to be applied on a f loaded from HDF5 file.

  • target (logical operation (True, False)) – Returns also the next dataset[idx + skip_idx_to_target] - default=False

  • skip_idx_to_target (integer) – Define which next target dataset is returned if target is True - default=1

Examples

Create a data loader. >>> import lettuce as lt >>> import torch >>> lattice = lt.Lattice(lt.D3Q27, device=”cpu”) >>> dataset_train = lt.LettuceDataset(lattice=lattice, >>> filebase= “./hdf5_output.h5”, >>> target=True) >>> train_loader = torch.utils.data.DataLoader(dataset_train, shuffle=True) >>> for (f, target, idx) in train_loader: >>> …

get_attr(attr)[source]
get_data(idx)[source]
exception lettuce.util.LettuceException[source]

Bases: Exception

exception lettuce.util.LettuceWarning[source]

Bases: UserWarning

lettuce.util.append_axes(array, n)[source]
lettuce.util.get_subclasses(cls, module)[source]
lettuce.util.grid_fine_to_coarse(flow: Flow, f_fine, tau_fine, tau_coarse)[source]
lettuce.util.torch_gradient(f, dx=1, order=2)[source]

Function to calculate the first derivative of tensors. Orders O(h²); O(h⁴); O(h⁶) are implemented.

Notes

See [1]. The function only works for periodic domains

References

lettuce.util.torch_jacobi(f, p, dx, dim, tol_abs=1e-10, max_num_steps=100000)[source]

Jacobi solver for the Poisson pressure equation

Command-Line Interface

Console script for lettuce. To get help for terminal commands, open a console and type:

>>>  lettuce --help