def reRun(self, cpus=False): print("Manually re-running NeutPy") try: from neutpy import neutrals except ModuleNotFoundError: raise ModuleNotFoundError( "Neutpy is not installed or could not be loaded. Neutrals data will be unavailable." ) if not self._check_conf("neutpy.conf"): raise IOError("No NeutPy main configuration file found.") self.npi = neutrals() if cpus: self.npi.set_cpu_cores(cpus) self.npi.from_gt3(self.core, self.inp) self.data = self.NeutralDataNT(self.npi.midpts[:, 0], self.npi.midpts[:, 1], self.npi.nn_s_raw, self.npi.nn_t_raw, self.npi.iznrate_s_raw, self.npi.iznrate_t_raw) self._save_data() try: self.core.update_ntrl_data(self.data) except: print('unable to update values in core instance.') pass
def __init__(self, inp, core, cpus=False): try: from neutpy import neutrals except ModuleNotFoundError: raise ModuleNotFoundError( "Neutpy is not installed or could not be loaded. Neutrals data will be unavailable." ) if abs(1.0 - core.sep_val) > .0001: print( "The separatrix value has been overwritten. Cannot run Neutrals calculation" ) return # Try to read in specified neutrals data file. If it's not there, then prepare inputs for and run neutpy self.NeutralDataNT = namedtuple( 'NeutralsData', 'R Z n_n_slow n_n_thermal izn_rate_slow izn_rate_thermal') self.inp = inp self.core = core try: with open(inp.neutfile_loc, "r") as f: ntrl_data = json.load(f) self.data = self.NeutralDataNT(ntrl_data['R'], ntrl_data['Z'], ntrl_data['nn_s_raw'], ntrl_data['nn_t_raw'], ntrl_data['izn_rate_slow'], ntrl_data['izn_rate_thermal']) print("Neutrals data successfully loaded from {}".format( inp.neutfile_loc)) self._update_core() except: # Run NeutPy print("Neutrals data not found. Running NeutPy") if not self._check_conf("neutpy.conf"): raise IOError("No NeutPy main configuration file found.") try: self._check_for_triangle() self.npi = neutrals() if cpus: self.npi.set_cpu_cores(cpus) self.npi.from_gt3(core, inp) self.data = self.NeutralDataNT(self.npi.midpts[:, 0], self.npi.midpts[:, 1], self.npi.nn_s_raw, self.npi.nn_t_raw, self.npi.iznrate_s_raw, self.npi.iznrate_t_raw) self._update_core() # Save data self._save_data() except EnvironmentError as e: print(str(e)) pass
#!/usr/bin/python from neutpy import neutrals if __name__ == "__main__": #neut1 = neutrals().from_file("inputs/144977_3000/toneutpy.conf") # type: neutrals #neut2 = neutrals().from_file("inputs/164436_3740/toneutpy.conf") # type: neutrals #neut3 = neutrals().from_file("inputs/175826_2010/toneutpy.conf") # type: neutrals neut4 = neutrals().from_file( "inputs/164988_1915/toneutpy.conf") # type: neutrals pass
def test_neutpy_run(self): self.npi = neutpy.neutrals() self.npi.from_gt3(self.testPlasma.core, self.testPlasma.inp)
def setUpClass(cls): cls.npi = neutpy.neutrals() cls.npi.set_cpu_cores(6)