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

More flexible solenoid definition, resolve issue 1147 #1179

Merged
merged 13 commits into from
Feb 27, 2024

Conversation

HelmutCERN
Copy link
Contributor

Allow for more flexible solenoid definition based on the two independent parameters, strength and length
Strength can be ks or ksi (ks*l)
and length l for a thick or lrad for the thin solenoid.
Backward compatible : as before, the thin solenoid can also be defined with L=0, and providing both ks and ksi. In this case Lrad is calculated from ks and ksi.

Code changes:
mad_elem.c mad_elem.h
new check_set_consistent_solenoid
for more tolerant solenoid definition
thick solenoid with L>0
and thin with Lrad>0
on the make_element level
ks is calculated when not specified or inconsistent from ksi/lenth

mad_node.c
Save attributes when modified by check_set_consistent_solenoid

Further changes also of more general interest :
mad_mkthin.cpp
Zero length elements are not sliced.
They can still get a slice number > 1 by selection which can confusing when looking at the sliced sequence.
Using a new code piece
zero_length_elements_1_slice(el_list* the_element_list)
called in makethin after set_selected_elements
the slice number is now kept at 1 for zero length elements,
and thick and slice number removed as active attribute in copy_thin.

mad_dict.c
missing slice number added to rfcavity

new check_set_consistent_solenoid
allows more tolerant solenoid definition, both
thick solenoid with L>0
and think with Lrad>0
fixed on the make_element level
ks is calculated when not specified or inconsistent from ksi/lenth
Zero length elements are not sliced.
They can still get a slice number > 1 by selection which can confusing when looking at the sliced sequence.
Using a new code piece
zero_length_elements_1_slice(el_list* the_element_list)
called in makethin after set_selected_elements 
the slice number is now kept at 1 for zero length elements,
and thick and slice number removed as active attribute in copy_thin.
Save attributes when modified by check_set_consistent_solenoid
missing slice number added to rfcavity
@rdemaria
Copy link
Contributor

Since there are not many solenoid users, how do you see if we allow only KSL (un purpose different from KS and KSI) in combination with L and LRAD. I see an advantage in breaking compatibility, but bringing in a simpler logic.

If you see too disruptive, let's keep this solution.

Since you were faster than me could you also add the small fix of the cavity in this PR?

@HelmutCERN
Copy link
Contributor Author

HelmutCERN commented May 12, 2023 via email

@rdemaria
Copy link
Contributor

Ok for your proposal. As an alternative, we could consider adding a ThinSolenoid element that takes KSL and LRAD only and keep the Solenoid with KS and L. Could this work for you? In twiss tables I would use KSL for both as we do with K1L for instance.

@HelmutCERN
Copy link
Contributor Author

HelmutCERN commented May 15, 2023 via email

@rdemaria
Copy link
Contributor

I see what you mean with KSL vs KSI now. Although I don't see a specific issue with KSL in solenoid, I see a potential issue if somebody check for KSL to determine if it is a multipole. So ok to keep KSI.

@ldeniau
Copy link
Contributor

ldeniau commented May 17, 2023

Here is what madng does when entering a quadrupole, same rule for elements thin and tick.

if l == 0 and abs(k1)+abs(k1s)+abs(k0)+abs(k0s) > 0 then
  warn("quadrupole '%s' defines strength with zero length", elm.name)
end
knl[1], ksl[1] = knl[1]+k0*l, ksl[1]+k0s*l
knl[2], ksl[2] = knl[2]+k1*l, ksl[2]+k1s*l

This very simple rule makes the overall code very simple. The elements maps are aware that they are thick or thin and use knl and ksl correctly and convert them to local strength if needed using l or lrad appropriately.

Fix for MethodicalAcceleratorDesign#1180
RBEND slicing worked correctly for slice=0 (no slicing) and slice=2 and more.
Even though is see no good reason to use
select, flag=makethin, class=rbend, slice = 1, thick = true;
this now now also translates to SBEND between dipedges.
@HelmutCERN
Copy link
Contributor Author

The pull request now includes the fix for the issue # 1180

@HelmutCERN
Copy link
Contributor Author

The differences in test-thick-dipole-2 and test-thick-dipole-3 reflect the improved naming/cleaning and the generated thin.seq should become the new thin.seq.ref. To my knowledge no more remains issues - ready to merge.

@rdemaria
Copy link
Contributor

Thanks a lot! Can you commit the new .ref? This will retrigger the tests then I can merge

@HelmutCERN
Copy link
Contributor Author

New references pushed, slicing related tests now look all ok

@rdemaria rdemaria merged commit 03ba2a6 into MethodicalAcceleratorDesign:master Feb 27, 2024
37 of 39 checks passed
@rdemaria
Copy link
Contributor

Delaying tests on windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants