jLM.Lattice#

Cythonized lattice manipulation functions

Functions

appendParticle(pLattice, x, y, z, sp)

Add a particle to a lattice site

checkParticle(lattice, targets, mask)

Generate a lattice set to 1 where if a particle in targets is present in at the lattice site, 0 otherwise.

checkSite

Generate a lattice set to 1 where the site type is in targets, 0 otherwise.

countParticlesInLattice(pLattice, sLattice, ...)

Count particles.

countSites

Count number of subvolumes

greedyMesh

Generate a simplified triangle mesh from a binary lattice.

hdf2lmRep(plattice1, plattice0[, txTable])

Convert an HDF5 particle lattice representation to LM native format

latticeHistogram

Compute histogram of particle types.

latticeStatsAll(plattice, slattice)

Compute number of particles in a particular site type, and the number of those site types

latticeStatsAll_h5fmt(plattice, slattice)

Compute number of particles in a particular site type, and the number of those site types

populateLattice

Add particles to lattice at random locations.

jLM.Lattice.appendParticle(pLattice, x, y, z, sp)#

Add a particle to a lattice site

Parameters:
  • plattice (numpy.ndarray) – Particle lattice (H5 format: shape=(nw,nz,ny,nz,np), dtype=uint8/uint32)

  • x (int) – x coordinate

  • y (int) – y coordinate

  • z (int) – z coordinate

  • sp (uint64) – Species type

Returns:

1 if added, 0 if site full

Return type:

int

jLM.Lattice.checkParticle(lattice, targets, mask)#

Generate a lattice set to 1 where if a particle in targets is present in at the lattice site, 0 otherwise.

Parameters:
  • lattice (uint8/uint32[:,:,:,:]) – Particle lattice.

  • targets (unsigned char[:]) – List of particle types to flag.

  • mask (long int[:,:,:]) – Output lattice (preallocated)

jLM.Lattice.checkSite()#

Generate a lattice set to 1 where the site type is in targets, 0 otherwise.

Parameters:
  • sites (unsigned char[:,:,:]) – Site lattice.

  • targets (unsigned char[:]) – List of site types to flag.

  • mask (long int[:,:,:]) – Output lattice (preallocated)

jLM.Lattice.countParticlesInLattice(pLattice, sLattice, spIdList, regIdList)#

Count particles.

Given a list of region ids and species ids, count all particles of those types within those regions.

Parameters:
  • pLattice (numpy.ndarray) – Particle lattice (HDF5 format, shape=(nx,ny,nz,pps))

  • sLattice (numpy.ndarray) – Site lattice (shape=(nx,ny,nz))

  • spIdList (numpy.ndarray) – List of particle ids to count (shape=(nsps,))

  • regIdList (numpy.ndarray) – List of region ids to consider (shape=(nreg,))

Returns:

Count

Return type:

int

jLM.Lattice.countSites()#

Count number of subvolumes

Parameters:

slattice (numpy.ndarray) – Site lattice

Returns:

Ndarray of shape=(256,) counting the number of site of each type

Return type:

numpy.ndarray

jLM.Lattice.greedyMesh()#

Generate a simplified triangle mesh from a binary lattice.

Parameters:

binaryLattice (numpy.ndarray) – Site lattice. One if site occupied, zero otherwise. (shape=(nx,ny,nz), dtype=uint8)

Returns:

Vertices (shape=(nverts,3), dtype=int32), and faces, each element which indexes into verticies. (shape=(nfaces, 3), dtype=uint8).

Return type:

(numpy.ndarray, numpy.ndarray)

Todo

The correct winding order is not always chosen.

jLM.Lattice.hdf2lmRep(plattice1, plattice0, txTable=None)#

Convert an HDF5 particle lattice representation to LM native format

Parameters:
  • plattice1 (numpy.ndarray) – Output LM format (dtype=uint8/uint32, shape=(nw,nz,ny,nx,np))

  • plattice0 (numpy.ndarray) – Input HDF5 format (dtype=uint8/uint32, shape=(nx,ny,nz,nw*np))

Keyword Arguments:

txTable (numpy.ndarray) – Optional particle id translation table: lmNative = txTable[h5Native]

jLM.Lattice.latticeHistogram()#

Compute histogram of particle types.

Parameters:
  • src (numpy.ndarray) – Result array, contains the number of particles at each lattice site in idxs. (shape=(nx,ny,nz,pps), dtype=uint8)

  • idxs (numpy.ndarray) – List of particle types to bin (shape=(nparticles,), dtype=int32)

Keyword Arguments:
  • axes (list) – Axis indexes to sum out (shape=(naxes,), dtype=int32)

  • target – Output array. None or an numpy.ndarray of the proper size

Returns:

New ndarray or reference to target

Return type:

numpy.ndarray

jLM.Lattice.latticeStatsAll(plattice, slattice)#

Compute number of particles in a particular site type, and the number of those site types

Parameters:
  • plattice (numpy.ndarray) – Particle lattice (shape=(nw,nz,ny,nx,np), dtype=uint8/uint32)

  • slattice (numpy.ndarray) – Site lattice (HDF5 format: shape=(nz,ny,nx), dtype=uint8)

Returns:

Number of particles, number of sites

Return type:

(numpy.ndarray,:py:class:numpy.ndarray)

jLM.Lattice.latticeStatsAll_h5fmt(plattice, slattice)#

Compute number of particles in a particular site type, and the number of those site types

Parameters:
  • plattice (numpy.ndarray) – Particle lattice (H5 format: shape=(nx,ny,nz,pps), dtype=uint8/uint32)

  • slattice (numpy.ndarray) – Site lattice (HDF5 format: shape=(nx,ny,nz), dtype=uint8)

Returns:

Number of particles, number of sites

Return type:

(numpy.ndarray,:py:class:numpy.ndarray)

jLM.Lattice.populateLattice()#

Add particles to lattice at random locations.

The particleDensityView argument is a \(N_{siteTypes}\times N_{particleTypes}\) array of slot occupancy probabilities. It describes the probability to find a particle type (including empty==0) at a particular particle slot.

Parameters:
  • pLattice (numpy.ndarray) – Particle lattice (H5 format, shape=(nw,nz,ny,nx,np), dtype=uint8/uint32)

  • sLattice (numpy.ndarray) – Site lattice (H5 format, shape=(nz,ny,nx), dtype=uint8)

  • particleDensity (numpy.ndarray) – Particle probability, (shape=(Nsites,Nsps), dtype=float64)

Keyword Arguments:
  • exact (bool) – If True, make a second pass that corrects the particle counts exactly

  • mask (numpy.ndarray) – Boolean mask to set region of lattice to populate, None (default) populates the entire lattice