Skip to content

Commit

Permalink
Merge pull request #199 from hiddenSymmetries/ml/vmec_verbose
Browse files Browse the repository at this point in the history
Control vmec printing
  • Loading branch information
mbkumar authored Feb 21, 2022
2 parents 69dc0cb + 112ce30 commit cb377be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/simsopt/mhd/vmec.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class Vmec(Optimizable):
keep_all_files: If ``False``, all ``wout`` output files will be deleted
except for the first and most recent ones from worker group 0. If
``True``, all ``wout`` files will be kept.
verbose: Whether to print to stdout when running vmec.
Attributes:
iter: Number of times VMEC has run.
Expand All @@ -199,6 +200,7 @@ def __init__(self,
filename: Union[str, None] = None,
mpi: Union[MpiPartition, None] = None,
keep_all_files: bool = False,
verbose: bool = True,
ntheta=50,
nphi=50):

Expand All @@ -220,6 +222,7 @@ def __init__(self,
raise ValueError('Invalid filename')

self.wout = Struct()
self.verbose = verbose

# Get MPI communicator:
if (mpi is None and MPI is not None):
Expand Down Expand Up @@ -252,10 +255,9 @@ def __init__(self,
self.ictrl[2] = 0 # numsteps
self.ictrl[3] = 0 # ns_index
self.ictrl[4] = 0 # iseq
verbose = True
reset_file = ''
logger.info('About to call runvmec to readin')
vmec.runvmec(self.ictrl, filename, verbose, self.fcomm, reset_file)
vmec.runvmec(self.ictrl, filename, self.verbose, self.fcomm, reset_file)
ierr = self.ictrl[1]
logger.info('Done with runvmec. ierr={}. Calling cleanup next.'.format(ierr))
# Deallocate arrays allocated by VMEC's fixaray():
Expand Down Expand Up @@ -522,9 +524,8 @@ def run(self):
self.ictrl[2] = 0 # numsteps
self.ictrl[3] = 0 # ns_index
self.ictrl[4] = 0 # iseq
verbose = True
reset_file = ''
vmec.runvmec(self.ictrl, input_file, verbose, self.fcomm, reset_file)
vmec.runvmec(self.ictrl, input_file, self.verbose, self.fcomm, reset_file)
ierr = self.ictrl[1]

# Deallocate arrays, even if vmec did not converge:
Expand Down
11 changes: 11 additions & 0 deletions tests/mhd/test_vmec.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,17 @@ def test_2_init_methods(self):
np.testing.assert_allclose(iota1, iota2, atol=1e-10)
np.testing.assert_allclose(bmnc1, bmnc2, atol=1e-10)

def test_verbose(self):
"""
I'm not sure how to confirm that nothing is printed if ``verbose``
is set to ``False``, but we can at least make sure the code
doesn't crash in this case.
"""
for verbose in [True, False]:
filename = os.path.join(TEST_DIR, 'input.li383_low_res')
vmec = Vmec(filename, verbose=verbose)
vmec.run()

def test_vmec_failure(self):
"""
Verify that failures of VMEC are correctly caught and represented
Expand Down

0 comments on commit cb377be

Please sign in to comment.