Skip to content

Add auxiliary variables #2348

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 18 commits into
base: main
Choose a base branch
from
Open

Add auxiliary variables #2348

wants to merge 18 commits into from

Conversation

benegee
Copy link
Contributor

@benegee benegee commented Apr 3, 2025

Add a container holding auxiliary node and surface node variables to semidiscretizations' cache, s.t. they can be used when computing rhs!.

As a first step, AcousticPerturbationEquations2DAuxVars are implemented. This is to demonstrate how auxiliary variables can be used instead of augmenting the solution state vector, as previously done, e.g., in AcousticPerturbationEquations2D.

This feature should ultimately be usable by

  • @tristanmontoya: covariant solver on surfaces
  • @paulaweiss: variable coefficients for prescribed wind field
  • @benegee: perturbation approach for compressible Euler equations

To discuss:

  • naming: aux_vars vs. auxiliary_variables (and derived names such as get_auxiliary_surface_node_vars)
  • ...

Closes #1623, closes #497, related #358

benegee added 3 commits April 3, 2025 17:45
- add container for node and surface auxiliary variables
- add initializer to SemidiscretizationHyperbolic
- dispatch on have_auxiliary_node_vars for 2D TreeMesh rhs!
to demonstrate how auxiliary variables can be used instead of augmenting
the solution state vector
ŕesults have to be identical to the corresponing AcousticPerturbationEquations2D results
Copy link
Contributor

github-actions bot commented Apr 3, 2025

Review checklist

This checklist is meant to assist creators of PRs (to let them know what reviewers will typically look for) and reviewers (to guide them in a structured review process). Items do not need to be checked explicitly for a PR to be eligible for merging.

Purpose and scope

  • The PR has a single goal that is clear from the PR title and/or description.
  • All code changes represent a single set of modifications that logically belong together.
  • No more than 500 lines of code are changed or there is no obvious way to split the PR into multiple PRs.

Code quality

  • The code can be understood easily.
  • Newly introduced names for variables etc. are self-descriptive and consistent with existing naming conventions.
  • There are no redundancies that can be removed by simple modularization/refactoring.
  • There are no leftover debug statements or commented code sections.
  • The code adheres to our conventions and style guide, and to the Julia guidelines.

Documentation

  • New functions and types are documented with a docstring or top-level comment.
  • Relevant publications are referenced in docstrings (see example for formatting).
  • Inline comments are used to document longer or unusual code sections.
  • Comments describe intent ("why?") and not just functionality ("what?").
  • If the PR introduces a significant change or new feature, it is documented in NEWS.md with its PR number.

Testing

  • The PR passes all tests.
  • New or modified lines of code are covered by tests.
  • New or modified tests run in less then 10 seconds.

Performance

  • There are no type instabilities or memory allocations in performance-critical parts.
  • If the PR intent is to improve performance, before/after time measurements are posted in the PR.

Verification

  • The correctness of the code was verified using appropriate tests.
  • If new equations/methods are added, a convergence test has been run and the results
    are posted in the PR.

Created with ❤️ by the Trixi.jl community.

github-actions[bot]

This comment was marked as resolved.

Copy link

codecov bot commented Apr 3, 2025

Codecov Report

Attention: Patch coverage is 73.71663% with 128 lines in your changes missing coverage. Please review.

Project coverage is 96.66%. Comparing base (f76ccaf) to head (7170717).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
...ns/acoustic_perturbation_2d_auxiliary_variables.jl 57.05% 64 Missing ⚠️
src/solvers/dgsem_tree/dg_2d.jl 82.03% 23 Missing ⚠️
src/solvers/dgsem_tree/dg_2d_parallel.jl 20.69% 23 Missing ⚠️
src/visualization/utilities.jl 46.43% 15 Missing ⚠️
src/solvers/dgsem_tree/containers_2d.jl 93.55% 2 Missing ⚠️
src/callbacks_step/stepsize_dg2d.jl 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2348      +/-   ##
==========================================
- Coverage   96.93%   96.66%   -0.28%     
==========================================
  Files         500      504       +4     
  Lines       41499    41942     +443     
