Skip to content

Commit

Permalink
Merge pull request #79 from tbody-cfs/circuit-modifications
Browse files Browse the repository at this point in the history
Add __getitem__, coil and current setter/getter for Circuit class
  • Loading branch information
bendudson committed Dec 14, 2022
2 parents 5baad4d + 09a3a54 commit 5f5d452
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions freegs/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,40 @@ def __init__(self, coils, current=0.0, control=True):
self.coils = coils
self.current = current
self.control = control

def __getitem__(self, name):
"""Returns a coil in the circuit using circuit[coil_name]"""

for label, coil, _ in self.coils:
if label == name:
return coil
raise KeyError("Circuit does not contain coil with label '{0}'".format(name))

@property
def current(self) -> float:
return self._current

@current.setter
def current(self, value: float):
"""
When updating the circuit current, also update the current in the coils in the circuit (with multipliers)
"""
self._current = value
for _, coil, multiplier in self.coils:
coil.current = multiplier * value

@property
def control(self) -> bool:
return self._control

@control.setter
def control(self, value: bool):
"""
When updating the circuit control switch, also update the control switch in the coils in the circuit
"""
self._control = value
for _, coil, _ in self.coils:
coil.control = value

def psi(self, R, Z):
"""
Expand Down

0 comments on commit 5f5d452

Please sign in to comment.