def relax(self, stopping_mxHxm=0.01): self.m.write_oommf_file(self.dirname + 'm0file.omf') self.m0 = 'm0file.omf' self.evolver = CGEvolve() self.driver = MinDriver('evolver', stopping_mxHxm, 'mesh', self.Ms, self.m0, basename=self.name) self.relaxation = True self.execute_mif()
def run_until(self, stopping_time, stages=1): self.m.write_oommf_file(self.dirname + 'm0file.omf') self.m0 = 'm0file.omf' self.evolver = RungeKuttaEvolve(self.alpha) self.driver = TimeDriver('evolver', stopping_time/stages, stages, 'mesh', self.Ms, self.m0, basename=self.name) self.relaxation = False self.execute_mif() self.t += stopping_time
def test_init_exceptions(self): # Invalid arguments (ValueError expected). for arg in self.args2: evolver = arg[0] stopping_mxHxm = arg[1] mesh = arg[2] Ms = arg[3] m0 = arg[4] basename = arg[5] with pytest.raises(ValueError): driver = MinDriver(evolver, stopping_mxHxm, mesh, Ms, m0, basename)
def run_until(self, stopping_time, stages=1): self.m.write_oommf_file(self.dirname + 'm0file.omf') self.m0 = 'm0file.omf' self.evolver = RungeKuttaEvolve(self.alpha) self.driver = TimeDriver('evolver', stopping_time / stages, stages, 'mesh', self.Ms, self.m0, basename=self.name) self.relaxation = False self.execute_mif() self.t += stopping_time
def test_init(self): # Valid arguments. for arg in self.args1: evolver = arg[0] stopping_mxHxm = arg[1] mesh = arg[2] Ms = arg[3] m0 = arg[4] basename = arg[5] driver = MinDriver(evolver, stopping_mxHxm, mesh, Ms, m0, basename) assert driver.evolver == evolver assert driver.stopping_mxHxm == stopping_mxHxm assert driver.mesh == mesh assert driver.Ms == Ms assert driver.m0 == m0 assert driver.basename == basename
class Sim(object): def __init__(self, mesh, Ms, name=None): self.mesh = mesh self.atlas = mesh.atlas self.Ms = Ms self.name = name self.energies = [] # Set default alpha value. self.alpha = 1 self.dirname = self.name + '/' if not os.path.exists(self.dirname): os.makedirs(self.dirname) self.mif_filename = self.dirname + self.name + '.mif' self.m = Field(self.atlas.cmin, self.atlas.cmax, self.mesh.d, dim=3) self.t = 0 def add(self, energy): self.energies.append(energy) def set_H(self, H): for energy in self.energies: if isinstance(energy, FixedZeeman): self.energies.remove(energy) zeeman = FixedZeeman(H) self.add(zeeman) def run_until(self, stopping_time, stages=1): self.m.write_oommf_file(self.dirname + 'm0file.omf') self.m0 = 'm0file.omf' self.evolver = RungeKuttaEvolve(self.alpha) self.driver = TimeDriver('evolver', stopping_time/stages, stages, 'mesh', self.Ms, self.m0, basename=self.name) self.relaxation = False self.execute_mif() self.t += stopping_time def m_average(self): return self.m.average() def relax(self, stopping_mxHxm=0.01): self.m.write_oommf_file(self.dirname + 'm0file.omf') self.m0 = 'm0file.omf' self.evolver = CGEvolve() self.driver = MinDriver('evolver', stopping_mxHxm, 'mesh', self.Ms, self.m0, basename=self.name) self.relaxation = True self.execute_mif() def set_m(self, m0): if isinstance(m0, (list, tuple)): self.m.set(m0) elif isinstance(m0, str): self.m = load_oommf_file(m0) elif hasattr(m0, '__call__'): self.m.set(m0) elif isinstance(m0, Field): self.m = m0 self.m.write_oommf_file(self.dirname + 'm0file.omf') else: raise ValueError('m0 type invalid.') def get_mif(self): mif = '# MIF 2.1\n\n' mif += self.atlas.get_mif() mif += self.mesh.get_mif() for i in self.energies: mif += i.get_mif() mif += self.evolver.get_mif() mif += self.driver.get_mif() mif += 'Destination table mmArchive\n' mif += 'Destination mags mmArchive\n\n' mif += 'Schedule DataTable table Stage 1\n' if self.relaxation: mif += 'Schedule Oxs_MinDriver::Spin mags Stage 1' else: mif += 'Schedule Oxs_TimeDriver::Spin mags Stage 1' return mif def create_mif(self): miffile = open(self.mif_filename, 'w') miffile.write(self.get_mif()) miffile.close() def last_omf_file(self): newest_omf = max(glob.iglob(self.dirname+'*.omf'), key=os.path.getctime) return newest_omf def last_odt_file(self): newest_odt = max(glob.iglob(self.dirname+'*.odt'), key=os.path.getctime) return newest_odt def update_self(self): newest_omf = self.last_omf_file() self.m = load_oommf_file(newest_omf) newest_odt = self.last_odt_file() self.odt_file = ODTFile(newest_odt) self.data = self.odt_file.last_row() def total_energy(self): return self.data['Totalenergy'] def execute_mif(self): self.create_mif() oommf_command = 'tclsh $OOMMFTCL boxsi +fg ' oommf_command += self.mif_filename oommf_command += ' -exitondone 1' os.system('cd ' + self.dirname) os.system(oommf_command) self.update_self()
class Sim(object): def __init__(self, mesh, Ms, name=None): self.mesh = mesh self.atlas = mesh.atlas self.Ms = Ms self.name = name self.energies = [] # Set default alpha value. self.alpha = 1 self.dirname = self.name + '/' if not os.path.exists(self.dirname): os.makedirs(self.dirname) self.mif_filename = self.dirname + self.name + '.mif' self.m = Field(self.atlas.cmin, self.atlas.cmax, self.mesh.d, dim=3) self.t = 0 def add(self, energy): self.energies.append(energy) def set_H(self, H): for energy in self.energies: if isinstance(energy, FixedZeeman): self.energies.remove(energy) zeeman = FixedZeeman(H) self.add(zeeman) def run_until(self, stopping_time, stages=1): self.m.write_oommf_file(self.dirname + 'm0file.omf') self.m0 = 'm0file.omf' self.evolver = RungeKuttaEvolve(self.alpha) self.driver = TimeDriver('evolver', stopping_time / stages, stages, 'mesh', self.Ms, self.m0, basename=self.name) self.relaxation = False self.execute_mif() self.t += stopping_time def m_average(self): return self.m.average() def relax(self, stopping_mxHxm=0.01): self.m.write_oommf_file(self.dirname + 'm0file.omf') self.m0 = 'm0file.omf' self.evolver = CGEvolve() self.driver = MinDriver('evolver', stopping_mxHxm, 'mesh', self.Ms, self.m0, basename=self.name) self.relaxation = True self.execute_mif() def set_m(self, m0): if isinstance(m0, (list, tuple)): self.m.set(m0) elif isinstance(m0, str): self.m = load_oommf_file(m0) elif hasattr(m0, '__call__'): self.m.set(m0) elif isinstance(m0, Field): self.m = m0 self.m.write_oommf_file(self.dirname + 'm0file.omf') else: raise ValueError('m0 type invalid.') def get_mif(self): mif = '# MIF 2.1\n\n' mif += self.atlas.get_mif() mif += self.mesh.get_mif() for i in self.energies: mif += i.get_mif() mif += self.evolver.get_mif() mif += self.driver.get_mif() mif += 'Destination table mmArchive\n' mif += 'Destination mags mmArchive\n\n' mif += 'Schedule DataTable table Stage 1\n' if self.relaxation: mif += 'Schedule Oxs_MinDriver::Spin mags Stage 1' else: mif += 'Schedule Oxs_TimeDriver::Spin mags Stage 1' return mif def create_mif(self): miffile = open(self.mif_filename, 'w') miffile.write(self.get_mif()) miffile.close() def last_omf_file(self): newest_omf = max(glob.iglob(self.dirname + '*.omf'), key=os.path.getctime) return newest_omf def last_odt_file(self): newest_odt = max(glob.iglob(self.dirname + '*.odt'), key=os.path.getctime) return newest_odt def update_self(self): newest_omf = self.last_omf_file() self.m = load_oommf_file(newest_omf) newest_odt = self.last_odt_file() self.odt_file = ODTFile(newest_odt) self.data = self.odt_file.last_row() def total_energy(self): return self.data['Totalenergy'] def execute_mif(self): self.create_mif() oommf_command = 'tclsh $OOMMFTCL boxsi +fg ' oommf_command += self.mif_filename oommf_command += ' -exitondone 1' os.system('cd ' + self.dirname) os.system(oommf_command) self.update_self()
def test_get_mif(self): for arg in self.args1: evolver = arg[0] stopping_mxHxm = arg[1] mesh = arg[2] Ms = arg[3] m0 = arg[4] basename = arg[5] driver = MinDriver(evolver, stopping_mxHxm, mesh, Ms, m0, basename) mif = driver.get_mif() mif_lines = driver.get_mif().split('\n') # Assert comment. l = mif_lines[0].split() assert l[0] == '#' assert l[1] == 'MinDriver' # Assert Specify line. l = mif_lines[1].split() assert l[0] == 'Specify' assert l[1].split(':')[0] == 'Oxs_MinDriver' assert l[2] == '{' # Assert parameters lines assert mif_lines[2][0] == '\t' l = mif_lines[2].split() assert l[0] == 'evolver' assert l[1] == evolver # Assert parameters lines assert mif_lines[3][0] == '\t' l = mif_lines[3].split() assert l[0] == 'stopping_mxHxm' assert float(l[1]) == stopping_mxHxm # Assert parameters lines assert mif_lines[4][0] == '\t' l = mif_lines[4].split() assert l[0] == 'mesh' assert l[1] == ':' + mesh # Assert parameters lines assert mif_lines[5][0] == '\t' l = mif_lines[5].split() assert l[0] == 'Ms' assert float(l[1]) == Ms # Assert parameters lines assert mif_lines[6][0] == '\t' l = mif_lines[6].split() assert l[0] == 'm0' assert l[1] == '{' # Assert initial state definition. if isinstance(m0, (list, tuple)): assert mif_lines[7][0:2] == '\t\t' l = mif_lines[7].split() assert l[0] == 'Oxs_UniformVectorField' assert l[1] == '{' assert mif_lines[8][0:3] == '\t\t\t' l = mif_lines[8].split() assert l[0] == 'vector' assert l[1] == '{' assert float(l[2]) == m0[0] assert float(l[3]) == m0[1] assert float(l[4]) == m0[2] assert l[5] == '}' assert mif_lines[9][0:2] == '\t\t' l = mif_lines[9].split() assert l[0] == '}' n = 9 elif isinstance(m0, str): assert mif_lines[7][0:2] == '\t\t' l = mif_lines[7].split() assert l[0] == 'Oxs_FileVectorField' assert l[1] == '{' assert mif_lines[8][0:3] == '\t\t\t' l = mif_lines[8].split() assert l[0] == 'atlas' assert l[1] == ':atlas' assert mif_lines[9][0:3] == '\t\t\t' l = mif_lines[9].split() assert l[0] == 'norm' assert float(l[1]) == 1 assert mif_lines[10][0:3] == '\t\t\t' l = mif_lines[10].split() assert l[0] == 'file' assert l[1] == m0 assert mif_lines[11][0:2] == '\t\t' l = mif_lines[11].split() assert l[0] == '}' n = 11 assert mif_lines[n+1] == '\t}' assert mif_lines[n+2][0] == '\t' l = mif_lines[n+2].split() assert l[0] == 'basename' assert l[1] == basename l = mif_lines[n+3] assert l == '\tvector_field_output_format {text %\#.8g}' # Assert mif end. assert mif_lines[n+4] == '}' # Assert new lines at the end of the string. assert mif[-2:] == '\n\n'