==========================================
+ Hits        40226    40540     +314     
- Misses       1273     1402     +129     
Flag Coverage Δ
unittests 96.66% <73.72%> (-0.28%) ⬇️

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.

@sloede
Copy link
Member

sloede commented Apr 4, 2025

As discussed today, it's great to see this is coming to Trixi.jl! Feel free to ping me in case of questions or for a review!

@DanielDoehring
Copy link
Contributor

@knstmrd is this maybe helpful for you?

@benegee benegee marked this pull request as ready for review April 10, 2025 06:03
@benegee
Copy link
Contributor Author

benegee commented Apr 10, 2025

CI now passes.
Ready for comments @trixi-framework/developers

@benegee
Copy link
Contributor Author

benegee commented Apr 10, 2025

Maybe unrelated, but what was the idea behind #576?

@sloede
Copy link
Member

sloede commented Apr 16, 2025

As discussed in the Trixi.jl meeting, it would be great if the first round of reviews could be done by @tristanmontoya 😊

@tristanmontoya
Copy link
Member

As discussed in the Trixi.jl meeting, it would be great if the first round of reviews could be done by @tristanmontoya 😊

Yes, I will get to that soon!

Copy link
Member

@tristanmontoya tristanmontoya left a comment

Choose a reason for hiding this comment

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

Nice work! This seems pretty much ready to go as far as I am concerned, aside from some suggestions regarding variable naming and documentation. My suggestion at this point is to leave the names of cache.auxiliary_variables and create_cache_auxiliary as-is, but anywhere we have auxiliary_node_vars or auxiliary_surface_node_vars, that could just be shortened to aux_node_vars or aux_surface_node_vars, since "vars" is already an abbreviation.

I was also wondering, for problems without auxiliary variables, does this add any performance overhead? It doesn't look like it would be significant, but might be good to double check.

Finally, am I correct that the auxiliary variables are recomputed, rather than interpolated, when the mesh is adapted? Does this give a different result than adding them to the solution state u, since in the latter case they would be interpolated alongside the conservative variables?

@@ -204,7 +206,8 @@ See also https://github.com/trixi-framework/Trixi.jl/issues/1671#issuecomment-17
=#
@inline function weak_form_kernel!(du, u,
element, mesh::TreeMesh{2},
nonconservative_terms::False, equations,
nonconservative_terms::False,
auxiliary_node_var::False, equations,
Copy link
Member

Choose a reason for hiding this comment

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

I would be consistent here with the naming of this parameter in other methods. In most places, you have have_auxiliary_node_vars. If you want to be consistent with nonconservative_terms, then maybe it should just be auxiliary_node_vars, but this could be confused with the actual variables rather than just a boolean (I would actually prefer to change nonconservative_terms to have_nonconservative_terms but that is a separate issue).

@@ -456,6 +456,44 @@ function get_data_1d(original_nodes, unstructured_data, nvisnodes, reinterpolate
vcat(original_nodes[1, 1, :], original_nodes[1, end, end])
end

@inline function apply_solution_variables(u, solution_variables,
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment documenting what this function does?

n_auxiliary_node_vars(equations)

Number of auxiliary variables used by `equations`. This function needs to be specialized
only if equations has auxiliary variables.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
only if equations has auxiliary variables.
only if `equations` has auxiliary variables.

have_auxiliary_node_vars(equations)
Trait function determining whether `equations` need to access additional auxiliary
variables.
The return value will be `True()` or `False()` to allow dispatching on the return type.
Copy link
Member

Choose a reason for hiding this comment

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

There should probably be some documentation of the fact that auxiliary variables currently only work with TreeMesh{2}, which would be updated as we add support for other meshes. I am not sure where that should go - perhaps here?

@DanielDoehring DanielDoehring added the enhancement New feature or request label Apr 24, 2025
@DanielDoehring
Copy link
Contributor

This looks quite comprehensive - we should be really careful if this is breaking or not.

@jlchan
Copy link
Contributor

jlchan commented Apr 24, 2025

Maybe unrelated, but what was the idea behind #576?

I think I requested that, but I can't remember why now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is it possible to develop variable coeffcient solver based on Trixi.jl framework? Fokker-Planck equation
5 participants