Giter Club home page Giter Club logo

trixi-framework / trixi.jl Goto Github PK

View Code? Open in Web Editor NEW
513.0 26.0 98.0 415.33 MB

Trixi.jl: Adaptive high-order numerical simulations of conservation laws in Julia

Home Page: https://trixi-framework.github.io/Trixi.jl

License: MIT License

Shell 0.03% Julia 99.76% Jupyter Notebook 0.16% Gnuplot 0.02% Python 0.03%
adaptive-mesh-refinement amr conservation-laws discontinuous-galerkin julia numerical-simulation-framework simulation summation-by-parts hyperbolic-equations

trixi.jl's Introduction

Trixi.jl

Docs-stable Docs-dev Slack Youtube Build Status Codecov Coveralls Aqua QA License: MIT DOI OpenSSF Best Practices


Trixi.jl at JuliaCon 2024
At this year's JuliaCon in Eindhoven, Netherlands, we will be present with several contributions from the Trixi Framework ecosystem:

The last talk is part of the Julia for High-Performance Computing minisymposium, which this year is hosted by our own Hendrik Ranocha.

We are looking forward to seeing you there ♥️


Trixi.jl is a numerical simulation framework for conservation laws written in Julia. A key objective for the framework is to be useful to both scientists and students. Therefore, next to having an extensible design with a fast implementation, Trixi.jl is focused on being easy to use for new or inexperienced users, including the installation and postprocessing procedures. Its features include:

  • 1D, 2D, and 3D simulations on line/quad/hex/simplex meshes
    • Cartesian and curvilinear meshes
    • Conforming and non-conforming meshes
    • Structured and unstructured meshes
    • Hierarchical quadtree/octree grid with adaptive mesh refinement
    • Forests of quadtrees/octrees with p4est via P4est.jl
  • High-order accuracy in space and time
  • Discontinuous Galerkin methods
  • Compatible with the SciML ecosystem for ordinary differential equations
  • Native support for differentiable programming
  • Periodic and weakly-enforced boundary conditions
  • Multiple governing equations:
    • Compressible Euler equations
    • Compressible Navier-Stokes equations
    • Magnetohydrodynamics (MHD) equations
    • Multi-component compressible Euler and MHD equations
    • Linearized Euler and acoustic perturbation equations
    • Hyperbolic diffusion equations for elliptic problems
    • Lattice-Boltzmann equations (D2Q9 and D3Q27 schemes)
    • Shallow water equations
    • Several scalar conservation laws (e.g., linear advection, Burgers' equation, LWR traffic flow)
  • Multi-physics simulations
  • Shared-memory parallelization via multithreading
  • Multi-node parallelization via MPI
  • Visualization and postprocessing of the results
    • In-situ and a posteriori visualization with Plots.jl
    • Interactive visualization with Makie.jl
    • Postprocessing with ParaView/VisIt via Trixi2Vtk

Installation

If you have not yet installed Julia, please follow the instructions for your operating system. Trixi.jl works with Julia v1.8 and newer. We recommend using the latest stable release of Julia.

For users

Trixi.jl and its related tools are registered Julia packages. Hence, you can install Trixi.jl, the visualization tool Trixi2Vtk, OrdinaryDiffEq.jl, and Plots.jl by executing the following commands in the Julia REPL:

julia> using Pkg

julia> Pkg.add(["Trixi", "Trixi2Vtk", "OrdinaryDiffEq", "Plots"])

You can copy and paste all commands to the REPL including the leading julia> prompts - they will automatically be stripped away by Julia. The package OrdinaryDiffEq.jl provides time integration schemes used by Trixi.jl, while Plots.jl can be used to directly visualize Trixi.jl's results from the REPL.

Note on package versions: If some of the examples for how to use Trixi.jl do not work, verify that you are using a recent Trixi.jl release by comparing the installed Trixi.jl version from

julia> using Pkg; Pkg.update("Trixi"); Pkg.status("Trixi")

to the latest release. If the installed version does not match the current release, please check the Troubleshooting section in the documentation.

The commands above can also be used to update Trixi.jl. A brief list of notable changes to Trixi.jl is available in NEWS.md.

For developers

If you plan on editing Trixi.jl itself, you can download Trixi.jl locally and use the code from the cloned directory:

git clone [email protected]:trixi-framework/Trixi.jl.git
cd Trixi.jl
mkdir run
cd run
julia --project=. -e 'using Pkg; Pkg.develop(PackageSpec(path=".."))' # Install local Trixi.jl clone
julia --project=. -e 'using Pkg; Pkg.add(["OrdinaryDiffEq", "Trixi2Vtk", "Plots"])' # Install additional packages

Note that the postprocessing tools Trixi2Vtk.jl and Plots.jl are optional and can be omitted.

If you installed Trixi.jl this way, you always have to start Julia with the --project flag set to your run directory, e.g.,

julia --project=.

if already inside the run directory. Further details can be found in the documentation.

Usage

In the Julia REPL, first load the package Trixi.jl

julia> using Trixi

Then start a simulation by executing

julia> trixi_include(default_example())

Please be patient since Julia will compile the code just before running it. To visualize the results, load the package Plots

julia> using Plots

and generate a heatmap plot of the results with

julia> plot(sol) # No trailing semicolon, otherwise no plot is shown

This will open a new window with a 2D visualization of the final solution:

The method trixi_include(...) expects a single string argument with the path to a Trixi.jl elixir, i.e., a text file containing Julia code necessary to set up and run a simulation. To quickly see Trixi.jl in action, default_example() returns the path to an example elixir with a short, two-dimensional problem setup. A list of all example elixirs packaged with Trixi.jl can be obtained by running get_examples(). Alternatively, you can also browse the examples/ subdirectory. If you want to modify one of the elixirs to set up your own simulation, download it to your machine, edit the configuration, and pass the file path to trixi_include(...).

Note on performance: Julia uses just-in-time compilation to transform its source code to native, optimized machine code at the time of execution and caches the compiled methods for further use. That means that the first execution of a Julia method is typically slow, with subsequent runs being much faster. For instance, in the example above the first execution of trixi_include takes about 20 seconds, while subsequent runs require less than 60 milliseconds.

Showcase of advanced features

The presentation From Mesh Generation to Adaptive Simulation: A Journey in Julia, originally given as part of JuliaCon 2022, outlines how to use Trixi.jl for an adaptive simulation of the compressible Euler equations in two spatial dimensions on a complex domain. More details as well as code to run the simulation presented can be found at the reproducibility repository for the presentation.

Documentation

Additional documentation is available that contains more information on how to modify/extend Trixi.jl's implementation, how to visualize output files etc. It also includes a section on our preferred development workflow and some tips for using Git. The latest documentation can be accessed either online or under docs/src.

Referencing

If you use Trixi.jl in your own research or write a paper using results obtained with the help of Trixi.jl, please cite the following articles:

@article{ranocha2022adaptive,
  title={Adaptive numerical simulations with {T}rixi.jl:
         {A} case study of {J}ulia for scientific computing},
  author={Ranocha, Hendrik and Schlottke-Lakemper, Michael and Winters, Andrew Ross
          and Faulhaber, Erik and Chan, Jesse and Gassner, Gregor},
  journal={Proceedings of the JuliaCon Conferences},
  volume={1},
  number={1},
  pages={77},
  year={2022},
  doi={10.21105/jcon.00077},
  eprint={2108.06476},
  eprinttype={arXiv},
  eprintclass={cs.MS}
}

@article{schlottkelakemper2021purely,
  title={A purely hyperbolic discontinuous {G}alerkin approach for
         self-gravitating gas dynamics},
  author={Schlottke-Lakemper, Michael and Winters, Andrew R and
          Ranocha, Hendrik and Gassner, Gregor J},
  journal={Journal of Computational Physics},
  pages={110467},
  year={2021},
  month={06},
  volume={442},
  publisher={Elsevier},
  doi={10.1016/j.jcp.2021.110467},
  eprint={2008.10593},
  eprinttype={arXiv},
  eprintclass={math.NA}
}

In addition, you can also refer to Trixi.jl directly as

@misc{schlottkelakemper2020trixi,
  title={{T}rixi.jl: {A}daptive high-order numerical simulations
         of hyperbolic {PDE}s in {J}ulia},
  author={Schlottke-Lakemper, Michael and Gassner, Gregor J and
          Ranocha, Hendrik and Winters, Andrew R and Chan, Jesse},
  year={2021},
  month={09},
  howpublished={\url{https://github.com/trixi-framework/Trixi.jl}},
  doi={10.5281/zenodo.3996439}
}

Authors

Trixi.jl was initiated by Michael Schlottke-Lakemper (University of Augsburg, Germany) and Gregor Gassner (University of Cologne, Germany). Together with Hendrik Ranocha (Johannes Gutenberg University Mainz, Germany), Andrew Winters (Linköping University, Sweden), and Jesse Chan (Rice University, US), they are the principal developers of Trixi.jl. The full list of contributors can be found in AUTHORS.md.

License and contributing

Trixi.jl is licensed under the MIT license (see LICENSE.md). Since Trixi.jl is an open-source project, we are very happy to accept contributions from the community. Please refer to CONTRIBUTING.md for more details. Note that we strive to be a friendly, inclusive open-source community and ask all members of our community to adhere to our CODE_OF_CONDUCT.md. To get in touch with the developers, join us on Slack or create an issue.

Acknowledgments

This project has benefited from funding by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) through the following grants:

  • Excellence Strategy EXC 2044-390685587, Mathematics Münster: Dynamics-Geometry-Structure.
  • Research unit FOR 5409 "Structure-Preserving Numerical Methods for Bulk- and Interface Coupling of Heterogeneous Models (SNuBIC)" (project number 463312734).
  • Individual grant no. 528753982.

This project has benefited from funding from the European Research Council through the ERC Starting Grant "An Exascale aware and Un-crashable Space-Time-Adaptive Discontinuous Spectral Element Solver for Non-Linear Conservation Laws" (Extreme), ERC grant agreement no. 714487.

This project has benefited from funding from Vetenskapsrådet (VR, Swedish Research Council), Sweden through the VR Starting Grant "Shallow water flows including sediment transport and morphodynamics", VR grant agreement 2020-03642 VR.

This project has benefited from funding from the United States National Science Foundation (NSF) under awards DMS-1719818 and DMS-1943186.

This project has benefited from funding from the German Federal Ministry of Education and Research (BMBF) through the project grant "Adaptive earth system modeling with significantly reduced computation time for exascale supercomputers (ADAPTEX)" (funding id: 16ME0668K).

This project has benefited from funding by the Daimler und Benz Stiftung (Daimler and Benz Foundation) through grant no. 32-10/22.

Trixi.jl is supported by NumFOCUS as an Affiliated Project.

trixi.jl's People

Contributors

amrueda avatar andrewwinters5000 avatar apey236 avatar arpit-babbar avatar arseniykholod avatar benegee avatar bennibolm avatar cczernik avatar danieldoehring avatar davknapp avatar dependabot[bot] avatar efaulhaber avatar felipesantillan avatar github-actions[bot] avatar gregorgassner avatar henry2004y avatar huiyuxie avatar jlchan avatar jmark avatar jmbender avatar joshualampert avatar juliaod avatar krisshchawla avatar lchristm avatar nichtlucas avatar patrickersing avatar ranocha avatar simoncan avatar sloede avatar xzczd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trixi.jl's Issues

Parallelize trixi2vtk

In GitLab by @sloede on Mar 21, 2020, 22:47

This should be fairly easy, e.g., with a @distributed loop over all files to convert. The only part that is not inherently thread-safe is the writing of the PVD file. This could be achieved, however, by returning the resulting VTK file (currently named vtk) as an array [vtk] and then use vcat as the reduction operator. This should result in an array of VTK files, that can then be written serially to the PVD file.

When to use type annotations for function parameters: best practice and what to do in Trixi?

In GitLab by @sloede on May 11, 2020, 14:28

@ranocha started a discussion in #42 about the (mis-)use of type annotations for function parameters, e.g. in src/solvers/dg.jl:

function calc_surface_flux!(surface_flux::Array{Float64, 4}, neighbor_ids::Matrix{Int},
                            u_surfaces::Array{Float64, 4}, dg::Dg, ::Val{true},
                            orientations::Vector{Int})
   ...
end

He suggested to remove type annotations that purely serve documentation purposes and are not required for multiple dispatch (in the example: all but ::Val{true}), and to instead capture the documentation aspects in a docstring instead. To me, this seems like a very reasonable proposal. However, before changing anything in Trixi, it would help (at least me) to have these two questions answered first:

  1. What are best practices in the Julia community regarding type annotations for function parameters?
  2. What is a good approach for us in Trixi, taking into account added complexity, required effort, and what can be reasonably implemented in practice?

As far as I understand, there are only two cases where you must use type annotations: If it is required for multiple dispatch, or if you use parametric types for which you need to access/use the actual type. In all other cases I can think of, type annotations are optional and, quoting the Julia manual:

Adding annotations serves three primary purposes: to take advantage of Julia's powerful multiple-dispatch mechanism, to improve human readability, and to catch programmer errors.

I think most cases in Trixi belong to the second or third category (or a mixture thereof): We often use type annotations like the ones above to show a user/programmer what kind of function parameters are expected, and to immediately throw an error if a programmer violates this. For example, in DG code we often have methods like flux or cons2prim that could very well work on the entire DG dataset (i.e., all elements, all nodes) or just on a single point.

Thus, back to my questions: What are the best practices ("the Julian way") and how do we want handle this in Trixi? The biggest advantages of the current style (annotations-as-documentation) are IMHO that

  1. They are always up to date.
  2. They are always use the same "formatting".

The biggest advantages of using docstrings are IMHO

  1. It does not abuse the type annotations for documentation, leaving the code more generic in the process.
  2. It allows to use Julia's internal doc mechanisms on the REPL
  3. Documentation is not just in the code but also on the GitLab Pages website.
    If we start to move towards using non-annotated function parameters together with docstrings, we would have to consider what our own guidelines would be, such that it is easy for students (and for ourselves) to decide when and how to put documentation in docstrings.

I have not yet made up my mind yet about the way we want to handle it in Trixi, but would be very interested in your ideas! Also, I'd by very interested in learning about the "true" Julian way - maybe @ranocha can shed some more light on this, since he is by far the most experienced Julia developer here ;-)

Visualisation of AMR Data

In GitLab by @gregorgassner on Mar 30, 2020, 11:46

I have the feeling that a constant number of visu nodes per element causes artefacts in the paraview visualisation.

It would be more natural, to have a "uniform" visu resolution accross the grid. Say, you choose

6 visu nodes for the finest level, the next level should have 12 nodes, the next level 24 nodes...such that that "data pixels" have the same size.

I have currently in my AMR results some artefacts, and I think (hope) these are related to visualisation issues...

Visualize element data

In GitLab by @sloede on Mar 14, 2020, 22:22

Extend plot2d.jl and trixi2vtu to visualize element-wise data in an easy and intuitive manner. That is, it should be straightforward to, e.g., add the current blending factors to the solution files and then plot them just as regular node-based data would be shown.

Implement ES mortars

In GitLab by @sloede on Mar 17, 2020, 15:54

Extend the current EC mortar capabilities to support ES (entropy-stable) mortars as well.

README adjustments, general Pkg question

In GitLab by @gregorgassner on Apr 1, 2020, 16:25

We should update the README, regarding the new visu tool.

Furthermore, is it really necessary to have this extra step:

julia --project='postprocessing/pkg/Trixi2Vtk' -e 'import Pkg; Pkg.instantiate()'

Couldn't we just integrate this step in the first, Trixi setup step?

We always need postprocessing when using Trixi I guess, so no need to separate those two things imo?

Fix automatic installation of Trixi dependencies

In GitLab by @sloede on Mar 27, 2020, 08:35

Fix bin/trixi to always use --project=$PROJECT_DIR when calling Julia. This way, the ] activate . ; instantiate procedure should work to install all required dependencies for Trixi.

Pre-calculate AMR projection matrices and store with DG solver

In GitLab by @sloede on Mar 17, 2020, 11:41

Currently, the coarsen_elements!/refine_element! use the l2mortar 1D projection matrices and multiply them each time. They could be pre-multiplied to save computing time - check if that makes sense from a performance perspective and if yes, implement it.

Discuss, fix, and document how we want to handle package installation etc.

In GitLab by @sloede on Mar 23, 2020, 06:25

Right now the installation instructions in the README.md do not work: If you run ] activate . and call instantiate, you can only access the installed packages if you always use --project=path when you start a Julia script. This begs the question, how we want to handle student installation and/or the development workflow for us.

