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
505 stars 98 forks source link

Maxwell 1D (Wave Equation) #1949

Open DanielDoehring opened 1 month ago

DanielDoehring commented 1 month ago

I always missed a classic wave equation system in Trixi.jl.

The obvious choice would be the standard 1D wave equation $$u{tt} - c^2 u{xx} = 0$$ with first order hyperbolic system

\partial_t \begin{pmatrix} v \\ w \end{pmatrix} + \partial_x \begin{pmatrix} c w \\ c v \end{pmatrix} = \boldsymbol 0

obtained from introducing the variables $v := c u_x$ and $w = -u_t$. This system, however, bears two main problems due to the change of variables:


As an alternative which does not bear this difficulties one can consider the Maxwell equations in 1D which simplify to

\partial_t \begin{pmatrix} E_{y,z} \\ B_{z,y} \end{pmatrix} + \partial_x \begin{pmatrix} c^2 B_{z,y} \\ E_{y,z} \end{pmatrix} = \begin{pmatrix} - \frac{j_{y,z}}{\varepsilon_0} \\ 0 \end{pmatrix}

where $E$ and $B$ field are orthogonal (which I try to denote with the alternating indices). This system has eigenvalues $\lambda- = -c, \lambda+ = c$, identical to the wave equation system.

I added the typical convergence test and an "application" of a standing wave which distributes energy between magnetic and electric.

github-actions[bot] commented 1 month ago

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

Code quality

Documentation

Testing

Performance

Verification

Created with :heart: by the Trixi.jl community.

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 91.66667% with 3 lines in your changes missing coverage. Please review.

Project coverage is 96.19%. Comparing base (58acd35) to head (6345c6f).

Files Patch % Lines
src/equations/maxwell_1d.jl 90.32% 3 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1949 +/- ## ========================================== - Coverage 96.19% 96.19% -0.00% ========================================== Files 460 462 +2 Lines 36993 37029 +36 ========================================== + Hits 35584 35617 +33 - Misses 1409 1412 +3 ``` | [Flag](https://app.codecov.io/gh/trixi-framework/Trixi.jl/pull/1949/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trixi-framework) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/trixi-framework/Trixi.jl/pull/1949/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trixi-framework) | `96.19% <91.67%> (-<0.01%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trixi-framework#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

ranocha commented 1 month ago

Thanks a lot! Could you please request a review from another developer in your area (Aachen/Cologne etc.) and ping Michael or me when you're ready for a final review?

andrewwinters5000 commented 3 weeks ago

Thanks for adding this equation system! It opens opportunities for multi-material wave propagation applications between different dielectric materials. Do not forget to add the new equation capability to the landing page of the README.md, although we could maybe hold-off until the Maxwell's equations are available in 2D and 3D as well. This opens a broader discussion regarding the strategy of maintaining a divergence-free magnetic field (say a la Dedner et al.) that will live in a different PR.

SimonCan commented 2 weeks ago

I always missed a classic wave equation system in Trixi.jl.

The obvious choice would be the standard 1D wave equation utt−c2uxx=0 with first order hyperbolic system

obtained from introducing the variables v:=cux and w=−ut. This system, however, bears two main problems due to the change of variables:

* The initialization is non-trivial

* Obtaining u is non-trivial

It is clear that the reconstruction of u from v is difficult. But could expand on the second point?

As an alternative which does not bear this difficulties one can consider the Maxwell equations in 1D which simplify to

where E and B field are orthogonal (which I try to denote with the alternating indices). This system has eigenvalues λ−=−c,λ+=c, identical to the wave equation system.

I added the typical convergence test and an "application" of a standing wave which distributes energy between magnetic and electric.

Do you mean that you distribute between magnetic and electric energy?

SimonCan commented 2 weeks ago

Have you considered solving a three-variable first order hyperbolic system that includes the equation $u_t + w = 0$?

SimonCan commented 2 weeks ago

Can you provide a reference to your 1d Maxwell equations? Are you in a vacuum? If so, why not set the currents to 0 as well? Why are there second order derivatives in space, like $\partialx E{y,z}$?

DanielDoehring commented 2 weeks ago

It is clear that the reconstruction of u from v is difficult. But could expand on the second point?

So the initialization?

Do you mean that you distribute between magnetic and electric energy?

Yes.

DanielDoehring commented 2 weeks ago

Can you provide a reference to your 1d Maxwell equations? Are you in a vacuum? If so, why not set the currents to 0 as well? Why are there second order derivatives in space, like ∂xEy,z?

These are no second derivatives, but meant to indicate the parity of the components of the electric and magnetic field, i.e., if you have $E_y$ then you have $B_z$ and vice-versa.

DanielDoehring commented 2 weeks ago

Can you provide a reference to your 1d Maxwell equations? Are you in a vacuum? If so, why not set the currents to 0 as well? Why are there second order derivatives in space, like ∂xEy,z?

A possible reference would be https://inria.hal.science/hal-01720293/document equation (1). Yes, at least $c$ is set to vacuum value.

In the docstring of the equations the currents/sources are set to 0. Only here they are mentioned for completeness.

DanielDoehring commented 2 weeks ago

Thanks for adding this equation system! It opens opportunities for multi-material wave propagation applications between different dielectric materials.

This was actually the main motivation to add such a system to Trixi for me.

Do not forget to add the new equation capability to the landing page of the README.md, although we could maybe hold-off until the Maxwell's equations are available in 2D and 3D as well.

Yes, this is actually the reason why I have not put them into the Readme yet.

SimonCan commented 2 weeks ago

It is clear that the reconstruction of u from v is difficult. But could expand on the second point?

So the initialization?

Yes. You would need to integrate to get u from v. Maybe your could point that out.

Do you mean that you distribute between magnetic and electric energy?

Yes.

Maybe it is good to point out that energy is being distributed.

SimonCan commented 2 weeks ago

Can you provide a reference to your 1d Maxwell equations? Are you in a vacuum? If so, why not set the currents to 0 as well? Why are there second order derivatives in space, like ∂xEy,z?

These are no second derivatives, but meant to indicate the parity of the components of the electric and magnetic field, i.e., if you have Ey then you have Bz and vice-versa.

That makes sense. But then the notation is confusing. In the initial wave equation subscripts are derivatives. Now they are components and parities. Maybe you could also mention parities in your description.

andrewwinters5000 commented 2 weeks ago

Can you provide a reference to your 1d Maxwell equations?

You could maybe use one of the papers from Acosta and Kopriva for the Maxwell's equations on this form. That or the book from Hesthaven "Numerical Methods for Conservation Laws: From Analysis to Algorithms" where he uses the Maxwell's equations as a prototypical example of a linear conservation law.

SimonCan commented 2 weeks ago

Looks good to me now.

DanielDoehring commented 2 weeks ago

Looks good to me now.

Can you approve the PR? Then we are ready to go :)