lgca.lgca_3dmoore.LGCA_3dMoore

class lgca.lgca_3dmoore.LGCA_3dMoore(nodes=None, dims=None, restchannels=0, density=0.1, bc='periodic', seed=None, propagation=True, **kwargs)

Bases: LGCA_Cubic

Classical LGCA on a 3D Moore lattice.

animate_density(density_t=None, colormap='viridis', opacity=0.5, cbar=True, interval=100, **kwargs)

Animate the density surface over time using Mayavi.

Parameters:
  • density_t (np.ndarray, optional) – Time series of density states. Shape: (time, lx, ly, lz).

  • threshold (float, default=0.5) – Density threshold for surface plotting.

  • colormap (str, default='viridis') – Colormap for the surface.

  • opacity (float, default=0.5) – Opacity of the surface.

  • interval (int, default=100) – Delay between frames in milliseconds.

  • **kwargs – Additional arguments passed to mlab.contour3d.

Returns:

animate_flux(nodes_t=None, scale_factor=1.0, opacity=0.6, interval=100, cbar=False, **kwargs)

Animate the flux vectors over time in the 3D lattice using Mayavi.

Parameters:
  • nodes_t (np.ndarray, optional) – Time series of node states. Shape: (time, lx, ly, lz, K).

  • scale_factor (float, default=1.0) – Scaling factor for the arrows.

  • opacity (float, default=0.6) – Opacity of the flux vectors.

  • interval (int, default=100) – Delay between frames in milliseconds.

  • **kwargs – Additional arguments passed to mlab.quiver3d.

Returns:

apply_abc()

Apply absorbing boundary conditions.

Update self.nodes, using the shadow border nodes and respecting the geometry.

apply_inflowbc()

Apply inflow boundary conditions.

Update self.nodes, using the shadow border nodes and respecting the geometry.

apply_pbc()

Apply periodic boundary conditions.

Update self.nodes, using the shadow border nodes and respecting the geometry.

apply_rbc()

Apply reflecting boundary conditions.

Update self.nodes, using the shadow border nodes and respecting the geometry.

c = array([[-1., -1., -1., -1., -1., -1., -1., -1., -1.,  0.,  0.,  0.,  0.,          0.,  0.,  0.,  0.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.],        [-1., -1., -1.,  0.,  0.,  0.,  1.,  1.,  1., -1., -1., -1.,  0.,          0.,  1.,  1.,  1., -1., -1., -1.,  0.,  0.,  0.,  1.,  1.,  1.],        [-1.,  0.,  1., -1.,  0.,  1., -1.,  0.,  1., -1.,  0.,  1., -1.,          1., -1.,  0.,  1., -1.,  0.,  1., -1.,  0.,  1., -1.,  0.,  1.]])
calc_flux(nodes)

Calculate the flux vector for all lattice sites in nodes.

The elements of the flux vectors are computed as the dot product between the LGCA’s neighborhood vectors and the velocity channel configuration in nodes.

Parameters:

nodes (numpy.ndarray) – Lattice configuration to compute the flux for. Must have more than or the same number of dimensions as self.nodes and nodes.shape[-1] >= self.velocitychannels. Is typically self.nodes.

Returns:

Array of flux vectors at each lattice site. Dimensions: nodes.shape[:-1] + (len(self.c),).

calc_permutations()

Initialize lazy computation structures for permutations. Only compute permutations when actually needed.

channel_weight(qty)

Compute neighbour weights for interaction fields.

cix = array([-1., -1., -1., -1., -1., -1., -1., -1., -1.,  0.,  0.,  0.,  0.,         0.,  0.,  0.,  0.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.])
ciy = array([-1., -1., -1.,  0.,  0.,  0.,  1.,  1.,  1., -1., -1., -1.,  0.,         0.,  1.,  1.,  1., -1., -1., -1.,  0.,  0.,  0.,  1.,  1.,  1.])
ciz = array([-1.,  0.,  1., -1.,  0.,  1., -1.,  0.,  1., -1.,  0.,  1., -1.,         1., -1.,  0.,  1., -1.,  0.,  1., -1.,  0.,  1., -1.,  0.,  1.])
get_flux_permutations(n_particles)

Get flux permutations for n_particles.

get_permutations(n_particles)

Get permutations for n_particles.

Parameters:

n_particles (int) – Number of occupied channels.

Returns:

Array of permutations for n_particles.

gradient(qty)

Return the spatial gradient of qty.

init_coords()

Initialize LGCA coordinates for a 3D cubic lattice.

init_nodes(density=0.1, nodes=None, **kwargs)

Initialize LGCA lattice configuration. Create the lattice and then assign particles to channels in the nodes.

Initializes self.nodes. If nodes is not provided, the lattice is initialized randomly so that each node contains on average density particles.

Parameters:
  • density (float, default=0.1) – If nodes is None, initialize lattice randomly with this average number of particles per node.

  • nodes (numpy.ndarray) – Custom initial lattice configuration. Dimensions: (self.lx, self.ly, self.lz, self.K).

See also

base.LGCA_base.random_reset

Initialize lattice nodes with average density density.

set_dims

Set LGCA dimensions.

init_coords

Initialize LGCA coordinates.

live_animate_density(**kwargs)

Live plot a 3D density surface based on a specified threshold using Mayavi.

Parameters:
  • threshold (float, default=0.5) – Density threshold for surface plotting.

  • colormap (str, default='viridis') – Colormap for the surface.

  • opacity (float, default=0.5) – Opacity of the surface.

  • **kwargs – Additional arguments passed to mlab.contour3d.

Returns:

live_animate_flux(scale_factor=1.0, opacity=0.5, cbar=False, **kwargs)

