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

Address possible NaN in ExactSbend & ChrUniformAcc #789

Merged
merged 14 commits into from
Jan 25, 2025

Conversation

cemitch99
Copy link
Member

@cemitch99 cemitch99 commented Jan 8, 2025

This PR addresses the special case when the square root appearing in the nonlinear map for the ExactSbend element becomes negative -- due, for example, to numerical roundoff.

A similar restriction of the domain of map definition appears for the ChrAcc element, and this is also addressed here. A modified cyclotron example is added with increased energy spread to illustrate the possibility of particle loss.

Fix #599 .

  • treat the special case of negative sqrt
  • mark particles as lost if outside the domain of map definition
  • find a problematic example to verify that Issue Exact sbend returns NaN for certain beam/element input values #599 is resolved
  • double-check the nonlinear map implementation
  • fix possible NaN in ChrAcc element also
  • add modified cyclotron example as benchmark test
  • choose values for analysis script

Follow-up: Check for any additional (nonlinear) elements that require further restrictions on the domain of definition to avoid nan's.

@cemitch99 cemitch99 added bug Something isn't working bug: affects latest release Bug also exists in latest release version labels Jan 9, 2025
@ax3l ax3l requested review from ax3l and SchroederSa January 9, 2025 00:20
@ax3l ax3l added the component: elements Elements/external fields label Jan 9, 2025
@cemitch99
Copy link
Member Author

Found two examples that illustrate the original problem and this fix. Just trying to decide what works best for testing.

@ax3l ax3l changed the title Address possible NaN in ExactSbend Address possible NaN in ExactSbend & ChrUniformAcc Jan 25, 2025
Copy link
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

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

That looks great, thank you for handling these corner cases!

examples/cyclotron/README.rst Outdated Show resolved Hide resolved
@ax3l ax3l enabled auto-merge (squash) January 25, 2025 00:09
@ax3l ax3l self-assigned this Jan 25, 2025
@ax3l ax3l merged commit 8771964 into ECP-WarpX:development Jan 25, 2025
16 checks passed
Copy link
Contributor

@SchroederSa SchroederSa left a comment

Choose a reason for hiding this comment

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

Thanks for taking care of this! I just added some meticulous hints to typos.


In this test, the initial values of :math:`\sigma_x`, :math:`\sigma_y`, :math:`\sigma_t`, :math:`\epsilon_x`, :math:`\epsilon_y`, and :math:`\epsilon_t` must agree with nominal values.

In addition, the fraction of charge that is lost must agree with the nominal value of 7.7754%, to within a specified tolerance.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit unclear where the number 7.7754% is coming from.

# add beam diagnostics
monitor = elements.BeamMonitor("monitor", backend="h5")

# design the accelerator lattice)
Copy link
Contributor

Choose a reason for hiding this comment

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

Little typo: ')' at the end of the line

amrex::ParticleReal const ptf_tot2 = std::pow(ptf_tot,2);

// check whether particle lies within the domain of map definition
if (pti_tot2 <= 1_prt || ptf_tot2 <= 1_prt) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a question: Are there coding practices on what to put in an 'if' clause and what in a 'else' clause? I would have naively thought the if(XXX) is testing the good / default case and the 'else:' handling the exception.
Thanks!

bunch_charge_C = 1.0e-9 # used with space charge
npart = 10000 # number of macro particles

# reference particle
Copy link
Contributor

Choose a reason for hiding this comment

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

There are an irregular number of spaces in line 28 and 32 after the '# '

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: affects latest release Bug also exists in latest release version bug Something isn't working component: elements Elements/external fields
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exact sbend returns NaN for certain beam/element input values
3 participants