jaxdem.utils.packing_utils#
Utility functions for calculating and changing the packing fraction.
Functions
|
Return the packing fraction |
|
Return the total particle volume. |
Quasi-statically compress (or decompress) toward |
|
|
Rescale the box to |
Classes
|
Why quasistatic compression stopped. |
|
Compression output; four-value unpacking remains supported. |
- jaxdem.utils.packing_utils.compute_particle_volume(state: State) jax.Array[source]#
Return the total particle volume.
- jaxdem.utils.packing_utils.compute_packing_fraction(state: State, system: System) jax.Array[source]#
Return the packing fraction
total_particle_volume / box_volume.The box volume is
prod(system.domain.box_size), independent of its anchor.
- jaxdem.utils.packing_utils.scale_to_packing_fraction(state: State, system: System, new_packing_fraction: float) tuple[State, System][source]#
Rescale the box to
new_packing_fraction, preserving its aspect ratio.
- class jaxdem.utils.packing_utils.CompressionReason(*values)[source]#
Bases:
IntEnumWhy quasistatic compression stopped.
- MAX_STEPS = 0#
- TARGET_REACHED = 1#
- MINIMIZATION_FAILED = 2#
- class jaxdem.utils.packing_utils.CompressionResult(state: State, system: System, packing_fraction: jax.Array, energy: jax.Array, steps: int, reason: CompressionReason, minimizer_reason: TerminationReason)#
Bases:
objectCompression output; four-value unpacking remains supported.
minimizer_reasondistinguishes exhaustion, nonfinite values, and search overflow whenreasonisMINIMIZATION_FAILED. If the first relaxation fails, no accepted energy exists andenergyis NaN.- packing_fraction: jax.Array#
- energy: jax.Array#
- steps: int#
- reason: CompressionReason#
- minimizer_reason: TerminationReason#
- jaxdem.utils.packing_utils.quasistatic_compress_to_packing_fraction(state: State, system: System, target_phi: float, *, step: float = 0.001, phi_tolerance: float = 1e-10, force_tol: float = 1e-12, torque_tol: float | None = None, max_n_min_steps_per_outer: int = 1000000, max_n_outer_steps: int = 1000000, progress: bool = False) CompressionResult[source]#
Quasi-statically compress (or decompress) toward
target_phi.Alternates
scale_to_packing_fractionwithminimizein steps no larger thanstepin packing fraction. The final step is truncated so the target is hit exactly (withinphi_tolerance). Works in both directions: iftarget_phi > current_phithe box shrinks and the particles move closer. Iftarget_phi < current_phithe box grows and the system relaxes.The function minimizes the state once up front and after each change of packing fraction. The returned potential energy can remain positive at mechanical equilibrium above jamming.
- Parameters:
state – Current state/system. Any domain type that
scale_to_packing_fractionsupports works.system – Current state/system. Any domain type that
scale_to_packing_fractionsupports works.target_phi – Target packing fraction.
step – Maximum magnitude of the per-outer-step increment in phi. Smaller values are more quasistatic (and cost more). 1e-3 is a reasonable default for dense compressions.
phi_tolerance – Absolute tolerance on the terminal packing fraction.
force_tol – Absolute force and torque tolerances for mechanical relaxation.
torque_tol – Absolute force and torque tolerances for mechanical relaxation.
max_n_min_steps_per_outer – FIRE iterations allowed per minimization (per outer step).
max_n_outer_steps – Hard cap on outer iterations (safety net).
progress – If
Trueandtqdmis importable, wrap the outer loop in a progress bar. Otherwise silent.
- Returns:
Inspect
reasonandminimizer_reasonbefore accepting a packing. Failure returns the last accepted state/system. Four-value unpacking remains available.final_phiiscompute_packing_fraction(state, system)at exit.final_peis the PE after the last minimization.- Return type: