Skip to content

Add nonlinear thin dipole fringe field map - #1158

Merged
ax3l merged 33 commits into
BLAST-ImpactX:developmentfrom
cemitch99:add_nonlinear_dipedge
Nov 7, 2025
Merged

Add nonlinear thin dipole fringe field map#1158
ax3l merged 33 commits into
BLAST-ImpactX:developmentfrom
cemitch99:add_nonlinear_dipedge

Conversation

@cemitch99

@cemitch99 cemitch99 commented Sep 25, 2025

Copy link
Copy Markdown
Member

This PR modifies the existing linear DipEdge element to support the nonlinear map of:

K. Hwang and S. Y. Lee, "Dipole fringe field map for compact synchrotrons," Phys. Rev. Accel. Beams 18, 122401 (2015)

The map is expressed in the explicit, symplectic form provided in:

C. Mitchell and K. Hwang, "Explicit symplectic representations of nonlinear dipole fringe field maps," in Proc. NAPAC2025, TUP040, Sacramento, CA, 2025.

  • set up modified DipEdge element inputs
  • add intermediate variable definitions
  • implement nonlinear map
  • update default values for field integral inputs
  • double-check map implementation
  • add entry/exit input flag
  • update documentation
  • add benchmark tests
  • update benchmark tolerance

@cemitch99
cemitch99 requested review from ax3l and qianglbl September 25, 2025 18:09
@cemitch99

Copy link
Copy Markdown
Member Author

The three failing tests are due to the Dashboard, and appear to be unrelated to this PR.

@ax3l ax3l self-assigned this Oct 30, 2025
Probably worth vectorizing now...

@ax3l ax3l left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks great!

I added formatting fixes (applying them now), small code suggestions (leaving for your review) and a final suggestion for he user-facing API that I can help with.

Comment thread docs/source/usage/parameters.rst Outdated
Comment thread docs/source/usage/python.rst Outdated
Comment thread docs/source/usage/python.rst Outdated
Comment thread examples/CMakeLists.txt Outdated
Comment thread examples/edge_effects/README.rst Outdated
Comment thread docs/source/usage/parameters.rst Outdated
Comment thread src/elements/DipEdge.H
Comment thread src/python/elements.cpp Outdated
Comment thread src/python/elements.cpp Outdated
Comment thread src/elements/DipEdge.H Outdated
Comment on lines +309 to +310
int m_model; //! model specification
Location m_flag; //! +1 for entry, or -1 for exit

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As a final update, I would like to make m_model and m_flag AMREX_ENUM as we do for SpaceChargeAlgo.

The reason is that I would like users to write in their input files / scripts a descriptive string or type instead of integers that one has to look up.

What would be good string values for each of those?
I assume:

  • model: "linear", "order6" ?
  • location: "entry", "exit"

Also would call m_flag simply m_location.

@cemitch99 cemitch99 Nov 4, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I agree m_location works well, with entry and exit as string values. For m_model, I would just use linear and nonlinear. The question of "order" is subtle here, and unrelated to the values of K0-K6 above (which is where I assume the number 6 originated).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note that "flag" (which can be renamed "location") is already specified here by a user-provided string (not an integer) with values "entry" and "exit" using enum in lines 47-51 of DipEdge.H. Can you clarify the advantage of changing this to an implementation similar to SpaceChargeAlgo (e.g., lines 21-26 of Algorithms.H)?

Comment thread docs/source/usage/parameters.rst Outdated
Comment thread docs/source/usage/parameters.rst Outdated
Comment thread docs/source/usage/python.rst Outdated
Comment thread docs/source/usage/python.rst Outdated
Comment thread docs/source/usage/python.rst Outdated
@ax3l

ax3l commented Nov 6, 2025

Copy link
Copy Markdown
Member

@cemitch99 I'll push a PR with changes in a minute

Comment thread src/python/elements.cpp Outdated
Comment thread src/elements/DipEdge.H Outdated
Comment thread src/elements/DipEdge.H Outdated
Comment thread src/elements/DipEdge.H Outdated
Comment thread src/initialization/InitElement.cpp Outdated
@ax3l

ax3l commented Nov 7, 2025

Copy link
Copy Markdown
Member

After this PR, need to update the QuadEdge control ("flag") well.

Comment on lines +213 to +216
pp_element.queryAdd("model", model_str);
dipedge::Model const model = amrex::getEnum<dipedge::Model>(model_str);
pp_element.queryAdd("location", location_str);
dipedge::Location const location = amrex::getEnum<dipedge::Location>(location_str);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@WeiqunZhang just checked in that we can read directly into an enum in ParmParse, too! :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not exactly right now. query works, but not queryAdd. We can certainly support that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

        auto model = Model::linear;
        ParmParse pp;
        pp.query("model", model);
        amrex::Print() << " model is " << amrex::getEnumNameString(model) << "\n";

will give us

$ ./main3d.gnu.ex model="nonlinear"
 model is nonlinear

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AMReX-Codes/amrex#4765 adds queryAdd for amrex_enum.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awesome, thnak you! Let me refactor this after the PR, so we can do a 25.11 release depending on AMReX 25.11

Comment thread src/elements/DipEdge.H Outdated
Comment thread src/elements/DipEdge.H Outdated
@ax3l
ax3l force-pushed the add_nonlinear_dipedge branch from ee63fd2 to 06636ad Compare November 7, 2025 04:25

@ax3l ax3l left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you, Chad!!

@ax3l
ax3l enabled auto-merge (squash) November 7, 2025 04:48
@ax3l
ax3l merged commit 4cb75b0 into BLAST-ImpactX:development Nov 7, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants