Skip to content

Conversation

DanielDoehring
Copy link
Member

@DanielDoehring DanielDoehring commented Jul 21, 2025

Probably due to historical debt, the volume integrals have been implemented for every dimension. There is currently no reason to do so, as this results only in duplicated code and makes changes such as discussed in #2472 and #2149 unnecessary cumbersome.

Holds also true for some other functions (mostly create_cache)

Copy link
Contributor

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.

@DanielDoehring DanielDoehring added discussion refactoring Refactoring code without functional changes labels Jul 21, 2025
@DanielDoehring DanielDoehring changed the title Make volume integrals dimension agnostic Make volume integrals, indicators, etc dimension agnostic Jul 21, 2025
Copy link

codecov bot commented Jul 21, 2025

Codecov Report

❌ Patch coverage is 88.88889% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.77%. Comparing base (0821209) to head (cf6d461).

Files with missing lines Patch % Lines
src/solvers/dgsem/calc_volume_integral.jl 87.50% 4 Missing ⚠️
src/solvers/dg.jl 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2488      +/-   ##
==========================================
+ Coverage   96.76%   96.77%   +0.01%     
==========================================
  Files         518      519       +1     
  Lines       42400    42303      -97     
==========================================
- Hits        41027    40938      -89     
+ Misses       1373     1365       -8     
Flag Coverage Δ
unittests 96.77% <88.89%> (+0.01%) ⬆️

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.

Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

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

Thanks for bringing this up. We have to discuss this in a larger group including @sloede and the other @trixi-framework/principal-developers

@JoshuaLampert
Copy link
Member

If we want this (and I am in favor of it), I would propose to put the dimension agnostic functions into dimension-general files, e.g., moving the calc_boundary_flux! functions from src/solvers/dgsem_structured/dg_*d.jl to src/solvers/dgsem_structured/dg.jl. Otherwise it's hard to find the file if you are, e.g., working on 2D, but the function is in the 1D file.

@DanielDoehring
Copy link
Member Author

If we want this (and I am in favor of it), I would propose to put the dimension agnostic functions into dimension-general files, e.g., moving the calc_boundary_flux! functions from src/solvers/dgsem_structured/dg_*d.jl to src/solvers/dgsem_structured/dg.jl. Otherwise it's hard to find the file if you are, e.g., working on 2D, but the function is in the 1D file.

That's an excellent idea!

@JoshuaLampert
Copy link
Member

Following a similar idea, wouldn't it also make sense to put mesh-agnostic functions (at least the ones, which are the same of all mesh types) into mesh-general files like https://github.com/trixi-framework/Trixi.jl/blob/531ee91d0dbe93e8fb8bf9f675b34f7982b9077e/src/solvers/dg.jl. Currently, we have quite some functions, which also allow non-TreeMeshes in the dgsem_tree subfolder.

@DanielDoehring
Copy link
Member Author

DanielDoehring commented Aug 11, 2025

Following a similar idea, wouldn't it also make sense to put mesh-agnostic functions (at least the ones, which are the same of all mesh types) into mesh-general files like https://github.com/trixi-framework/Trixi.jl/blob/531ee91d0dbe93e8fb8bf9f675b34f7982b9077e/src/solvers/dg.jl. Currently, we have quite some functions, which also allow non-TreeMeshes in the dgsem_tree subfolder.

I like the idea and I would be fine with adding a file like volume_integrals.jl somewhere in the src/solvers directory.
However, this is maybe againts the following convention/code structure?

Trixi.jl/src/solvers/dg.jl

Lines 830 to 837 in 531ee91

# Discretizations specific to each mesh type of Trixi.jl
# If some functionality is shared by multiple combinations of meshes/solvers,
# it is defined in the directory of the most basic mesh and solver type.
# The most basic solver type in Trixi.jl is DGSEM (historic reasons and background
# of the main contributors).
# We consider the `TreeMesh` to be the most basic mesh type since it is Cartesian
# and was the first mesh in Trixi.jl. The order of the other mesh types is the same
# as the include order below.

@JoshuaLampert
Copy link
Member

Yes, it would be against this code structure, but the question is, which code structure is easier to understand and work with. I was just last week talking to a Trixi.jl newcomer, who wants to contribute to Trixi.jl and was confused about seeing code relevant for the P4estMesh in the TreeMesh folder and therefore didn't find the relevant code. If we want to keep the current structure, I would at least highlight this structure more prominently in the docs, e.g., in the development section.

@DanielDoehring
Copy link
Member Author

Yes, it would be against this code structure, but the question is, which code structure is easier to understand and work with. I was just last week talking to a Trixi.jl newcomer, who wants to contribute to Trixi.jl and was confused about seeing code relevant for the P4estMesh in the TreeMesh folder and therefore didn't find the relevant code. If we want to keep the current structure, I would at least highlight this structure more prominently in the docs, e.g., in the development section.

As a follow up: Maybe it also makes sense to bundle (in a different PR) identical rhs! functions, such as done for the parabolic solver:

function rhs_parabolic!(du, u, t, mesh::Union{P4estMesh{2}, P4estMesh{3}},

This way we can also reduce redundant code and re-do really only the stuff that is actually different, thus giving better code semantics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion refactoring Refactoring code without functional changes taal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants