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

Fix logical errors and typos in Spec equilibrium object #457

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
61 changes: 30 additions & 31 deletions src/simsopt/mhd/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,11 @@ def pressure_profile(self, pressure_profile):

# Check inputs
if not isinstance(pressure_profile, ProfileSpec):
ValueError('Input should be a ProfileSpec')
raise ValueError('Input should be a ProfileSpec')

# Check size
if pressure_profile.dofs.full_x.size != self.mvol:
ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')
raise ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')

# Update pressure profile
if pressure_profile is not self._pressure_profile:
Expand Down Expand Up @@ -478,17 +478,17 @@ def volume_current_profile(self, volume_current_profile):
"""

if not isinstance(volume_current_profile, ProfileSpec):
ValueError('Input should be a ProfileSpec')
raise ValueError('Input should be a ProfileSpec')

# Check size
if volume_current_profile.dofs.full_x.size != self.mvol:
ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')
raise ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')

# Volume current is a cumulative property
volume_current_profile.cumulative = True

if volume_current_profile is not self._volume_current_profile:
logging.debug('Replacing pressure_profile in setter')
logging.debug('Replacing volume_current_profile in setter')
if self._volume_current_profile is not None:
self.remove_parent(self._volume_current_profile)
self._volume_current_profile = volume_current_profile
Expand Down Expand Up @@ -516,14 +516,14 @@ def interface_current_profile(self, interface_current_profile):
"""

if not isinstance(interface_current_profile, ProfileSpec):
ValueError('Input should be a ProfileSpec')
raise ValueError('Input should be a ProfileSpec')

# Check size
if interface_current_profile.dofs.full_x.size != self.mvol:
ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')
raise ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')

if interface_current_profile is not self._interface_current_profile:
logging.debug('Replacing pressure_profile in setter')
logging.debug('Replacing interface_current_profile in setter')
if self._interface_current_profile is not None:
self.remove_parent(self._interface_current_profile)
self._interface_current_profile = interface_current_profile
Expand Down Expand Up @@ -551,14 +551,14 @@ def iota_profile(self, iota_profile):
"""

if not isinstance(iota_profile, ProfileSpec):
ValueError('Input should be a ProfileSpec')
raise ValueError('Input should be a ProfileSpec')

# Check size
if iota_profile.dofs.full_x.size != self.mvol:
ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')
raise ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')

if iota_profile is not self._iota_profile:
logging.debug('Replacing pressure_profile in setter')
logging.debug('Replacing iota_profile in setter')
if self._iota_profile is not None:
self.remove_parent(self._iota_profile)
self._iota_profile = iota_profile
Expand Down Expand Up @@ -586,14 +586,14 @@ def oita_profile(self, oita_profile):
"""

if not isinstance(oita_profile, ProfileSpec):
ValueError('Input should be a ProfileSpec')
raise ValueError('Input should be a ProfileSpec')

# Check size
if oita_profile.dofs.full_x.size != self.mvol:
ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')
raise ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')

if oita_profile is not self._oita_profile:
logging.debug('Replacing pressure_profile in setter')
logging.debug('Replacing oita_profile in setter')
if self._oita_profile is not None:
self.remove_parent(self._oita_profile)
self._oita_profile = oita_profile
Expand Down Expand Up @@ -621,14 +621,14 @@ def mu_profile(self, mu_profile):
"""

if not isinstance(mu_profile, ProfileSpec):
ValueError('Input should be a ProfileSpec')
raise ValueError('Input should be a ProfileSpec')

# Check size
if mu_profile.dofs.full_x.size != self.mvol:
ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')
raise ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')

if mu_profile is not self._mu_profile:
logging.debug('Replacing pressure_profile in setter')
logging.debug('Replacing mu_profile in setter')
if self._mu_profile is not None:
self.remove_parent(self._mu_profile)
self._mu_profile = mu_profile
Expand Down Expand Up @@ -656,17 +656,17 @@ def pflux_profile(self, pflux_profile):
"""

if not isinstance(pflux_profile, ProfileSpec):
ValueError('Input should be a ProfileSpec')
raise ValueError('Input should be a ProfileSpec')

# Check size
if pflux_profile.dofs.full_x.size != self.mvol:
ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')
raise ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')

# pflux is a cumulative property
pflux_profile.cumulative = True

if pflux_profile is not self._pflux_profile:
logging.debug('Replacing pressure_profile in setter')
logging.debug('Replacing pflux_profile in setter')
if self._pflux_profile is not None:
self.remove_parent(self._pflux_profile)
self._pflux_profile = pflux_profile
Expand All @@ -692,19 +692,18 @@ def tflux_profile(self, tflux_profile):
Args:
ProfileSpec instance for the toroidal flux profile
"""

if not isinstance(tflux_profile, ProfileSpec):
ValueError('Input should be a ProfileSpec')
raise ValueError('Input should be a ProfileSpec')

# Check size
if tflux_profile.dofs.full_x.size != self.mvol:
ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')
raise ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')

# pflux is a cumulative property
tflux_profile.cumulative = True

if tflux_profile is not self._tflux_profile:
logging.debug('Replacing pressure_profile in setter')
logging.debug('Replacing tflux_profile in setter')
if self._tflux_profile is not None:
self.remove_parent(self._tflux_profile)
self._tflux_profile = tflux_profile
Expand Down Expand Up @@ -732,14 +731,14 @@ def helicity_profile(self, helicity_profile):
"""

if not isinstance(helicity_profile, ProfileSpec):
ValueError('Input should be a ProfileSpec')
raise ValueError('Input should be a ProfileSpec')

# Check size
if helicity_profile.dofs.full_x.size != self.mvol:
ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')
raise ValueError('Invalid number of dofs. Shoudl be equal to Mvol!')

if helicity_profile is not self._helicity_profile:
logging.debug('Replacing pressure_profile in setter')
logging.debug('Replacing helicity_profile in setter')
if self._helicity_profile is not None:
self.remove_parent(self._tflux_profile)
self._helicity_profile = helicity_profile
Expand Down Expand Up @@ -942,7 +941,7 @@ def run(self, update_guess: bool = True):
# Check that number of volumes in internal memory is consistent with
# the input file
if self.nvol != si.nvol:
ValueError('Inconsistent Nvol')
raise ValueError('Inconsistent Nvol')

# nfp must be consistent between the surface and SPEC. The surface's
# value trumps.
Expand Down Expand Up @@ -1029,10 +1028,10 @@ def run(self, update_guess: bool = True):
si.curtor = si.ivolume[self.nvol - 1] + np.sum(si.isurf)

if self.iota_profile is not None:
si.iota[0:self.nvol+1] = self.iota_profile.get(np.arange(0, self.nvol))
si.iota[0:self.nvol+1] = self.iota_profile.get(np.arange(0, self.nvol+1))

if self.oita_profile is not None:
si.oita[0:self.nvol+1] = self.oita_profile.get(np.arange(0, self.nvol))
si.oita[0:self.nvol+1] = self.oita_profile.get(np.arange(0, self.nvol+1))

if self.mu_profile is not None:
si.mu[0:self.nvol] = self.mu_profile.get(np.arange(0, self.nvol))
Expand Down Expand Up @@ -1286,7 +1285,7 @@ def as_spec(self):

@as_spec.setter
def as_spec(self, array):
if array.shape != [2*self.mntor+1, 2*self.mmpol+1]:
if array.shape != (2*self._mntor+1, 2*self._mmpol+1):
raise ValueError('Array size is not consistent witn mmpol and mntor')
self._array = array

Expand Down
Loading