def setup_module(module=None): # define the mesh x_max = 20e-9 # m simplexes = 10 mesh = IntervalMesh(simplexes, 0, x_max) def m_gen(coords): x = coords[0] mx = min(1.0, 2.0 * x / x_max - 1.0) my = np.sqrt(1.0 - mx**2) mz = 0.0 return np.array([mx, my, mz]) Ms = 0.86e6 A = 1.3e-11 global sim sim = Sim(mesh, Ms) sim.alpha = 0.2 sim.set_m(m_gen) sim.pins = [0, 10] exchange = Exchange(A) sim.add(exchange) # Save H_exc and m at t0 for comparison with nmag global H_exc_t0, m_t0 H_exc_t0 = exchange.compute_field() m_t0 = sim.m t = 0 t1 = 5e-10 dt = 1e-11 # s av_f = open(os.path.join(MODULE_DIR, "averages.txt"), "w") tn_f = open(os.path.join(MODULE_DIR, "third_node.txt"), "w") global averages averages = [] global third_node third_node = [] while t <= t1: mx, my, mz = sim.m_average averages.append([t, mx, my, mz]) av_f.write( str(t) + " " + str(mx) + " " + str(my) + " " + str(mz) + "\n") mx, my, mz = h.components(sim.m) m2x, m2y, m2z = mx[2], my[2], mz[2] third_node.append([t, m2x, m2y, m2z]) tn_f.write( str(t) + " " + str(m2x) + " " + str(m2y) + " " + str(m2z) + "\n") t += dt sim.run_until(t) av_f.close() tn_f.close()
def animation(): global it while True: u, v, w = helpers.components(Ms[it]) q.mlab_source.set(u=u, v=v, w=w, scalars=w) it += 1 if it == len(Ms): print "End of data." break yield
def setup_module(module=None): x_max = 100e-9 # m simplexes = 50 mesh = dolfin.IntervalMesh(simplexes, 0, x_max) def m_gen(coords): x = coords[0] mx = min(1.0, x / x_max) mz = 0.1 my = np.sqrt(1.0 - (0.99 * mx**2 + mz**2)) return np.array([mx, my, mz]) K1 = 520e3 # J/m^3 Ms = 0.86e6 sim = Sim(mesh, Ms) sim.alpha = 0.2 sim.set_m(m_gen) anis = UniaxialAnisotropy(K1, (0, 0, 1)) sim.add(anis) # Save H_anis and m at t0 for comparison with nmag global H_anis_t0, m_t0 H_anis_t0 = anis.compute_field() m_t0 = sim.m av_f = open(os.path.join(MODULE_DIR, "averages.txt"), "w") tn_f = open(os.path.join(MODULE_DIR, "third_node.txt"), "w") t = 0 t_max = 3e-10 dt = 5e-12 # s while t <= t_max: mx, my, mz = sim.m_average averages.append([t, mx, my, mz]) av_f.write( str(t) + " " + str(mx) + " " + str(my) + " " + str(mz) + "\n") mx, my, mz = h.components(sim.m) m2x, m2y, m2z = mx[2], my[2], mz[2] third_node.append([t, m2x, m2y, m2z]) tn_f.write( str(t) + " " + str(m2x) + " " + str(m2y) + " " + str(m2z) + "\n") t += dt sim.run_until(t) av_f.close() tn_f.close()
def test_method_of_computing_the_average_matters(): length = 20e-9 # m simplices = 10 mesh = df.IntervalMesh(simplices, 0, length) S1 = df.FunctionSpace(mesh, "Lagrange", 1) S3 = df.VectorFunctionSpace(mesh, "Lagrange", 1, dim=3) llg = LLG(S1, S3) llg.set_m(( '(2*x[0]-L)/L', 'sqrt(1 - ((2*x[0]-L)/L)*((2*x[0]-L)/L))', '0'), L=length) average1 = llg.m_average average2 = np.mean(components(llg.m_numpy), axis=1) diff = np.abs(average1 - average2) assert diff.max() > 5e-2
import numpy import finmag.util.helpers as helpers from mayavi import mlab """ Visualise the final configuration of the magnetisation. """ x = numpy.genfromtxt("1d_coord.txt") y = numpy.zeros(len(x)) z = numpy.zeros(len(x)) Ms = numpy.genfromtxt("1d_M.txt") Mx, My, Mz = helpers.components(Ms[-1]) figure = mlab.figure(bgcolor=(0,0,0), fgcolor=(1,1,1)) q = mlab.quiver3d(x, y, z, Mx, My, Mz, figure=figure) q.scene.z_plus_view() mlab.axes(figure=figure) mlab.show()
import numpy import finmag.util.helpers as helpers from mayavi import mlab """ Visualise the evolution of the vector field M over time. """ x = numpy.genfromtxt("1d_coord.txt") y = numpy.zeros(len(x)) z = numpy.zeros(len(x)) Ms = numpy.genfromtxt("1d_M.txt") u, v, w = helpers.components(Ms[0]) figure = mlab.figure(bgcolor=(0,0,0), fgcolor=(1,1,1)) q = mlab.quiver3d(x, y, z, u, v, w, figure=figure) q.scene.z_plus_view() mlab.axes(figure=figure) it = 0 @mlab.animate(delay=1000) def animation(): global it while True: u, v, w = helpers.components(Ms[it]) q.mlab_source.set(u=u, v=v, w=w, scalars=w) it += 1 if it == len(Ms): print "End of data."
import numpy import pylab from finmag.util.helpers import norm, angle, components, \ vectors, rows_to_columns # Load the data which dolfin has created and odeint has integrated. Ms = numpy.genfromtxt("1d_M.txt") # Each entry in ys is M for a particular moment in time. # Each M is all the x-values of M on the mesh, followed by the y and z-values. """ The time series of the average value of M across the mesh. """ ts = numpy.genfromtxt("1d_times.txt") averages = rows_to_columns(numpy.array([components(M).mean(1) for M in Ms])) pylab.plot(ts, averages[0], ":", label="Mx") pylab.plot(ts, averages[1], label="My") pylab.plot(ts, averages[2], "-.", label="Mz") pylab.legend() pylab.title("dolfin - average magnetisation over time, without pinning") pylab.xlabel("time [s]") pylab.ylabel("magnetisation [A/m]") pylab.show()