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 27 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
  • update "thin" Aperture element to use consistent naming
  • make Aperture constructor non-breaking with warnings
  • 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
src/particles/elements/Drift.H Outdated Show resolved Hide resolved
@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.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, then we can keep it simple and document <= zero as no-aperture 👍

src/particles/elements/mixin/aperture.H Outdated Show resolved Hide resolved
src/python/elements.cpp Outdated Show resolved Hide resolved
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
@cemitch99
Copy link
Member Author

cemitch99 commented Jan 14, 2025

Problems on Windows after merging in 'development'...
Appears to have resolved.

@ax3l ax3l self-assigned this Jan 14, 2025
Comment on lines +458 to +459
* ``<element_name>.aperture_x`` (``float``, in meters) horizontal half-aperture (elliptical or rectangular)
* ``<element_name>.aperture_y`` (``float``, in meters) vertical half-aperture (elliptical or rectangular)
Copy link
Member

Choose a reason for hiding this comment

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

Oh, breaking change for existing aperture element users.

Not necessarily needed for this PR to work, but we can make it work by adding a bit more logic to transition.

Copy link
Member Author

@cemitch99 cemitch99 Jan 15, 2025

Choose a reason for hiding this comment

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

Yes, I agree. The case for consistent naming is pretty strong. One of the main aperture users is @SchroederSa, who was the first to suggest that xmax and ymax were not the best names. Did you have in mind to support both input syntax by modifying InitElement.cpp and python/elements.cpp?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I'll add a fallback to make the transition easier there.

docs/source/usage/python.rst Show resolved Hide resolved
Comment on lines 431 to 432
pp_element.get("aperture_x", aperture_x);
pp_element.get("aperture_y", aperture_y);
Copy link
Member

Choose a reason for hiding this comment

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

If we want to rename the parameter (not needed for this PR), then I would add a bool has_xmax = pp_element.query("xmax", xmax); then if true, throw a warning and set the value for aperture_x (unless that one is set as well). Same for y.

But as I said, I don't think we need to rename the Aperture arguments with this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Still have to add this part.

src/particles/elements/Aperture.H Show resolved Hide resolved
src/particles/elements/mixin/aperture.H Outdated Show resolved Hide resolved
src/python/elements.cpp Outdated Show resolved Hide resolved
src/python/elements.cpp Outdated Show resolved Hide resolved
Comment on lines +350 to +351
py::arg("aperture_x"),
py::arg("aperture_y"),
Copy link
Member

Choose a reason for hiding this comment

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

As above: we could avoid this breaking change for the Aperture element itself.

Copy link
Member

@ax3l ax3l Jan 15, 2025

Choose a reason for hiding this comment

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

The break of API arg name here might be ok, for python people might not use the named arguments yet that much.

ax3l added 4 commits January 14, 2025 18:06
We do not want to create variables from them.
Mirror directory structure and separate from "physical"
elements as we do in Python.
@ax3l ax3l added the changes input scripts / defaults Changes the syntax or meaning of input scripts and/or defaults label Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes input scripts / defaults Changes the syntax or meaning of input scripts and/or defaults component: elements Elements/external fields
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Apertures for "thick" elements
3 participants