Skip to content

Commit

Permalink
Add option in SolutionSavingCallback to write meta data (#247)
Browse files Browse the repository at this point in the history
* option `write_meta_data` for API

* add to docs
  • Loading branch information
LasNikas authored Nov 6, 2023
1 parent 7802e25 commit a868f18
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 10 additions & 5 deletions src/callbacks/solution_saving.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ To ignore a custom quantity for a specific system, return `nothing`.
- `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`: Write meta data.
- `verbose=false`: Print to standard IO when a file is written.
# Examples
Expand All @@ -52,6 +53,7 @@ struct SolutionSavingCallback{I, CQ}
interval :: I
save_initial_solution :: Bool
save_final_solution :: Bool
write_meta_data :: Bool
verbose :: Bool
output_directory :: String
prefix :: String
Expand All @@ -63,7 +65,7 @@ function SolutionSavingCallback(; interval::Integer=0, dt=0.0,
save_initial_solution=true,
save_final_solution=true,
output_directory="out", append_timestamp=false,
prefix="", verbose=false,
prefix="", verbose=false, write_meta_data=true,
custom_quantities...)
if dt > 0 && interval > 0
throw(ArgumentError("Setting both interval and dt is not supported!"))
Expand All @@ -79,8 +81,8 @@ function SolutionSavingCallback(; interval::Integer=0, dt=0.0,

solution_callback = SolutionSavingCallback(interval,
save_initial_solution, save_final_solution,
verbose, output_directory, prefix,
custom_quantities, [-1])
write_meta_data, verbose, output_directory,
prefix, custom_quantities, [-1])

if dt > 0
# Add a `tstop` every `dt`, and save the final solution.
Expand Down Expand Up @@ -134,7 +136,8 @@ end

# affect!
function (solution_callback::SolutionSavingCallback)(integrator)
(; interval, output_directory, custom_quantities, verbose, prefix, latest_saved_iter) = solution_callback
(; interval, output_directory, custom_quantities, write_meta_data,
verbose, prefix, latest_saved_iter) = solution_callback

vu_ode = integrator.u
semi = integrator.p
Expand All @@ -157,7 +160,9 @@ function (solution_callback::SolutionSavingCallback)(integrator)

@trixi_timeit timer() "save solution" trixi2vtk(vu_ode, semi, integrator.t; iter=iter,
output_directory=output_directory,
prefix=prefix, custom_quantities...)
prefix=prefix,
write_meta_data=write_meta_data,
custom_quantities...)

# Tell OrdinaryDiffEq that u has not been modified
u_modified!(integrator, false)
Expand Down
8 changes: 5 additions & 3 deletions src/visualization/write2vtk.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
trixi2vtk(vu_ode, semi, t; iter=nothing, output_directory="out", prefix="", custom_quantities...)
trixi2vtk(vu_ode, semi, t; iter=nothing, output_directory="out", prefix="",
write_meta_data=true, custom_quantities...)
Convert Trixi simulation data to VTK format.
Expand All @@ -12,6 +13,7 @@ Convert Trixi simulation data to VTK format.
- `iter`: Iteration number when multiple iterations are to be stored in separate files.
- `output_directory`: Output directory path. Defaults to `"out"`.
- `prefix`: Prefix for output files. Defaults to an empty string.
- `write_meta_data`: Write meta data.
- `custom_quantities...`: Additional custom quantities to include in the VTK output. TODO.
Expand All @@ -22,7 +24,7 @@ trixi2vtk(sol[end], semi, 0.0, iter=1, output_directory="output", prefix="soluti
TODO: example for custom_quantities
"""
function trixi2vtk(vu_ode, semi, t; iter=nothing, output_directory="out", prefix="",
custom_quantities...)
write_meta_data=true, custom_quantities...)
(; systems, neighborhood_searches) = semi
v_ode, u_ode = vu_ode.x

Expand All @@ -41,7 +43,7 @@ function trixi2vtk(vu_ode, semi, t; iter=nothing, output_directory="out", prefix
trixi2vtk(v, u, t, system, periodic_box;
output_directory=output_directory,
system_name=filenames[system_index], iter=iter, prefix=prefix,
custom_quantities...)
write_meta_data=write_meta_data, custom_quantities...)
end
end

Expand Down

0 comments on commit a868f18

Please sign in to comment.