Skip to content

List of JustPIC functions

Here an overview of all functions in JustPIC.jl, , for a complete list see here:

JustPIC.AMDGPUBackend Type
julia
AMDGPUBackend

Backend tag for AMDGPU-based array allocation and execution paths.

source
JustPIC.AbstractAdvectionIntegrator Type
julia
AbstractAdvectionIntegrator

Abstract supertype for time integrators used by particle, passive-marker, and marker-chain advection routines.

source
JustPIC.CPUBackend Type
julia
CPUBackend

Backend tag for CPU array allocation and CPU execution paths.

source
JustPIC.Euler Type
julia
Euler()

Forward-Euler advection integrator.

This is the cheapest available integrator and is mainly useful for simple tests or when first-order accuracy is sufficient.

source
JustPIC.MarkerChain Type
julia
MarkerChain{Backend,N,I,T1,T2,T3,TV} <: AbstractParticles

Container for a 2D marker chain used to represent a free surface or topographic interface.

The chain stores current and previous marker coordinates, the topography sampled at grid vertices, and a per-cell activity mask.

Use init_markerchain to create a chain, fill_chain_from_chain! or fill_chain_from_vertices! to overwrite its geometry, and advect_markerchain! to evolve it in time.

source
JustPIC.Particles Type
julia
Particles{Backend, N, I, T1, T2, D, V} <: AbstractParticles

Main particle container used by JustPIC for material points stored cell-by-cell in CellArrays.

coords is an N-tuple of particle-coordinate arrays, index marks which slots are active inside each cell, nxcell is the target initial occupancy per cell, and min_xcell/max_xcell define the occupancy range used by injection and cleanup routines.

Use init_particles to construct this type instead of calling the inner constructor directly.

source
JustPIC.PassiveMarkers Type
julia
PassiveMarkers{Backend,T} <: AbstractParticles

Lightweight particle container for passive tracers that only store coordinates.

Unlike Particles, passive markers do not keep per-cell occupancy metadata and are intended for tracer-style advection and interpolation workflows where the markers do not feed back into the simulation.

Use init_passive_markers to construct this type.

source
JustPIC.PhaseRatios Type
julia
PhaseRatios{Backend,T}

Storage for phase-fraction fields sampled at multiple grid locations.

Depending on dimension, the container holds phase ratios at cell centers, vertices, staggered velocity nodes, and in 3D also at edge midpoints.

The fields store, for each location, the fractional occupancy of each material phase inferred from particle labels.

source
JustPIC.RungeKutta2 Type
julia
RungeKutta2= 0.5)

Second-order Runge-Kutta advection integrator.

The parameter α controls the intermediate stage location and must satisfy 0 < α < 1. The default α = 0.5 corresponds to the midpoint method.

source
JustPIC.RungeKutta4 Type
julia
RungeKutta4()

Classical fourth-order Runge-Kutta advection integrator.

source
JustPIC.TA Method
julia
TA()
TA(backend)

Return the plain array type associated with backend.

For the CPU backend this is Array. Extension packages may add backend-specific definitions for accelerator arrays.

source
JustPIC.cell_length Method
julia
cell_length(chain::MarkerChain)

Return the horizontal cell size of a 2D marker chain.

This is the spacing between consecutive entries in chain.cell_vertices.

source
JustPIC.nphases Method
julia
nphases(x::PhaseRatios)

Return the number of phases in x::PhaseRatios.

This method returns a Val wrapper for the phase count; use numphases when you need the integer directly.

source
JustPIC._2D.SubgridDiffusionCellArrays Type
julia
SubgridDiffusionCellArrays(particles; loc = :vertex)

Allocate scratch storage used by the subgrid thermal diffusion routines.

The returned object stores old particle temperatures, per-particle temperature increments, characteristic diffusion timescales, and a grid-sized accumulation buffer.

loc selects whether the accumulation buffer should match a vertex-based or cell-centered grid layout.

source
JustPIC._2D.PhaseRatios Method
julia
PhaseRatios(T, backend, nphases, ni)
PhaseRatios(backend, nphases, ni)
PhaseRatios(nphases, ni)

Allocate a PhaseRatios container for nphases material phases on a grid of size ni.

The default element type is Float64 and the default backend is CPUBackend.

Arguments

  • T: scalar storage type for the phase fractions.

  • backend: backend type used to allocate the arrays.

  • nphases: number of material phases.

  • ni: number of cells in each spatial direction.

source
JustPIC._2D.advect_markerchain! Method
julia
advect_markerchain!(chain, method, V, grid_vxi, dt)

Advect a marker chain for one time step and rebuild its derived topography data.

This convenience wrapper runs marker advection, reassigns markers to cells, resamples the chain, updates vertex elevations, and enforces mean-height conservation.

Use this when evolving a free surface or interface represented by a MarkerChain.

source
JustPIC._2D.advection! Method
julia
advection!(particles::Particles, method::AbstractAdvectionIntegrator, V, grid_vi::NTuple{N,NTuple{N,T}}, dt)

Advect particles through the staggered velocity field V over a time step dt.

grid_vi contains the coordinate tuples associated with each staggered velocity component. The particle coordinates are updated in place.

Arguments

  • particles: Particles container to advect.

  • method: time integrator such as Euler(), RungeKutta2(), or RungeKutta4().

  • V: tuple of staggered velocity component arrays.

  • grid_vi: tuple of coordinate tuples matching the staggering of V.

  • dt: timestep.

source
JustPIC._2D.advection! Method
julia
advection!(chain::MarkerChain, method, V, grid_vi, dt)

Advect the marker coordinates in chain through the staggered velocity field V without performing resampling or topography reconstruction.

This lower-level method is useful if you want to customize the post-advection marker-chain processing yourself.

source
JustPIC._2D.advection_LinP! Method
julia
advection_LinP!(particles, method, V, grid_vi, dt)

Advect particles using the linear-plus-pressure (LinP) velocity interpolation scheme.

This variant uses the same time integrators as advection! but evaluates velocities with the LinP reconstruction near staggered pressure points.

This method is useful when you want the interpolation behavior described in the velocity-interpolation documentation under LinP.

source
JustPIC._2D.advection_MQS! Method
julia
advection_MQS!(particles, method, V, dt)

Advect particles using the monotonic quadratic spline (MQS) velocity interpolation scheme.

Compared with advection!, this method reconstructs staggered velocities with MQS where enough stencil support is available.

Near boundaries or when the required stencil is unavailable, the implementation falls back to linear interpolation.

The public entry point reads the staggered velocity coordinates and spacing from particles.xi_vel and particles.di.velocity.

source
JustPIC._2D.cell_array Method
julia
cell_array(x, ncells, ni)

Create a CellArray filled with x, using ncells entries per cell over a grid of size ni.

This helper is useful when allocating per-cell particle fields or phase-ratio storage with the same logical layout as the particle containers.

source
JustPIC._2D.centroid2particle! Method
julia
centroid2particle!(Fp, xci, F, particles)

Interpolate cell-centered field values F to particle values Fp.

xci contains the center coordinates of the grid carrying F. The destination Fp is mutated in place and may be either a single particle field or a tuple of particle fields.

source
JustPIC._2D.checkpointing_particles Method
julia
checkpointing_particles(dst, particles; phases=nothing, phase_ratios=nothing, chain=nothing, t=nothing, dt=nothing, particle_args=nothing)

Write particle state and optional companion data to a JLD2 checkpoint.

By default the file is saved as particles_checkpoint.jld2 in dst. Additional keyword arguments are serialized into the checkpoint after being converted to plain Julia arrays where needed.

Common keywords

  • phases: per-particle phase labels.

  • phase_ratios: PhaseRatios container to checkpoint.

  • chain: marker-chain state.

  • t: simulation time.

  • dt: timestep size.

  • particle_args: tuple of extra particle-carried fields.

Notes

  • Arrays are converted to plain Julia arrays before serialization so the checkpoint can be reloaded independently of the active backend.
source
JustPIC._2D.clean_particles! Method
julia
clean_particles!(particles, grid, args)

Remove invalid or inactive particle slots and keep particle-associated fields in args consistent with the particle storage layout.

This is typically used after particle deletion or reinjection to compact each cell's active particle block.

source
JustPIC._2D.compute_rock_fraction! Method
julia
compute_rock_fraction!(ratios, chain::MarkerChain, xvi, dxi)

Fill ratios with the fraction of each control volume that lies below the marker chain.

The result is written at cell centers, vertices, and staggered velocity nodes using the topography currently stored in chain.

source
JustPIC._2D.compute_topography_vertex! Method
julia
compute_topography_vertex!(chain::MarkerChain)

Interpolate the marker-chain geometry back to the vertex-based topography array chain.h_vertices.

This is typically called after marker advection or resampling.

source
JustPIC._2D.fill_chain_from_chain! Method
julia
fill_chain_from_chain!(chain::MarkerChain, topo_x, topo_y)

Replace the marker positions in chain with coordinates sampled from an existing topographic polyline.

After the markers are reassigned, the vertex-based topography stored on the chain is recomputed and synchronized with h_vertices0.

topo_x and topo_y should describe an open polyline that spans the chain's horizontal extent.

source
JustPIC._2D.fill_chain_from_vertices! Method
julia
fill_chain_from_vertices!(chain::MarkerChain, topo_y)

Reconstruct a marker chain from topography values given at grid vertices.

topo_y is copied into both the current and previous vertex topography fields before the marker coordinates are rebuilt.

This is useful when the interface is naturally represented on the vertex grid and you want to refresh the marker representation from that discretization.

source
JustPIC._2D.find_parent_cell_bisection Method
julia
find_parent_cell_bisection(px::Number, x::AbstractVector, seed::Int)

Performs an iterative bisection search on the cell-edge vector x to find the index of the cell containing px, starting from the initial guess seed.

Arguments

  • px::Number: Coordinate of the point we want to locate.

  • x::AbstractVector: Monotonic vector of cell-edge coordinates.

  • seed::Int: Initial cell index guess used to start the search.

Returns

  • An integer index i such that x[i] ≤ px ≤ x[i + 1].
source
JustPIC._2D.force_injection! Method
julia
force_injection!(particles, p_new)

Convenience method for force_injection! when no companion particle fields need to be initialized.

source
JustPIC._2D.force_injection! Method
julia
force_injection!(particles, p_new, fields, values)

Insert particles from p_new directly into free particle slots.

Arguments

  • particles: destination Particles container.

  • p_new: per-cell collection of coordinates to inject; NaN marks empty input slots.

  • fields: tuple of particle fields to initialize together with the coordinates.

  • values: values written into each corresponding entry of fields.

Notes

  • This is a low-level routine: it does not search for nearest-neighbor values.

  • Injection only happens into currently inactive particle slots.

source
JustPIC._2D.grid2particle_flip! Method
julia
grid2particle_flip!(Fp, xvi, F, F0, particles; α = 0.0)

Update particle values with a PIC/FLIP blend.

α = 1 gives pure PIC, α = 0 gives pure FLIP, and intermediate values blend between the two updates.

Arguments

  • Fp: particle field to update in place.

  • F: current grid field.

  • F0: previous grid field.

  • particles: particle container.

  • α: PIC fraction in the PIC/FLIP blend.

source
JustPIC._2D.init_cell_arrays Method
julia
init_cell_arrays(particles::Particles, ::Val{N})

Allocate N cell-aligned scratch arrays with the same cell layout as particles.coords.

This is mainly used internally to create per-particle temporary storage for quantities such as interpolated fields or time-integration work arrays.

Returns

  • An N-tuple of CellArrays with the same particle-cell layout as particles.coords.
source
JustPIC._2D.init_markerchain Method
julia
init_markerchain(backend, nxcell, min_xcell, max_xcell, xv, initial_elevation)

Create a 2D MarkerChain sampled along the horizontal grid xv.

nxcell controls the initial number of markers per cell, while initial_elevation can be either a scalar or a vector specifying the initial surface height.

Returns

  • A MarkerChain whose marker positions, vertex topography, and occupancy masks are initialized consistently.
source
JustPIC._2D.init_particles Method
julia
init_particles(backend, nxcell, max_xcell, min_xcell, xvi...)

Initialize a Particles container on the grid defined by the vertex coordinates xvi.

If nxcell is a number, particles are distributed randomly within cell quadrants. If it is an NTuple, it is interpreted as the number of particles to place regularly along each coordinate direction within every cell.

Arguments

  • backend: backend type such as CPUBackend.

  • nxcell: either the target number of particles per cell, or an NTuple describing a structured per-dimension layout.

  • max_xcell: number of particle slots reserved per cell.

  • min_xcell: minimum occupancy used by reinjection routines.

  • xvi: 1D coordinate arrays describing the mesh vertices in each dimension.

Returns

  • A Particles object whose coordinates and occupancy arrays are ready for advection/interpolation routines.

Example

julia
xvi = LinRange(0, 1, 33), LinRange(0, 1, 33)
particles = init_particles(CPUBackend, 24, 48, 12, xvi...)
source
JustPIC._2D.inject_particles! Method
julia
inject_particles!(particles::Particles, args)

Inject particles into cells whose occupancy falls below particles.min_xcell.

Arguments

  • particles: The particles object.

  • args: tuple of particle fields that should be populated for newly injected particles.

Notes

  • New particles are placed quadrant-by-quadrant inside the cell.

  • New field values are copied from the nearest existing particle in the same neighborhood.

  • The public entry point uses the vertex grid and cell spacing stored in particles.

source
JustPIC._2D.inject_particles_phase! Method
julia
inject_particles_phase!(particles, particles_phases, args, fields, grid)

Inject particles into under-populated cells while also copying phase labels and field values from nearby particles.

This is the phase-aware variant of inject_particles!.

particles_phases stores a phase id per particle slot, while args/fields hold companion particle properties that must be initialized consistently for the new particles.

source
JustPIC._2D.interpolate_velocity_to_markerchain! Method
julia
interpolate_velocity_to_markerchain!(chain::MarkerChain, chain_V::NTuple{N, CellArray}, V, grid_vi::NTuple{N, NTuple{N, T}}) where {N, T}

Interpolate the staggered velocity field V to the current marker positions in chain and store the result in chain_V.

chain_V must be preallocated with the same cell layout as the marker-chain coordinates.

source
JustPIC._2D.lerp Method
julia
lerp(v, t::NTuple{nD,T}) where {nD,T}

Linearly interpolates the value v between the elements of the tuple t. This function is specialized for tuples of length nD.

Arguments

  • v: The value to be interpolated.

  • t: The tuple of values to interpolate between.

source
JustPIC._2D.move_particles! Method
julia
move_particles!(particles::AbstractParticles, args)

Reassign particles to the correct parent cells after their coordinates have been updated.

This routine keeps the coordinate arrays in particles and the companion fields in args sorted by parent cell, preserving the package's spatially local memory layout.

Arguments

  • particles: particle container whose coordinates have already been modified.

  • args: tuple of per-particle fields that must move together with the particle coordinates.

Notes

  • Particles that leave the domain are discarded.

  • args must use the same cell layout as particles.coords.

  • The public entry point uses the vertex grid and spacing stored in particles.

source
JustPIC._2D.particle2centroid! Method
julia
particle2centroid!(F, Fp, xci::NTuple, particles::Particles)

Interpolate particle-centered values Fp to cell centers F.

xci contains the 1D coordinate arrays of the cell centers. This is the cell-centered counterpart to particle2grid! and mutates F in place.

source
JustPIC._2D.particle2grid! Method
julia
particle2grid!(F, Fp, particles)

Interpolate particle-centered values Fp onto the grid nodes F.

The operation is performed in place and supports both scalar fields and tuples of component arrays.

Arguments

  • F: destination nodal array, or tuple of nodal arrays.

  • Fp: particle field stored with the same cell layout as particles.

  • particles: the Particles container supplying particle coordinates and active-slot information. Its stored xvi coordinates define the target vertex grid.

Notes

  • This routine mutates F in place.

  • The interpolation loops over nodes and nearby cells, which avoids atomics on the particles themselves.

source
JustPIC._2D.resample! Method
julia
resample!(chain::MarkerChain)

Resample the markers within each chain cell when the chain becomes too sparse or too distorted.

This keeps the marker spacing reasonably regular, which improves interpolation quality and the stability of subsequent marker-chain operations.

source
JustPIC._2D.semilagrangian_advection! Method
julia
semilagrangian_advection!(F, F0, method, V, grid_vi, grid, dt)

Advect a grid field with a semi-Lagrangian backtracking step.

Each destination node in F is traced backward through the velocity field V, then sampled from F0 on the vertex grid grid. grid_vi contains the staggered coordinates associated with the velocity components.

Notes

  • F is overwritten in place.

  • F0 is the source field from the previous step.

  • For tuple-valued fields, each component is backtracked independently.

source
JustPIC._2D.semilagrangian_advection_LinP! Method
julia
semilagrangian_advection_LinP!(F, F0, method, V, grid_vi, grid, dt)

Semi-Lagrangian advection variant that evaluates backtracked velocities with the LinP interpolation scheme.

Use this when the advecting velocity should be reconstructed with the LinP scheme instead of plain linear interpolation.

source
JustPIC._2D.semilagrangian_advection_MQS! Method
julia
semilagrangian_advection_MQS!(F, F0, method, V, grid_vi, grid, dt)

Semi-Lagrangian advection variant that evaluates backtracked velocities with the MQS interpolation scheme.

Use this when the advecting velocity should be reconstructed with the MQS scheme instead of plain linear interpolation.

source
JustPIC._2D.semilagrangian_advection_markerchain! Method
julia
semilagrangian_advection_markerchain!(chain, method, V, grid_vxi, grid, dt; max_slope_angle = 45.0)

Backtrack a marker chain through V and update the chain geometry with a semi-Lagrangian step.

The optional max_slope_angle limiter is used while reconstructing the interface to avoid excessively steep local segments.

source
JustPIC._2D.subgrid_diffusion! Method
julia
subgrid_diffusion!(pT, T_grid, ΔT_grid, subgrid_arrays, particles, dt; d = 1.0)

Apply the vertex-based subgrid diffusion correction to particle temperatures.

Temperatures are interpolated from the grid to particles, relaxed using the local subgrid model, mapped back to the grid as a correction, and then reapplied to the particle temperatures.

Arguments

  • pT: particle temperature field updated in place.

  • T_grid: source temperature on the vertex grid.

  • ΔT_grid: resolved-grid temperature increment.

  • subgrid_arrays: scratch storage created with SubgridDiffusionCellArrays.

  • particles: particle container.

  • dt: timestep.

  • d: dimensionless subgrid diffusion coefficient.

source
JustPIC._2D.subgrid_diffusion_centroid! Method
julia
subgrid_diffusion_centroid!(pT, T_grid, ΔT_grid, subgrid_arrays, particles, dt; d = 1.0)

Centroid-grid variant of subgrid_diffusion!.

Use this when the resolved temperature field lives at cell centers instead of vertices.

source
JustPIC._2D.@idx Macro
julia
@idx(args...)

Make a linear range from 1 to args[i], with i ∈ [1, ..., n]

source
JustPIC._3D.SubgridDiffusionCellArrays Type
julia
SubgridDiffusionCellArrays(particles; loc = :vertex)

Allocate scratch storage used by the subgrid thermal diffusion routines.

The returned object stores old particle temperatures, per-particle temperature increments, characteristic diffusion timescales, and a grid-sized accumulation buffer.

loc selects whether the accumulation buffer should match a vertex-based or cell-centered grid layout.

source
JustPIC._3D.PhaseRatios Method
julia
PhaseRatios(T, backend, nphases, ni)
PhaseRatios(backend, nphases, ni)
PhaseRatios(nphases, ni)

Allocate a PhaseRatios container for nphases material phases on a grid of size ni.

The default element type is Float64 and the default backend is CPUBackend.

Arguments

  • T: scalar storage type for the phase fractions.

  • backend: backend type used to allocate the arrays.

  • nphases: number of material phases.

  • ni: number of cells in each spatial direction.

source
JustPIC._3D.advect_markerchain! Method
julia
advect_markerchain!(chain, method, V, grid_vxi, dt)

Advect a marker chain for one time step and rebuild its derived topography data.

This convenience wrapper runs marker advection, reassigns markers to cells, resamples the chain, updates vertex elevations, and enforces mean-height conservation.

Use this when evolving a free surface or interface represented by a MarkerChain.

source
JustPIC._3D.advection! Method
julia
advection!(particles::Particles, method::AbstractAdvectionIntegrator, V, grid_vi::NTuple{N,NTuple{N,T}}, dt)

Advect particles through the staggered velocity field V over a time step dt.

grid_vi contains the coordinate tuples associated with each staggered velocity component. The particle coordinates are updated in place.

Arguments

  • particles: Particles container to advect.

  • method: time integrator such as Euler(), RungeKutta2(), or RungeKutta4().

  • V: tuple of staggered velocity component arrays.

  • grid_vi: tuple of coordinate tuples matching the staggering of V.

  • dt: timestep.

source
JustPIC._3D.advection! Method
julia
advection!(chain::MarkerChain, method, V, grid_vi, dt)

Advect the marker coordinates in chain through the staggered velocity field V without performing resampling or topography reconstruction.

This lower-level method is useful if you want to customize the post-advection marker-chain processing yourself.

source
JustPIC._3D.advection_LinP! Method
julia
advection_LinP!(particles, method, V, grid_vi, dt)

Advect particles using the linear-plus-pressure (LinP) velocity interpolation scheme.

This variant uses the same time integrators as advection! but evaluates velocities with the LinP reconstruction near staggered pressure points.

This method is useful when you want the interpolation behavior described in the velocity-interpolation documentation under LinP.

source
JustPIC._3D.advection_MQS! Method
julia
advection_MQS!(particles, method, V, dt)

Advect particles using the monotonic quadratic spline (MQS) velocity interpolation scheme.

Compared with advection!, this method reconstructs staggered velocities with MQS where enough stencil support is available.

Near boundaries or when the required stencil is unavailable, the implementation falls back to linear interpolation.

The public entry point reads the staggered velocity coordinates and spacing from particles.xi_vel and particles.di.velocity.

source
JustPIC._3D.cell_array Method
julia
cell_array(x, ncells, ni)

Create a CellArray filled with x, using ncells entries per cell over a grid of size ni.

This helper is useful when allocating per-cell particle fields or phase-ratio storage with the same logical layout as the particle containers.

source
JustPIC._3D.centroid2particle! Method
julia
centroid2particle!(Fp, xci, F, particles)

Interpolate cell-centered field values F to particle values Fp.

xci contains the center coordinates of the grid carrying F. The destination Fp is mutated in place and may be either a single particle field or a tuple of particle fields.

source
JustPIC._3D.checkpointing_particles Method
julia
checkpointing_particles(dst, particles; phases=nothing, phase_ratios=nothing, chain=nothing, t=nothing, dt=nothing, particle_args=nothing)

Write particle state and optional companion data to a JLD2 checkpoint.

By default the file is saved as particles_checkpoint.jld2 in dst. Additional keyword arguments are serialized into the checkpoint after being converted to plain Julia arrays where needed.

Common keywords

  • phases: per-particle phase labels.

  • phase_ratios: PhaseRatios container to checkpoint.

  • chain: marker-chain state.

  • t: simulation time.

  • dt: timestep size.

  • particle_args: tuple of extra particle-carried fields.

Notes

  • Arrays are converted to plain Julia arrays before serialization so the checkpoint can be reloaded independently of the active backend.
source
JustPIC._3D.clean_particles! Method
julia
clean_particles!(particles, grid, args)

Remove invalid or inactive particle slots and keep particle-associated fields in args consistent with the particle storage layout.

This is typically used after particle deletion or reinjection to compact each cell's active particle block.

source
JustPIC._3D.compute_rock_fraction! Method
julia
compute_rock_fraction!(ratios, chain::MarkerChain, xvi, dxi)

Fill ratios with the fraction of each control volume that lies below the marker chain.

The result is written at cell centers, vertices, and staggered velocity nodes using the topography currently stored in chain.

source
JustPIC._3D.compute_topography_vertex! Method
julia
compute_topography_vertex!(chain::MarkerChain)

Interpolate the marker-chain geometry back to the vertex-based topography array chain.h_vertices.

This is typically called after marker advection or resampling.

source
JustPIC._3D.fill_chain_from_chain! Method
julia
fill_chain_from_chain!(chain::MarkerChain, topo_x, topo_y)

Replace the marker positions in chain with coordinates sampled from an existing topographic polyline.

After the markers are reassigned, the vertex-based topography stored on the chain is recomputed and synchronized with h_vertices0.

topo_x and topo_y should describe an open polyline that spans the chain's horizontal extent.

source
JustPIC._3D.fill_chain_from_vertices! Method
julia
fill_chain_from_vertices!(chain::MarkerChain, topo_y)

Reconstruct a marker chain from topography values given at grid vertices.

topo_y is copied into both the current and previous vertex topography fields before the marker coordinates are rebuilt.

This is useful when the interface is naturally represented on the vertex grid and you want to refresh the marker representation from that discretization.

source
JustPIC._3D.find_parent_cell_bisection Method
julia
find_parent_cell_bisection(px::Number, x::AbstractVector, seed::Int)

Performs an iterative bisection search on the cell-edge vector x to find the index of the cell containing px, starting from the initial guess seed.

Arguments

  • px::Number: Coordinate of the point we want to locate.

  • x::AbstractVector: Monotonic vector of cell-edge coordinates.

  • seed::Int: Initial cell index guess used to start the search.

Returns

  • An integer index i such that x[i] ≤ px ≤ x[i + 1].
source
JustPIC._3D.force_injection! Method
julia
force_injection!(particles, p_new)

Convenience method for force_injection! when no companion particle fields need to be initialized.

source
JustPIC._3D.force_injection! Method
julia
force_injection!(particles, p_new, fields, values)

Insert particles from p_new directly into free particle slots.

Arguments

  • particles: destination Particles container.

  • p_new: per-cell collection of coordinates to inject; NaN marks empty input slots.

  • fields: tuple of particle fields to initialize together with the coordinates.

  • values: values written into each corresponding entry of fields.

Notes

  • This is a low-level routine: it does not search for nearest-neighbor values.

  • Injection only happens into currently inactive particle slots.

source
JustPIC._3D.grid2particle_flip! Method
julia
grid2particle_flip!(Fp, xvi, F, F0, particles; α = 0.0)

Update particle values with a PIC/FLIP blend.

α = 1 gives pure PIC, α = 0 gives pure FLIP, and intermediate values blend between the two updates.

Arguments

  • Fp: particle field to update in place.

  • F: current grid field.

  • F0: previous grid field.

  • particles: particle container.

  • α: PIC fraction in the PIC/FLIP blend.

source
JustPIC._3D.init_cell_arrays Method
julia
init_cell_arrays(particles::Particles, ::Val{N})

Allocate N cell-aligned scratch arrays with the same cell layout as particles.coords.

This is mainly used internally to create per-particle temporary storage for quantities such as interpolated fields or time-integration work arrays.

Returns

  • An N-tuple of CellArrays with the same particle-cell layout as particles.coords.
source
JustPIC._3D.init_markerchain Method
julia
init_markerchain(backend, nxcell, min_xcell, max_xcell, xv, initial_elevation)

Create a 2D MarkerChain sampled along the horizontal grid xv.

nxcell controls the initial number of markers per cell, while initial_elevation can be either a scalar or a vector specifying the initial surface height.

Returns

  • A MarkerChain whose marker positions, vertex topography, and occupancy masks are initialized consistently.
source
JustPIC._3D.init_particles Method
julia
init_particles(backend, nxcell, max_xcell, min_xcell, xvi...)

Initialize a Particles container on the grid defined by the vertex coordinates xvi.

If nxcell is a number, particles are distributed randomly within cell quadrants. If it is an NTuple, it is interpreted as the number of particles to place regularly along each coordinate direction within every cell.

Arguments

  • backend: backend type such as CPUBackend.

  • nxcell: either the target number of particles per cell, or an NTuple describing a structured per-dimension layout.

  • max_xcell: number of particle slots reserved per cell.

  • min_xcell: minimum occupancy used by reinjection routines.

  • xvi: 1D coordinate arrays describing the mesh vertices in each dimension.

Returns

  • A Particles object whose coordinates and occupancy arrays are ready for advection/interpolation routines.

Example

julia
xvi = LinRange(0, 1, 33), LinRange(0, 1, 33)
particles = init_particles(CPUBackend, 24, 48, 12, xvi...)
source
JustPIC._3D.inject_particles! Method
julia
inject_particles!(particles::Particles, args)

Inject particles into cells whose occupancy falls below particles.min_xcell.

Arguments

  • particles: The particles object.

  • args: tuple of particle fields that should be populated for newly injected particles.

Notes

  • New particles are placed quadrant-by-quadrant inside the cell.

  • New field values are copied from the nearest existing particle in the same neighborhood.

  • The public entry point uses the vertex grid and cell spacing stored in particles.

source
JustPIC._3D.inject_particles_phase! Method
julia
inject_particles_phase!(particles, particles_phases, args, fields, grid)

Inject particles into under-populated cells while also copying phase labels and field values from nearby particles.

This is the phase-aware variant of inject_particles!.

particles_phases stores a phase id per particle slot, while args/fields hold companion particle properties that must be initialized consistently for the new particles.

source
JustPIC._3D.interpolate_velocity_to_markerchain! Method
julia
interpolate_velocity_to_markerchain!(chain::MarkerChain, chain_V::NTuple{N, CellArray}, V, grid_vi::NTuple{N, NTuple{N, T}}) where {N, T}

Interpolate the staggered velocity field V to the current marker positions in chain and store the result in chain_V.

chain_V must be preallocated with the same cell layout as the marker-chain coordinates.

source
JustPIC._3D.lerp Method
julia
lerp(v, t::NTuple{nD,T}) where {nD,T}

Linearly interpolates the value v between the elements of the tuple t. This function is specialized for tuples of length nD.

Arguments

  • v: The value to be interpolated.

  • t: The tuple of values to interpolate between.

source
JustPIC._3D.move_particles! Method
julia
move_particles!(particles::AbstractParticles, args)

Reassign particles to the correct parent cells after their coordinates have been updated.

This routine keeps the coordinate arrays in particles and the companion fields in args sorted by parent cell, preserving the package's spatially local memory layout.

Arguments

  • particles: particle container whose coordinates have already been modified.

  • args: tuple of per-particle fields that must move together with the particle coordinates.

Notes

  • Particles that leave the domain are discarded.

  • args must use the same cell layout as particles.coords.

  • The public entry point uses the vertex grid and spacing stored in particles.

source
JustPIC._3D.particle2centroid! Method
julia
particle2centroid!(F, Fp, xci::NTuple, particles::Particles)

Interpolate particle-centered values Fp to cell centers F.

xci contains the 1D coordinate arrays of the cell centers. This is the cell-centered counterpart to particle2grid! and mutates F in place.

source
JustPIC._3D.particle2grid! Method
julia
particle2grid!(F, Fp, particles)

Interpolate particle-centered values Fp onto the grid nodes F.

The operation is performed in place and supports both scalar fields and tuples of component arrays.

Arguments

  • F: destination nodal array, or tuple of nodal arrays.

  • Fp: particle field stored with the same cell layout as particles.

  • particles: the Particles container supplying particle coordinates and active-slot information. Its stored xvi coordinates define the target vertex grid.

Notes

  • This routine mutates F in place.

  • The interpolation loops over nodes and nearby cells, which avoids atomics on the particles themselves.

source
JustPIC._3D.resample! Method
julia
resample!(chain::MarkerChain)

Resample the markers within each chain cell when the chain becomes too sparse or too distorted.

This keeps the marker spacing reasonably regular, which improves interpolation quality and the stability of subsequent marker-chain operations.

source
JustPIC._3D.semilagrangian_advection! Method
julia
semilagrangian_advection!(F, F0, method, V, grid_vi, grid, dt)

Advect a grid field with a semi-Lagrangian backtracking step.

Each destination node in F is traced backward through the velocity field V, then sampled from F0 on the vertex grid grid. grid_vi contains the staggered coordinates associated with the velocity components.

Notes

  • F is overwritten in place.

  • F0 is the source field from the previous step.

  • For tuple-valued fields, each component is backtracked independently.

source
JustPIC._3D.semilagrangian_advection_LinP! Method
julia
semilagrangian_advection_LinP!(F, F0, method, V, grid_vi, grid, dt)

Semi-Lagrangian advection variant that evaluates backtracked velocities with the LinP interpolation scheme.

Use this when the advecting velocity should be reconstructed with the LinP scheme instead of plain linear interpolation.

source
JustPIC._3D.semilagrangian_advection_MQS! Method
julia
semilagrangian_advection_MQS!(F, F0, method, V, grid_vi, grid, dt)

Semi-Lagrangian advection variant that evaluates backtracked velocities with the MQS interpolation scheme.

Use this when the advecting velocity should be reconstructed with the MQS scheme instead of plain linear interpolation.

source
JustPIC._3D.semilagrangian_advection_markerchain! Method
julia
semilagrangian_advection_markerchain!(chain, method, V, grid_vxi, grid, dt; max_slope_angle = 45.0)

Backtrack a marker chain through V and update the chain geometry with a semi-Lagrangian step.

The optional max_slope_angle limiter is used while reconstructing the interface to avoid excessively steep local segments.

source
JustPIC._3D.subgrid_diffusion! Method
julia
subgrid_diffusion!(pT, T_grid, ΔT_grid, subgrid_arrays, particles, dt; d = 1.0)

Apply the vertex-based subgrid diffusion correction to particle temperatures.

Temperatures are interpolated from the grid to particles, relaxed using the local subgrid model, mapped back to the grid as a correction, and then reapplied to the particle temperatures.

Arguments

  • pT: particle temperature field updated in place.

  • T_grid: source temperature on the vertex grid.

  • ΔT_grid: resolved-grid temperature increment.

  • subgrid_arrays: scratch storage created with SubgridDiffusionCellArrays.

  • particles: particle container.

  • dt: timestep.

  • d: dimensionless subgrid diffusion coefficient.

source
JustPIC._3D.subgrid_diffusion_centroid! Method
julia
subgrid_diffusion_centroid!(pT, T_grid, ΔT_grid, subgrid_arrays, particles, dt; d = 1.0)

Centroid-grid variant of subgrid_diffusion!.

Use this when the resolved temperature field lives at cell centers instead of vertices.

source
JustPIC._3D.@idx Macro
julia
@idx(args...)

Make a linear range from 1 to args[i], with i ∈ [1, ..., n]

source