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

Maxwell 1D (Wave Equation) #1949

Merged
merged 26 commits into from
Jul 5, 2024
Merged

Conversation

DanielDoehring
Copy link
Contributor

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:

  • The initialization is non-trivial
  • Obtaining $u$ is non-trivial

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.

@DanielDoehring DanielDoehring added the enhancement New feature or request label May 22, 2024
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 with its PR number.

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 May 26, 2024

Codecov Report

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

Project coverage is 96.19%. Comparing base (4d91a86) to head (7d3fc24).
Report is 1 commits behind head on main.

Files Patch % Lines
src/equations/maxwell_1d.jl 89.66% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1949      +/-   ##
==========================================
- Coverage   96.19%   96.19%   -0.00%     
==========================================
  Files         460      462       +2     
  Lines       36993    37027      +34     
==========================================
+ Hits        35584    35615      +31     
- Misses       1409     1412       +3     
Flag Coverage Δ
unittests 96.19% <91.18%> (-<0.01%) ⬇️

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.

@ranocha
Copy link
Member

ranocha commented May 26, 2024

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?

@DanielDoehring DanielDoehring requested a review from SimonCan May 27, 2024 08:24
@andrewwinters5000
Copy link
Member

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
Copy link
Contributor

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
Copy link
Contributor

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

@SimonCan
Copy link
Contributor

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 $\partial_x E_{y,z}$?

@DanielDoehring
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

Co-authored-by: Simon Candelaresi <[email protected]>
@DanielDoehring
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Member

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.

@DanielDoehring
Copy link
Contributor Author

Looks good to me now.

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

@DanielDoehring DanielDoehring requested a review from SimonCan June 27, 2024 10:16
SimonCan
SimonCan previously approved these changes Jul 1, 2024
@DanielDoehring DanielDoehring requested a review from ranocha July 2, 2024 22:17
Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

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

Thanks!

src/equations/maxwell_1d.jl Outdated Show resolved Hide resolved
src/equations/maxwell_1d.jl Outdated Show resolved Hide resolved
src/equations/maxwell_1d.jl Outdated Show resolved Hide resolved
@ranocha
Copy link
Member

ranocha commented Jul 4, 2024

The CI failure is caused by this PR:

https://github.com/trixi-framework/Trixi.jl/actions/runs/9780448374/job/27002159772?pr=1949#step:7:6768

WARNING: Method definition (::Type{Trixi.MaxwellEquations1D{RealT} where RealT<:Real})(Real) in module Trixi at /home/runner/work/Trixi.jl/Trixi.jl/src/equations/maxwell_1d.jl:39 overwritten at /home/runner/work/Trixi.jl/Trixi.jl/src/equations/maxwell_1d.jl:42.
ERROR: Method overwriting is not permitted during Module precompilation. Use `__precompile__(false)` to opt-out of precompilation.
┌ Error: Unexpected error: /tmp/jl_RgfOJIreru/done.log was not created, but precompilation exited
└ @ Aqua ~/.julia/packages/Aqua/tHrmY/src/persistent_tasks.jl:118

@DanielDoehring
Copy link
Contributor Author

I think I found an implementation without CI failures.

src/equations/maxwell_1d.jl Outdated Show resolved Hide resolved
Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

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

Thanks a lot! This PR be merged when my last comment is addressed and CI passes 👍

@DanielDoehring DanielDoehring enabled auto-merge (squash) July 5, 2024 09:01
@ranocha ranocha disabled auto-merge July 5, 2024 15:02
Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

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

Thanks!

@ranocha ranocha merged commit fc2a761 into trixi-framework:main Jul 5, 2024
36 of 37 checks passed
@DanielDoehring DanielDoehring deleted the Maxwell1D branch October 15, 2024 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants