def _update_m(self, system): # An example .omf filename is: # test_sample-Oxs_TimeDriver-Magnetization-01-0000008.omf ovffiles = glob.iglob( os.path.join(self.dirname, f'{system.name}.out', 'm_full*.ovf')) lastovffile = list(sorted(ovffiles))[-1] m_field = df.read(lastovffile) # This line exists because the mesh generated in df.read # method comes from the discrtisedfield module where the # _script method is not implemented. m_field.mesh = system.m.mesh system.m = m_field
def _update_m(self, system): # Find last omf file. dirname = self._filenames(system)["dirname"] last_omf_file = max(glob.iglob("{}*.omf".format(dirname)), key=os.path.getctime) # Update system's magnetisaton. m_field = df.read(last_omf_file) # Temporary solution for having script in mesh object. # Overwrites the df.Mesh with oc.Mesh. m_field.mesh = system.m.mesh system.m = m_field
def _update_m(self, system): # An example .omf filename is: # test_sample-Oxs_TimeDriver-Magnetization-01-0000008.omf omffiles = glob.iglob(os.path.join(self.dirname, f'{system.name}*.omf')) lastomffile = sorted(omffiles)[-1] m_field = df.read(lastomffile) # This line exists because the mesh generated in df.read # method comes from the discrtisedfield module where the # _script method is not implemented. m_field.mesh = system.m.mesh system.m = m_field
def effective_field(self): _dict = {'Demag': 'Oxs_Demag::Field', 'Exchange': 'Oxs_UniformExchange::Field', 'UniaxialAnisotropy': 'Oxs_UniaxialAnisotropy::Field', 'Zeeman': 'Oxs_FixedZeeman::Field', 'Hamiltonian': 'Oxs_RungeKuttaEvolve::Total field'} td = oc.TimeDriver() td.drive(self.system, derive=_dict[self.cls]) dirname = os.path.join(self.system.name, 'drive-{}'.format(self.system.drive_number-1)) ohf_file = max(glob.iglob(os.path.join(dirname, '*.ohf')), key=os.path.getctime) return df.read(ohf_file)
def energy_density(self): _dict = {'Demag': 'Oxs_Demag::Energy density', 'Exchange': 'Oxs_UniformExchange::Energy density', 'UniaxialAnisotropy': ('Oxs_UniaxialAnisotropy::' 'Energy density'), 'Zeeman': 'Oxs_FixedZeeman::Energy density', 'Hamiltonian': ('Oxs_RungeKuttaEvolve::' 'Total energy density')} td = oc.TimeDriver() td.drive(self.system, derive=_dict[self.cls]) dirname = os.path.join(self.system.name, 'drive-{}'.format(self.system.drive_number-1)) oef_file = max(glob.iglob(os.path.join(dirname, '*.oef')), key=os.path.getctime) return df.read(oef_file)
def test_write_read_ovf_file_text(self): tol = 1e-12 filename = "test_write_ovf_file_text.omf" value = (1e-3 + np.pi, -5, 6) for f in self.vector_fs: f.value = value f.write(filename) f_loaded = df.read(filename) assert f.mesh.p1 == f_loaded.mesh.p1 assert f.mesh.p2 == f_loaded.mesh.p2 assert f.mesh.cell == f_loaded.mesh.cell assert f.mesh.cell == f_loaded.mesh.cell assert np.all(abs(f.value - f_loaded.value) < tol) os.system("rm {}".format(filename))
def effective_field(self): _dict = { "Demag": "Oxs_Demag::Field", "Exchange": "Oxs_UniformExchange::Field", "UniaxialAnisotropy": "Oxs_UniaxialAnisotropy::Field", "Zeeman": "Oxs_FixedZeeman::Field", "Hamiltonian": "Oxs_RungeKuttaEvolve:evolver:Total field" } td = oc.TimeDriver() td.drive(self.system, derive=_dict[self.cls]) dirname = os.path.join(self.system.name, "") ohf_file = max(glob.iglob("{}*.ohf".format(dirname)), key=os.path.getctime) return df.read(ohf_file)
def test_write_vector_norm_file(self): tol = 1e-12 mesh = df.Mesh(p1=(0, 0, 0), p2=(10, 10, 10), cell=(5, 5, 5)) f = df.Field(mesh, dim=1, value=-3.1) filename = "test_write_oommf_file_text1.omf" f.write(filename) f_loaded = df.read(filename) assert f.mesh.p1 == f_loaded.mesh.p1 assert f.mesh.p2 == f_loaded.mesh.p2 assert f.mesh.cell == f_loaded.mesh.cell assert f.mesh.cell == f_loaded.mesh.cell assert np.all(abs(f.value - f_loaded.array[..., 0]) < tol) assert np.all(abs(0 - f_loaded.array[..., 1]) < tol) assert np.all(abs(0 - f_loaded.array[..., 2]) < tol) os.system("rm {}".format(filename))
def energy_density(self): _dict = { "Demag": "Oxs_Demag::Energy density", "Exchange": "Oxs_UniformExchange::Energy density", "UniaxialAnisotropy": ("Oxs_UniaxialAnisotropy::" "Energy density"), "Zeeman": "Oxs_FixedZeeman::Energy density", "Hamiltonian": ("Oxs_RungeKuttaEvolve:evolver:" "Total energy density") } td = oc.TimeDriver() td.drive(self.system, derive=_dict[self.cls]) dirname = os.path.join(self.system.name, "") oef_file = max(glob.iglob("{}*.oef".format(dirname)), key=os.path.getctime) return df.read(oef_file)
def step(f, t): mesh = df.Mesh(p1=(0, 0, 0), p2=self.grid_params.l, cell=self.grid_params.d) field = df.Field(mesh, value=(0,0,1), norm=1) field.array[:] = np.transpose(f, (1,2,3,0)) #field.norm = self.sim_params.Ms field.write("{}/m0.omf".format(self.path)) out = subprocess.Popen("tclsh $OOMMFTCL boxsi +fg run.mif", cwd="./{}".format(self.path), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = out.communicate() if out.returncode: if not stdout is None: print(stdout.decode('utf-8'), file=sys.stderr) if not stderr is None: print(stderr.decode('utf-8'), file=sys.stderr) sys.stderr.flush() raise RuntimeError last_omf_file = max(glob.iglob("{}/system*.omf".format(self.path)), key=os.path.getctime) field = df.read(last_omf_file) #field.norm = 1 t[:] = np.transpose(field.array, (3,0,1,2))
def get_field(self): filename = self.omf_files[self.time_slider.value] return df.read(filename)
def step_fields(self): for filename in self.step_filenames: yield df.read(filename)
def m0(self): m0filename = 'm0.omf' return df.read(os.path.join(self.dirname, m0filename))