diff --git a/src/simsopt/mhd/vmec.py b/src/simsopt/mhd/vmec.py index cd4bf4dc6..2d6d5bfbc 100644 --- a/src/simsopt/mhd/vmec.py +++ b/src/simsopt/mhd/vmec.py @@ -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. @@ -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): @@ -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): @@ -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(): @@ -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: diff --git a/tests/mhd/test_vmec.py b/tests/mhd/test_vmec.py index 7269dd3c8..8092bb7a3 100755 --- a/tests/mhd/test_vmec.py +++ b/tests/mhd/test_vmec.py @@ -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