diff --git a/src/simsopt/mhd/spec.py b/src/simsopt/mhd/spec.py index 05e304a52..ec7444417 100644 --- a/src/simsopt/mhd/spec.py +++ b/src/simsopt/mhd/spec.py @@ -141,6 +141,12 @@ def __init__(self, filename = f"{filename}.sp" logger.info(f"Initializing a SPEC object from file: {filename}") + # If spec has run before, clear the f90wrap array caches. + # See https://github.com/hiddenSymmetries/simsopt/pull/431 + # This addresses the issue https://github.com/hiddenSymmetries/simsopt/issues/357 + if spec.allglobal._arrays: + self._clear_f90wrap_array_caches() + if tolerance <= 0: raise ValueError( 'tolerance should be greater than zero' @@ -716,6 +722,18 @@ def set_dofs(self, x): if p is not None: p.phiedge = x[0] + def _clear_f90wrap_array_caches(self): + """ + Clear the f90wrap array caches. This is necessary when a new file is + read after SPEC has run before. + + See https://github.com/hiddenSymmetries/simsopt/pull/431 + + This function is for addressing the issue https://github.com/hiddenSymmetries/simsopt/issues/357 + """ + spec.allglobal._arrays = {} + spec.inputlist._arrays = {} + def init(self, filename: str): """ Initialize SPEC fortran state from an input file.