Add atoctupole to Matlab version#1077
Open
TeresiaOlsson wants to merge 2 commits into
Open
Conversation
Author
|
However, the PR is related to issue #465. Is there a reason why the octupole hasn't been implemented similarly to the sextupole? To change that both in the Matlab and Python versions would make the octupole nicer to use. |
Contributor
|
@TeresiaOlsson : I agree that the Octupole should have been implemented similarly to the Sextupole. Here is a python implementation which does this while keeping the compatibility with the previous syntax: class Octupole(Multipole):
"""Octupole element, with no changes from multipole at present."""
_BUILD_ATTRIBUTES = [*LongElement._BUILD_ATTRIBUTES, "_O"]
_stacklevel = 7 # Stacklevel for warnings
DefaultOrder = 3
def __init__(self, family_name: str, length: float, *args, **kwargs):
"""
Args:
family_name: Name of the element
length: Element length [m]
strength: Octupolar strength [m^-4].
Keyword arguments:
PolynomB: normal multipoles
PolynomA: skew multipoles
MaxOrder: Number of desired multipoles
NumIntSteps=10: Number of integration steps
KickAngle: Correction deviation angles (H, V)
FieldScaling: Scaling factor applied to the magnetic field
(*PolynomA* and *PolynomB*)
Default PassMethod: ``StrMPoleSymplectic4Pass``
"""
kwargs.setdefault("PassMethod", "StrMPoleSymplectic4Pass")
match args:
case [poly_a, poly_b]:
pass
case [strength]:
poly_a = kwargs.pop("PolynomA", [])
poly_b = [0.0, 0.0, 0.0, strength]
case []:
poly_a = kwargs.pop("PolynomA", [])
poly_b = kwargs.pop("PolynomB", [0.0, 0.0, 0.0, 0.0])
case _:
msg = "Octupole strength should be a float."
raise ValueError(msg)
super().__init__(family_name, length, poly_a, poly_b, **kwargs)
# noinspection PyPep8Naming
@property
def _O(self) -> float:
"""Octupolar strength [m^-4]."""
arr = self.PolynomB
return 0.0 if len(arr) < 4 else float(arr[3])
# noinspection PyPep8Naming
@_O.setter
def _O(self, strength):
self.PolynomB[3] = strengthNow With this you can implement the Matlab octupole in a nicer way. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When saving a pyAT lattice to a m-file using
at.save_mit can currently not be loaded in the Matlab version if the lattice contains octupoles since there is no atoctupole element in the Matlab version.This is the output of
at.save_m:I have added an atoctupole element to the Matlab version based on the same syntax as atmultipole.