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 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 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 example1(Ms=8.6e5): x0 = y0 = z0 = 0 x1 = y1 = z1 = 10 nx = ny = nz = 1 mesh = df.Box(x0, x1, y0, y1, z0, z1, nx, ny, nz) S1 = df.FunctionSpace(mesh, "Lagrange", 1) S3 = df.VectorFunctionSpace(mesh, "Lagrange", 1, dim=3) vis = df.Function(S3) 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, 1e5)) 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) max_time = 2 * np.pi / (llb.gamma * 1e5) ts = np.linspace(0, max_time, num=100) mlist = [] Ms_average = [] for t in ts: llb.run_until(t) mlist.append(llb.M) vis.vector()[:] = mlist[-1] Ms_average.append(llb.M_average) df.plot(vis) time.sleep(0.00) print 'llb times', llb.call_field_times save_plot(ts, Ms_average, 'Ms_%g-time.png' % Ms) df.interactive()
def example1_sundials(Ms): x0 = y0 = z0 = 0 x1 = y1 = z1 = 10 nx = ny = nz = 1 mesh = df.Box(x0, x1, y0, y1, z0, z1, nx, ny, nz) S1 = df.FunctionSpace(mesh, "Lagrange", 1) S3 = df.VectorFunctionSpace(mesh, "Lagrange", 1, dim=3) vis = df.Function(S3) llb = LLB(S1, S3) llb.alpha = 0.00 llb.set_m((1, 1, 1)) llb.Ms = Ms H_app = Zeeman((0, 0, 1e5)) H_app.setup(S3, llb._m, Ms=Ms) llb.interactions.append(H_app) exchange = BaryakhtarExchange(13.0e-12, 1e-2) exchange.setup(S3, llb._m, llb._Ms) llb.interactions.append(exchange) integrator = llg_integrator(llb, llb.M, abstol=1e-10, reltol=1e-6) max_time = 2 * np.pi / (llb.gamma * 1e5) ts = np.linspace(0, max_time, num=50) mlist = [] Ms_average = [] for t in ts: integrator.advance_time(t) mlist.append(integrator.m.copy()) llb.M = mlist[-1] vis.vector()[:] = mlist[-1] Ms_average.append(llb.M_average) df.plot(vis) time.sleep(0.0) print llb.count save_plot(ts, Ms_average, 'Ms_%g-time-sundials.png' % Ms) df.interactive()
def example1(Ms=8.6e5): x0 = y0 = z0 = 0 x1 = y1 = z1 = 10 nx = ny = nz = 1 mesh = df.Box(x0, x1, y0, y1, z0, z1, nx, ny, nz) S1 = df.FunctionSpace(mesh, "Lagrange", 1) S3 = df.VectorFunctionSpace(mesh, "Lagrange", 1, dim=3) vis = df.Function(S3) llb = LLB(S1, S3, rtol=1e-6, atol=1e-10) llb.Ms = Ms llb.alpha = 0.0 llb.set_m((1, 1, 1)) H_app = Zeeman((0, 0, 1e5)) H_app.setup(S3, llb._m, Ms=Ms) llb.interactions.append(H_app) exchange = BaryakhtarExchange(13.0e-12, 1e-5) exchange.setup(S3, llb._m, llb._Ms) llb.interactions.append(exchange) max_time = 2 * np.pi / (llb.gamma * 1e5) ts = np.linspace(0, max_time, num=100) mlist = [] Ms_average = [] for t in ts: llb.run_until(t) mlist.append(llb.M) vis.vector()[:] = mlist[-1] Ms_average.append(llb.M_average) df.plot(vis) time.sleep(0.00) print llb.count save_plot(ts, Ms_average, 'Ms_%g-time.png' % Ms) df.interactive()
import dolfin as df import numpy from scipy.integrate import odeint from finmag.sim.llg import LLG """ Compute the behaviour of a one-dimensional strip of magnetic material, with exchange interaction. """ nm=1e-9 xdim = 30 ydim = 30 zdim = 3 mesh = dolfin.Box(0,0,0,xdim*nm,ydim*nm, zdim*nm, xdim/3, ydim/3, zdim/3) llg = LLG(mesh) llg.alpha=1.0 llg.H_app=(0,0,0) llg.A =1.3e-11 llg.D = 4e-3 #llg.set_m(( # 'MS * (2*x[0]/L - 1)', # 'sqrt(MS*MS - MS*MS*(2*x[0]/L - 1)*(2*x[0]/L - 1))', # '0'), L=length, MS=llg.Ms) llg.set_m(( 'MS', '0',
import numpy as np import dolfin as df from finmag import Simulation from finmag.energies import Exchange, DMI_Old, DMI mesh = df.Box(0, 0, 0, 30e-9, 30e-9, 3e-9, 10, 10, 1) Ms = 8.6e5 sim = Simulation(mesh, Ms) sim.set_m((Ms, 0, 0)) A = 1.3e-11 D = 4e-3 sim.add(Exchange(A)) sim.add(DMI(D)) series = df.TimeSeries("solution/m") t = np.linspace(0, 1e-9, 1000) for i in t: sim.run_until(i) p = df.plot(sim.llg._m) p.write_png("m_{}".format(i)) series.store(sim.llg._m.vector(), i) df.interactive()
self.H_gradm = df.PETScVector() self.integrator = native_llb.StochasticLLGIntegratorSTT( self.m, self.m_pred, self._Ms, self._T, self.real_volumes, self._alpha, self.P, self.beta, self.stochastic_update_field, self.method) # seems that in the presence of current, the time step have to very # small self.dt = 1e-14 # TODO: fix the using_u0 here. if __name__ == "__main__": mesh = df.Box(0, 0, 0, 5, 5, 5, 1, 1, 1) sim = SLLG(mesh, 8.6e5, unit_length=1e-9) sim.alpha = 0.1 sim.set_m((1, 0, 0)) ts = np.linspace(0, 1e-9, 11) print sim.Ms sim.T = 2000 sim.dt = 1e-14 H0 = 1e6 sim.add(Zeeman((0, 0, H0))) A = helpers.scalar_valued_dg_function(13.0e-12, mesh) exchange = Exchange(A) sim.add(exchange)
In dolfin 1.1.0, the ordering of degrees of freedom does not correspond to geometrical structures such as vertices anymore. This has to be investigated further. For now, the re-ordering can be turned off using the commented line below. """ # df.parameters.reorder_dofs_serial = False # for dolfin 1.1.0 """ The goal is to compute the values of f(r, t) = sin(x) * sin(t) on a mesh for different points in time. The cost of updating f a couple of times is measured. """ L = math.pi / 2 n = 10 mesh = df.Box(0, 0, 0, L, L, L, n, n, n) #mesh = df.BoxMesh(0, 0, 0, L, L, L, n, n, n) # dor dolfin 1.1.0 ts = np.linspace(0, math.pi / 2, 100) # dolfin expression code S = df.FunctionSpace(mesh, "CG", 1) expr = df.Expression("sin(x[0]) * sin(t)", t=0.0) start = time.time() for t in ts: expr.t = t f_dolfin = df.interpolate(expr, S) t_dolfin = time.time() - start print "Time needed for dolfin expression: {:.2g} s.".format(t_dolfin)
import dolfin as df import numpy as np from finmag.native import sundials from finmag.util.timings import default_timer from finmag.energies import Demag if __name__ == '__main__': x0 = y0 = z0 = 0 x1 = 500e-9 y1 = 500e-9 z1 = 2e-9 nx = 120 ny = 120 nz = 3 mesh = df.Box(x0, y0, z0, x1, y1, z1, nx, ny, nz) print mesh.num_vertices() Vv = df.VectorFunctionSpace(mesh, 'Lagrange', 1) Ms = 8.6e5 expr = df.Expression(('1+x[0]', '1+2*x[1]','1+3*x[2]')) m = df.project(expr, Vv) m = df.project(df.Constant((1, 0, 0)), Vv) demag = Demag("FK") demag.setup(Vv, m, Ms) demag.compute_field() print default_timer
import numpy from scipy.integrate import odeint from finmag.sim.llg import LLG """ Compute the behaviour of a one-dimensional strip of magnetic material, with exchange interaction. """ nm=1e-9 xdim = 30 ydim = 30 mesh = dolfin.Rectangle(0,0,xdim*nm,ydim*nm, xdim/3, ydim/3) plotmesh = dolfin.Box(0,0,0,xdim*nm,ydim*nm, nm, xdim/3, ydim/3,1) plotV = dolfin.VectorFunctionSpace(plotmesh,"CG",1) plotM = dolfin.Function(plotV) llg = LLG(mesh) llg.alpha=1.0 llg.H_app=(0,0,0) llg.A =1.3e-11 llg.D = 4e-3 #llg.set_m(( # 'MS * (2*x[0]/L - 1)', # 'sqrt(MS*MS - MS*MS*(2*x[0]/L - 1)*(2*x[0]/L - 1))',
import dolfin as df import numpy from scipy.integrate import odeint from finmag.sim.llg import LLG """ Compute the behaviour of a one-dimensional strip of magnetic material, with exchange interaction. """ length = 60e-9 # in meters simplexes = 20 #mesh = dolfin.Interval(simplexes, 0, length) #mesh = dolfin.Rectangle(0,0,length,length, simplexes, simplexes) mesh = dolfin.Box(0,0,0,length,length, length/20, simplexes, simplexes, simplexes/20) llg = LLG(mesh) llg.alpha=0.1 llg.H_app=(0,0,0) llg.A = 1.3e-11 llg.D = 4e-3 #llg.set_m(( # 'MS * (2*x[0]/L - 1)', # 'sqrt(MS*MS - MS*MS*(2*x[0]/L - 1)*(2*x[0]/L - 1))', # '0'), L=length, MS=llg.Ms) llg.set_m(( 'MS',
""" import dolfin import dolfin as df import numpy from scipy.integrate import odeint from finmag.sim.llg import LLG """ Compute the behaviour of a one-dimensional strip of magnetic material, with exchange interaction. """ nm = 1e-9 simplexes = 20 mesh = dolfin.Box(0, 0, 0, 60 * nm, 3 * nm, 3 * nm, simplexes, 1, 1) llg = LLG(mesh) llg.alpha = 1.0 llg.H_app = (0, 0, 0) llg.A = 1.3e-11 llg.D = 4e-3 #llg.set_m(( # 'MS * (2*x[0]/L - 1)', # 'sqrt(MS*MS - MS*MS*(2*x[0]/L - 1)*(2*x[0]/L - 1))', # '0'), L=length, MS=llg.Ms) llg.set_m(('MS', '0', '0'), MS=llg.Ms) llg.setup(use_dmi=True, use_exchange=True) llg.pins = []