def doTest(self, M_file, H_file, epsilon): # load ref M = readOMF(M_file) H_ref = readOMF(H_file) H = VectorField(M.mesh) axis = VectorField(M.mesh); axis.fill((1.0/math.sqrt(3.0), 1.0/math.sqrt(3.0), 1.0/math.sqrt(3.0))) k = Field(M.mesh); k.fill(520e3) Ms = Field(M.mesh); Ms.fill(8e5) # calculate magneto.uniaxial_anisotropy(axis, k, Ms, M, H) # compare self.assertVectorFieldEqual(H_ref, H, epsilon)
def compute_uniaxial_and_cubic(state, H_aniso): tmp = VectorField(self.system.mesh) E0 = magneto.uniaxial_anisotropy(axis1, k_uni, Ms, state.M, tmp) E1 = magneto.cubic_anisotropy(axis1, axis2, k_cub, Ms, state.M, H_aniso) state.cache.E_aniso_sum = E0 + E1 H_aniso.add(tmp)
def calc(axis_vec, M_vec): axis = VectorField(mesh) axis.fill(axis_vec) M = VectorField(mesh) M.fill(M_vec) H = VectorField(mesh) H.fill((0, 0, 0)) E = magneto.uniaxial_anisotropy(axis, k, Ms, M, H) * mesh.cell_volume return H.average(), E
def doTest(self, M_file, H_file, epsilon): # load ref M = readOMF(M_file) H_ref = readOMF(H_file) H = VectorField(M.mesh) axis = VectorField(M.mesh) axis.fill( (1.0 / math.sqrt(3.0), 1.0 / math.sqrt(3.0), 1.0 / math.sqrt(3.0))) k = Field(M.mesh) k.fill(520e3) Ms = Field(M.mesh) Ms.fill(8e5) # calculate magneto.uniaxial_anisotropy(axis, k, Ms, M, H) # compare self.assertVectorFieldEqual(H_ref, H, epsilon)
def calculate(self, state, id): if id == "H_aniso": if hasattr(state.cache, "H_aniso"): return state.cache.H_aniso H_aniso = state.cache.H_aniso = VectorField(self.system.mesh) axis1 = self.axis1 axis2 = self.axis2 k_uni = self.k_uniaxial k_cub = self.k_cubic skip_uni = k_uni.isUniform() and k_uni.uniform_value == 0.0 have_uni = not skip_uni skip_cub = k_cub.isUniform() and k_cub.uniform_value == 0.0 have_cub = not skip_cub Ms = self.system.Ms if not have_uni and not have_cub: H_aniso.fill((0.0, 0.0, 0.0)) state.cache.E_aniso_sum = 0.0 elif not have_uni and have_cub: state.cache.E_aniso_sum = magneto.cubic_anisotropy(axis1, axis2, k_cub, Ms, state.M, H_aniso) elif have_uni and not have_cub: state.cache.E_aniso_sum = magneto.uniaxial_anisotropy(axis1, k_uni, Ms, state.M, H_aniso) elif have_uni and have_cub: tmp = VectorField(self.system.mesh) E0 = magneto.uniaxial_anisotropy(axis1, k_uni, Ms, state.M, tmp) E1 = magneto.cubic_anisotropy(axis1, axis2, k_cub, Ms, state.M, H_aniso) state.cache.E_aniso_sum = E0 + E1 H_aniso.add(tmp) return H_aniso elif id == "E_aniso": if not hasattr(state.cache, "E_aniso"): foo = state.H_aniso return state.cache.E_aniso_sum * self.system.mesh.cell_volume else: raise KeyError("AnisotropyField.calculate: Can't calculate %s", id)
def compute_uniaxial(state, H_aniso): return magneto.uniaxial_anisotropy(axis1, k_uni, Ms, state.M, H_aniso)
def calc(axis_vec, M_vec): axis = VectorField(mesh); axis.fill(axis_vec) M = VectorField(mesh); M.fill(M_vec) H = VectorField(mesh); H.fill((0, 0, 0)) E = magneto.uniaxial_anisotropy(axis, k, Ms, M, H) * mesh.cell_volume return H.average(), E