Skip to content
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

WIP: Add FV method for T8codeMesh #1844

Draft
wants to merge 77 commits into
base: main
Choose a base branch
from

Conversation

bennibolm
Copy link
Contributor

@bennibolm bennibolm commented Feb 13, 2024

This PR adds the implementation of a first-order and second order finite volume scheme.
The mesh is organized with t8code. Therefore, it supports MPI parallelization.

Visualization is implemented using a t8code routine directly and therefore without .h5 files and Trixi2Vtk.

Validation is done in comments.

TODOs:

  • Check if convergence_test works parallel. If I remember correctly, it doesn't. Update: Seems to work now.
  • Reconstruction stencil on periodic boundaries
  • Second order extended reconstruction stencil. Adapt smaller reconstruction stencils
  • MPI parallel with extended reconstruction stencil (Problem: Using data from other ranks)

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.

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.

Copy link

codecov bot commented Feb 13, 2024

Codecov Report

Attention: Patch coverage is 0.29326% with 1020 lines in your changes missing coverage. Please review.

Project coverage is 86.80%. Comparing base (cde00a8) to head (8d7c2e1).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/solvers/fv_t8code/fv.jl 0.00% 316 Missing ⚠️
src/meshes/t8code_mesh.jl 1.02% 290 Missing ⚠️
src/solvers/fv_t8code/containers.jl 0.00% 276 Missing ⚠️
src/callbacks_step/analysis_dg2d.jl 0.00% 56 Missing ⚠️
examples/t8code_2d_fv/elixir_advection_basic.jl 0.00% 23 Missing ⚠️
src/callbacks_step/stepsize_dg2d.jl 0.00% 22 Missing ⚠️
examples/t8code_2d_fv/elixir_euler_blast_wave.jl 0.00% 12 Missing ⚠️
src/callbacks_step/save_solution.jl 0.00% 10 Missing ⚠️
...2d_fv/elixir_euler_kelvin_helmholtz_instability.jl 0.00% 9 Missing ⚠️
examples/t8code_2d_fv/elixir_euler_free_stream.jl 0.00% 6 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (cde00a8) and HEAD (8d7c2e1). Click for more details.

HEAD has 4 uploads less than BASE
Flag BASE (cde00a8) HEAD (8d7c2e1)
unittests 26 22
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1844      +/-   ##
==========================================
- Coverage   96.32%   86.80%   -9.52%     
==========================================
  Files         470      476       +6     
  Lines       37485    38502    +1017     
==========================================
- Hits        36106    33420    -2686     
- Misses       1379     5082    +3703     
Flag Coverage Δ
unittests 86.80% <0.29%> (-9.52%) ⬇️

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.

Comment on lines 1169 to 1179
# Simple meshes
# Temporary routines to create simple `cmesh`s by hand