Create trixi2txt postprocessing script to convert HDF5 files to text

In GitLab by @sloede on Mar 27, 2020, 07:05

This can be helpful if Trixi output data is needed for postprocessing by other programs. It should basically write CSV files in the following format:

# filename = "solution_0000123.h5"
# time = 1.2345
# polydeg = 4
# <other global attributes follow>
x       y       rho     u       v
0.0     0.1     1.0     0.0     0.0
0.0     0.1     1.0     0.0     0.0
...

x and y refer to the node coordinates. In case of solution files with element variables, these should by default not be written (as they would have a different length). Provide a --separate-celldata/-s flag to write this data to a separate file instead, using the element coordinates (not node coordinates!) for x and y.

Mesh files should be handled in a similar way.

Add tool for automated EOC analysis [REPLACEMENT ISSUE]

The original issue

Id: 39
Title: Add tool for automated EOC analysis

could not be created.
This is a dummy issue, replacing the original one. It contains everything but the original issue description. In case the gitlab repository is still existing, visit the following link to show the original issue:

TODO

Create testing tool for automated testing

In GitLab by @sloede on Mar 14, 2020, 22:25

This is necessary...

  • for automated testing of the repository using CI/CD pipelines
  • to remain sane when new features are developed that are not orthogonal to existing features anymore
  • to remain sane when students and other collaborators start contributing code

Use CompatHelper (when moving to GitHub?)

In GitLab by @ranocha on May 13, 2020, 13:22

For packages registered in the general Julia registry, a [compat] section in Project.toml is necessary for automatic merging. This will also allow to drop the Manifest.toml without losing reproducibility. On GitHub, CompatHelper can be used to automate the process of adding/updating the [compat] section but it is not available on Gitlab.

Xref https://gitlab.mi.uni-koeln.de/numsim/code/Trixi.jl/-/merge_requests/43#note_651.

Plot 1D time dependent data

In GitLab by @gregorgassner on Mar 29, 2020, 18:10

It would be good to have the capability to store single quantities in every time step, to make a time series plot. entropy over time, kinetic energy, etc...

Implement logging mechanism

In GitLab by @sloede on Mar 14, 2020, 12:25

Store all regular output plus additional debug information in a log file such
that it can be recovered later, e.g., in out/trixi_YYYMMDDHHmmss.log

The logging mechanism of Julia (https://docs.julialang.org/en/v1/stdlib/Logging/) should be used. The idea is the following (roughly as discussed with Gregor):

  • All output to console or log files actually goes through logging infrastructure
  • We use only two standard log levels, i.e., @info and @debug
    • @info is the normal runtime output
    • @debug is additional output that can help with debugging
  • By default, @info goes to stdout while @debug is not evaluated at all.
  • If log=True or log=<filename> is provided to run(), all @info messages go additionally to out/trixi.log or out/<filename>.log
  • If debug=True is provided to run() (or ENV["JULIA_DEBUG"] is set appropriately), all @debug messages are shown at stdout as well. In combination with log=True/<filename>, however, debug messages will only be shown in the log file.

It might be interesting to enable other default output if logging-to-file is enabled, e.g., to copy the parameters file used to the beginning of the log file, or some information on when and where and with which command line arguments trixi was started.

Potential use cases where it might be interesting to have a permanent log:

  • AMR: current number of elements; elements added/removed; number of elements at each level
  • shock capturing: information about minimum/maximum alpha values; number of pure DG/blended DG-FV elements

Entropy-stable AMR

In GitLab by @sloede on Mar 29, 2020, 08:45

Use this issue to discuss and track possible implementations for entropy-stable AMR.

Increase test coverage [REPLACEMENT ISSUE]

The original issue

Id: 49
Title: Increase test coverage

could not be created.
This is a dummy issue, replacing the original one. It contains everything but the original issue description. In case the gitlab repository is still existing, visit the following link to show the original issue:

TODO

postprocessing

In GitLab by @andrewwinters5000 on Mar 26, 2020, 21:39

should be clarified in the documentation that there is a postprocessing tool for the *.h5 files. Also, there should be another Project.toml because the postprocessing step requires the installation of two additional packages:

  • WriteVTK
  • ProgressMeter

Also, on my machine running the postprocessing requires the deactivation of saving PVD, tex

postprocessing/trixi2vtu -s --save-pvd=no out/*.h5

Remove GaussQuadrature from dependencies

In GitLab by @sloede on Apr 6, 2020, 13:01

Right now we use the GaussQuadrature module only for calculating the LG and LGL nodes and weights. I feel like we could just add the implementations here (they were implemented at some point in the very beginning) and drop the dependence on the GaussQuadrature.jl package, which should also slightly improve startup times.

General plan and layout

In GitLab by @ranocha on May 7, 2020, 17:07

Hi! I'm totally new to this project and haven't been involved in the discussions and the work resulting in the current version. Hence, I hesitate a bit to start discussions that can possibly necessitate huge changes to your workflow and/or the code. On the other hand, I couldn't find such discussions online (since they probably happened in person) and the resulting comments may be of interest for future users of Trixi.

My first impression of Trixi is that it's heavily inspired by monolithic Fortran codes like Flexi/Fluxo, which is totally natural, of course. In my opinion, a different approach might be useful in Julia: Instead of providing a single executable running a parameter file, an approach to create a library of tools might be of interest.
For example, if a student shall run some experiments with a slightly different initial condition, Trixi itself has to be modified, e.g. at https://gitlab.mi.uni-koeln.de/numsim/code/Trixi.jl/-/blob/master/src/equations/linearscalaradvection.jl#L46.
An alternative to parameter files could be to supply the parameters as pure Julia code using the Trixi library. In that case, students could write the initial condition as a Julia function without the need to modify Trixi itself. Since functions are first-class citizens in Julia, they can be passed around as arguments (or as part of structs).

The structure of Trixi using many modules and global variables reminds me of Fortran modules etc. While using constant global variables is okay (type stable) in Julia, passing parameters is more encouraged.

Another reminder of Fortran and co are the type annotations for function arguments. Unless they direct multiple dispatch, they shouldn't be used in Julia.

function calc_surface_flux!(surface_flux, neighbor_ids,
                            u_surfaces, dg::D, ::Val{true},
                            orientations)
   ...
end

is compiled to exactly the same machine code as

function calc_surface_flux!(surface_flux::Array{Float64, 4}, neighbor_ids::Matrix{Int},
                            u_surfaces::Array{Float64, 4}, dg::Dg, ::Val{true},
                            orientations::Vector{Int})
   ...
end

if the arguments are the same. The first version is more general, since the array type can be exchanged. For example, it is possible to use the same code to run a simulation with Float32 (or possibly some floating point type with higher accuracy), which can be useful sometimes. I prefer to include the additional kind of documentation provided by the type annotations in docstrings for the functions.

The multiple dispatch feature of Julia seems to be abused sometimes in the current version, e.g. in https://gitlab.mi.uni-koeln.de/numsim/code/Trixi.jl/-/blob/master/src/solvers/dg.jl#L1171. Such type-unstable code results in a possibly huge performance impact.
For example, I started from the current master branch with this git diff.

diff --git a/parameters_ec.toml b/parameters_ec.toml
index 8cd35d1..3bf5612 100644
--- a/parameters_ec.toml
+++ b/parameters_ec.toml
@@ -18,7 +18,7 @@ volume_flux_type = "chandrashekar_ec"
 # volume_flux_type = "central"
 # sources = 
 t_start = 0.0
-t_end   = 0.4
+t_end   = 4.0 # 0.4
 
 # restart = true
 # restart_filename = "out/restart_000100.h5"
diff --git a/src/equations/euler.jl b/src/equations/euler.jl
index c3978b9..5fdc582 100644
--- a/src/equations/euler.jl
+++ b/src/equations/euler.jl
@@ -670,62 +670,67 @@ function Equations.riemann!(surface_flux::AbstractArray{Float64, 1},
   calcflux1D!(f_ll, equation, rho_ll, rho_v1_ll, rho_v2_ll, rho_e_ll, orientation)
   calcflux1D!(f_rr, equation, rho_rr, rho_v1_rr, rho_v2_rr, rho_e_rr, orientation)
 
-  if equation.surface_flux_type == :laxfriedrichs
-    λ_max = max(v_mag_ll, v_mag_rr) + max(c_ll, c_rr)
-    surface_flux[1] = 1/2 * (f_ll[1] + f_rr[1]) - 1/2 * λ_max * (rho_rr    - rho_ll)
-    surface_flux[2] = 1/2 * (f_ll[2] + f_rr[2]) - 1/2 * λ_max * (rho_v1_rr - rho_v1_ll)
-    surface_flux[3] = 1/2 * (f_ll[3] + f_rr[3]) - 1/2 * λ_max * (rho_v2_rr - rho_v2_ll)
-    surface_flux[4] = 1/2 * (f_ll[4] + f_rr[4]) - 1/2 * λ_max * (rho_e_rr  - rho_e_ll)
-  elseif equation.surface_flux_type in (:central, :kennedygruber, :chandrashekar_ec, :yuichi)
-    symmetric_twopoint_flux!(surface_flux, Val(equation.surface_flux_type),
-                             equation, orientation,
-                             rho_ll, rho_v1_ll, rho_v2_ll, rho_e_ll,
-                             rho_rr, rho_v1_rr, rho_v2_rr, rho_e_rr)
-
-  elseif equation.surface_flux_type == :hllc
-    error("not yet implemented or tested")
-    v_tilde = (sqrt(rho_ll) * v_ll + sqrt(rho_rr) * v_rr) / (sqrt(rho_ll) + sqrt(rho_rr))
-    h_ll = (rho_e_ll + p_ll) / rho_ll
-    h_rr = (rho_e_rr + p_rr) / rho_rr
-    h_tilde = (sqrt(rho_ll) * h_ll + sqrt(rho_rr) * h_rr) / (sqrt(rho_ll) + sqrt(rho_rr))
-    c_tilde = sqrt((equation.gamma - 1) * (h_tilde - 1/2 * v_tilde^2))
-    s_ll = v_tilde - c_tilde
-    s_rr = v_tilde + c_tilde
-
-    if s_ll > 0
-      surface_flux[1, surface_id] = f_ll[1]
-      surface_flux[2, surface_id] = f_ll[2]
-      surface_flux[3, surface_id] = f_ll[3]
-    elseif s_rr < 0
-      surface_flux[1, surface_id] = f_rr[1]
-      surface_flux[2, surface_id] = f_rr[2]
-      surface_flux[3, surface_id] = f_rr[3]
-    else
-      s_star = ((p_rr - p_ll + rho_ll * v_ll * (s_ll - v_ll) - rho_rr * v_rr * (s_rr - v_rr))
-                / (rho_ll * (s_ll - v_ll) - rho_rr * (s_rr - v_rr)))
-      if s_ll <= 0 && 0 <= s_star
-        surface_flux[1, surface_id] = (f_ll[1] + s_ll *
-            (rho_ll * (s_ll - v_ll)/(s_ll - s_star) - rho_ll))
-        surface_flux[2, surface_id] = (f_ll[2] + s_ll *
-            (rho_ll * (s_ll - v_ll)/(s_ll - s_star) * s_star - rho_v_ll))
-        surface_flux[3, surface_id] = (f_ll[3] + s_ll *
-            (rho_ll * (s_ll - v_ll)/(s_ll - s_star) *
-            (rho_e_ll/rho_ll + (s_star - v_ll) * (s_star + rho_ll/(rho_ll * (s_ll - v_ll))))
-            - rho_e_ll))
-      else
-        surface_flux[1, surface_id] = (f_rr[1] + s_rr *
-            (rho_rr * (s_rr - v_rr)/(s_rr - s_star) - rho_rr))
-        surface_flux[2, surface_id] = (f_rr[2] + s_rr *
-            (rho_rr * (s_rr - v_rr)/(s_rr - s_star) * s_star - rho_v_rr))
-        surface_flux[3, surface_id] = (f_rr[3] + s_rr *
-            (rho_rr * (s_rr - v_rr)/(s_rr - s_star) *
-            (rho_e_rr/rho_rr + (s_star - v_rr) * (s_star + rho_rr/(rho_rr * (s_rr - v_rr))))
-            - rho_e_rr))
-      end
-    end
-  else
-    error("unknown Riemann solver '$(string(equation.surface_flux_type))'")
-  end
+  symmetric_twopoint_flux!(surface_flux, Val(:chandrashekar_ec),
+                           equation, orientation,
+                           rho_ll, rho_v1_ll, rho_v2_ll, rho_e_ll,
+                           rho_rr, rho_v1_rr, rho_v2_rr, rho_e_rr)
+
 end
 
 # Original riemann! implementation, non-optimized but easier to understand

If I understood the code correctly, the result should be the same since I use surface_flux_type = "chandrashekar_ec" in parameters_ec.toml. (Of course, this code is less general but it serves the purpose to demonstrate type stability in a simple way.)
Running the current master with this parameters_ec.toml, I get

              trixi                     Time                   Allocations      
                                ----------------------   -----------------------
        Tot / % measured:            18.1s / 99.5%            589MiB / 83.5%    

 Section                ncalls     time   %tot     avg     alloc   %tot      avg
 -------------------------------------------------------------------------------
 main loop                   1    18.0s   100%   18.0s    480MiB  97.5%   480MiB
   rhs                   1.75k    17.3s  95.8%  9.88ms   99.2MiB  20.2%  58.1KiB
     surface flux        1.75k    13.6s  75.5%  7.78ms   10.2MiB  2.06%  5.95KiB
     volume integral     1.75k    2.89s  16.0%  1.65ms   76.3MiB  15.5%  44.6KiB
     ...

With the type stable version from git diff, I get

        Tot / % measured:            5.22s / 90.0%            675MiB / 73.0%    

 Section                ncalls     time   %tot     avg     alloc   %tot      avg
 -------------------------------------------------------------------------------
 main loop                   1    4.70s   100%   4.70s    480MiB  97.5%   480MiB
   rhs                   1.75k    3.99s  84.8%  2.28ms   99.3MiB  20.2%  58.1KiB
     volume integral     1.75k    2.92s  62.2%  1.67ms   76.3MiB  15.5%  44.6KiB
     ...
     surface flux        1.75k    235ms  4.99%   134μs   10.2MiB  2.07%  5.97KiB

That impact is way more than I expected - I hope I didn't code bullshit here...
The additional git diff

diff --git a/src/equations/euler.jl b/src/equations/euler.jl
index c3978b9..b1f1b73 100644
--- a/src/equations/euler.jl
+++ b/src/equations/euler.jl
@@ -358,7 +358,9 @@ end
                                               equation::Euler,
                                               u::AbstractArray{Float64},
                                               element_id::Int, n_nodes::Int)
-  calcflux_twopoint!(f1, f2, f1_diag, f2_diag, Val(equation.volume_flux_type),
+  # calcflux_twopoint!(f1, f2, f1_diag, f2_diag, Val(equation.volume_flux_type),
+  #                    equation, u, element_id, n_nodes)
+  calcflux_twopoint!(f1, f2, f1_diag, f2_diag, Val(:chandrashekar_ec),
                      equation, u, element_id, n_nodes)
 end

improves the performance for the volume terms to

        Tot / % measured:            3.13s / 97.4%            576MiB / 83.2%    

 Section                ncalls     time   %tot     avg     alloc   %tot      avg
 -------------------------------------------------------------------------------
 main loop                   1    3.04s   100%   3.04s    467MiB  97.5%   467MiB
   rhs                   1.75k    2.25s  73.9%  1.29ms   85.6MiB  17.9%  50.1KiB
     volume integral     1.75k    1.20s  39.5%   687μs   62.6MiB  13.1%  36.6KiB
     ...
     surface flux        1.75k    237ms  7.79%   136μs   10.2MiB  2.13%  5.97KiB

A general solution to get type stable code in a library like approach could be to use parametric types and supply the fluxes as Julia functions instead of strings or symbols.

I saw the additional repositories Abraxas and trixi-tests but haven't looked at them yet. In Julia, it is pretty common to include some (unit) tests in every package which are triggered for every PR on GitHub (merge request on GitLab). In this way, some additional example code is provided and some basic functionality is guaranteed to work with new changes. While I didn't like that approach at the beginning (since I wasn't used to it), I really started to like it while developing more complex code, in particular if some time has passed between development cycles. I think it would be really nice if some small/basic tests are included here in test/runtests.jl etc. They could be triggered for every merge request as GitLab pipeline, I think. If Trixi shall be registered as Julia package (as hinted to in https://gitlab.mi.uni-koeln.de/numsim/code/Trixi.jl/-/issues/20#note_276), running tests and reporting coverage results (e.g. via Travis and Codecov/Coveralls) is usually seen as a requirement and sign of good coding standards.

Okay, this grew into a lot of text. I hope we can start a constructive discussion and improve Trixi, building on your nice work :)

Enable automated testing

In GitLab by @sloede on May 9, 2020, 07:55

As suggested by @ranocha in #42, it would be great to have tests run automatically whenever a MR is created/updated or once master is changed. Right now, the only testing tool we have is Abraxas.jl, with tests being defined in trixi-tests. However, since it requires a setup process for testing (i.e., clone & instantiate external packages), it is somewhat cumbersome to set up for testing and not very Julian.

A more Julian way would be to follow @ranocha's lead and use (abuse) Julia's canonical unit testing capabilities for packages, which uses test/runtests.jl to set up automated testing (docs) and employs the unit testing capabilities in Julia Base with @test and @testset (docs).

One reason I have shunned away from this approach so far is that it does not allow to do full integration testing in a sane manner. That is, for a full-fledged test of Trixi, you should run an entire simulation setup and then compare all output files with some references. However, for this to work, you have to be able to store (and more importantly, update) reference files, which quickly and significantly increases the repository size. However, @erik-f has started to implement a convtest function for easy h-convergence testing in !41. Among other changes, run now returns the final L2/Linf errors calculated. Therefore, we could use this information together with the already-present parameter files to set up some simple Trixi tests in a Julian way and without the need for a more sophisticated testing infrastructure. It would only be able to confirm that the L2/Linf errors are correct, but in many cases that is enough to detect breaking changes (or errors) in an implementation.

Therefore, I propose the following changes:

  1. Move all parameters file from the root directory to a separate directory, e.g., examples/.
  2. Once !41 is merged, create tests in test/runtests.jl that cover a broad range of "features" in Trixi by running the appropriate parameter files from examples/ and comparing the resulting L2/Linf errors (with a tolerance, of course).
  3. Set up our CI/CD pipelines to run these tests at least for every MR and every push to master.

Trixi "features" that should be tested are:

  • All systems of equations: linear scalar advection, Euler, MHD
  • Static local refinement/mortars
  • AMR
  • Shock capturing
  • EC/ES
  • Source terms
  • ... (feel free to add to this list!)

While this will not provide us with anything like absolute quality assurance, I see this as a quick way forward towards improving confidence that we do not break existing functionality with new commits. In the future, we can even use this to show code coverage results for the automated testing.

As usual, please feel free to discuss and improve!

Rename stuff for consistency & clarity

In GitLab by @sloede on Mar 15, 2020, 08:22

  • u_t -> ut for consistency with FLUXO
  • weights -> weights1d (also add weights2d)
  • nodes -> nodes1d (also add nodes2d)
  • inverse_jacobian -> inverse_jacobian1d (also add jacobian1d, jacobian2d
  • All "getter" methods that obtain a certain attribute from an object should be prefixed by get such that the original name is free to be used as the variable name.
    Examples: nnodes, polydeg, nelements, nsurfaces,

Reduce allocations in volume integral and surface flux calculations

In GitLab by @sloede on Mar 12, 2020, 09:20

Currently, our timings/allocations for parameters_ec.toml for our two most expensive kernels look like this:

     volume integral        190    13.2s  54.3%  69.2ms   4.33GiB  81.6%  23.4MiB
     surface flux           190    9.20s  38.0%  48.4ms    718MiB  13.2%  3.78MiB

This should be improved considerably if we want to

Move numerical fluxes to solvers

In GitLab by @ranocha on May 18, 2020, 12:35

Right now, the volume and surface fluxes are part of the equations/models. In my opinion, they belong more to the specific discretization (DG) and a lax_friedrichs_flux can be used for all models/equations (with specific methods implemented there).

Add L2/Linf checking to tests [REPLACEMENT ISSUE]

The original issue

Id: 47
Title: Add L2/Linf checking to tests

could not be created.
This is a dummy issue, replacing the original one. It contains everything but the original issue description. In case the gitlab repository is still existing, visit the following link to show the original issue:

TODO

Add tool for automated bisection on solution stability

In GitLab by @sloede on Apr 14, 2020, 07:24

From time to time it is useful to twiddle with a parameter to figure out what its optimal setting is to just remain stable. Examples: CFL number for different time integration schemes, solution resolution, intensity of shock capturing etc.
Instead of figuring this out manually, it would be nice to automate this in an easy-to-use and robust way.

As a starting point for thoughts on an implementation:

Instead of starting Trixi with

Trixi.run("parameters.toml")

we add a new run-like method bisect, e.g., like this

Trixi.bisect("parameters.toml", :CFL, (0.4, 1.4), max_l2=1.0, max_linf=nothing, precision=0.01)

This should run Trixi multiple times with a bisection algorithm, using parameters.toml as the base configuration, always changing (= overriding) the value of CFL, which should range between 0.4 and 1.4, and optimize it with a precision of up to 2 decimal places. As a stability indicator, we define "unstable" as the L2 error being > 1.0, and we use no criterion on Linf.

Feel free to chime in if you have thoughts on a possible implementation or if you find other cases where such a feature might be interesting.

Add MHD equations

In GitLab by @andrewwinters5000 on Mar 30, 2020, 20:43

Just add the capability to solve the standard MHD equations with LLF or HLLC type numerical fluxes. No GLM or entropy stuff. Those features come next...

Delete `ffmpeg` from `amr_finetuning` branch

In GitLab by @sloede on Apr 3, 2020, 08:11

Someone accidentally committed a 70M file (ffmpeg) to the amr_finetuning branch. I found a way that probably fixes it and will keep the rest of the repo's history intact:

https://rtyley.github.io/bfg-repo-cleaner/

However, to minimize the chances for any screw ups, we should follow the following strategy:

  1. Commit all current work to the amr_finetuning branch.
  2. Delete ffmpeg from the amr_finetuning branch.
  3. Delete MR !24 since it will be affected by the cleanup and I don't know if GitLab will break as a result
  4. I do the cleanup
  5. Everyone has to git fetch/git pull their amr_finetuning branch.

@gregorgassner I think you are the only one affected by 1), so please let me know once you've done that (afterwards you need to stop working on the branch). Steps 2) - 4) I will be able to do alone, but we can also do it in a shared session if you prefer.

Exploit tensor structure for AMR projections

In GitLab by @sloede on Mar 18, 2020, 13:01

That is, first apply 1D projections for each line in the x-direction, then in the y-direction. Probably interpolate_nodes can already be used for this. This should be much cheaper than the current approach, which does the full projection.

Maybe there is also potential to use this for mortar projections (probably not, since they are already 1D).

Usage of unicode

In GitLab by @ranocha on May 14, 2020, 16:05

Since Julia allows us to use unicode (which I really like), we might consider making use of that possibility. For example, we could write l∞ instead of linf for errors in the maximum norm. Another use case is γ instead of gamma for the Euler equations and its siblings.

In the REPL and most major editors, you can use LaTeX extensions, e.g. l\infty and TAB to get l∞.

Implement nonconservative terms

In GitLab by @andrewwinters5000 on Apr 9, 2020, 07:20

Look into FLUXO to decipher (and simplify) how to implement the nonconservative terms for MHD. Right now the goal of this if the following:

  1. If you run MHD the GLM will always be activated so there are no if statements in the code to deactivate it.

  2. Only implement the Powell term because it is the most physically consistent (removes fictious Lorentz force).

  3. Both nonconservative terms are proportional to div(B) and related to the cleaning of it. Therefore, the Powell term and Galilean term should always be active and work with the standard or split DG

  4. Nonconservative terms should only alter the flux computation (in the volume and on the boundary) within the MHD module. In this sense the new implementation will not touch the dg.jl or dg_amr.jl portion. This way the nonconservative contribution will not spoil the non-conforming/AMR capabilities

  5. Exploit the Cartesian simplicity of the normals and metrics such that everything (hopefully) comes down to an orientation check (similar to the physical flux)

  6. After the nonconservative terms are implemented and tested, implement the entropy conservative and entropy stable fluxes for MHD

plotting in Atom

In GitLab by @andrewwinters5000 on Mar 27, 2020, 08:13

On line 116 of README.md I think there is a typo. It says to use a file "postprocessing/plotfast.jl" and I think this needs to be "postprocessing/plot2d.jl". Also, these instructions for plotting do not work for me (I use Atom for my Julia coding). When I run TrixiPlot.main() it says that the main is not defined (see below):

Screenshot_2020-03-27_at_08.12.23

Allow selective timing in `rhs!`

In GitLab by @sloede on Mar 14, 2020, 09:58

Currently, rhs! contains duplicated code: one version with timers, one without timers. The reason is that a call to rhs! is needed for the entropy time derivative to work (from calc_entropy_timederivative). Optimally, it should be possible to either

  • pass an argument to rhs! that disables timing without duplicated code, or
  • write a macro that can disable timers from "outside", i.e., from the call site.

Corresponding question on Discourse: https://discourse.julialang.org/t/disable-timeroutputs-jl-timers-selectively-within-function/35957

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.