コード例 #1
0
ファイル: show.py プロジェクト: imtambovtcev/LC_SK
def make_path(data_path, save_file, sort='surf'):
    file_list = [file for file in data_path.iterdir() if file.suffix == '.npz']
    print(file_list)
    if sort == 'surf':
        file_list = sorted(file_list,
                           key=lambda x: -float(x.name.split('_')[-2]))
    else:
        file_list = sorted(file_list,
                           key=lambda x: float(x.name.split('_')[-1][:-4]))

    print(file_list)

    path = []
    for file in file_list:
        container = magnes.io.load(str(file))
        if 'STATE' in container:
            print()
            ini = container["STATE"]
        else:
            print(
                f'minimize from 0 image of the path with {container["PATH"].shape = }'
            )
            ini = list(container["PATH"])[0]
        path.append(ini)

    path = np.array(path)

    shapes = np.array([s.shape for s in path])
    xmin = np.min([shapes[:, 0].max(), 100])
    size = [xmin, shapes[:, 1].max(), shapes[:, 2].max()]
    PATH = []
    for s0 in path:
        s = np.copy(s0)
        s = np.concatenate(
            [s for i in range(np.max([size[0] // s.shape[0] + 1, 1]))], axis=0)
        #     if size[0] % s0.shape[0] == 0:
        #         s = np.concatenate([s for i in range(size[0]//s.shape[0])],axis=0)
        #     if size[1] % s0.shape[1] == 0:
        #         s = np.concatenate([s for i in range(size[1]//s.shape[1])],axis=1)
        #     if size[2] % s.shape[2] == 0:
        #         s = np.concatenate([s for i in range(size[2]//s.shape[2])],axis=2)
        s = magnes.utils.state_reshape(s, size, [0, 0, 0])
        PATH.append(s)
    PATH = np.array(PATH)
    print(PATH.shape)
    system = magnes.io.load(str(file_list[0])).extract_system()
    system = magnes.System(system.primitives, system.representatives, size,
                           system.bc)
    container = magnes.io.container('.npz')
    container.store_system(system)
    container['PATH'] = PATH
    container['COMMENT'] = file_list
    container.save(str(save_file))
コード例 #2
0
ファイル: mag_mat_to_npz.py プロジェクト: imtambovtcev/LC_SK
def convert(filename, dubilcate=0, y_size=0, save=True):
    dubilcate = int(dubilcate)
    y_size = int(y_size)
    assert filename[-4:] == '.mat'
    data = loadmat(filename)
    x = np.array(data['Sx'])
    y = np.array(data['Sy'])
    z = np.array(data['Sz'])
    print(f'{x.shape = }')
    print(f'{y.shape = }')
    print(f'{z.shape = }')
    if y_size == 0:
        x = np.moveaxis(x, 0, 2)
        x = np.moveaxis(x, 0, 1)
        y = np.moveaxis(y, 0, 2)
        y = np.moveaxis(y, 0, 1)
        z = np.moveaxis(z, 0, 2)
        z = np.moveaxis(z, 0, 1)
        s = np.zeros([x.shape[0], x.shape[1], x.shape[2], 1, 3])
        s[:, :, :, 0, 0] = x
        s[:, :, :, 0, 1] = y
        s[:, :, :, 0, 2] = z
    else:
        s = np.zeros([x.shape[0], y_size, x.shape[2], 1, 3])
    print(f'{s.shape = }')
    s = s[:, :, 2:-2, :]
    print(f'{s.shape = }')
    s_norm = np.squeeze(np.linalg.norm(s, axis=4))
    assert np.all(np.abs(s_norm - 1) < 0.01)
    if dubilcate > 0:
        s1 = np.copy(s)
        for i in range(dubilcate):
            s1 = np.concatenate([s1, s], axis=0)
    #s[:,:,:,:,0]=-s[:,:,:,:,0]
    s[:, :, :, :, 1] = -s[:, :, :, :, 1]
    #s[:, :, :, :, 2] = -s[:, :, :, :, 2]
    size = list(s_norm.shape)
    primitives = [(1., 0., 0.), (0., 1., 0.), (0., 0., 1.)]
    representatives = [(0., 0., 0.)]
    bc = [magnes.BC.PERIODIC, magnes.BC.PERIODIC, magnes.BC.FREE]
    system = magnes.System(primitives, representatives, size, bc)
    print(system)
    state = system.field3D()
    state.upload(s)
    state.satisfy_constrains()
    s = state.download()
    if save:
        container = magnes.io.container()
        container.store_system(system)
        container["STATE"] = s
        container.save(filename[:-4] + '.npz')
    return s
コード例 #3
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']
コード例 #4
0
ファイル: utilities.py プロジェクト: imtambovtcev/LC_SK
def system_reshape(system,new_size):
    primitives = system.primitives
    representatives = system.representatives
    bc = system.bc
    exchange = system.exchange
    anisotropy = system.anisotropy
    H = system.field

    new_system = magnes.System(primitives, representatives,new_size, bc)
    for ex in exchange:
       new_system.add(ex)
    new_system.set_external_field(reshape_field(H,new_size))
    for ani in anisotropy:
        new_ani=reshape_anisotropy(ani,new_size)
        new_system.add(magnes.Anisotropy(axis=new_ani.axis, strength=new_ani.strength))
    return new_system
コード例 #5
0
                                 x0=[0, -30, -30])
size = list(ini.shape[0:3])

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())
コード例 #6
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)")
コード例 #7
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)")