# \[ANN\] Trixi.jl v0.3: SciML integration and a new modular approach for easy extension

**URL:** <https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419>\
**Category:** Package Announcements\
**Tags:** parallel, pde, numerics, physics, math\
**Created:** [November 19, 2020, 10:06am UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419 "2020-11-19T10:06:42Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [November 20, 2020, 5:27pm UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/21 "2020-11-20T17:27:15Z")

</div>

> [@jlchan](#):
>
> That’s really cool to hear someone’s using that method, and I would love to contribute (especially since reading your code will probably improve my own Julia skills)!
> 
> This last week is busy wrapping up our semester, but I’m hoping to try out Trixi for an AMR-based project next week. If that works, I’d love to help with mortars.
> 
> Looking forward to corresponding more!

Sounds great! As @ranocha stated before, let us know if you have questions about using Trixi, either here or by creating an issue in GitHub.

Our current status is that we have a working implementation of your EC mortar flux correction in [#247](https://github.com/trixi-framework/Trixi.jl/pull/247), but it needs to be ported to the newly released Trixi (it is still based on our earlier, monolithic approach). Once that works again, the next step would be to extend it to ES mortars, which shouldn’t be too hard (I think).

---

<div class="post-metadata">

**Author:** ![jlchan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlchan/32/10958_2.png) [@jlchan](https://discourse.julialang.org/u/jlchan)\
**Post date:** [November 20, 2020, 5:30pm UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/22 "2020-11-20T17:30:51Z")

</div>

> Our current status is that we have a working implementation of your EC mortar flux correction in [#247](https://github.com/trixi-framework/Trixi.jl/pull/247), but it needs to be ported to the newly released Trixi (it is still based on our earlier, monolithic approach). Once that works again, the next step would be to extend it to ES mortars, which shouldn’t be too hard (I think).

That was fast! And agreed, I don’t think ES mortars (assuming it’s from some entropy dissipative flux penalization) would be very difficult.

---

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [December 30, 2020, 1:13pm UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/23 "2020-12-30T13:13:05Z")

</div>

> [@rveltz](#):
>
> Do you think it is possible to have a plot recipe? For example, how do you plot while simulating?

We now natively support visualizing results with [Plots.jl](https://github.com/JuliaPlots/Plots.jl) both during and after a simulation. With the current [Trixi.jl](https://user-images.githubusercontent.com/3637659/103352227-f1b28580-4aa5-11eb-896b-8752e28d203c.mp4) release (v0.3.6), plotting a solution from the REPL is as easy as loading `Plots` and throwing the `ODESolution` object from the call to `DiffEqBase.solve!` at it:

```julia
julia> trixi_include(default_example())
[...]

julia> using Plots

julia> plot(sol)

```

For in-situ visualization, use a `VisualizationCallback` to create a new plot of the current solution in regular time step intervals:  
 ![trixi-in-situ-visualization](https://global.discourse-cdn.com/julialang/original/3X/8/a/8a6d3c1086f8b1d803180a975d6b809c6f87172e.gif)

The features and how to use them are described in detail in the official [docs](https://trixi-framework.github.io/Trixi.jl/stable/visualization/#Plots.jl). We are looking for feedback on how to further improve the visualization/postprocessing capabilities in Trixi, so please feel welcome to leave a message here or [create an issue](https://github.com/trixi-framework/Trixi.jl/issues/new).

Thanks @rvelts once more for these valuable suggestions!

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 30, 2020, 1:52pm UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/24 "2020-12-30T13:52:41Z")

</div>

> [@sloede](#):
>
> For in-situ visualization, use a `VisualizationCallback` to create a new plot of the current solution in regular time step intervals:

That’s amazing.

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [December 30, 2020, 3:26pm UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/25 "2020-12-30T15:26:59Z")

</div>

That’s really cool!! I think it will boost the use of trixi (at least mine!).

On a side note, I cannot run your examples, like /examples/1d/ elixir\_advection\_amr.jl  
For one, it says `LinearScalarAdvectionEquation1D not defined`

---

<div class="post-metadata">

**Author:** ![sloede](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sloede/32/44787_2.png) [@sloede](https://discourse.julialang.org/u/sloede)\
**Post date:** [December 30, 2020, 4:01pm UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/26 "2020-12-30T16:01:49Z")

</div>

> [@rveltz](#):
>
> On a side note, I cannot run your examples, like /examples/1d/ elixir\_advection\_amr.jl  
> For one, it says `LinearScalarAdvectionEquation1D not defined`

Hm, that should not happen. If you create an issue on GitHub (with a little more info on how to reproduce your error), I will look into it. In general, all elixirs are run at least once during CI testing, where all tests are passing, thus this should not be too difficult to figure out.

---

<div class="post-metadata">

**Author:** ![ziolai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ziolai/32/23422_2.png) [@ziolai](https://discourse.julialang.org/u/ziolai)\
**Post date:** [April 13, 2022, 9:52am UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/27 "2022-04-13T09:52:40Z")

</div>

Vielen Dank for making Trixi.jl available to my students!

My students would like to define the velocity vector by separately solving the eikonal equation and interpolating the velocity vector to the mesh that Trixi.jl employs.

How do you suggest to proceed?

Vielen dank und grusse.

---

<div class="post-metadata">

**Author:** ![ranocha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranocha/32/35588_2.png) [@ranocha](https://discourse.julialang.org/u/ranocha)\
**Post date:** [April 13, 2022, 1:11pm UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/28 "2022-04-13T13:11:38Z")

</div>

Dear @ziolai,  
thank you very much! That sounds like an interesting application and we would like to know more about it - since we also need a bit more information about the problem to give a good answer. Would you mind [opening an issue in our repository](https://github.com/trixi-framework/Trixi.jl/issues/new)?  
Some first hints: I guess you want to solve some linear advection equation. If so, you can setup a new equation type as described in our tutorials, e.g., [this one on a conservative equation](https://trixi-framework.github.io/Trixi.jl/stable/tutorials/adding_new_scalar_equations/) or [this one on a non-conservative equation with variable coefficients](https://trixi-framework.github.io/Trixi.jl/stable/tutorials/adding_nonconservative_equation/). Then, you could solve the eikonal equation in whatever way you like and interpolate it to our solution nodes. You could for example wrap the interpolation object as callable function and pass that when creating the semidiscretization of Trixi.jl. Alternatively, you oculd initialize the variable coefficients with some default values and overwrite them after setting up the data, e.g., after setting up the ODE problem (via `semidiscretize`). If you do that, you need o get the node coordinates, e.g., via

```julia
semi = SemidiscretizationHyperbolic(...)

```

For example, you can get the following on a `TreeMesh` in 2D:

```julia
julia> using Trixi

julia> trixi_include(default_example())

julia> semi.cache.elements.node_coordinates # undocumented internal state - be cautious
2×4×4×256 Array{Float64, 4}:
[...]

```

Here, the first dimension of the array is the spatial dimension (2D in this case), the second and third dimensions are the tensor-product nodes of our Gauss-Lobatto-Legendre nodes in a quad element, and the last dimension of the array is the element index. If you want to have a plain vector of structs, you can wrap this, e.g., as

```julia
julia> reinterpret(SVector{2, Float64}, vec(semi.cache.elements.node_coordinates))
4096-element reinterpret(SVector{2, Float64}, ::Vector{Float64}):
 [-1.0, -1.0]
 [-0.9654508497187474, -1.0]
 [-0.9095491502812526, -1.0]
 [-0.875, -1.0]
[...]

```

---

<div class="post-metadata">

**Author:** ![ziolai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ziolai/32/23422_2.png) [@ziolai](https://discourse.julialang.org/u/ziolai)\
**Post date:** [April 14, 2022, 6:05am UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/29 "2022-04-14T06:05:10Z")

</div>

Dear Hendrik,

Thank you so much for providing a wealth of information!

A group of four master students is looking into the mondeling of macroscopic pedestrian flow models based on a 2013 paper of Twarogowska, Goatin en Duvigneau. This assignment is part of compulsory mathematical modelling course that is part of their curriculum.

Please allow me to discuss the two options that you suggest with the students and get back to you next week.

Happy Easter weekend, Domenico.

---

<div class="post-metadata">

**Author:** ![martinmestre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martinmestre/32/215857_2.png) [@martinmestre](https://discourse.julialang.org/u/martinmestre)\
**Post date:** [April 15, 2022, 10:32pm UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/30 "2022-04-15T22:32:08Z")

</div>

Hello @ranocha ! I am interested in the package. Do you know if it can be used to solve the systems of partial differential equations that appear in General Relativity ?  
Kind regards!

---

<div class="post-metadata">

**Author:** ![ranocha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranocha/32/35588_2.png) [@ranocha](https://discourse.julialang.org/u/ranocha)\
**Post date:** [April 16, 2022, 9:17am UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/31 "2022-04-16T09:17:21Z")

</div>

Thanks for your interest! I don’t have experience with numerical solutions of the equations of general relativity. Could you please [open an issue](https://github.com/trixi-framework/Trixi.jl/issues/new) and provide a few more details there, e.g., equations desrcribing a minimal example that could be interesting for you - say with reduced dimensions etc. and not full 3+1D?

---

<div class="post-metadata">

**Author:** ![ziolai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ziolai/32/23422_2.png) [@ziolai](https://discourse.julialang.org/u/ziolai)\
**Post date:** [April 26, 2022, 8:40pm UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/32 "2022-04-26T20:40:30Z")

</div>

Please advice on how to replace flux(u) = u^3 by e.g. flux(u,x) = x \* u (or flux(u) = f(x) g(u)) in Tutorial 5: “Adding New Conservation Law”.

In a next step, we will be concerned with replacing f(x) with interpolation.

In a next-next step, we will concerned with loading the data to interpolate from file and the extension from 1D to 2D.

Thx! D.

---

<div class="post-metadata">

**Author:** ![ranocha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranocha/32/35588_2.png) [@ranocha](https://discourse.julialang.org/u/ranocha)\
**Post date:** [April 27, 2022, 6:07am UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/33 "2022-04-27T06:07:49Z")

</div>

[https://trixi-framework.github.io/Trixi.jl/stable/tutorials/adding\_nonconservative\_equation/](https://trixi-framework.github.io/Trixi.jl/stable/tutorials/adding_nonconservative_equation/)

---

<div class="post-metadata">

**Author:** ![ziolai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ziolai/32/23422_2.png) [@ziolai](https://discourse.julialang.org/u/ziolai)\
**Post date:** [April 27, 2022, 7:51am UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/34 "2022-04-27T07:51:32Z")

</div>

Danke!

So to make sure that my students and I understand this well: there is no way to adapt the conservative formulation, i.e., Tutorial 5?

We desire to solve \partial u / \partial t + \partial [f(x) g(u)] / \partial x = 0, where f(x) is given by interpolation. Are you suggestion to interpolate using cubic splines such that the interpolation that defines f((x) can be differentiated?

Alternatively, would it be feasible to solve the eikonal equation using Trixi, first separately and later coupled with the transport equation. This would leverage the interpolation to functionality already in place in Trixi.

Edit: even with the differentiation of f(x), the flux remains explicitly dependent upon x. Are you suggesting to employ Tutorial 6 to make the conservative part of the flux x-dependent?

Thx!

---

<div class="post-metadata">

**Author:** ![ranocha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranocha/32/35588_2.png) [@ranocha](https://discourse.julialang.org/u/ranocha)\
**Post date:** [April 27, 2022, 8:48am UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/35 "2022-04-27T08:48:17Z")

</div>

The current version of Trixi.jl does not handle variable coefficients natively (see [https://github.com/trixi-framework/Trixi.jl/issues/358](https://github.com/trixi-framework/Trixi.jl/issues/358)). Thus, you need to introduce an auxiliary conserved variable as described in the tutorial on a non-conservative equation I linked above. You can of course use this setup for a conservative system. That’s what we do for our acoustics equations.

Trixi.jl will initialize the conserved variables (including the auxiliary variable for `f(x)`) at the discretization nodes. It doesn’t need to be smooth to run at all, but if your input is smooth, it can only help to preserve that (e.g., using splines as you wrote).

---

<div class="post-metadata">

**Author:** ![ziolai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ziolai/32/23422_2.png) [@ziolai](https://discourse.julialang.org/u/ziolai)\
**Post date:** [April 27, 2022, 9:06am UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/36 "2022-04-27T09:06:18Z")

</div>

Right!

Suppose that we modify Tutorial 6 to solve the equation u\_t + [a(x,t) u]\_x = 0 instead of the current form u\_t + a(x,t) u\_x = 0 (i.e. placing the function a(x,t) inside of the x-derivative). How do you modify

```julia
function flux_nonconservative(u_mine, u_other, orientation,
                              equations::NonconservativeLinearAdvectionEquation)
    _, advection_velocity = u_mine
    scalar, _ = u_other

    return SVector(advection_velocity * scalar, zero(scalar))
end

```

accordingly?

Does

```julia
function flux_nonconservative(u_mine, u_other, orientation,
                              equations::NonconservativeLinearAdvectionEquation)
    scalar, advection_velocity = u_other

    return SVector(advection_velocity * scalar, zero(scalar))
end

```

suffice? Thx.

---

<div class="post-metadata">

**Author:** ![ranocha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranocha/32/35588_2.png) [@ranocha](https://discourse.julialang.org/u/ranocha)\
**Post date:** [April 27, 2022, 9:17am UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/37 "2022-04-27T09:17:50Z")

</div>

If you don’t have a nonconservative equation, you do not need any `flux_nonconservative` - only `Trixi.flux` as in [7 Adding a new scalar conservation law · Trixi.jl](https://trixi-framework.github.io/Trixi.jl/stable/tutorials/adding_new_scalar_equations/)

---

<div class="post-metadata">

**Author:** ![ziolai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ziolai/32/23422_2.png) [@ziolai](https://discourse.julialang.org/u/ziolai)\
**Post date:** [April 27, 2022, 9:33am UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/38 "2022-04-27T09:33:30Z")

</div>

Or, alternatively, (staying with Tutorial 6), and do

```julia
flux(u, orientation, equation::NonconservativeLinearAdvectionEquation) = SVector(u[1]*u[2], zero(scalar) )

have_nonconservative_terms(::NonconservativeLinearAdvectionEquation) = Val(false)

```

?

---

<div class="post-metadata">

**Author:** ![ranocha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranocha/32/35588_2.png) [@ranocha](https://discourse.julialang.org/u/ranocha)\
**Post date:** [April 27, 2022, 12:04pm UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/39 "2022-04-27T12:04:40Z")

</div>

`have_nonconservative_terms(::NonconservativeLinearAdvectionEquation) = Val(false)` is the default.  
`flux(u, orientation, equation::NonconservativeLinearAdvectionEquation) = SVector(u[1]*u[2], zero(scalar) )` must be something like `flux(u, orientation, equation::NonconservativeLinearAdvectionEquation) = SVector(u[1]*u[2], zero(eltype(u)))` (since `scalar` is not defined…).

---

<div class="post-metadata">

**Author:** ![ziolai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ziolai/32/23422_2.png) [@ziolai](https://discourse.julialang.org/u/ziolai)\
**Post date:** [April 27, 2022, 1:19pm UTC](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419/40 "2022-04-27T13:19:02Z")

</div>

Ganz sch"on! So far, so good!

Next, we would like to replace  
`advection_velocity = 2 + cos(x[1])`  
by  
`advection_velocity = interpolate(x[1],data-from-eikonal-solve)`

Is is feasible to define data-from-eikonal-solve as a data member of the struct NonconservativeLinearAdvectionEquation as examples show in defining gamma as a data member of the CompressibleEulerEquations2D?

Edit: I have the interpolation in place. All good.

[Previous page](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419.md?page=1)

[Next page](https://discourse.julialang.org/t/ann-trixi-jl-v0-3-sciml-integration-and-a-new-modular-approach-for-easy-extension/50419.md?page=3)