# Directly ported from: `src/t8_cmesh/t8_cmesh_examples.c: t8_cmesh_new_periodic_hybrid`.
function cmesh_new_periodic_hybrid(comm)::t8_cmesh_t
n_dims = 2
vertices = [ # Just all vertices of all trees. partly duplicated
-1.0, -1.0, 0, # tree 0, triangle
0, -1.0, 0,
0, 0, 0,
-1.0, -1.0, 0, # tree 1, triangle
Copy link
Contributor Author

@bennibolm bennibolm Feb 20, 2024

Choose a reason for hiding this comment

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

The following 300 lines are just by-hand building routines for simple cmeshs. This is only temporary and will be deleted in the future.

src/meshes/mesh_io.jl Outdated Show resolved Hide resolved
src/meshes/t8code_mesh.jl Outdated Show resolved Hide resolved
Comment on lines +278 to +281
function integrate_via_indices(func::Func, u,
mesh::T8codeMesh, equations,
solver::FV, cache, args...;
normalize = true) where {Func}
Copy link
Contributor Author

@bennibolm bennibolm Feb 20, 2024

Choose a reason for hiding this comment

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

TODO: Relocate this routine, calc_error_norms and analyze to analysis.jl since they are dimension independent.

@bennibolm
Copy link
Contributor Author

bennibolm commented Jul 19, 2024

After c4a4813, doing some validation:

Convergence test
First order with elixir_advection_basic.jl (with a periodic quad mesh and time integration method CarpenterKennedy2N54 and T=1.0):

convergence_test("examples/t8code_2d_fv/elixir_advection_basic.jl", 7, order=1, initial_refinement_level=2)

l2
scalar
error     EOC
2.33e-01  -
1.50e-01  0.64
8.55e-02  0.81
4.58e-02  0.90
2.37e-02  0.95
1.21e-02  0.98
6.08e-03  0.99

linf
scalar
error     EOC
3.28e-01  -
2.11e-01  0.63
1.21e-01  0.81
6.47e-02  0.90
3.35e-02  0.95
1.71e-02  0.97
8.60e-03  0.99

non-periodic domain:

convergence_test("../examples/t8code_2d_fv/elixir_advection_nonperiodic.jl", 7, initial_refinement_level=3, order=1)

l2
scalar
error     EOC
1.94e-01  -
1.24e-01  0.64
7.22e-02  0.78
3.92e-02  0.88
2.05e-02  0.93
1.05e-02  0.97
5.32e-03  0.98

linf
scalar
error     EOC
3.30e-01  -
2.11e-01  0.64
1.21e-01  0.81
6.47e-02  0.90
3.35e-02  0.95
1.71e-02  0.97
8.60e-03  0.99

Second order with elixir_advection_basic.jl (with a periodic quad mesh and time integration method CarpenterKennedy2N54 and T=1.0):
Using parameter r = 2, epsilon = 1.0e-13

convergence_test("examples/t8code_2d_fv/elixir_advection_basic.jl", 6, order=2, initial_refinement_level=1)

l2
scalar
error     EOC
2.54e-01  -
7.64e-02  1.73
1.89e-02  2.02
5.81e-03  1.70
1.74e-03  1.74
5.15e-04  1.75

linf
scalar
error     EOC
3.56e-01  -
1.19e-01  1.58
3.77e-02  1.66
1.42e-02  1.41
5.41e-03  1.39
2.07e-03  1.39

When I remove the limiting completely by lambda = [0.0; 1.0], I get

l2
scalar
error     EOC
2.09e-01  -
5.31e-02  1.97
9.68e-03  2.46
1.97e-03  2.29
4.59e-04  2.11
1.12e-04  2.03

linf
scalar
error     EOC
2.95e-01  -
7.20e-02  2.03
1.36e-02  2.40
2.78e-03  2.30
6.48e-04  2.10
1.59e-04  2.03

Free stream preservation:
Note: There is still a problem with using the mapping for FV with t8codemesh. Therefore, it's just the basic mesh used in this test.
Simulation of compressible Euler equation with a constant initial condition

trixi_include("examples/t8code_2d_fv/elixir_euler_free_stream.jl", tspan=(0.0, 100.0))
  • order=1: cfl=0.9, ~7000 time steps: Errors <1.0e-15
  • order=2: cfl=0.9, ~7000 time steps: Errors <1.0e-10 (smaller CFL doesn't make a difference) :/
  • order=2: No Limiting activated, cfl=0.9, ~7000 time steps: Errors <1.0e-15

mesh.tree_node_coordinates = tree_node_coordinates
mesh.max_number_faces = 2 * NDIMS # TODO: How to automatically adapt for other element types, e.g. triangles?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a t8code routine that gives the maximum number of faces of all elements in a forest?

@bennibolm
Copy link
Contributor Author

As in the dg elixirs with T8codeMesh, I added !isinteractive() && finalize(mesh) to the end of each fv elixir in 0994aab. This caused segmentation fault errors in the mpi tests (see here).
Also, somehow the nonperiodic test case failed.
So, I remove it again in a46520f.

@sloede
Copy link
Member

sloede commented Aug 28, 2024

As in the dg elixirs with T8codeMesh, I added !isinteractive() && finalize(mesh) to the end of each fv elixir in 0994aab. This caused segmentation fault errors in the mpi tests (see here). Also, somehow the nonperiodic test case failed. So, I remove it again in a46520f.

@jmark Could these issues be fixed by your PR we discussed yesterday? Or are they likely to be caused by the same (or similar) causes?

@bennibolm
Copy link
Contributor Author

As in the dg elixirs with T8codeMesh, I added !isinteractive() && finalize(mesh) to the end of each fv elixir in 0994aab. This caused segmentation fault errors in the mpi tests (see here). Also, somehow the nonperiodic test case failed. So, I remove it again in a46520f.

@jmark Could these issues be fixed by your PR we discussed yesterday? Or are they likely to be caused by the same (or similar) causes?

Actually, the PR we talked about was the reason I added the lines in the first place. After failing, I was not sure, it should work in my examples at all, so I removed it again.
But @jmark and I already talked about this yesterday, and I will add it again and try to figure out what's going on here.

Long story short, I'm aware of the merged PR, and I am in contact with @jmark.

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

Successfully merging this pull request may close these issues.

2 participants