Exemplo n.º 1
0
def drawSpinWave(rpath, kpt, ibnd, Lx=5, Ly=5):
    global tb, eig0_set, Tc, Tc_MF, magList_HF, magList_MF, S
    # create mc main directory
    print('output spin waves on band%d at kpt %.3f %.3f %.3f' % (ibnd, *kpt))
    io.loadParam(updateGUI=False, rpath=rpath)
    # initialize tight-binding model
    tb = WannierKit.TBmodel()
    __tbInit()

    eig, vec = tb.solveHk(kpt=kpt, return_orb=True)
    #print(vec[:,ibnd])
    tb.plot2DStructure(vec[:, ibnd],
                       kpt=np.array(kpt),
                       Lx=Lx,
                       Ly=Ly,
                       S=io.S[0])
Exemplo n.º 2
0
def mainLoop(rpath):
    global tb, eig0_set, Tc, Tc_MF, magList_HF, magList_MF, S
    # create mc main directory
    print('start renormalized spin-wave theoretical calculations')
    #mainDir=rpath+'swt/'
    #aux.createDir(mainDir)
    io.loadParam(updateGUI=False, rpath=rpath)
    # initialize tight-binding model
    tb = WannierKit.TBmodel()
    __tbInit()
    tb.plotbands()
    eig0_min = np.min(eig0_set)
    print('spin-wave gap at 0K is: %.6f' % eig0_min)
    if (eig0_min > 0):
        Sigma = 0
        for eig in eig0_set:
            Sigma += 1. / eig
        Tc_ = (S + 1) * len(eig0_set) / 3. / Sigma
        print('mean field estimation for Tc: %.3f' % Tc_)
        exit()

        print('start scf procedure for each temperature, to get M-T curv')
        # calc M-T curv
        Tc, magList_HF = __MTCurv(path='./', draw=True, algo='HF_longWave')
        print('Hatree-Fock and long wave approximation give Tc:', Tc,
              '(Kelvin)')
        print
        Tc_MF, magList_MF = __MTCurv(path='./', draw=True, algo='meanfield')
        print('Mean-field approximation give Tc:', Tc_MF, '(Kelvin)')
        print('Spin-wave theory Tc (Hatree-Fock long wave limit): {:.1f}\n'.
              format(Tc))
        print(
            'Spin-wave theory Tc (Mean-field approximation): {:.1f}\n'.format(
                Tc_MF))
        __spinWave_T_vs_Occ('./', algo='HF_longWave')
        __spinWave_T_vs_Occ('./', algo='Mean_Field')
        return Tc
    else:
        print('find zero or negative spin-wave gap!')
        print('Spin-wave theory find no Tc!\n')
        return 0
Exemplo n.º 3
0
def startSimulation(updateGUI=True, rpath=''):
    time0 = time.time()
    # clean possible existed files
    with open('./out', 'w') as fout:
        fout.write('#T #H\n')
    with open('./spinDotSpin.txt', 'w') as fout:
        fout.write('#T #H\n')

    if updateGUI:
        gui.submitBtn.config(state='disabled')
        io.collectParam()
    else:
        if not io.loadParam(updateGUI=False, rpath=rpath):
            'Error: win::startSimulation load file failed. stop this function.'
            return

    TList = np.linspace(io.T0, io.T1, io.nT)
    HList = np.linspace(io.H0, io.H1, io.nH)
    bondList = [
        lat.Bond(
            bond_data[0],
            bond_data[1],  # source and target  
            np.array([int(x) for x in bond_data[2]]),  # over lat.
            bond_data[3],
            bond_data[4],
            bond_data[5],  # strength Jxx, Jyy, Jzz
            bond_data[6],
            bond_data[7],
            bond_data[8],  # strength Jxy, Jxz, Jyz
            bond_data[9],
            bond_data[10],
            bond_data[11],  # strength Jyx, Jzx, Jzy
            True if io.modelType != 'Ising' else False)  # On
        for bond_data in io.bondList
    ]  # ergodic
    LMatrix = np.array(io.LMatrix)
    pos = np.array(io.pos)

    if (io.modelType == 'Ising'):
        if io.algorithm != 'Metropolis' and io.algorithm != 'Wolff':
            print(
                'For now, only Metropolis and Wolff algorithm is supported for Ising model'
            )
            if updateGUI: gui.submitBtn.config(state='normal')
            return

        paramPack = []
        for iH, H in enumerate(HList):
            for iT, T in enumerate(TList):
                paramPack.append([
                    iH * len(TList) + iT, T, bondList, LMatrix, pos, io.S,
                    io.DList, H, io.nsweep, io.nthermal, io.ninterval,
                    io.LPack[0], io.LPack[1], io.LPack[2], io.algorithm,
                    io.GcOrb, io.orbGroupList, io.groupInSC, io.dipoleAlpha,
                    io.spinFrame
                ])

        TResult = []
        HResult = []
        SpinIResult = []
        SpinJResult = []
        susResult = []
        energyResult = []
        capaResult = []
        u4Result = []
        autoCorrResult = []
        while (True):  # using pump strategy to reduce the costs of RAM
            if len(paramPack) == 0:
                break
            # pump tasks
            paramPack_tmp = []
            for index in range(io.ncores):
                paramPack_tmp.append(paramPack.pop(0))
                if len(paramPack) == 0:
                    break
            pool = Pool(processes=io.ncores)
            for result in pool.imap_unordered(startMC, paramPack_tmp):
                ID, T, h, spin_i, spin_j, spin_ij, autoCorr, E, E2, U4, N = result
                TResult.append(T)
                HResult.append(h)
                SpinIResult.append(spin_i)
                SpinJResult.append(spin_j)
                susResult.append((spin_ij - spin_i * spin_j) / T)
                autoCorrResult.append(autoCorr)
                energyResult.append(E)
                capaResult.append((E2 - E * E) / T**2 * N)
                u4Result.append(U4)
            pool.close()
        if updateGUI:
            gui.updateResultViewer(
                TList=TResult if io.xAxisType == 'T' else HResult,
                magList=[(si + sj) / 2
                         for si, sj in zip(SpinIResult, SpinJResult)],
                susList=capaResult)
    # continuous model settings
    elif (io.modelType == 'XY' or io.modelType == 'Heisenberg'):
        for bond in bondList:
            bond.On = True  # switch on the vector type bonding
        if io.algorithm != 'Metropolis' and io.algorithm != 'Wolff':
            print(
                'For now, only Metropolis and Wolff algorithm is supported for O(n) model'
            )
            if updateGUI: gui.submitBtn.config(state='normal')
            return

        On = 2 if io.modelType == 'XY' else 3
        paramPack = []
        for iH, H in enumerate(HList):
            for iT, T in enumerate(TList):
                paramPack.append([
                    iH * len(TList) + iT, T, bondList, LMatrix, pos, io.S,
                    io.DList, H, io.nsweep, io.nthermal, io.ninterval,
                    io.LPack[0], io.LPack[1], io.LPack[2], io.algorithm, On,
                    io.GcOrb, io.orbGroupList, io.groupInSC, io.dipoleAlpha,
                    io.spinFrame
                ])

        TResult = []
        HResult = []
        SpinIResult = []
        SpinJResult = []
        susResult = []
        energyResult = []
        capaResult = []
        u4Result = []
        autoCorrResult = []
        while (True):  # using pump strategy to reduce the costs of RAM
            if len(paramPack) == 0:
                break
            # pump tasks
            paramPack_tmp = []
            for index in range(io.ncores):
                paramPack_tmp.append(paramPack.pop(0))
                if len(paramPack) == 0:
                    break
            pool = Pool(processes=io.ncores)
            for result in pool.imap_unordered(startMCForOn, paramPack_tmp):
                ID, T, h, spin_i, spin_j, spin_ij, autoCorr, E, E2, U4, N = result
                TResult.append(T)
                HResult.append(h)
                SpinIResult.append(np.sqrt(sum(spin_i * spin_i)))
                SpinJResult.append(np.sqrt(sum(spin_j * spin_j)))
                susResult.append((spin_ij - np.dot(spin_i, spin_j)) / T)
                autoCorrResult.append(autoCorr)
                energyResult.append(E)
                capaResult.append((E2 - E * E) / T**2 * N)
                u4Result.append(U4)
            pool.close()
        if updateGUI:
            gui.updateResultViewer(
                TList=TResult if io.xAxisType == 'T' else HResult,
                magList=SpinIResult,
                susList=capaResult)
    else:
        print("for now only Ising, XY and Heisenberg model is supported")
        if updateGUI: gui.submitBtn.config(state='normal')
        return

    # writting result file
    f = open('./result.txt', 'w')
    f.write(
        '#Temp #<Si>    #<Sj>    #Susc    #Energy_per_orb(K)  #capacity_per_orb(K/K) #Binder_cumulate #auto-corr.\n'
    )
    for T, si, sj, sus, energy, capa, u4, autoCorr in zip(
            TResult, SpinIResult, SpinJResult, susResult, energyResult,
            capaResult, u4Result, autoCorrResult):
        f.write('%.3f %.6f %.6f %.6f %.6f %.6f %.6f %.6f\n' %
                (T, si, sj, sus, energy, capa, u4, autoCorr))
    f.close()
    if updateGUI: gui.submitBtn.config(state='normal')
    print("time elapsed %.3f s" % (time.time() - time0))
    return