Esempio n. 1
0
def minimize(ini,
             J=1.,
             D=np.tan(np.pi / 10),
             Kbulk=0.,
             Ksurf=0.,
             primitives=[(1., 0., 0.), (0., 1., 0.), (0., 0., 1.)],
             representatives=[(0., 0., 0.)],
             bc=[magnes.BC.PERIODIC, magnes.BC.PERIODIC, magnes.BC.FREE],
             maxtime=None,
             maxiter=None,
             alpha=0.5,
             precision=1e-7,
             catcherN=1000):
    size = list(ini.shape)[:3]
    Nz = ini.shape[2]
    system = magnes.System(primitives, representatives, size, bc)
    origin = magnes.Vertex(cell=[0, 0, 0])
    system.add(
        magnes.Exchange(origin, magnes.Vertex([1, 0, 0]), J, [D, 0., 0.]))
    system.add(
        magnes.Exchange(origin, magnes.Vertex([0, 1, 0]), J, [0., D, 0.]))
    system.add(
        magnes.Exchange(origin, magnes.Vertex([0, 0, 1]), J, [0., 0., D]))
    K = Kbulk * np.ones(Nz)
    K[0] = Kbulk + Ksurf
    K[-1] = Kbulk + Ksurf
    K = K.reshape(1, 1, Nz, 1)
    system.add(magnes.Anisotropy(K))
    state = system.field3D()
    state.upload(ini)
    state.satisfy_constrains()
    # fig, _, _ = magnes.graphics.plot_field3D(system, state, slice2D='xz', sliceN=int(system.size[1] / 2))
    # plt.show()
    catcher = magnes.EveryNthCatcher(catcherN)

    reporters = [
    ]  # [magnes.TextStateReporter()]#,magnes.graphics.VectorStateReporter3D(slice2D='xz',sliceN=0)]
    minimizer = magnes.StateNCG(system,
                                reference=None,
                                stepsize=alpha,
                                maxiter=maxiter,
                                maxtime=maxtime,
                                precision=precision,
                                reporter=magnes.MultiReporter(reporters),
                                catcher=catcher)
    blockPrint()
    minimizer.optimize(state)
    enablePrint()
    return system, state.download(), state.energy_contributions_sum()['total']
Esempio n. 2
0
print(ini.shape)
print(size)
Nz = ini.shape[2]
primitives = [(1., 0., 0.), (0., 1., 0.), (0., 0., 1.)]
representatives = [(0., 0., 0.)]
bc = [magnes.BC.PERIODIC, magnes.BC.PERIODIC, magnes.BC.FREE]

J = 1.
D = np.tan(np.pi / 10)
K1 *= (D**2)
K2 *= (D**2)

system = magnes.System(primitives, representatives, size, bc)
origin = magnes.Vertex(cell=[0, 0, 0])
system.add(magnes.Exchange(origin, magnes.Vertex([1, 0, 0]), J, [D, 0., 0.]))
system.add(magnes.Exchange(origin, magnes.Vertex([0, 1, 0]), J, [0., D, 0.]))
system.add(magnes.Exchange(origin, magnes.Vertex([0, 0, 1]), J, [0., 0., D]))
K = np.zeros(size[2])
K[0] = K2
K[-1] = K2
K = K.reshape(1, 1, size[2], 1)
system.add(magnes.Anisotropy(K))
system.add(magnes.Anisotropy(K1, axis=[1., 0., 0.]))
print(system)
state = system.field3D()
state.upload(ini)
state.satisfy_constrains()
print(state.energy_contributions_sum())
s = state.download()
container = magnes.io.container()
Esempio n. 3
0
def change_everything(file,save,K_bulk,K_surf):
    if os.path.isdir(file):
        for f in os.listdir(file):
            container = magnes.io.load(file+f)
            ini = container["STATE"]
            size = list(ini.shape[0:3])

            Nz = ini.shape[2]
            primitives = [(1., 0., 0.), (0., 1., 0.), (0., 0., 1.)]
            representatives = [(0., 0., 0.)]
            bc = [magnes.BC.PERIODIC, magnes.BC.PERIODIC, magnes.BC.FREE]

            J = 1.
            D = np.tan(np.pi / 10)

            system = magnes.System(primitives, representatives, size, bc)
            origin = magnes.Vertex(cell=[0, 0, 0])
            system.add(magnes.Exchange(origin, magnes.Vertex([1, 0, 0]), J, [D, 0., 0.]))
            system.add(magnes.Exchange(origin, magnes.Vertex([0, 1, 0]), J, [0., D, 0.]))
            system.add(magnes.Exchange(origin, magnes.Vertex([0, 0, 1]), J, [0., 0., D]))
            K = K_bulk * np.ones(Nz)
            K[0] = K_bulk + K_surf
            K[-1] = K_bulk + K_surf
            K = K.reshape(1, 1, Nz, 1)
            system.add(magnes.Anisotropy(K))
            print(system)
            state = system.field3D()
            state.upload(ini)
            state.satisfy_constrains()
            s = state.download()
            container = magnes.io.container()
            container.store_system(system)
            container["STATE"] = s
            container.save(file+f)
    elif os.path.isfile(file):
        container = magnes.io.load(file)
        ini = container["STATE"]
        size = list(ini.shape[0:3])

        Nz = ini.shape[2]
        primitives = [(1., 0., 0.), (0., 1., 0.), (0., 0., 1.)]
        representatives = [(0., 0., 0.)]
        bc = [magnes.BC.PERIODIC, magnes.BC.PERIODIC, magnes.BC.FREE]

        J = 1.
        D = np.tan(np.pi / 10)

        system = magnes.System(primitives, representatives, size, bc)
        origin = magnes.Vertex(cell=[0, 0, 0])
        system.add(magnes.Exchange(origin, magnes.Vertex([1, 0, 0]), J, [D, 0., 0.]))
        system.add(magnes.Exchange(origin, magnes.Vertex([0, 1, 0]), J, [0., D, 0.]))
        system.add(magnes.Exchange(origin, magnes.Vertex([0, 0, 1]), J, [0., 0., D]))
        K = K_bulk * np.ones(Nz)
        K[0] = K_bulk + K_surf
        K[-1] = K_bulk + K_surf
        K = K.reshape(1, 1, Nz, 1)
        system.add(magnes.Anisotropy(K))
        print(system)
        state = system.field3D()
        state.upload(ini)
        state.satisfy_constrains()
        s = state.download()
        container = magnes.io.container()
        container.store_system(system)
        container["STATE"] = s
        container.save(save)
    else:
        print("It is a special file (socket, FIFO, device file)")
Esempio n. 4
0
def change_anisotropy(file,save,K_factor):
    if os.path.isdir(file):
        for f in os.listdir(file):
            container = magnes.io.load(file+f)
            ini = container["STATE"]
            size = list(ini.shape[0:3])

            Nz = ini.shape[2]
            primitives = [(1., 0., 0.), (0., 1., 0.), (0., 0., 1.)]
            representatives = [(0., 0., 0.)]
            bc = [magnes.BC.PERIODIC, magnes.BC.PERIODIC, magnes.BC.FREE]

            J = 1.
            D = np.tan(np.pi / 10)

            system = magnes.System(primitives, representatives, size, bc)
            origin = magnes.Vertex(cell=[0, 0, 0])
            system.add(magnes.Exchange(origin, magnes.Vertex([1, 0, 0]), J, [D, 0., 0.]))
            system.add(magnes.Exchange(origin, magnes.Vertex([0, 1, 0]), J, [0., D, 0.]))
            system.add(magnes.Exchange(origin, magnes.Vertex([0, 0, 1]), J, [0., 0., D]))
            K = K_bulk * np.ones(Nz)
            K[0] = K_bulk + K_surf
            K[-1] = K_bulk + K_surf
            K = K.reshape(1, 1, Nz, 1)
            system.add(magnes.Anisotropy(K))
            print(system)
            state = system.field3D()
            state.upload(ini)
            state.satisfy_constrains()
            s = state.download()
            container = magnes.io.container()
            container.store_system(system)
            container["STATE"] = s
            container.save(file+f)
    elif os.path.isfile(file):
        container = magnes.io.load(file)
        path = container["PATH"]
        old_system=container.extract_system()
        H=old_system.field
        exchange=old_system.exchange
        anisotropy=old_system.anisotropy
        size = old_system.size

        primitives = old_system.primitives
        representatives =old_system.representatives
        bc = old_system.bc

        system = magnes.System(primitives, representatives, size, bc)

        for ex in exchange:
            system.add(ex)
        system.set_external_field(H)
        for ani in anisotropy:
            system.add(magnes.Anisotropy(axis=ani.axis,strength=ani.strength*K_factor))
        print(system)
        container = magnes.io.container(save)
        container.store_system(system)
        container["PATH"] = path
        container.save(save)
    else:
        print("It is a special file (socket, FIFO, device file)")