Skip to content

[WIP] Magnetostatic solver refactor and bug fixes #5175

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

Open
wants to merge 35 commits into
base: development
Choose a base branch
from

Conversation

roelof-groenewald
Copy link
Member

@roelof-groenewald roelof-groenewald commented Aug 27, 2024

This PR introduces a major refactor of the magnetostatic solver primarily with three goals:

  1. Allow the magnetostatic solver to be used with either the explicit or semi-implicit electrostatic potential solvers.
  2. Fix a bug in the calculation of B from A. Currently the AMReX gradient function is used to get $\nabla A$ on a grid matching the E-field staggering; this field is then interpolated to match the B-field staggering for each component needed in calculating $B = \nabla \times A$. However, this interpolation causes significant non-zero B-field divergence as is shown in the plot below. Instead, now $A$ is interpolated to match the E-field staggering and B is calculated directly from that A-field using the standard FD curl calculation.

image
Example of non-zero B-field divergence introduced with the current magnetostatic solver implementation.

image
Same simulation as above but with the fixes from this PR included (note the colorbar range)

  1. Add the inductive electric field term ($E_{ind} = -\frac{dA}{dt}$) during ES+MS evolution.

This PR builds on and requires first merging:

@roelof-groenewald roelof-groenewald added bug Something isn't working enhancement New feature or request component: magnetostatic magneticstatic solver labels Aug 27, 2024
@roelof-groenewald roelof-groenewald changed the title Magnetostatic solver refactor and bug fixes [WIP] Magnetostatic solver refactor and bug fixes Aug 30, 2024
@roelof-groenewald roelof-groenewald marked this pull request as ready for review August 30, 2024 21:58
Copy link
Member

@clarkse clarkse left a comment

Choose a reason for hiding this comment

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

This looks good @roelof-groenewald thank you for shaking this out.

if (field_boundary_hi[0] == FieldBoundaryType::PEC) {
if (adim == 0) {
hibc[adim][0] = LinOpBCType::Neumann;
dirichlet_flag[adim][1] = false;
Copy link
Member

Choose a reason for hiding this comment

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

This can be changed to use an STL map data structure as in the ProjectionDivCleaner. Seesm like a good time to do this refactoring.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great idea! I'll add that to my tasks for the upcoming hackathon (also changing it for the current ES solver).

@@ -249,9 +269,9 @@ void
WarpX::setVectorPotentialBC ( amrex::Vector<amrex::Array<std::unique_ptr<amrex::MultiFab>,3>>& A ) const
Copy link
Member

Choose a reason for hiding this comment

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

Should this have some sort of warning about the inaccuracy of the field near an EB surface? This is now effetively going to be a staircase EB instead of cut cell correct?

@@ -326,7 +326,7 @@ WarpX::ProjectionCleanDivB() {
} else if ( WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::Yee
|| WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::HybridPIC
|| ( (WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrame
|| WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrameElectroMagnetostatic)
|| WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrameSemiImplicit)
Copy link
Member

Choose a reason for hiding this comment

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

Is the explicit version of the solver going away completely? I.e. the LabFrameElectroMagnetostatic Algo?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the magnetostatic solver is just changed to function as an add-on to an electrostatic solver. So instead of defining it as it's own solver (explicit ES + MS) the type of ES solver is set in the input and the extra flag do_magnetostatic sets whether the MS solve will be added on to the ES solve.

roelof-groenewald pushed a commit that referenced this pull request Nov 11, 2024
#5446)

…ch is currently hard coded, and adding assert to force EB being enabled
in order to avoid a seg fault in AMReX when computing the gradient
solution.

This PR partially addresses
#5444. This PR adds
semi-coarsening in 3D and then adds an assert to keep the magnetostatic
solver from being run without an EB. This is required since in AMReX
MLMG->getGradSolution will segfault when not using an EB.

It should also be noted that
#5175 will use a different scheme
around the embedded boundaries to compute gradients, and will likely
mitigate these issues.

A work around in RZ to use the outer edge is to enable the embedded
boundary and set the boundary radius larger than the outer grid radius.
This works like it would without an embedded boundary and can be used
until either the refactor or the bugfix in AMReX for getGradSolution.

---------

Signed-off-by: S. Eric Clark <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working component: magnetostatic magneticstatic solver enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants