trixi-framework / Trixi.jl

Trixi.jl: Adaptive high-order numerical simulations of conservation laws in Julia
https://trixi-framework.github.io/Trixi.jl
MIT License
523 stars 103 forks source link

Taal aka Trixi as a library #177

Closed ranocha closed 3 years ago

ranocha commented 4 years ago

Taal: Trixi as a library

This is a draft of a possible approach to restructure Trixi.jl to

Design principles

Some design principles I had in mind while writing this draft:

Draft of the new layout of Trixi

Here is a list of suggested changes.

Disclaimer

This is just a rough first draft and needs to be refined. We definitely have to figure out a lot of details and invest a lot of time to make this work.

Thoughts, ideas, suggestions? I'm open to discussions.

ranocha commented 4 years ago

By the way,

julia> round(Int, 42 * 4.2, RoundUp)
177

Seems to fit to #42 :wink:

gregorgassner commented 4 years ago

I am curious about the very last file: where does a user get the interface information, when looking at this linear scalar advection problem.

Say, I want to do a new initial condition, but don't mess around with the internals. In principles, I could implement it directly in the elixir...however, I have to know how the interface of initial condition looks like, right? Hence, I have to dig through the Trixi internals anyways...?

sloede commented 4 years ago

First of all: Great work! :+1: I think this is a very good start for getting the ball rolling on this most complex undertaking we have tried so far with Trixi...

Two initial thoughts/questions:

  1. Where would elements live? I didn't see it up there. Or would this also end up in the cache?
  2. How does multi-physics work? For instance, how would your example file look for, e.g., examples/paper-self-gravitating-gas-dynamics/parameters_sedov_self_gravity.toml?
ranocha commented 4 years ago

Say, I want to do a new initial condition, but don't mess around with the internals. In principles, I could implement it directly in the elixir...however, I have to know how the interface of initial condition looks like, right? Hence, I have to dig through the Trixi internals anyways...?

The interface will be documented. Hence, people can either browse the source code of Trixi or look at the docs - maybe some of the tutorials?

ranocha commented 4 years ago
  1. Where would elements live? I didn't see it up there. Or would this also end up in the cache?

Right now, elements is an ElementContainer, which looks like this.

struct ElementContainer2D{NVARS, POLYDEG} <: AbstractContainer
  u::Array{Float64, 4}                   # [variables, i, j, elements]
  u_t::Array{Float64, 4}                 # [variables, i, j, elements]
  u_tmp2::Array{Float64, 4}              # [variables, i, j, elements]
  u_tmp3::Array{Float64, 4}              # [variables, i, j, elements]
  inverse_jacobian::Vector{Float64}      # [elements]
  node_coordinates::Array{Float64, 4}    # [orientation, i, j, elements]
  surface_ids::Matrix{Int}               # [direction, elements]
  surface_flux_values::Array{Float64, 4} # [variables, i, direction, elements]
  cell_ids::Vector{Int}                  # [elements]
end
ranocha commented 4 years ago

How does multi-physics work? For instance, how would your example file look for, e.g., examples/paper-self-gravitating-gas-dynamics/parameters_sedov_self_gravity.toml?

That depends on how much we want to hide from the user. For example, we could create a type EulerGravitySemidiscretization, that will contain a parameterized ODE problem for the hyperbolic diffusion part. This ODE problem is re-initialized with the given data and solved to steady state for every RHS evaluation.

sloede commented 4 years ago

Could you maybe give an example of how the Taal script for examples/paper-self-gravitating-gas-dynamics/parameters_sedov_self_gravity.toml could look like, just to get an idea?

ranocha commented 4 years ago

Maybe something like

using OrdinaryDiffEq
using Trixi
using StaticArrays

eqs_euler = CompressibleEulerEquations2D(gamma=1.4)
eqs_gravity = HyperbolicDiffusionEquations2D()
initial_conditions = initial_conditions_sedov_self_gravity # from Trixi

mesh = TreeMesh2D(coordinates_min=(-4.0, -4.0),
                  coordinates_max=( 4.0,  4.0),
                  initial_refinement_level=2,
                  periodicity=false)

volume_integral = VolumeIntegralShockCapturing(volume_flux_function_dg=flux_chandrashekar,
                                               volume_flux_function_fv=flux_hll,
                                               shock_indicator_variable=density_pressure)
solver = DG2D(polydeg=3, surface_flux=flux_hll,
              volume_integral=volume_integral)

# maybe we can also pass a time integration method as parameter, depending on how we would like
# to structure this part
semidisc = EulerGravitySemidiscretization(mesh, eqs_euler, eqs_gravity, initial_conditions, solver,
                                          source_terms=source_terms_harmonic,
                                          resid_tol=1.0e-4, cfl_gravity=1.2,
                                          G=6.674e-8, rho0=0.0)

cfl_callback = StepsizeLimiter(calc_max_dt(eqs, mesh, solver, cfl=0.5))
analysis_callback = AnalysisCallback(solver, extra_analysis_quantities=["entropy", "energy_total","energy_internal"])
amr_callback = AdaptiveMeshRefinementCallback(indicator=amr_indicator_sedov_self_gravity,
                                              interval=1, alpha_max=1.0, alpha_min=0.0)
# primitive_variables is something like Trixi.cons2prim
output_callback = OutputCallback(solution_interval=100, solution_variables=primitive_variables, restart_interval=10)
callback = CallbackSet(cfl_callback, analysis_callback, output_callback)

ode = init!(semidisc) # some better name...

tspan = (0.0, 1.0)
sol = solve(ode, CarpenterKennedy2N54(williamson_condition=false),
            dt=calc_max_dt(ode), save_everystep=false,
            callback=callback)