lgca.ms_moore.MSLGCA_NoVE_Moore¶
- class lgca.ms_moore.MSLGCA_NoVE_Moore(*, n_species=1, **kwargs)¶
Bases:
MultiSpeciesNoVE_LGCA_base,NoVE_LGCA_Cubic,LGCA_3dMooreNo-volume-exclusion multi-species 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.- Return type:
None
- 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.- Return type:
None
- apply_rbc()¶
Apply reflecting boundary conditions.
Update
self.nodes, using the shadow border nodes and respecting the geometry.- Return type:
None
- 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_entropy(base=None)¶
Calculate entropy of the lattice. :type base: :param base: base of the logarithm, defaults to 2 :return: entropy according to information theory as scalar
- 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 asself.nodesandnodes.shape[-1] >= self.velocitychannels. Is typicallyself.nodes.- Returns:
Array of flux vectors at each lattice site. Dimensions:
nodes.shape[:-1] + (len(self.c),).
- calc_mean_alignment()¶
Calculate the mean alignment measure. The mean alignment is a measure for local alignment of particle orientation in the lattice. It is calculated as the agreement in direction between the flux of a lattice site and the flux of the director field summed up and normalized over all lattice sites. .. note:: This is buggy! :return: Local alignment parameter: ranging from -1 (antiparallel alignment) through 0 (no alignment) to 1 (parallel alignment)
- calc_normalized_entropy(base=None)¶
Calculate entropy of the lattice normalized to maximal possible entropy. :type base: :param base: base of the logarithm, defaults to 2 :return: normalized entropy as scalar
- calc_permutations()¶
Initialize lazy computation structures for permutations. Only compute permutations when actually needed.
- calc_polar_alignment_parameter()¶
Calculate the polar alignment parameter. The polar alignment parameter is a measure for global agreement of particle orientation in the lattice. It is calculated as the magnitude of the sum of the velocities of all particles normalized by the number of particles. :return: Polar alignment parameter of the lattice from 0 (no alignment) to 1 (complete alignment)
- 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. In the implementation, set
self.nodes.Must match what is done in
set_dims()andinit_coords(). For arguments and attribute types seelgca.base.LGCA_base.- Return type:
None
- 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
qtyin the 26-neighbourhood of each node.
- plot_density(density=None, colormap='viridis', opacity=0.5, cbar=True, contours=5, vmax=None, **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()¶
Perform the transport step of the LGCA: Move particles through the lattice according to their velocity.
Propagate the particles by updating
self.nodes, respecting the geometry. Boundary conditions are enforced later byapply_boundaries().- Return type:
None
- random_reset(density)¶
Populate a total density distributed over all species.
- 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=None, capacity=None)¶
Set the dimensions of the instance according to given values.
- Return type:
None
- set_interaction(**kwargs)¶
Set the interaction rule and respective needed parameters.
Set
self.interactionand possibly add entries inself.interaction_params. Do not use this to specify a custom interaction. In order to do this (as of now),self.interactionandself.interaction_paramsmust 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) – How long the simulation should be performed.record (
bool) – Record the full lattice configuration for each timestep inself.nodes_t.recorddens (
bool) – Record the number of particles at each lattice site for each timestep inself.dens_t.recordN (
bool) – Record the total number of particles in the lattice for each timestep inself.n_t.recordpertype (
bool) – Record the number of particles in velocity channels/resting channels at each lattice site for each timestep inself.velcells_tandself.restcells_t, respectively.showprogress (
bool) – Show a simple progress bar with a percentage of performed timesteps in the standard output.
- Return type:
None
- 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.- Return type:
None