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

Apply transverse aperture to thick elements. #788

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

Conversation

cemitch99
Copy link
Member

@cemitch99 cemitch99 commented Jan 8, 2025

Adds the comparison of particles against the transverse aperture within thick elements, at the end of each space charge slice. This will close #763 .

Note: Need to verify that using the same name Aperture for the thin aperture element and for the mixin class will not cause conflicts. Otherwise, one of these should be renamed.

  • add mixin class
  • add application to a drift (as a template)
  • address particle id
  • add a benchmark example
  • add element documentation
  • add Python support
  • add application to other elements
  • add example documentation

@cemitch99 cemitch99 added this to the Advanced Methods (SciDAC-5) milestone Jan 9, 2025
@cemitch99 cemitch99 added the component: elements Elements/external fields label Jan 9, 2025
@ax3l ax3l self-requested a review January 9, 2025 00:21
@@ -121,6 +128,11 @@ namespace impactx
py = pyout;
pt = ptout;

// apply transverse aperture
if (m_xmax > 0 && m_ymax > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

I would move the if into mixin/aperture.H.

@cemitch99
Copy link
Member Author

Note: Windows test fail now, but all tests were previously passing.

examples/aperture/input_aperture_thick.in Outdated Show resolved Hide resolved
examples/aperture/run_aperture_thick.py Outdated Show resolved Hide resolved
src/particles/elements/mixin/aperture.H Outdated Show resolved Hide resolved
src/particles/elements/mixin/aperture.H Outdated Show resolved Hide resolved
src/particles/elements/mixin/aperture.H Outdated Show resolved Hide resolved
Comment on lines 57 to 58
amrex::ParticleReal xmax = 0,
amrex::ParticleReal ymax = 0,
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if for all potential elements, xmax and ymax are general enough argument names.

They do make sense for the Aperture element, but for all other thick elements we might need something more specific, e.g., x_open or x_aperture?

Another small change I thought we could do is use std::optional<amrex::ParticleReal> ... = std::nullopt. That way, we do not redefine 0 with a jump, which technically is a fully blocking aperture. The equivalent in Python is then x_aperture = None, which is clearly no aperture.

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I like x_aperture, and I'll make that change. Will look into using std::optional.

Copy link
Member

@ax3l ax3l Jan 10, 2025

Choose a reason for hiding this comment

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

To get the value out of std::optional, call operator* or .value().

We will need to write the real value into m_x_aperture because we cannot (should not) use std::optional on GPU. For no value, I would maybe write a negative value into the member variable and only apply the aperture for >=0. That way, 0 is well-defined (blocking).

Copy link
Member Author

@cemitch99 cemitch99 Jan 10, 2025

Choose a reason for hiding this comment

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

To clarify the last comment: We're avoiding std::optional altogether? If so, I actually prefer the existing approach, to apply the aperture when x_aperture > 0 and y_aperture >0. Why? 1) Allowing for blocking with x_aperture = 0 requires changing the logic/math in the mixin class, 2) A thick element with zero aperture has no use case (eg, its action is the same as a thin screen for blocking), 3) Allowing this case means setting the default values of x_aperture, y_aperture to an arbitrarily-chosen negative number.

src/particles/elements/mixin/aperture.H Outdated Show resolved Hide resolved
Comment on lines 222 to 226
.def_property_readonly("xmax",
&elements::Aperture::xmax,
"horizontal aperture in m"
)
.def_property_readonly("ymax",
Copy link
Member

Choose a reason for hiding this comment

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

Naming: please see above.

src/python/elements.cpp Outdated Show resolved Hide resolved
cemitch99 and others added 4 commits January 9, 2025 17:08
src/python/elements.cpp Outdated Show resolved Hide resolved
src/python/elements.cpp Outdated Show resolved Hide resolved
src/python/elements.cpp Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: elements Elements/external fields
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Apertures for "thick" elements
2 participants