solver¶
Low-level ODE integration primitives. Most users should prefer run_simulation from jbubble.simulation, which wraps these with post-processing. Use solve_eom directly when you need access to the raw diffrax.Solution object.
jbubble.solver.SaveSpec
¶
Bases: Module
Specification for ODE output sampling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_samples
|
int
|
Number of evenly-spaced time points to record. Default: 1024. |
required |
jbubble.solver.SolverConfig
¶
Bases: Module
Numerical integration settings for :func:solve_eom.
Fields
solver : diffrax.AbstractSolver
ODE solver. Default: Kvaerno5().
stepsize_controller : diffrax.AbstractStepSizeController
Step-size controller. Default: PIDController(rtol=1e-3, atol=1e-6).
dt0 : float
Initial step size [s]. Default: 1e-9.
max_steps : int
Maximum solver steps per integration. Default: 50 000.
jbubble.solver.solve_eom(eom, pulse, *, y0=None, t_max=None, save_spec=None, config=None, adjoint=None, progress=False)
¶
Solve bubble dynamics for an EquationOfMotion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eom
|
EquationOfMotion
|
Assembled equation of motion (e.g. |
required |
pulse
|
Pulse
|
Driving acoustic pulse. |
required |
y0
|
BubbleState
|
Initial state (dimensionless). If None, derived from
|
None
|
t_max
|
float
|
Integration end time [s]. If None, derived from |
None
|
save_spec
|
SaveSpec
|
Output sampling specification. Default: 1024 evenly-spaced time points. |
None
|
config
|
SolverConfig
|
Numerical integration settings. Default: Kvaerno5 with PIDController(rtol=1e-3, atol=1e-6). |
None
|
adjoint
|
AbstractAdjoint
|
Adjoint method for gradient computation. Default: diffrax built-in
( |
None
|
progress
|
bool
|
Show a text progress meter. |
False
|
Returns:
| Type | Description |
|---|---|
Solution
|
Solution object with |
Source code in jbubble/solver.py
Solver choice and tolerances¶
The default solver is Kvaerno5 (an implicit 5th-order Runge–Kutta method) with a PID step-size controller at relative tolerance \(10^{-3}\) and absolute tolerance \(10^{-6}\). This is appropriate for most bubble dynamics simulations.
For highly stiff problems (e.g. very small bubbles, extreme driving pressures, or large shear moduli in the medium), tighten the tolerances:
import diffrax
from jbubble import SolverConfig
config = SolverConfig(
stepsize_controller=diffrax.PIDController(rtol=1e-5, atol=1e-8),
max_steps=50_000,
)
For gradient-based fitting, consider using the RecursiveCheckpointAdjoint to reduce memory usage during backpropagation: