Skip to content

Commit 2d2b437

Browse files
marcelschurerLasNikassvchbefaulhaber
authored
Write metadata to a dedicated JSON file (#737)
* Integrate write2json for initial metadata export * Remove old `write_meta_data` parameter from VTK writing functions and callbacks * Add `solver_name` to metadata and format files * update `write2json.jl` to match merge * rename file * update references * rename function * Refactor write2vtk! * formatting * refactor functions * implement suggestions * fix bugs * add add_meta_data! function for `system::ParticlePackingSystem` * relocate `add_meta_data!` to `system.jl` * formatting * Rename 'tlsph' to 'place_on_shell' (#814) * rename * format * forgot some * format * naming * forgot some more * fix test * incorporate review comments * format --------- Co-authored-by: Niklas Neher <73897120+LasNikas@users.noreply.github.com> * dispatch `FluidSystem` * Write one unified metadata file for all systems * improve JSON-file structure * improve consistency * Enhance structure of the JSON-File * Fix `rho0` in `AkinciFreeSurfaceCorrection` * Rename 'tlsph' to 'place_on_shell' (#814) * rename * format * forgot some * format * naming * forgot some more * fix test * incorporate review comments * format --------- Co-authored-by: Niklas Neher <73897120+LasNikas@users.noreply.github.com> * Rename 'tlsph' to 'place_on_shell' (#814) * rename * format * forgot some * format * naming * forgot some more * fix test * incorporate review comments * format --------- Co-authored-by: Niklas Neher <73897120+LasNikas@users.noreply.github.com> * Refactor metadata handling * Add settable filename * Add filename display to SolutionSavingCallback output * Rename 'tlsph' to 'place_on_shell' (#814) * rename * format * forgot some * format * naming * forgot some more * fix test * incorporate review comments * format --------- Co-authored-by: Niklas Neher <73897120+LasNikas@users.noreply.github.com> * add function for `ParticlePackingSystem` * improve structure * Formatting Code * Rename 'tlsph' to 'place_on_shell' (#814) * rename * format * forgot some * format * naming * forgot some more * fix test * incorporate review comments * format --------- Co-authored-by: Niklas Neher <73897120+LasNikas@users.noreply.github.com> * fix failing tests * Rename 'tlsph' to 'place_on_shell' (#814) * rename * format * forgot some * format * naming * forgot some more * fix test * incorporate review comments * format --------- Co-authored-by: Niklas Neher <73897120+LasNikas@users.noreply.github.com> * Combine PST and TVF into a unified framework (#884) * Combine PST and TVF into a unified framework * Require update callback for PST * Fix WCSPH * Update PST only in callback * Fix EDAC * Update docs * Fix alle example files * Fix tests * Fix periodic channel * Fix docs * Update news * Fix tests * Fix example file * improve structure and fixing problems * add `shifting_technique` to `io.jl` * change filename of the JSON-File * add suggestions * Enhance data handling for `OpenBoundarySPHSystem` * correct formatting issue * Remove autoinfiltrate * rename `number_of_threads` --------- Co-authored-by: Niklas Neher <73897120+LasNikas@users.noreply.github.com> Co-authored-by: Sven Berger <berger.sven@gmail.com> Co-authored-by: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com>
1 parent 6010689 commit 2d2b437

10 files changed

Lines changed: 384 additions & 133 deletions

File tree

examples/fluid/falling_water_spheres_2d.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ ode = semidiscretize(semi, tspan)
9494

9595
info_callback = InfoCallback(interval=1000)
9696
saving_callback = SolutionSavingCallback(dt=0.01, output_directory="out",
97-
prefix="", write_meta_data=true)
97+
prefix="")
9898

9999
callbacks = CallbackSet(info_callback, saving_callback)
100100

examples/fsi/falling_sphere_3d.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@ trixi_include(@__MODULE__,
1616
solid_smoothing_kernel=WendlandC2Kernel{3}(),
1717
sphere_type=RoundSphere(),
1818
output_directory="out", prefix="",
19-
write_meta_data=false, # Files with meta data can't be read by meshio
2019
tspan=(0.0, 1.0), abstol=1e-6, reltol=1e-3)

examples/fsi/falling_spheres_2d.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ semi = Semidiscretization(fluid_system, boundary_system, solid_system_1, solid_s
124124
ode = semidiscretize(semi, tspan)
125125

126126
info_callback = InfoCallback(interval=50)
127-
saving_callback = SolutionSavingCallback(dt=0.02, output_directory="out", prefix="",
128-
write_meta_data=true)
127+
saving_callback = SolutionSavingCallback(dt=0.02, output_directory="out", prefix="")
129128

130129
callbacks = CallbackSet(info_callback, saving_callback)
131130

examples/n_body/n_body_system.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ end
105105

106106
TrixiParticles.vtkname(system::NBodySystem) = "n-body"
107107

108-
function TrixiParticles.write2vtk!(vtk, v, u, t, system::NBodySystem; write_meta_data=true)
108+
function TrixiParticles.write2vtk!(vtk, v, u, t, system::NBodySystem)
109109
(; mass) = system
110110

111111
vtk["velocity"] = v
@@ -114,6 +114,10 @@ function TrixiParticles.write2vtk!(vtk, v, u, t, system::NBodySystem; write_meta
114114
return vtk
115115
end
116116

117+
function TrixiParticles.add_system_data!(system_data, system::NBodySystem)
118+
return system_data
119+
end
120+
117121
function Base.show(io::IO, system::NBodySystem)
118122
print(io, "NBodySystem{", ndims(system), "}() with ")
119123
print(io, TrixiParticles.nparticles(system), " particles")

src/TrixiParticles.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ include("callbacks/callbacks.jl")
5656
# included separately. `gpu.jl` in turn depends on the semidiscretization type.
5757
include("general/semidiscretization.jl")
5858
include("general/gpu.jl")
59-
include("io/io.jl")
6059
include("preprocessing/preprocessing.jl")
60+
include("io/io.jl")
6161
include("visualization/recipes_plots.jl")
6262

6363
export Semidiscretization, semidiscretize, restart_with!

src/callbacks/post_process.jl

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ function (pp::PostprocessCallback)(integrator)
266266

267267
if isfinished(integrator) ||
268268
(pp.write_file_interval > 0 && backup_condition(pp, integrator))
269-
write_postprocess_callback(pp)
269+
write_postprocess_callback(pp, integrator)
270270
end
271271

272272
# Tell OrdinaryDiffEq that `u` has not been modified
@@ -285,13 +285,14 @@ end
285285
end
286286

287287
# After the simulation has finished, this function is called to write the data to a JSON file
288-
function write_postprocess_callback(pp::PostprocessCallback)
288+
function write_postprocess_callback(pp::PostprocessCallback, integrator)
289289
isempty(pp.data) && return
290290

291291
mkpath(pp.output_directory)
292292

293293
data = Dict{String, Any}()
294-
write_meta_data!(data, pp.git_hash[])
294+
data["meta"] = create_meta_data_dict(pp, integrator)
295+
295296
prepare_series_data!(data, pp)
296297

297298
time_stamp = ""
@@ -341,15 +342,6 @@ function create_series_dict(values, times, system_name="")
341342
"time" => times)
342343
end
343344

344-
function write_meta_data!(data, git_hash)
345-
meta_data = Dict("solver_name" => "TrixiParticles.jl",
346-
"solver_version" => git_hash,
347-
"julia_version" => string(VERSION))
348-
349-
data["meta"] = meta_data
350-
return data
351-
end
352-
353345
function write_csv(abs_file_path, data)
354346
times = Float64[]
355347

src/callbacks/solution_saving.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
SolutionSavingCallback(; interval::Integer=0, dt=0.0, save_times=Array{Float64, 1}([]),
33
save_initial_solution=true, save_final_solution=true,
44
output_directory="out", append_timestamp=false, prefix="",
5-
verbose=false, write_meta_data=true, max_coordinates=2^15,
6-
custom_quantities...)
5+
verbose=false, max_coordinates=2^15, custom_quantities...)
76
87
98
Callback to save the current numerical solution in VTK format in regular intervals.
@@ -26,9 +25,8 @@ To ignore a custom quantity for a specific system, return `nothing`.
2625
- `save_final_solution=true`: Save the final solution.
2726
- `output_directory="out"`: Directory to save the VTK files.
2827
- `append_timestamp=false`: Append current timestamp to the output directory.
29-
- 'prefix=""': Prefix added to the filename.
28+
- `prefix=""`: Prefix added to the filename.
3029
- `custom_quantities...`: Additional user-defined quantities.
31-
- `write_meta_data=true`: Write meta data.
3230
- `verbose=false`: Print to standard IO when a file is written.
3331
- `max_coordinates=2^15`: The coordinates of particles will be clipped if their
3432
absolute values exceed this threshold.
@@ -70,7 +68,6 @@ mutable struct SolutionSavingCallback{I, CQ}
7068
save_times :: Vector{Float64}
7169
save_initial_solution :: Bool
7270
save_final_solution :: Bool
73-
write_meta_data :: Bool
7471
verbose :: Bool
7572
output_directory :: String
7673
prefix :: String
@@ -84,8 +81,9 @@ function SolutionSavingCallback(; interval::Integer=0, dt=0.0,
8481
save_times=Float64[],
8582
save_initial_solution=true, save_final_solution=true,
8683
output_directory="out", append_timestamp=false,
87-
prefix="", verbose=false, write_meta_data=true,
88-
max_coordinates=Float64(2^15), custom_quantities...)
84+
prefix="", verbose=false,
85+
max_coordinates=Float64(2^15),
86+
custom_quantities...)
8987
if (dt > 0 && interval > 0) || (length(save_times) > 0 && (dt > 0 || interval > 0))
9088
throw(ArgumentError("Setting multiple save times for the same solution " *
9189
"callback is not possible. Use either `dt`, `interval` or `save_times`."))
@@ -101,8 +99,8 @@ function SolutionSavingCallback(; interval::Integer=0, dt=0.0,
10199

102100
solution_callback = SolutionSavingCallback(interval, Float64.(save_times),
103101
save_initial_solution, save_final_solution,
104-
write_meta_data, verbose, output_directory,
105-
prefix, max_coordinates, custom_quantities,
102+
verbose, output_directory, prefix,
103+
max_coordinates, custom_quantities,
106104
-1, Ref("UnknownVersion"))
107105

108106
if length(save_times) > 0
@@ -133,6 +131,8 @@ function initialize_save_cb!(solution_callback::SolutionSavingCallback, u, t, in
133131
solution_callback.latest_saved_iter = -1
134132
solution_callback.git_hash[] = compute_git_hash()
135133

134+
write_meta_data(solution_callback, integrator)
135+
136136
# Save initial solution
137137
if solution_callback.save_initial_solution
138138
solution_callback(integrator)
@@ -151,8 +151,8 @@ end
151151

152152
# `affect!`
153153
function (solution_callback::SolutionSavingCallback)(integrator)
154-
(; interval, output_directory, custom_quantities, write_meta_data, git_hash,
155-
verbose, prefix, latest_saved_iter, max_coordinates) = solution_callback
154+
(; interval, output_directory, custom_quantities, git_hash, verbose,
155+
prefix, latest_saved_iter, max_coordinates) = solution_callback
156156

157157
dvdu_ode = get_du(integrator)
158158
vu_ode = integrator.u
@@ -176,8 +176,8 @@ function (solution_callback::SolutionSavingCallback)(integrator)
176176

177177
@trixi_timeit timer() "save solution" trixi2vtk(dvdu_ode, vu_ode, semi, integrator.t;
178178
iter, output_directory, prefix,
179-
write_meta_data, git_hash=git_hash[],
180-
max_coordinates, custom_quantities...)
179+
git_hash=git_hash[], max_coordinates,
180+
custom_quantities...)
181181

182182
# Tell OrdinaryDiffEq that `u` has not been modified
183183
u_modified!(integrator, false)

0 commit comments

Comments
 (0)