Skip to content

Fix #1194: Unify signatures of mesh constructors#3000

Merged
ranocha merged 11 commits into
trixi-framework:mainfrom
vincmarks:feature/mesh-swap
May 21, 2026
Merged

Fix #1194: Unify signatures of mesh constructors#3000
ranocha merged 11 commits into
trixi-framework:mainfrom
vincmarks:feature/mesh-swap

Conversation

@vincmarks
Copy link
Copy Markdown
Contributor

I added mesh constructors so that mesh types become interchangeable.

What's new

  • initial_refinement_level (like TreeMesh):
# Before: only worked for TreeMesh
TreeMesh((-1.0, -1.0), (1.0, 1.0); initial_refinement_level = 4, n_cells_max = 30_000)

# Now: remove n_cells_max and just swap the mesh type
StructuredMesh((-1.0, -1.0), (1.0, 1.0); initial_refinement_level = 4)
P4estMesh((-1.0, -1.0), (1.0, 1.0);     initial_refinement_level = 4, polydeg = 3)
T8codeMesh((-1.0, -1.0), (1.0, 1.0);    initial_refinement_level = 4)
DGMultiMesh(dg;  initial_refinement_level = 4, coordinates_min = (-1.0, -1.0), coordinates_max = (1.0, 1.0))
  • cells_per_dimension positional (now also for P4estMesh/T8codeMesh)
P4estMesh((16, 16), (-1.0, -1.0), (1.0, 1.0); polydeg = 3)
T8codeMesh((16, 16), (-1.0, -1.0), (1.0, 1.0))
  • keyword-based (now also for StructuredMesh/T8codeMesh/DGMultiMesh)
StructuredMesh((16, 16); coordinates_min = (-1.0, -1.0), coordinates_max = (1.0, 1.0))
DGMultiMesh(dg; cells_per_dimension = (16, 16), coordinates_min = (-1.0, -1.0), coordinates_max = (1.0, 1.0))

I already added some explanation in the docs and an example file (examples/special_elixirs/elixir_advection_mesh_swap.jl).

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

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.

@ranocha
Copy link
Copy Markdown
Member

ranocha commented May 7, 2026

Thanks a lot! We just had a developer meeting and brainstormed a bit about the desired interface. Something like T8codeMesh((16, 16), (-1.0, -1.0), (1.0, 1.0)) looks a bit obscure. Thus, we thought it would be best if the constructor working for all mesh types uses keyword arguments only, e.g.,

TreeMesh(coordinates_min = (-1.0, -1.0),
         coordinates_max = (1.0, 1.0), 
         initial_refinement_level = 4, n_cells_max = 30_000)
StructuredMesh(coordinates_min = (-1.0, -1.0),
               coordinates_max = (1.0, 1.0), 
               initial_refinement_level = 4)
P4estMesh(coordinates_min = (-1.0, -1.0),
          coordinates_max = (1.0, 1.0), 
          initial_refinement_level = 4)
T8codeMesh(coordinates_min = (-1.0, -1.0),
           coordinates_max = (1.0, 1.0), 
           initial_refinement_level = 4)
DGMultiMesh(dg; coordinates_min = (-1.0, -1.0),
            coordinates_max = (1.0, 1.0), 
            initial_refinement_level = 4)

Under the hood, these keyword-only constructors should forward the keyword arguments to constructors taking positional arguments (to be able to use dispatch there). Could you please update the API accordingly?

@vincmarks
Copy link
Copy Markdown
Contributor Author

Thanks a lot! We just had a developer meeting and brainstormed a bit about the desired interface. Something like T8codeMesh((16, 16), (-1.0, -1.0), (1.0, 1.0)) looks a bit obscure. Thus, we thought it would be best if the constructor working for all mesh types uses keyword arguments only, e.g.,

TreeMesh(coordinates_min = (-1.0, -1.0),
         coordinates_max = (1.0, 1.0), 
         initial_refinement_level = 4, n_cells_max = 30_000)
StructuredMesh(coordinates_min = (-1.0, -1.0),
               coordinates_max = (1.0, 1.0), 
               initial_refinement_level = 4)
P4estMesh(coordinates_min = (-1.0, -1.0),
          coordinates_max = (1.0, 1.0), 
          initial_refinement_level = 4)
T8codeMesh(coordinates_min = (-1.0, -1.0),
           coordinates_max = (1.0, 1.0), 
           initial_refinement_level = 4)
DGMultiMesh(dg; coordinates_min = (-1.0, -1.0),
            coordinates_max = (1.0, 1.0), 
            initial_refinement_level = 4)

Under the hood, these keyword-only constructors should forward the keyword arguments to constructors taking positional arguments (to be able to use dispatch there). Could you please update the API accordingly?

Thanks for the feedback, I'll update the API accordingly.

@ranocha
Copy link
Copy Markdown
Member

ranocha commented May 13, 2026

Please ping me when this PR is ready for a review.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.09%. Comparing base (bc1048b) to head (8554ea4).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3000   +/-   ##
=======================================
  Coverage   97.09%   97.09%           
=======================================
  Files         630      630           
  Lines       48855    48881   +26     
=======================================
+ Hits        47435    47461   +26     
  Misses       1420     1420           
Flag Coverage Δ
unittests 97.09% <100.00%> (+<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.

@vincmarks vincmarks marked this pull request as ready for review May 13, 2026 12:40
@vincmarks
Copy link
Copy Markdown
Contributor Author

@ranocha, the PR is ready for review

Comment thread src/meshes/structured_mesh.jl Outdated
Comment thread src/solvers/dgmulti/types.jl Outdated
Comment thread examples/special_elixirs/elixir_advection_mesh_swap.jl Outdated
Comment thread examples/special_elixirs/elixir_advection_mesh_swap.jl Outdated
Comment thread src/meshes/p4est_mesh.jl Outdated
Comment thread src/meshes/p4est_mesh.jl Outdated
Comment thread src/meshes/structured_mesh.jl Outdated
Comment thread src/meshes/structured_mesh.jl Outdated
Comment thread src/meshes/t8code_mesh.jl Outdated
Comment thread src/meshes/tree_mesh.jl Outdated
Comment thread docs/src/meshes/mesh_constructor_comparison.md
@DanielDoehring DanielDoehring added the refactoring Refactoring code without functional changes label May 17, 2026
@vincmarks
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback! In the last view commits (ad76138, 60ec745,ebe65fc,1eda211) I made the following changes:

  • Renamed initial_refinement_level to refinement_level
  • Removed DGMultiMesh from the docstrings
  • Documented the P4estMesh kwargs accordingly
  • Added a length check for coordinates_min/coordinates_max with testing
  • Deleted the elixir file and replaced it with runnable examples in the docs. Let me know if you prefer to remove those as well.

Comment thread docs/src/meshes/mesh_constructor_comparison.md Outdated
Comment thread docs/src/meshes/mesh_constructor_comparison.md Outdated
Comment thread docs/src/meshes/mesh_constructor_comparison.md
Comment thread src/meshes/p4est_mesh.jl Outdated
Comment thread src/meshes/t8code_mesh.jl Outdated
Comment thread src/meshes/tree_mesh.jl Outdated
@ranocha ranocha linked an issue May 21, 2026 that may be closed by this pull request
@ranocha ranocha mentioned this pull request May 21, 2026
7 tasks
Copy link
Copy Markdown
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!

@ranocha ranocha merged commit a70bfa2 into trixi-framework:main May 21, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring Refactoring code without functional changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify signatures of mesh constructors

3 participants