From a868f185b04c7f6e4529361a005804abbc6b0074 Mon Sep 17 00:00:00 2001 From: Niklas Neher <73897120+LasNikas@users.noreply.github.com> Date: Mon, 6 Nov 2023 09:50:51 +0100 Subject: [PATCH] Add option in `SolutionSavingCallback` to write meta data (#247) * option `write_meta_data` for API * add to docs --- src/callbacks/solution_saving.jl | 15 ++++++++++----- src/visualization/write2vtk.jl | 8 +++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/callbacks/solution_saving.jl b/src/callbacks/solution_saving.jl index 9d290d46d..2846556d8 100644 --- a/src/callbacks/solution_saving.jl +++ b/src/callbacks/solution_saving.jl @@ -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 @@ -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 @@ -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!")) @@ -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. @@ -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 @@ -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) diff --git a/src/visualization/write2vtk.jl b/src/visualization/write2vtk.jl index 8bedd5642..88e640956 100644 --- a/src/visualization/write2vtk.jl +++ b/src/visualization/write2vtk.jl @@ -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. @@ -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. @@ -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 @@ -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