Callbacks
TrixiParticles.DensityReinitializationCallback
— TypeDensityReinitializationCallback(; interval::Integer=0, dt=0.0)
Callback to reinitialize the density field when using ContinuityDensity
[42].
Keywords
interval=0
: Reinitialize the density everyinterval
time steps.dt
: Reinitialize the density in regular intervals ofdt
in terms of integration time.reinit_initial_solution
: Reinitialize the initial solution (default=false)
TrixiParticles.InfoCallback
— MethodInfoCallback()
Create and return a callback that prints a human-readable summary of the simulation setup at the beginning of a simulation and then resets the timer. When the returned callback is executed directly, the current timer values are shown.
TrixiParticles.PostprocessCallback
— TypePostprocessCallback(; interval::Integer=0, dt=0.0, exclude_boundary=true, filename="values",
output_directory="out", append_timestamp=false, write_csv=true,
write_json=true, write_file_interval=1, funcs...)
Create a callback to post-process simulation data at regular intervals. This callback allows for the execution of a user-defined function func
at specified intervals during the simulation. The function is applied to the current state of the simulation, and its results can be saved or used for further analysis. The provided function cannot be anonymous as the function name will be used as part of the name of the value.
The callback can be triggered either by a fixed number of time steps (interval
) or by a fixed interval of simulation time (dt
).
Keywords
funcs...
: Functions to be executed at specified intervals during the simulation. Each function must have the arguments(v, u, t, system)
, and will be called for every system, wherev
andu
are the wrapped solution arrays for the corresponding system andt
is the current simulation time. Note that working with thesev
andu
arrays requires undocumented internal functions of TrixiParticles. See Custom Quantities for a list of pre-defined functions that can be used here.interval=0
: Specifies the number of time steps between each invocation of the callback. If set to0
, the callback will not be triggered based on time steps. Eitherinterval
ordt
must be set to something larger than 0.dt=0.0
: Specifies the simulation time interval between each invocation of the callback. If set to0.0
, the callback will not be triggered based on simulation time. Eitherinterval
ordt
must be set to something larger than 0.exclude_boundary=true
: If set totrue
, boundary particles will be excluded from the post-processing.filename="values"
: The filename of the postprocessing files to be saved.output_directory="out"
: The path where the results of the post-processing will be saved.write_csv=true
: If set totrue
, write a csv file.write_json=true
: If set totrue
, write a json file.append_timestep=false
: If set totrue
, the current timestamp will be added to the filename.write_file_interval=1
: Files will be written after everywrite_file_interval
number of postprocessing execution steps. A value of 0 indicates that files are only written at the end of the simulation, eliminating I/O overhead.
Examples
# Create a callback that is triggered every 100 time steps
postprocess_callback = PostprocessCallback(interval=100, example_quantity=kinetic_energy)
# Create a callback that is triggered every 0.1 simulation time units
postprocess_callback = PostprocessCallback(dt=0.1, example_quantity=kinetic_energy)
TrixiParticles.SolutionSavingCallback
— TypeSolutionSavingCallback(; interval::Integer=0, dt=0.0, save_times=Array{Float64, 1}([]),
save_initial_solution=true, save_final_solution=true,
output_directory="out", append_timestamp=false, prefix="",
verbose=false, write_meta_data=true, max_coordinates=2^15,
custom_quantities...)
Callback to save the current numerical solution in VTK format in regular intervals. Either pass interval
to save every interval
time steps, or pass dt
to save in intervals of dt
in terms of integration time by adding additional tstops
(note that this may change the solution).
Additional user-defined quantities can be saved by passing functions as keyword arguments, which map (v, u, t, system)
to an Array
where the columns represent the particles in the same order as in u
. To ignore a custom quantity for a specific system, return nothing
.
Keywords
interval=0
: Save the solution everyinterval
time steps.dt
: Save the solution in regular intervals ofdt
in terms of integration time by adding additionaltstops
(note that this may change the solution).save_times=[]
List of times at which to save a solution.save_initial_solution=true
: Save the initial solution.save_final_solution=true
: Save the final solution.output_directory="out"
: Directory to save the VTK files.append_timestamp=false
: Append current timestamp to the output directory.- 'prefix=""': Prefix added to the filename.
custom_quantities...
: Additional user-defined quantities.write_meta_data=true
: Write meta data.verbose=false
: Print to standard IO when a file is written.max_coordinates=2^15
: The coordinates of particles will be clipped if their absolute values exceed this threshold.custom_quantities...
: Additional custom quantities to include in the VTK output. Each custom quantity must be a function of(v, u, t, system)
, which will be called for every system, wherev
andu
are the wrapped solution arrays for the corresponding system andt
is the current simulation time. Note that working with thesev
andu
arrays requires undocumented internal functions of TrixiParticles. See Custom Quantities for a list of pre-defined custom quantities that can be used here.
Examples
# Save every 100 time steps
saving_callback = SolutionSavingCallback(interval=100)
# Save in intervals of 0.1 in terms of simulation time
saving_callback = SolutionSavingCallback(dt=0.1)
# Additionally store the kinetic energy of each system as "my_custom_quantity"
saving_callback = SolutionSavingCallback(dt=0.1, my_custom_quantity=kinetic_energy)
TrixiParticles.StepsizeCallback
— MethodStepsizeCallback(; cfl::Real)
Set the time step size according to a CFL condition if the time integration method isn't adaptive itself.
The current implementation is using the simplest form of CFL condition, which chooses a time step size that is constant during the simulation. The step size is therefore only applied once at the beginning of the simulation.
The step size $\Delta t$ is chosen as the minimum
\[ \Delta t = \min(\Delta t_\eta, \Delta t_a, \Delta t_c),\]
where
\[ \Delta t_\eta = 0.125 \, h^2 / \eta, \quad \Delta t_a = 0.25 \sqrt{h / \lVert g \rVert}, \quad \Delta t_c = \text{CFL} \, h / c,\]
with $\nu = \alpha h c / (2n + 4)$, where $\alpha$ is the parameter of the viscosity and $n$ is the number of dimensions.
This is an experimental feature and may change in future releases.
References
TrixiParticles.UpdateCallback
— MethodUpdateCallback(; interval::Integer, dt=0.0)
Callback to update quantities either at the end of every interval
time steps or in intervals of dt
in terms of integration time by adding additional tstops
(note that this may change the solution).
Keywords
interval=1
: Update quantities at the end of everyinterval
time steps.dt
: Update quantities in regular intervals ofdt
in terms of integration time by adding additionaltstops
(note that this may change the solution).
Custom Quantities
The following pre-defined custom quantities can be used with the SolutionSavingCallback
and PostprocessCallback
.
TrixiParticles.avg_density
— Methodavg_density
Returns the average_density over all particles in a system.
TrixiParticles.avg_pressure
— Methodavg_pressure
Returns the average pressure over all particles in a system.
TrixiParticles.kinetic_energy
— Methodkinetic_energy
Returns the total kinetic energy of all particles in a system.
TrixiParticles.max_density
— Methodmax_density
Returns the maximum density over all particles in a system.
TrixiParticles.max_pressure
— Methodmax_pressure
Returns the maximum pressure over all particles in a system.
TrixiParticles.min_density
— Methodmin_density
Returns the minimum density over all particles in a system.
TrixiParticles.min_pressure
— Methodmin_pressure
Returns the minimum pressure over all particles in a system.
TrixiParticles.total_mass
— Methodtotal_mass
Returns the total mass of all particles in a system.