Пример #1
0
 def tearDown(self):
     """
     Tear down the test fixture. This subroutine is automatically
     run by python's unittest module before every test. Here we
     call runvmec with the cleanup flag to deallocate arrays, such
     that runvmec can be called again later.
     """
     self.ictrl[0] = 16 # cleanup
     vmec_f90wrap.runvmec(self.ictrl, self.filename, self.verbose, \
                              self.fcomm, reset_file)
Пример #2
0
 def reset(self):
     ier = 0
     numsteps = 0
     ns_index = -1
     #iseq = MPI.COMM_WORLD.Get_rank()
     iseq = 0
     input_file = ''
     reset_file = ''
     # prepare Fortran arguments
     self.ictrl[0] = 16
     self.ictrl[1] = ier
     self.ictrl[2] = numsteps
     self.ictrl[3] = ns_index
     self.ictrl[4] = iseq
     # run VMEC
     print("In core.reset")
     verbose = True
     vmec.runvmec(self.ictrl, input_file, verbose, self.comm, reset_file)
Пример #3
0
    def test_run_read(self):
        """
        Try running VMEC, then reading in results from the wout file.
        """

        self.ictrl[0] = 1 + 2 + 4 + 8
        vmec_f90wrap.runvmec(self.ictrl, self.filename, self.verbose, \
                                 self.fcomm, reset_file)

        self.assertTrue(self.ictrl[1] in success_codes)

        self.assertEqual(vmec_f90wrap.vmec_input.nfp, 3)
        self.assertEqual(vmec_f90wrap.vmec_input.mpol, 4)
        self.assertEqual(vmec_f90wrap.vmec_input.ntor, 3)
        print('rbc.shape:', vmec_f90wrap.vmec_input.rbc.shape)
        print('rbc:',vmec_f90wrap.vmec_input.rbc[101:103, 0:4])

        # n = 0, m = 0:
        self.assertAlmostEqual(vmec_f90wrap.vmec_input.rbc[101,0], 1.3782)

        # n = 0, m = 1:
        self.assertAlmostEqual(vmec_f90wrap.vmec_input.zbs[101,1], 4.6465E-01)

        # n = 1, m = 1:
        self.assertAlmostEqual(vmec_f90wrap.vmec_input.zbs[102,1], 1.6516E-01)

        # Now try reading in the output
        wout_file = os.path.join(os.path.dirname(__file__), 'wout_li383_low_res.nc')
        ierr = 0
        vmec_f90wrap.read_wout_mod.read_wout_file(wout_file, ierr)
        self.assertEqual(ierr, 0)
        self.assertAlmostEqual(vmec_f90wrap.read_wout_mod.betatot, \
                                   0.0426215030653306, places=4)

        print('iotaf.shape:',vmec_f90wrap.read_wout_mod.iotaf.shape)
        print('rmnc.shape:',vmec_f90wrap.read_wout_mod.rmnc.shape)

        self.assertAlmostEqual(vmec_f90wrap.read_wout_mod.iotaf[-1], \
                                   0.654868168783638, places=4)

        self.assertAlmostEqual(vmec_f90wrap.read_wout_mod.rmnc[0, 0], \
                                   1.4773028173065, places=4)
Пример #4
0
 def finalize(self):
     ier = 0
     numsteps = 0
     ns_index = -1
     #iseq = MPI.COMM_WORLD.Get_rank()
     iseq = 0
     input_file = ''
     reset_file = ''
     # prepare Fortran arguments
     self.ictrl[0] = 16 + 32
     self.ictrl[1] = ier
     self.ictrl[2] = numsteps
     self.ictrl[3] = ns_index
     self.ictrl[4] = iseq
     # run VMEC
     print("In core.finalize")
     #vmec.parallel_vmec_module.parvmec = True
     #vmec.parallel_vmec_module.ns_resltn = 0 # Sam says "Need to do this otherwise situations arrise which cause problems."
     verbose = True
     vmec.runvmec(self.ictrl, input_file, verbose, self.comm, reset_file)
Пример #5
0
    def test_read_input(self):
        """
        Try reading a VMEC input file.
        """
        self.ictrl[0] = run_modes['input']
        vmec_f90wrap.runvmec(self.ictrl, self.filename, self.verbose, \
                                 self.fcomm, reset_file)

        self.assertTrue(self.ictrl[1] in success_codes)

        self.assertEqual(vmec_f90wrap.vmec_input.nfp, 3)
        self.assertEqual(vmec_f90wrap.vmec_input.mpol, 4)
        self.assertEqual(vmec_f90wrap.vmec_input.ntor, 3)
        print('rbc.shape:', vmec_f90wrap.vmec_input.rbc.shape)
        print('rbc:',vmec_f90wrap.vmec_input.rbc[101:103, 0:4])

        # n = 0, m = 0:
        self.assertAlmostEqual(vmec_f90wrap.vmec_input.rbc[101,0], 1.3782)

        # n = 0, m = 1:
        self.assertAlmostEqual(vmec_f90wrap.vmec_input.zbs[101,1], 4.6465E-01)

        # n = 1, m = 1:
        self.assertAlmostEqual(vmec_f90wrap.vmec_input.zbs[102,1], 1.6516E-01)
Пример #6
0
    def run(self,
            mode='main',
            ier=0,
            numsteps=-1,
            ns_index=-1,
            iseq=0,
            input_file=None,
            verbose=None,
            comm=None,
            reset_file='',
            **kwargs):
        """Interface for Fortran subroutine runvmec in Sources/TimeStep/runvmec.f

        Args:
            mode (str): The running mode of VMEC. It should be one of the
                following options,
                ('all', 'input', 'output', 'main'). (default: 'main').
            ier (int): Flag for error condition. (default: 0).
            numsteps (int): Number time steps to evolve the equilibrium.
                Iterations will stop EITHER if numsteps > 0 and when the
                number of vmec iterations exceeds numsteps; OR if the ftol
                condition is satisfied, whichever comes first. The
                timestep_flag must be set (in ictrl_flag) for this to be
                in effect. If numsteps <= 0, then vmec will choose
                consecutive (and increasing) values from the ns_array
                until ftol is satisfied on each successive multi-grid.
                (default: -1).
            ns_index (int): if > 0 on entry, specifies index (in ns_array)
                of the radial grid to be used for the present iteration
                phase. If ns_index <= 0, vmec will use the previous value
                of this index (if the ftol condition was not satisfied
                during the last call to runvmec) or the next value of this
                index, and it will iterate through each successive
                non-zero member of the ns_array until ftol-convergence
                occurs on each multigrid.
                (default: -1).
            iseq (int): specifies a unique sequence label for identifying
                output files in a sequential vmec run.
                (default: 0).
            input_file (str): Filename for VMEC input namelist.
                (default: None -> self.input_file).
            verbose (bool): If wants scree outputs.
                (default: None -> self.verbose).
            comm (int): MPI_Communicater, should be converted to Fortran
                format using MPI.py2f().
                (default: None -> self.comm).
            reset_file (str): Filename for reset runs. (default: '').

        Returns:
            None
        """
        # check arguments
        mode = mode.lower()
        assert mode in run_modes, ("Unsupported running mode. Should "
                                   "be one of [{:}].").format(','.join(
                                       run_modes.keys()))
        assert ier == 0, "Error flag should be zero at input."
        if input_file is None:
            input_file = self.input_file + '_{:03d}_{:06d}'.format(
                self.group, self.iter)
            #input_file = self.input_file+'_{:06d}'.format(self.iter)
        else:
            if 'input.' not in input_file:
                input_file = 'input.' + input_file
        #self.output_file = input_file.replace('input.', 'wout_')+'.nc'
        # Need to include os.getcwd() if the input file is not in the current working directory.
        self.output_file = os.path.join(os.getcwd(), \
               os.path.basename(input_file).replace('input.', 'wout_')+'.nc')
        if verbose is None:
            verbose = self.verbose
        if comm is None:
            comm = self.comm
        # prepare Fortran arguments
        self.ictrl[0] = run_modes[mode]
        self.ictrl[1] = ier
        self.ictrl[2] = numsteps
        self.ictrl[3] = ns_index
        self.ictrl[4] = iseq

        #vmec.parallel_vmec_module.parvmec = True
        #vmec.parallel_vmec_module.ns_resltn = 0 # Sam says "Need to do this otherwise situations arrise which cause problems."

        # run VMEC
        vmec.runvmec(self.ictrl, input_file, verbose, comm, reset_file)
        self.iter += 1
        self.success = self.ictrl[1] in self.success_code

        #vmec.parallel_vmec_module.finalizesurfacecomm(vmec.parallel_vmec_module.ns_comm)
        #vmec.parallel_vmec_module.finalizerunvmec(vmec.parallel_vmec_module.runvmec_comm_world)

        return self.success