def initialize(self, system): self.system = system self.Ms = Field(system.mesh) self.Ms.fill(0.0) self.alpha = Field(system.mesh) self.alpha.fill(0.0) self.__valid_factors = False # Find other active modules self.field_terms = [] self.field_energies = [] self.llge_terms = [] for mod in system.modules: prop = mod.properties() if 'EFFECTIVE_FIELD_TERM' in prop.keys(): self.field_terms.append(prop['EFFECTIVE_FIELD_TERM']) if 'EFFECTIVE_FIELD_ENERGY' in prop.keys(): self.field_energies.append(prop['EFFECTIVE_FIELD_ENERGY']) if 'LLGE_TERM' in prop.keys(): self.llge_terms.append(prop['LLGE_TERM']) logger.info("LandauLifshitzGilbert module configuration:") logger.info(" - H_tot = %s", " + ".join(self.field_terms) or "0") logger.info(" - E_tot = %s", " + ".join(self.field_energies) or "0") logger.info(" - dM/dt = %s", " + ".join(["LLGE(M, H_tot)"] + self.llge_terms) or "0") if not self.__do_precess: logger.info(" - Precession term is disabled")
def __initFactors(self): self.__f1 = f1 = Field(self.system.mesh) # precession factors of llge self.__f2 = f2 = Field(self.system.mesh) # damping factors of llge alpha, Ms = self.alpha, self.Ms # Prepare factors for x, y, z in self.system.mesh.iterateCellIndices(): alpha_i, Ms_i = alpha.get(x, y, z), Ms.get(x, y, z) if Ms_i != 0.0: gamma_prime = GYROMAGNETIC_RATIO / (1.0 + alpha_i**2) f1_i = -gamma_prime f2_i = -alpha_i * gamma_prime / Ms_i else: f1_i, f2_i = 0.0, 0.0 f1.set(x, y, z, f1_i) f2.set(x, y, z, f2_i) # If precession is disabled, blank f1. if not self.__do_precess: f1.fill(0.0) # Done. self.__valid_factors = True
def initialize(self, system): self.system = system self.k_uniaxial = Field(self.system.mesh) self.k_uniaxial.fill(0.0) self.k_cubic = Field(self.system.mesh) self.k_cubic.fill(0.0) self.axis1 = VectorField(self.system.mesh) self.axis1.fill((0.0, 0.0, 0.0)) self.axis2 = VectorField(self.system.mesh) self.axis2.fill((0.0, 0.0, 0.0))
def __update_field(self, state): # Get value of homogeneous field if hasattr(state, self.__value_id): value = getattr(state, self.__value_id) else: if not self.__default_value: raise ValueError( "HomogeneousField: Can't initialize field '%s' because no initial value is given!" % self.__var_id) value = self.__default_value # Create field (Field or VectorField) from value try: if isinstance(value, numbers.Number): value = float(value) field = Field(self.__mesh) field.fill(value) elif hasattr(value, "__iter__") and len(value) == 3: value = tuple(map(float, value)) field = VectorField(self.__mesh) field.fill(value) else: raise ValueError except ValueError: raise ValueError( "HomogeneousField: Expected scalar value or 3-tuple of scalar values for the 'value' (second) parameter" ) # Store value and field in state setattr(state, self.__value_id, value) setattr(state, self.__field_id, field) return field
def initialize(self, system): self.system = system self.A = Field(self.system.mesh) self.A.fill(0.0) self.__peri_x = system.mesh.periodic_bc[0].find("x") != -1 self.__peri_y = system.mesh.periodic_bc[0].find("y") != -1 self.__peri_z = system.mesh.periodic_bc[0].find("z") != -1
def calculate_minimizer_dM_minimize_BB(self, state): # TODO other LLG terms? if not self.__valid_factors: self.__initFactors() if hasattr(state.cache, "minimizer_dM_minimize_BB"): return state.cache.minimizer_dM_minimize_BB result = state.cache.minimizer_dM_minimize_BB = VectorField( self.system.mesh) # Get effective field H_tot = self.calculate_H_tot(state) # TODO do this in every step? zero = Field(self.system.mesh) zero.fill(0.0) # changed; set llge coefficient to 1.0 for minimization factor = Field(self.system.mesh) factor.fill(1.) magneto.llge(zero, factor, state.M, H_tot, result) return result
def set_param(self, id, val): if id == self.__var_id: if isinstance(val, numbers.Number): fld = Field(self.system.mesh) fld.fill(val) elif hasattr(val, "__iter__") and len(val) == 3: val = tuple(map(float, val)) field = VectorField(self.system.mesh) field.fill(val) elif isinstance(val, Field): fld = Field(self.system.mesh) fld.assign(val) elif isinstance(val, VectorField): fld = VectorField(self.system.mesh) fld.assign(val) else: raise ValueError self.__field = fld else: raise ValueError("%s: Don't know how to update %s." % (self.name(), id))
def calculate_minimizer_dM(self, state): # TODO other LLG terms? if not self.__valid_factors: self.__initFactors() if hasattr(state.cache, "minimizer_dM"): return state.cache.minimizer_dM result = state.cache.minimizer_dM = VectorField(self.system.mesh) # Get effective field H_tot = self.calculate_H_tot(state) # TODO do this in every step? zero = Field(self.system.mesh) zero.fill(0.0) magneto.llge(zero, self.__f2, state.M, H_tot, result) return result
def initialize(self, system): self.system = system self.P = Field(self.system.mesh) self.P.fill(0.0) self.xi = Field(self.system.mesh) self.xi.fill(0.0)
def initialize(self, system): self.system = system self.A = Field(self.system.mesh) self.A.fill(0.0)