def compute_field(mesh, nx=1, ny=1, m0=(1, 0, 0), pbc=None): Ms = 1e6 sim = Simulation(mesh, Ms, unit_length=1e-9, name='dy', pbc=pbc) sim.set_m(m0) parameters = { 'absolute_tolerance': 1e-10, 'relative_tolerance': 1e-10, 'maximum_iterations': int(1e5) } demag = Demag(macrogeometry=MacroGeometry(nx=nx, ny=ny)) demag.parameters['phi_1'] = parameters demag.parameters['phi_2'] = parameters sim.add(demag) field = sim.llg.effective_field.get_dolfin_function('Demag') # XXX TODO: Would be good to compare all the field values, not # just the value at a single point! (Max, 25.7.2014) return field(0, 0, 0) / Ms
def test_thin_film_demag_against_real_demag(): sim = Sim( df.BoxMesh(df.Point(0, 0, 0), df.Point(500e-9, 500e-9, 1e-9), 50, 50, 1), Ms) sim.set_m((0, 0, 1)) tfdemag = ThinFilmDemag() sim.add(tfdemag) H_tfdemag = tfdemag.compute_field().view().reshape((3, -1)).mean(1) demag = Demag() sim.add(demag) H_demag = demag.compute_field().view().reshape((3, -1)).mean(1) diff = np.abs(H_tfdemag - H_demag) / Ms print "Standard Demag:\n", H_demag print "ThinFilmDemag:\n", H_tfdemag print "Difference relative to Ms:\n", diff assert np.allclose(H_tfdemag, H_demag, atol=0.05 * Ms) # 5% of Ms sim.set_m((1, 0, 0)) H_tfdemag = tfdemag.compute_field().view().reshape((3, -1)).mean(1) H_demag = demag.compute_field().view().reshape((3, -1)).mean(1) print "Running again, changed m in the meantime." diff = np.abs(H_tfdemag - H_demag) / Ms print "Standard Demag:\n", H_demag print "ThinFilmDemag:\n", H_tfdemag print "Difference relative to Ms:\n", diff assert np.allclose(H_tfdemag, H_demag, atol=0.005 * Ms) # 0.5% of Ms
def ring_down(m0=(1, 0.01, 0), pbc=None): n = 49 assert n >= 1 and n % 2 == 1 Ms = 8.6e5 sim = Simulation(mesh, Ms, unit_length=1e-9, name='dy', pbc='1d') sim.alpha = 1e-3 sim.set_m(m0) sim.set_tol(1e-8, 1e-8) parameters = { 'absolute_tolerance': 1e-10, 'relative_tolerance': 1e-10, 'maximum_iterations': int(1e5) } Ts = [] for i in range(-n / 2 + 1, n / 2 + 1): Ts.append((10. * i, 0, 0)) demag = Demag(Ts=Ts) demag.parameters['phi_1'] = parameters demag.parameters['phi_2'] = parameters sim.add(demag) sim.add(Exchange(1.3e-11)) sim.schedule('save_ndt', every=2e-12) sim.run_until(4e-9)
def relax_system(): Ms = 8.6e5 sim = Simulation(mesh, Ms, unit_length=1e-9, name = 'dy') sim.alpha = 0.001 sim.set_m(np.load('m_000088.npy')) #sim.set_tol(1e-6, 1e-6) A = 1.3e-11 sim.add(Exchange(A)) parameters = { 'absolute_tolerance': 1e-10, 'relative_tolerance': 1e-10, 'maximum_iterations': int(1e5) } demag = Demag() demag.parameters['phi_1'] = parameters demag.parameters['phi_2'] = parameters print demag.parameters sim.add(demag) sim.schedule('save_ndt', every=2e-12) sim.schedule('save_vtk', every=2e-12, filename='vtks/m.pvd') sim.schedule('save_m', every=2e-12, filename='npys/m.pvd') sim.run_until(1e-9)
def run_finmag(demagsolver): """Run the finmag simulation and store data in (demagsolvertype)averages.txt.""" sim = Sim(mesh, Ms, unit_length=unit_length) sim.alpha = 0.5 sim.set_m((1, 0, 1)) exchange = Exchange(13.0e-12) sim.add(exchange) demag = Demag(solver=demagsolver) sim.add(demag) fh = open(os.path.join(MODULE_DIR, demagsolver + "averages.txt"), "w") fe = open(os.path.join(MODULE_DIR, demagsolver + "energies.txt"), "w") # Progressbar bar = pb.ProgressBar(maxval=60, \ widgets=[pb.ETA(), pb.Bar('=', '[', ']'), ' ', pb.Percentage()]) logger.info("Time integration") times = np.linspace(0, 3.0e-10, 61) #times = np.linspace(0, 3.0e-10, 100000) for counter, t in enumerate(times): bar.update(counter) # Integrate sim.run_until(t) print counter print("press return to continue") _ = raw_input() # Save averages to file mx, my, mz = sim.m_average fh.write(str(t) + " " + str(mx) + " " + str(my) + " " + str(mz) + "\n") # Energies E_e = exchange.compute_energy() E_d = demag.compute_energy() fe.write(str(E_e) + " " + str(E_d) + "\n") # Energy densities if counter == 10: exch_energy = exchange.energy_density_function() demag_energy = demag.demag.energy_density_function() finmag_exch, finmag_demag = [], [] R = range(100) for i in R: finmag_exch.append(exch_energy([15, 15, i])) finmag_demag.append(demag_energy([15, 15, i])) # Store data np.save( os.path.join(MODULE_DIR, "finmag%s_exch_density.npy" % demagsolver), np.array(finmag_exch)) np.save( os.path.join(MODULE_DIR, "finmag%s_demag_density.npy" % demagsolver), np.array(finmag_demag)) fh.close() fe.close()
def compute_field(n=1, m0=(1, 0, 0), pbc=None): assert n >= 1 and n % 2 == 1 Ms = 1e6 sim = Simulation(mesh, Ms, unit_length=1e-9, name='dy', pbc=pbc) sim.set_m(m0) parameters = { 'absolute_tolerance': 1e-10, 'relative_tolerance': 1e-10, 'maximum_iterations': int(1e5) } Ts = [] for i in range(-n / 2 + 1, n / 2 + 1): Ts.append((10. * i, 0, 0)) demag = Demag(Ts=Ts) demag.parameters['phi_1'] = parameters demag.parameters['phi_2'] = parameters sim.add(demag) sim.set_m((1, 0, 0)) field1 = sim.llg.effective_field.get_dolfin_function('Demag') sim.set_m((0, 0, 1)) field2 = sim.llg.effective_field.get_dolfin_function('Demag') return (field1(0, 0, 0) / Ms, field2(0, 0, 0) / Ms)
def compute_scalar_potential_llg(mesh, m_expr=df.Constant([1, 0, 0]), Ms=1.): S3 = df.VectorFunctionSpace(mesh, "Lagrange", 1, dim=3) m = Field(S3, value=m_expr) m.set_with_numpy_array_debug(helpers.fnormalise(m.get_numpy_array_debug())) demag = Demag() demag.setup(m, Field(df.FunctionSpace(mesh, 'DG', 0), Ms), unit_length=1) phi = demag.compute_potential() normalise_phi(phi, mesh) return phi
def compute_scalar_potential_native_gcr(mesh, m_expr=df.Constant([1, 0, 0]), Ms=1.0): gcrdemag = Demag("GCR") V = df.VectorFunctionSpace(mesh, "Lagrange", 1) m = Field(V, value=m_expr) m.set_with_numpy_array_debug(helpers.fnormalise(m.get_numpy_array_debug())) gcrdemag.setup(m, Ms, unit_length=1) phi1 = gcrdemag.compute_potential() normalise_phi(phi1, mesh) return phi1
def demag_energy(): mesh = from_geofile(os.path.join(MODULE_DIR, "sphere_fine.geo")) S3 = df.VectorFunctionSpace(mesh, "Lagrange", 1) m_function = df.interpolate(df.Constant((1, 0, 0)), S3) m = Field(S3, m_function) demag = Demag('FK') demag.setup(m, Field(df.FunctionSpace(mesh, 'DG', 0), Ms), unit_length=1) E = demag.compute_energy() rel_error = abs(E - E_analytical) / abs(E_analytical) print "Energy with FK method: {}.".format(E) return E, rel_error
def __init__(self, mesh): self.mesh = mesh self.S1 = df.FunctionSpace(mesh, 'CG', 1) self.S3 = df.VectorFunctionSpace(mesh, 'CG', 1, dim=3) #zero = df.Expression('0.3') m_init = df.Constant([1, 1, 1.0]) self.m = df.interpolate(m_init, self.S3) self.field = df.interpolate(m_init, self.S3) self.dmdt = df.interpolate(m_init, self.S3) self.spin = self.m.vector().array() self.t = 0 #It seems it's not safe to specify rank in df.interpolate??? self._alpha = df.interpolate(df.Constant("0.001"), self.S1) self._alpha.vector().set_local(self._alpha.vector().array()) print 'dolfin', self._alpha.vector().array() self.llg = LLG(self.S1, self.S3, unit_length=1e-9) #normalise doesn't work due to the wrong order self.llg.set_m(m_init, normalise=True) parameters = { 'absolute_tolerance': 1e-10, 'relative_tolerance': 1e-10, 'maximum_iterations': int(1e5) } demag = Demag() demag.parameters['phi_1'] = parameters demag.parameters['phi_2'] = parameters self.exchange = Exchange(13e-12) self.zeeman = Zeeman([0, 0, 1e5]) self.llg.effective_field.add(self.exchange) #self.llg.effective_field.add(demag) self.llg.effective_field.add(self.zeeman) self.m_petsc = df.as_backend_type(self.llg.m_field.f.vector()).vec() self.h_petsc = df.as_backend_type(self.field.vector()).vec() self.alpha_petsc = df.as_backend_type(self._alpha.vector()).vec() self.dmdt_petsc = df.as_backend_type(self.dmdt.vector()).vec() alpha = 0.001 gamma = 2.21e5 LLG1 = -gamma / (1 + alpha * alpha) * df.cross( self.m, self.field) - alpha * gamma / (1 + alpha * alpha) * df.cross( self.m, df.cross(self.m, self.field)) self.L = df.dot(LLG1, df.TestFunction(self.S3)) * df.dP
def setup_finmag(): mesh = from_geofile(os.path.join(MODULE_DIR, "sphere.geo")) S3 = df.VectorFunctionSpace(mesh, "Lagrange", 1) m = Field(S3) m.set(df.Constant((1, 0, 0))) Ms = 1 demag = Demag() demag.setup(m, Field(df.FunctionSpace(mesh, 'DG', 0), Ms), unit_length=1e-9) H = demag.compute_field() return dict(m=m, H=H, Ms=Ms, S3=S3, table=start_table())
def run_finmag(): """Run the finmag simulation and store data in averages.txt.""" sim = Sim(mesh, Ms, unit_length=unit_length) sim.alpha = 0.5 sim.set_m((1, 0, 1)) exchange = Exchange(13.0e-12) sim.add(exchange) demag = Demag(solver="FK") sim.add(demag) fh = open(os.path.join(MODULE_DIR, "averages.txt"), "w") fe = open(os.path.join(MODULE_DIR, "energies.txt"), "w") logger.info("Time integration") times = np.linspace(0, 3.0e-10, 61) for counter, t in enumerate(times): # Integrate sim.run_until(t) # Save averages to file mx, my, mz = sim.m_average fh.write(str(t) + " " + str(mx) + " " + str(my) + " " + str(mz) + "\n") # Energies E_e = exchange.compute_energy() E_d = demag.compute_energy() fe.write(str(E_e) + " " + str(E_d) + "\n") # Energy densities if counter == 10: exch_energy = exchange.energy_density_function() demag_energy = demag.energy_density_function() finmag_exch, finmag_demag = [], [] R = range(100) for i in R: finmag_exch.append(exch_energy([15, 15, i])) finmag_demag.append(demag_energy([15, 15, i])) # Store data np.save(os.path.join(MODULE_DIR, "finmag_exch_density.npy"), np.array(finmag_exch)) np.save(os.path.join(MODULE_DIR, "finmag_demag_density.npy"), np.array(finmag_demag)) fh.close() fe.close()
def example3(Ms): x0 = y0 = z0 = 0 x1 = 500 y1 = 10 z1 = 500 nx = 50 ny = 1 nz = 1 mesh = df.Box(x0, y0, z0, x1, y1, z1, nx, ny, nz) sim = Sim(mesh, Ms, unit_length=1e-9) sim.alpha = 0.01 sim.set_m((1, 0, 0.1)) H_app = Zeeman((0, 0, 5e5)) sim.add(H_app) exch = fe.Exchange(13.0e-12) sim.add(exch) demag = Demag(solver="FK") sim.add(demag) llg = sim.llg max_time = 1 * np.pi / (llg.gamma * 1e5) ts = np.linspace(0, max_time, num=100) for t in ts: print t sim.run_until(t) df.plot(llg._m) df.interactive()
def test_current_time(): size = 20e-9 simplices = 4 mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(size, size, size), simplices, simplices, simplices) Ms = 860e3 A = 13.0e-12 sim = Sim(mesh, Ms) sim.set_m((1, 0, 0)) sim.add(Exchange(A)) sim.add(Demag()) t = 0.0 t_max = 1e-10 dt = 1e-12 while t <= t_max: t += dt sim.run_until(t) # cur_t is equal to whatever time the integrator decided to probe last assert not sim.integrator.cur_t == 0.0 # t is equal to our current simulation time assert abs(sim.t - t) < epsilon
def test_differentiate_heff(): ns = [2, 2, 2] mesh = df.BoxMesh(0, 0, 0, 1, 1, 1, *ns) sim = Simulation(mesh, 1.2) sim.set_m([1, 0, 0]) sim.add(Demag()) sim.add(Exchange(2.3 * mu0)) compute_H = compute_H_func(sim) # Check that H_eff is linear without Zeeman np.random.seed(1) m1 = fnormalise(np.random.randn(*sim.m.shape)) m2 = fnormalise(np.random.randn(*sim.m.shape)) # TODO: need to use a non-iterative solver here to increase accuracy assert np.max( np.abs(compute_H(m1) + compute_H(m2) - compute_H(m1 + m2))) < 1e-6 # Add the zeeman field now sim.add(Zeeman([2.5, 3.5, 4.3])) # Check that both fd2 and fd4 give the same result assert np.max( np.abs( differentiate_fd4(compute_H, m1, m2) - differentiate_fd2(compute_H, m1, m2))) < 1e-10
def example2(Ms): x0 = y0 = z0 = 0 x1 = 500 y1 = 10 z1 = 100 nx = 50 ny = 1 nz = 1 mesh = df.Box(x0, y0, z0, x1, y1, z1, nx, ny, nz) S1 = df.FunctionSpace(mesh, "Lagrange", 1) S3 = df.VectorFunctionSpace(mesh, "Lagrange", 1, dim=3) llb = LLB(S1, S3) llb.alpha = 0.01 llb.beta = 0.0 llb.M0 = Ms llb.set_M((Ms, 0, 0)) llb.set_up_solver(jacobian=False) llb.chi = 1e-4 H_app = Zeeman((0, 0, 5e5)) H_app.setup(S3, llb._M, Ms=1) llb.interactions.append(H_app) exchange = Exchange(13.0e-12, 1e-2) exchange.chi = 1e-4 exchange.setup(S3, llb._M, Ms, unit_length=1e-9) llb.interactions.append(exchange) demag = Demag("FK") demag.setup(S3, llb._M, Ms=1) llb.interactions.append(demag) max_time = 1 * np.pi / (llb.gamma * 1e5) ts = np.linspace(0, max_time, num=100) for t in ts: print t llb.run_until(t) df.plot(llb._M) df.interactive()
def create_initial_state(): print "Creating initial relaxed state." sim = Sim(mesh, Ms=Ms, unit_length=1e-9) sim.set_m(m_gen) sim.alpha = 0.5 sim.add(Exchange(1.3e-11)) sim.add(Demag()) sim.relax() np.savetxt(initial_m_file, sim.m)
def test_field(): """ Test the demag field. H_demag should be equal to -1/3 M, and with m = (1, 0 ,0) and Ms = 1,this should give H_demag = (-1/3, 0, 0). """ # Using mesh with radius 10 nm (nmag ex. 1) mesh = from_geofile(os.path.join(MODULE_DIR, "sphere1.geo")) S3 = df.VectorFunctionSpace(mesh, "Lagrange", 1) m_function = df.interpolate(df.Constant((1, 0, 0)), S3) m = Field(S3, m_function) demag = Demag() demag.setup(m, Field(df.FunctionSpace(mesh, 'DG', 0), Ms), unit_length=1e-9) # Compute demag field H_demag = demag.compute_field() H_demag.shape = (3, -1) x, y, z = H_demag[0], H_demag[1], H_demag[2] print "Max values in direction:" print "x: %g, y: %g, z: %g" % (max(x), max(y), max(z)) print "Min values in direction:" print "x: %g, y: %g, z: %g" % (min(x), min(y), min(z)) x, y, z = average(x), average(y), average(z) print "Average values in direction" print "x: %g, y: %g, z: %g" % (x, y, z) # Compute relative erros x = abs((x + 1. / 3 * Ms) / Ms) y = abs(y / Ms) z = abs(z / Ms) print "Relative error:" print "x: %g, y: %g, z: %g" % (x, y, z) assert x < TOL, "x-average is %g, should be -1/3." % x assert y < TOL, "y-average is %g, should be zero." % y assert z < TOL, "z-average is %g, should be zero." % z
def example_simulation(): Ms = 8.6e5 mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(40, 20, 20), 10, 5, 5) example = Simulation(mesh, Ms, name="sim_with_scheduling") example.set_m((0.1, 1, 0)) example.add(Exchange(13.0e-12)) example.add(Demag()) example.add(Zeeman((Ms/2, 0, 0))) return example
def run_simulation(stop_when_mx_eq_zero): """ Runs the simulation using field #1 from the problem description. Stores the average magnetisation components regularly, as well as the magnetisation when the x-component of the average magnetisation crosses the value 0 for the first time. """ mesh = from_geofile(os.path.join(MODULE_DIR, "bar.geo")) sim = Simulation(mesh, Ms, name="dynamics", unit_length=1e-9) sim.alpha = alpha sim.gamma = gamma sim.set_m(np.load(m_0_file)) sim.add(Demag()) sim.add(Exchange(A)) """ Conversion between mu0 * H in mT and H in A/m. mu0 * H = 1 mT = 1 * 1e-3 T = 1 * 1e-3 Vs/m^2 divide by mu0 with mu0 = 4pi * 1e-7 Vs/Am gives H = 1 / 4pi * 1e4 A/m with the unit A/m which is indeed what we want. Consequence: Just divide the value of mu0 * H in Tesla by mu0 to get the value of H in A/m. """ Hx = -24.6e-3 / mu0 Hy = 4.3e-3 / mu0 Hz = 0 sim.add(Zeeman((Hx, Hy, Hz))) def check_if_crossed(sim): mx, _, _ = sim.m_average if mx <= 0: print "The x-component of the spatially averaged magnetisation first crossed zero at t = {}.".format( sim.t) np.save(m_at_crossing_file, sim.m) # When this function returns True, it means this event is done # and doesn't need to be triggered anymore. # When we return False, it means we want to stop the simulation. return not stop_when_mx_eq_zero sim.schedule(check_if_crossed, every=1e-12) sim.schedule('save_averages', every=10e-12, at_end=True) sim.schedule('save_vtk', every=10e-12, at_end=True, overwrite=True) sim.run_until(2.0e-9) return sim.t
def run_finmag(): # Setup setupstart = time.time() mesh = df.Box(0, 0, 0, 30, 30, 100, 15, 15, 50) sim = Simulation(mesh, Ms=0.86e6, unit_length=1e-9) sim.set_m((1, 0, 1)) demag = Demag("FK") demag.parameters["poisson_solver"]["method"] = "cg" demag.parameters["poisson_solver"]["preconditioner"] = "jacobi" demag.parameters["laplace_solver"]["method"] = "cg" demag.parameters["laplace_solver"]["preconditioner"] = "bjacobi" sim.add(demag) sim.add(Exchange(13.0e-12)) # Dynamics dynamicsstart = time.time() sim.run_until(3.0e-10) endtime = time.time() # Write output to results.txt output = open(os.path.join(MODULE_DIR, "results.txt"), "a") output.write("\nBackend %s:\n" % df.parameters["linear_algebra_backend"]) output.write("\nSetup: %.3f sec.\n" % (dynamicsstart - setupstart)) output.write("Dynamics: %.3f sec.\n\n" % (endtime - dynamicsstart)) output.write(str(default_timer)) output.close()
def run_simulation(): print "Running simulation of STT dynamics." sim = Sim(mesh, Ms=Ms, unit_length=1e-9) sim.set_m(np.loadtxt(initial_m_file)) sim.alpha = 0.01 sim.add(Exchange(1.3e-11)) sim.add(Demag()) sim.llg.use_slonczewski(J=0.1e12, P=0.4, d=10e-9, p=(0, 1, 0)) with open(averages_file, "w") as f: dt = 5e-12 t_max = 10e-9 for t in np.arange(0, t_max, dt): sim.run_until(t) f.write("{} {} {} {}\n".format(t, *sim.m_average))
def relax_system(mesh): sim = Sim(mesh, Ms=8.0e5, unit_length=1e-9) sim.gamma = 2.211e5 sim.alpha = 1 sim.add(Exchange(A=13e-12)) sim.add(Demag()) sim.set_m(init_m) sim.relax(stopping_dmdt=0.01) np.save('m0.npy', sim.m) df.plot(sim._m)
def run_simulation(lfactor, m_init, m_init_name=""): L = lfactor * lexch divisions = int(round(lfactor * 2)) # that magic number influences L mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(L, L, L), divisions, divisions, divisions) exchange = Exchange(A) anisotropy = UniaxialAnisotropy(K1, [0, 0, 1]) demag = Demag() sim = Simulation(mesh, Ms) sim.set_m(m_init) sim.add(exchange) sim.add(anisotropy) sim.add(demag) sim.relax() # Save average magnetisation. mx, my, mz = sim.m_average with open(os.path.join(MODULE_DIR, "data_m.txt"), "a") as f: t = time.asctime() f.write("{} {} {} {} {} {}\n".format(m_init_name, lfactor, mx, my, mz, t)) # Save energies. # We could call sim.total_energy, but we want the individual contributions. e_exc = exchange.compute_energy() / (sim.Volume * Km) e_anis = anisotropy.compute_energy() / (sim.Volume * Km) e_demag = demag.compute_energy() / (sim.Volume * Km) e_total = e_exc + e_anis + e_demag # relative total energy density with open(os.path.join(MODULE_DIR, "data_energies.txt"), "a") as f: t = time.asctime() f.write("{} {} {} {} {} {} {}\n".format(m_init_name, lfactor, e_total, e_exc, e_anis, e_demag, t)) return e_total
def test_demag_energy_density(): """ With a sphere mesh, unit magnetisation in x-direction, we expect the demag energy to be E = 1/6 * mu0 * Ms^2 * V. (See section about demag solvers in the documentation for how this is found.) To make it simple, we define Ms = sqrt(6/mu0). Energy density is then E/V = 1. """ TOL = 5e-2 mesh = sphere(r=1.0, maxh=0.2) S3 = df.VectorFunctionSpace(mesh, "Lagrange", 1) mu0 = 4 * np.pi * 1e-7 demag = Demag() m = Field(S3, value=(1, 0, 0)) Ms = np.sqrt(6.0 / mu0) demag.setup(m, Field(df.FunctionSpace(mesh, 'DG', 0), Ms), 1) density = demag.energy_density() deviation = np.abs(density - 1.0) print "Demag energy density (expect array of 1s):" print density print "Max deviation:", np.max(deviation) assert np.max(deviation) < TOL, \ "Max deviation is %g, should be zero." % np.max(deviation)
def test_llb_save_data(): mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(10, 10, 5), 2, 2, 1) def region1(coords): if coords[2] < 0.5: return True else: return False def region2(coords): return not region1(coords) def init_Ms(coords): if region1(coords) > 0: return 8.6e5 else: return 8.0e5 def init_T(pos): return 1 * pos[2] mat = Material(mesh, name='FePt', unit_length=1e-9) mat.Ms = init_Ms mat.set_m((1, 0, 0)) mat.T = init_T mat.alpha = 0.1 assert(mat.T[0] == 0) sim = LLB(mat, name='test_llb') sim.set_up_solver() ts = np.linspace(0, 1e-11, 11) H0 = 1e6 sim.add(Zeeman((0, 0, H0))) sim.add(Exchange(mat)) demag = Demag(solver='FK') sim.add(demag) sim.save_m_in_region(region1, name='bottom') sim.save_m_in_region(region2, name='top') sim.schedule('save_ndt', every=1e-12) for t in ts: print 't===', t sim.run_until(t)
def setup_sim(self, m0): Hz = [8e4, 0, 0] # A/m A = 1.3e-11 # J/m Ms = 800e3 # A/m alpha = 1. mesh = df.BoxMesh(0, 0, 0, *(self.box_size + self.box_divisions)) sim = Simulation(mesh, Ms) sim.alpha = alpha sim.set_m(m0) sim.add(Demag()) sim.add(Exchange(A)) sim.add(Zeeman(Hz)) return sim
def test_compute_main(): Ms = 1700e3 A = 2.5e-6 * 1e-5 Hz = [10e3 * Oersted_to_SI(1.), 0, 0] mesh = df.BoxMesh(0, 0, 0, 50, 50, 10, 6, 6, 2) mesh = df.BoxMesh(0, 0, 0, 5, 5, 5, 1, 1, 1) print mesh # Find the ground state sim = Simulation(mesh, Ms) sim.set_m([1, 0, 0]) sim.add(Demag()) sim.add(Exchange(A)) sim.add(Zeeman(Hz)) sim.relax()
def test_compute_A(): Ms = 1700e3 A = 2.5e-6 * 1e-5 Hz = [10e3 * Oersted_to_SI(1.), 0, 0] mesh = df.BoxMesh(0, 0, 0, 5, 5, 5, 2, 2, 2) sim = Simulation(mesh, Ms) sim.set_m([1, 0, 0]) sim.add(Demag()) # sim.add(Exchange(A)) # sim.add(Zeeman(Hz)) sim.relax() print mesh A0, m0 = compute_A(sim) print A0[:3, :3] print m0
def run_simulation(do_precession): Ms = 0.86e6 mesh = df.BoxMesh(df.Point(0, 0, 0), df.Point(30e-9, 30e-9, 100e-9), 6, 6, 20) sim = Simulation(mesh, Ms) sim.set_m((1, 0, 1)) sim.do_precession = do_precession sim.add(Demag()) sim.add(Exchange(13.0e-12)) averages = [] for t in ts: sim.run_until(t) averages.append(sim.m_average) return np.array(averages)