Live plot the flux vectors in the 3D lattice using Mayavi.

This method updates the plot in real-time as the simulation progresses.

Parameters:
  • scale_factor (float, default=1.0) – Scaling factor for the arrows.

  • opacity (float, default=0.6) – Opacity of the flux vectors.

  • **kwargs – Additional arguments passed to mlab.quiver3d.

Returns:

Mayavi quiver3d object.

nb_sum(qty)

Sum values of qty in the 26-neighbourhood of each node.

plot_density(density=None, colormap='viridis', opacity=0.5, cbar=True, **kwargs)

Plot a 3D surface based on the local density using a specified threshold using Mayavi.

Parameters:
  • threshold (float, default=0.5) – Density threshold for surface plotting.

  • colormap (str, default='viridis') – Colormap for the surface.

  • opacity (float, default=0.5) – Opacity of the surface.

  • **kwargs – Additional arguments passed to mlab.contour3d.

Returns:

Mayavi contour3d object.

plot_density_cubes(density=None, colormap='viridis', opacity=0.5, cbar=True, **kwargs)

Plot a 3D surface based on the local density using a specified threshold using Mayavi.

Parameters:
  • threshold (float, default=0.5) – Density threshold for surface plotting.

  • colormap (str, default='viridis') – Colormap for the surface.

  • opacity (float, default=0.5) – Opacity of the surface.

  • **kwargs – Additional arguments passed to mlab.contour3d.

Returns:

Mayavi contour3d object.

plot_flux(nodes=None, scale_factor=1.0, opacity=0.5, cbar=False, **kwargs)

Plot the local flux vectors in the 3D lattice using Mayavi.

Parameters:
  • nodes (np.ndarray, optional) – State of the lattice. If None, uses self.nodes.

  • scale_factor (float, default=1.0) – Scaling factor for the arrows.

  • color (str or tuple, default='blue') – Color of the flux vectors.

  • opacity (float, default=0.6) – Opacity of the flux vectors.

  • **kwargs – Additional arguments passed to mlab.quiver3d.

Returns:

Mayavi quiver3d object.

plot_scalarfield(field, mask=None, colormap='viridis', opacity=0.5, cbar=True, cbarlabel='Scalar field', vmin=None, vmax=None, **kwargs)

Plot a 3D scalar field using Mayavi. Parameters ———- field mask colormap opacity cbar kwargs

Returns:

print_interactions()

Print the list of pre-implemented interactions for this LGCA type.

print_nodes()

Print the full lattice configuration as integers.

propagation()

Move particles according to their velocity channels.

random_reset(density)

Randomly fill channels so that each node has on average density particles.

Each channel is independently occupied with probability density / self.K.

Parameters:

density (float) – Desired average number of particles per node. density = total_number_of_particles / number_of_nodes.

set_bc(bc)

Set the boundary conditions.

Selects a method which is called every timestep to enforce boundary conditions. The methods to select from are implemented in the derived classes. The chosen one is assigned to self.apply_boundaries().

Parameters:

bc ({'absorbing', 'reflecting', 'periodic', 'inflow'}) – Boundary conditions. Not all bc are supported in all geometries (yet).

set_dims(dims=None, nodes=None, restchannels=0, capacity=None)

Set LGCA dimensions.

Initializes self.K, self.restchannels, self.dims, self.lx, self.ly, and self.lz.

Parameters:
  • dims (tuple of int, default=(10, 10, 10)) – Lattice dimensions. Must match with specified geometry.

  • nodes (numpy.ndarray) – Custom initial lattice configuration.

  • restchannels (int, default=0) – Number of resting channels.

See also

init_nodes

Initialize LGCA lattice configuration.

init_coords

Initialize LGCA coordinates.

set_interaction(**kwargs)

Set the interaction rule and respective needed parameters.

Set self.interaction and possibly add entries in self.interaction_params. Do not use this to specify a custom interaction. In order to do this (as of now), self.interaction and self.interaction_params must be manipulated directly from an external script.

Parameters:
  • kwargs['interaction'] (str, default='random_walk') – Name of the predefined interaction in lgca.interactions.

  • **kwargs – Interaction parameters.

set_r_int(r)

Change the interaction radius. Update shadow border nodes accordingly.

This has effects on self.nodes, the coordinates and the computed fields.

Parameters:

r (int) – New interaction radius.

timeevo(timesteps=100, record=False, recordN=False, recorddens=True, showprogress=True, recordpertype=False)

Perform a simulation of the LGCA for timesteps timesteps.

Different quantities can be recorded during the simulation, e.g. the total number of particles at each timestep. They are stored in LGCA attributes.

Parameters:
  • timesteps (int, default=100) – How long the simulation should be performed.

  • record (bool, default=False) – Record the full lattice configuration for each timestep in self.nodes_t.

  • recorddens (bool, default=True) – Record the number of particles at each lattice site for each timestep in self.dens_t.

  • recordN (bool, default=False) – Record the total number of particles in the lattice for each timestep in self.n_t.

  • recordpertype (bool, default=False) – Record the number of particles in velocity channels/resting channels at each lattice site for each timestep in self.velcells_t and self.restcells_t, respectively.

  • showprogress (bool, default=True) – Show a simple progress bar with a percentage of performed timesteps in the standard output.

timestep()

Update the state of the LGCA from time k to k+1. Includes the interaction and propagation steps.

total_population()

Calculate the amount of particles in the lattice.

Returns:

Total population size.

update_dynamic_fields()

Update “fields” from the current LGCA state that store important variables to compute other dynamic steps.

Computes self.cell_density, number of particles at each lattice node.