Skip to content

Write metadata to a dedicated JSON file #737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: dev
Choose a base branch
from

Conversation

marcelschurer
Copy link
Contributor

@marcelschurer marcelschurer commented Mar 24, 2025

This PR adds the new function trixi2json, which exports simulation metadata to a dedicated JSON file at the start of the simulation. Previously, metadata was stored within the VTK output files. The structure and design of write_json.jl closely follow the existing implementation in write_vtk.jl for consistency.

This is what the JSON files looks like for the hydrostatic_water_comun_2d.jl example:

boundary_1_metadata.json:

{
  "state_equation": "StateEquationCole",
  "julia_version": "1.11.5",
  "boundary_model": "BoundaryModelDummyParticles",
  "density_calculator": "AdamiPressureExtrapolation",
  "viscosity_model": "Nothing",
  "solver_version": {
    "x": "v0.2.6-27-g7825eb968"
  },
  "smoothing_length": 0.06,
  "solver_name": "TrixiParticles.jl",
  "smoothing_kernel": "SchoenbergCubicSplineKernel"
}

fluid_1_metadata.json:

{
  "viscosity_alpha": 0.02,
  "smoothing_kernel": "SchoenbergCubicSplineKernel",
  "acceleration": [
    0.0,
    -9.81
  ],
  "julia_version": "1.11.5",
  "state_equation": "StateEquationCole",
  "density_calculator": "ContinuityDensity",
  "state_equation_rho0": 1000.0,
  "viscosity": "ArtificialViscosityMonaghan",
  "solver": "WCSPH",
  "viscosity_epsilon": 0.01,
  "state_equation_c": 10.0,
  "smoothing_length_factor": 0.8333333333333334,
  "correction_method": "Nothing",
  "state_equation_exponent": 7.0,
  "solver_version": {
    "x": "v0.2.6-27-g7825eb968"
  },
  "solver_name": "TrixiParticles.jl",
  "viscosity_beta": 0.0,
  "state_equation_pa": 0.0
}

Remark: Unit tests for this function will be added in a follow-up PR. In that upcoming PR, I will implement the functionality to read meta_data alongside the simulation data in read_vtk.jl.

@marcelschurer marcelschurer changed the title write2json Write metadata to a dedicated JSON file Mar 24, 2025
Copy link

codecov bot commented May 19, 2025

Codecov Report

Attention: Patch coverage is 35.22013% with 103 lines in your changes missing coverage. Please review.

Project coverage is 69.65%. Comparing base (a91211d) to head (ff5651f).
Report is 5 commits behind head on dev.

Files with missing lines Patch % Lines
src/io/io.jl 0.00% 91 Missing ⚠️
src/io/write_vtk.jl 25.00% 6 Missing ⚠️
src/preprocessing/particle_packing/system.jl 0.00% 3 Missing ⚠️
src/callbacks/solution_saving.jl 0.00% 2 Missing ⚠️
src/callbacks/post_process.jl 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #737      +/-   ##
==========================================
- Coverage   70.12%   69.65%   -0.48%     
==========================================
  Files         106      107       +1     
  Lines        6822     6913      +91     
==========================================
+ Hits         4784     4815      +31     
- Misses       2038     2098      +60     
Flag Coverage Δ
unit 69.65% <35.22%> (-0.48%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LasNikas LasNikas marked this pull request as ready for review May 21, 2025 08:47
@marcelschurer marcelschurer requested a review from LasNikas June 4, 2025 07:38
@LasNikas LasNikas requested review from efaulhaber and svchb June 4, 2025 07:53
@LasNikas
Copy link
Collaborator

LasNikas commented Jun 4, 2025

/run-gpu-tests

@@ -84,8 +81,8 @@ function SolutionSavingCallback(; interval::Integer=0, dt=0.0,
save_times=Float64[],
save_initial_solution=true, save_final_solution=true,
output_directory="out", append_timestamp=false,
prefix="", verbose=false, write_meta_data=true,
max_coordinates=Float64(2^15), custom_quantities...)
prefix="", verbose=false, max_coordinates=Float64(2^15),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change!

@@ -216,6 +216,8 @@ function initialize_postprocess_callback!(cb::PostprocessCallback, u, t, integra
# Apply the callback
cb(integrator)

write_meta_data(cb, integrator)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is called both by the postprocess and the savesolution callback? Do they both create the file and the second overwrites the first?

Copy link
Collaborator

@LasNikas LasNikas Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do they both create the file and the second overwrites the first?

Yes

src/io/io.jl Outdated
(; systems) = semi

output_directory = callback.output_directory
prefix = hasproperty(callback, :prefix) ? callback.prefix : ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not clean. Why does the postprocess callback write this file anyway? This will mostly be used for restarting, no? Then it should be sufficient if only the saving callback writes this file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One may start a simulation only with a postprocess callback without writing the solution.

@svchb svchb added breaking changes This change will break the public API and requires a new major release labels Jun 13, 2025
@svchb svchb modified the milestone: 0.4 Jun 13, 2025
@svchb
Copy link
Collaborator

svchb commented Jun 13, 2025

  1. This is missing a test
  2. The files need more structure
  1. It should be one file for all the systems!

So something like this:

{
  "info":{
        "julia_version": "1.11.5",
        "solver_name": "TrixiParticles.jl",
        "solver_version:": "v0.2.6-27-g7825eb968"
   }
  "systems":[
     "fluid_1":{
        "phase": "fluid",
        "type": "WCSPH",
        "viscosity_model":{
           "type": "ArtificialViscosityMonaghan",
           "alpha": 0.02,
           "beta": 0.0,
           "epsilon": 0.01
          },
        "smoothing_kernel": "SchoenbergCubicSplineKernel",
        "state_equation":{
          "type": "StateEquationCole",
          "rho0": 1000.0,
          "c": 10.0,
          "exponent": 7.0,
          "pa": 0.0
        }
....

@efaulhaber efaulhaber changed the base branch from main to dev June 13, 2025 09:45
svchb and others added 4 commits June 13, 2025 13:26
* add sgs

* update

* fix

* remove

* fix doc

* fix

* fixes

* typo

* tpo

* format

* add explanation

* adjust tests

* add to validation setup for wcsph

* review fixes

* Update taylor_green_vortex_2d.jl

* Update validation_taylor_green_vortex_2d.jl

* Update dam_break_2d.jl

* fix and add citations

* add news

* implement suggestions

* format

* rename viscosity

* too much renaming

* implement suggestions

* Update validation_taylor_green_vortex_2d.jl

* fix tests again

---------

Co-authored-by: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com>
Co-authored-by: Niklas Neher <73897120+LasNikas@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking changes This change will break the public API and requires a new major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants