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 51 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 (WIP 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.

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

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

l2
scalar              
error     EOC       
2.25e-01  -         
1.42e-01  0.67      
8.02e-02  0.82      
4.28e-02  0.91      
2.21e-02  0.95      
1.12e-02  0.98      
5.66e-03  0.99      

mean      0.89      
----------------------------------------------------------------------------------------------------
linf
scalar              
error     EOC       
3.34e-01  -         
2.09e-01  0.68      
1.20e-01  0.80      
6.50e-02  0.88      
3.39e-02  0.94      
1.73e-02  0.97      
8.75e-03  0.99      

mean      0.88      
----------------------------------------------------------------------------------------------------
Dict{Symbol, Any} with 3 entries:
  :variables => ("scalar",)
  :l2        => [0.886]
  :linf      => [0.875399]

non-periodic domain:

convergence_test("../examples/t8code_2d_fv/elixir_advection_nonperiodic.jl", 7, initial_refinement_level=2)

l2
scalar              
error     EOC       
2.68e-01  -         
1.94e-01  0.47      
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      

mean      0.78      
----------------------------------------------------------------------------------------------------
linf
scalar              
error     EOC       
4.47e-01  -         
3.30e-01  0.44      
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      

mean      0.79      
----------------------------------------------------------------------------------------------------
Dict{Symbol, Any} with 3 entries:
  :variables => ("scalar",)
  :l2        => [0.778692]
  :linf      => [0.785136]

Second-order: (WIP)
TODOs:

  • Reconstruction stencil on periodic boundaries
  • MPI parallel (Problem: Using data from other ranks)
convergence_test("../examples/t8code_2d_fv/elixir_advection_basic.jl", 6, initial_refinement_level=2)
l2
scalar              
error     EOC       
1.01e-01  -         
2.03e-02  2.31      
3.72e-03  2.45      
7.01e-04  2.41      
1.42e-04  2.30      
3.12e-05  2.19      

mean      2.33      
----------------------------------------------------------------------------------------------------
linf
scalar              
error     EOC       
1.95e-01  -         
5.57e-02  1.81      
1.68e-02  1.73      
4.61e-03  1.87      
1.21e-03  1.93      
3.09e-04  1.97      

mean      1.86      
----------------------------------------------------------------------------------------------------
Dict{Symbol, Any} with 3 entries:
  :variables => ("scalar",)
  :l2        => [2.33155]
  :linf      => [1.8605]

Free stream preservation:
Simulation of linear advection equation and compressible Euler equation with a constant initial condition, cfl<=0.8 results in machine precision errors for all defined meshes.

TODOs:

  • Check if convergence_test works parallel. If I remember correctly, it doesn't.

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 85.78256% with 119 lines in your changes are missing coverage. Please review.

Project coverage is 79.43%. Comparing base (9a694b6) to head (357ac9d).
Report is 9 commits behind head on main.

Files Patch % Lines
src/solvers/fv_t8code/containers.jl 79.74% 46 Missing ⚠️
src/solvers/fv_t8code/fv.jl 89.93% 29 Missing ⚠️
src/meshes/t8code_mesh.jl 90.57% 20 Missing ⚠️
src/callbacks_step/analysis_dg2d.jl 66.07% 19 Missing ⚠️
src/callbacks_step/save_solution.jl 80.00% 2 Missing ⚠️
src/callbacks_step/stepsize_dg2d.jl 90.91% 2 Missing ⚠️
src/meshes/mesh_io.jl 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1844       +/-   ##
===========================================
- Coverage   96.08%   79.43%   -16.65%     
===========================================
  Files         450      455        +5     
  Lines       36169    37053      +884     
===========================================
- Hits        34750    29430     -5320     
- Misses       1419     7623     +6204     
Flag Coverage Δ
unittests 79.43% <85.78%> (-16.65%) ⬇️

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.

Comment on lines 224 to 233
# TODO: Implement this function as soon as there is support for this in `t8code`.
function save_mesh_file(mesh::T8codeMesh, output_directory, timestep, mpi_parallel)
error("Mesh file output not supported yet for `T8codeMesh`.")
# function save_mesh_file(mesh::T8codeMesh, output_directory, timestep, mpi_parallel)
# error("Mesh file output not supported yet for `T8codeMesh`.")

# return joinpath(output_directory, "dummy_mesh.h5")
# end

function save_mesh_file(mesh::T8codeMesh, output_directory, timestep, mpi_parallel)
return joinpath(output_directory, "dummy_mesh.h5")
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All those plotting routines are very improvised and are not in the standard Trixi way.
I use the t8code internal routines to directly create vtu files inside Trixi.jl.
They probably should be deleted or changed for this PR.

mesh.tree_node_coordinates = tree_node_coordinates
mesh.max_number_faces = 4 # TODO: How to automatically adapt for other element types, e.g. triangles?
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.

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

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 bennibolm changed the title WIP: Add first-order FV method for T8codeMesh WIP: Add FV method for T8codeMesh Apr 16, 2024
@bennibolm
Copy link
Contributor Author

Note: Right now, it is not possible to use the extended reconstruction kernel (for 2order FV) mpi parallel. That's due to the structure of ghost elements in the t8code ghost cell structure. Only direct (=along an edge) neighbors are listed as ghost cells.
Example: Hybrid mesh on 2 mpi ranks. Plotted the cells and ghost cells of rank 0:
t8code_ghost_cells

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.

None yet

1 participant