def base_init(self, magParameters=None, steps=1000, p_start=pi / 18): if magParameters is None: self.mag_params = utils.MagParameters() else: self.mag_params = magParameters (self.sphs, self.times) = generate_dynamics(self.mag_params, steps=steps) def partial_energy(sph): energy.llg_state_energy(sph, self.mag_params) self.energys = map(partial_energy, self.sphs)
def check_dfdm(m_cart): """Compare dfdm function with finite differenced dfdm.""" # Some parameters magnetic_parameters = utils.MagParameters() t = 0.3 # Use LL to get dmdt: alpha = magnetic_parameters.alpha gamma = magnetic_parameters.gamma Hvec = magnetic_parameters.Hvec Ms = magnetic_parameters.Ms h_eff = Hvec dmdt_cart = (gamma/(1+alpha**2)) * sp.cross(m_cart, h_eff) \ - (alpha*gamma/((1+alpha**2)*Ms)) * sp.cross(m_cart, sp.cross( m_cart, h_eff)) # Calculate with function dfdm_func = llg_cartesian_dfdm(magnetic_parameters, t, m_cart, dmdt_cart) def f(t, m_cart, dmdt_cart): # f is the residual + dm/dt (see notes 27/2/13) return llg_cartesian_residual(magnetic_parameters, t, m_cart, dmdt_cart) + dmdt_cart # FD it dfdm_fd = sp.zeros((3, 3)) r = f(t, m_cart, dmdt_cart) delta = 1e-8 for i, m in enumerate(m_cart): m_temp = sp.array(m_cart).copy() # Must force a copy here m_temp[i] += delta r_temp = f(t, m_temp, dmdt_cart) r_diff = (r_temp - r) / delta for j, r_diff_j in enumerate(r_diff): dfdm_fd[i][j] = r_diff_j print dfdm_fd # Check the max of the difference utils.assert_almost_zero(sp.amax(dfdm_func - dfdm_fd), 1e-6)
def check_residual(residual, initial_m): mag_params = utils.MagParameters() tmax = 3.0 f_residual = ft.partial(residual, mag_params) # Timestep to a solution + convert to spherical m_list, result_times = ode.odeint(f_residual, sp.array(initial_m), tmax, dt=0.01) m_sph = [utils.array2sph(m) for m in m_list] result_pols = [m.pol for m in m_sph] result_azis = [m.azi for m in m_sph] # Calculate exact solutions exact_times, exact_azis = \ mlsn.calculate_equivalent_dynamics(mag_params, result_pols) # Check utils.assert_list_almost_equal(exact_azis, result_azis, 1e-3) utils.assert_list_almost_equal(exact_times, result_times, 1e-3)
def check_zeeman(m, H, ans): """Helper function for test_zeeman.""" mag_params = utils.MagParameters() mag_params.Hvec = H utils.assert_almost_equal(zeeman_energy(m, mag_params), ans(mag_params))
def setUp(self): mag_params = utils.MagParameters() mag_params.alpha = 0.1 self.base_init(mag_params, steps=10000)
def setUp(self): mag_params = utils.MagParameters() mag_params.K1 = 0.6 self.base_init(mag_params)