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

Python: ShortRF Properties #646

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/python/elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,21 @@ void init_elements(py::module& m)
py::arg("rotation") = 0,
"A short RF cavity element."
)
.def_property("V",
[](ShortRF & short_rf) { return short_rf.m_V; },
[](ShortRF & short_rf, amrex::ParticleReal V) { short_rf.m_V = V; },
"Normalized RF voltage V = maximum energy gain/(m*c^2)"
)
.def_property("freq",
[](ShortRF & short_rf) { return short_rf.m_freq; },
[](ShortRF & short_rf, int freq) { short_rf.m_freq = freq; },
"RF frequency in Hz"
)
.def_property("phase",
[](ShortRF & short_rf) { return short_rf.m_phase; },
[](ShortRF & short_rf, int phase) { short_rf.m_phase = phase; },
Comment on lines +977 to +984
Copy link
Member

Choose a reason for hiding this comment

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

Actually I just noticed this, should freq and phase be amrex::ParticleReal too, as opposed to int? If so, I can fix it in the follow-up PR.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for catching this! Those should definitely be amrex::ParticleReal.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ooops, yes please. Copy pasted this, dang!

Copy link
Member

Choose a reason for hiding this comment

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

@ax3l
I will fix it in the upcoming PR. Question, which I guess is pybind11-related: why does the compiler not complain about/catch this discrepancy between types?

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 am surprised as well, should issue a narrowing warning.
https://godbolt.org/z/f6bE3xPPE

Thx for the fix in #647

"RF synchronous phase in degrees (phase = 0 corresponds to maximum energy gain, phase = -90 corresponds go zero energy gain for bunching)"
)
;
register_beamoptics_push(py_ShortRF);

Expand Down
Loading