예제 #1
0
def main():
    MODULE_DIR = os.path.dirname(os.path.abspath(__file__))

    L = 10
    mesh_unit = SI(1e-9, "m")  # mesh unit (1 nm)
    layers = [(0.0, L)]  # the mesh
    discretization = 0.1  # discretization

    # Initial magnetization
    xfactor = float(SI("m") / (L * mesh_unit))

    def m0(r):
        return [
            np.cos(r[0] * np.pi * xfactor),
            np.sin(r[0] * np.pi * xfactor), 0
        ]

    mat_Py = nmag.MagMaterial(name="Py", Ms=SI(1, "A/m"))

    sim = nmag.Simulation("Hans' configuration", do_demag=False)

    mesh_file_name = '1d.nmesh'
    mesh_lists = unidmesher.mesh_1d(layers, discretization)
    unidmesher.write_mesh(mesh_lists, out=mesh_file_name)

    sim.load_mesh(mesh_file_name, [("Py", mat_Py)], unit_length=mesh_unit)
    sim.set_m(m0)

    np.save(os.path.join(MODULE_DIR, "nmag_hansconf.npy"),
            sim.get_subfield("E_exch_Py"))
예제 #2
0
파일: esigar.py 프로젝트: fangohr/nmag-test
    return (H_func, SI("A/m"))

#--------------------------------------------
## Here we set up the simulation

# Create the simulation object
sim = nmag.Simulation(sim_name, do_demag=False)

# Set the coupling between the two magnetisations
sim.set_local_magnetic_coupling(mat_Fe2, mat_Dy, SI(-2.2337e-4, "N/A^2"))

# Creates the mesh from the layer structure
mesh_file_name = '%s.nmesh' % mesh_name
if not os.path.exists(mesh_file_name) or new_mesh:
  print "Creating the mesh"
  mesh_lists = unidmesher.mesh_1d(layers, discretization)
  unidmesher.write_mesh(mesh_lists, out=mesh_file_name)

# Load the mesh
if os.path.exists(mesh_file_name):
    sim.load_mesh(mesh_file_name, mat_allocation, unit_length=SI(1e-9, "m"))
else:
    raise StandardError,"Need file %s" % mesh_file

#--------------------------------------------
## Run the simulation to calculate the hysteresis loop

H_funcs = [H_func(H) for H in Hs]

if go_fast:
    # Set additional parameters for the time-integration
예제 #3
0
  def setup(self):
    nf = self.norm_factor

    # Create the material for Fe2 in DyFe2 and YFe2
    # A unique material can be used because the iron moment per unit volume
    # in DyFe2 and YFe2 are the same.
    # NOTE: The demagnetising field acts as a shape anisotropy in the 1D model:
    # H_demag = -M_x which can be expressed as an uniaxial anisotropy
    #   H_demag = (2 K_1 m*u) / (mu0*M_sat)
    # where the axis u = (1, 0, 0) and K_1 = -mu0*M_sat^2/2
    # NOTE: Strictly this is wrong
    demag_Fe2 = \
      nmag.uniaxial_anisotropy(axis=[1, 0, 0],
                               K1=-self.enable_demag*0.5*mu0*self.Ms_Fe2**2)
    mat_Fe2 = \
      nmag.MagMaterial(name="Fe2",
                       Ms=self.Ms_Fe2,
                       exchange_coupling=self.A_Fe2,
                       anisotropy=demag_Fe2,
                       llg_normalisationfactor=SI(nf, "1/s"),
                       llg_damping=SI(self.damping),
                       llg_polarisation=SI(self.P),
		       llg_xi=SI(self.xi))

    # Create the material
    # the sum comes from taking the data from Jurgen's simulations
    # where the total moment in DyFe2 is given Ms_DyFe2 = Ms_Dy - Ms_Fe2
    cubic_Dy = \
      nmag.cubic_anisotropy(axis1=[1, -1, 0],
                            axis2=[1,  1, 0],
                            K1=SI(33.853774961e6, "J/m^3"),
                            K2=SI(-16.1710504363e6, "J/m^3"),
                            K3=SI(16.3584237059e6, "J/m^3"))

    demag_Dy = \
      nmag.uniaxial_anisotropy(axis=[1, 0, 0],
                               K1=-self.enable_demag*0.5*mu0*self.Ms_Dy**2)
    mat_Dy = \
      nmag.MagMaterial(name="Dy",
                       Ms=self.Ms_Dy,
                       exchange_coupling=SI(0.0e-12, "J/m"),
                       anisotropy=demag_Dy + cubic_Dy,
                       llg_normalisationfactor=SI(nf, "1/s"),
                       llg_damping=SI(self.damping),
		       llg_polarisation=0.0)

    #--------------------------------------------
    ## Here we set up the simulation

    # Create the simulation object
    sim = nmag.Simulation(self.sim_name, do_demag=False,
                          adjust_tolerances=False)

    # Set the coupling between the two magnetisations
    #sim.set_local_magnetic_coupling(mat_Fe2, mat_Dy, SI(-2.2337e-4, "N/A^2"))
    sim.set_local_magnetic_coupling(mat_Fe2, mat_Dy, self.A_lc)

    x0 = self.width_soft*0.5
    x1 = x0 + self.width_hard
    layers = [(-x1, -x0), (-x0, x0), (x0, x1)]
    mat_allocation = [("DyFe2_up", [mat_Dy, mat_Fe2]),
                      ("YFe2", mat_Fe2),
                      ("DyFe2_down", [mat_Dy, mat_Fe2])]

    # Creates the mesh from the layer structure
    if not os.path.exists(self.mesh_file_name) or self.new_mesh:
        print "Creating the mesh"
        mesh_lists = unidmesher.mesh_1d(layers, self.discretization)
        unidmesher.write_mesh(mesh_lists, out=self.mesh_file_name)
    sim.load_mesh(self.mesh_file_name, mat_allocation, unit_length=SI(1e-9, "m"))

    self.sim = sim
    return sim
예제 #4
0
# Create the material
mat_Py = nmag.MagMaterial(name="Py",
                          Ms=SI(0.86e6, "A/m"),
                          exchange_coupling=SI(0, "J/m"),  # disables exchange?
                          anisotropy=nmag.uniaxial_anisotropy(
                              axis=[0, 0, 1], K1=SI(520e3, "J/m^3")),
                          llg_gamma_G=SI(0.2211e6, "m/A s"),
                          llg_damping=SI(0.2),
                          llg_normalisationfactor=SI(0.001e12, "1/s"))

# Create the simulation object
sim = nmag.Simulation("1d", do_demag=False)

# Creates the mesh from the layer structure
mesh_file_name = '1d.nmesh'
mesh_lists = unidmesher.mesh_1d(layers, discretization)
unidmesher.write_mesh(mesh_lists, out=mesh_file_name)

# Load the mesh
sim.load_mesh(mesh_file_name, [("Py", mat_Py)], unit_length=mesh_unit)

# Set the initial magnetisation
sim.set_m(m0)

# Save the anisotropy field once at the beginning of the simulation
# for comparison with finmag
np.savetxt("anis_t0_ref.txt", sim.get_subfield("H_anis_Py"))
np.savetxt("m_t0_ref.txt", sim.get_subfield("m_Py"))

with open("third_node_ref.txt", "w") as fh:
    t = t0 = 0