def interpolate_spins(initial, final, t, i3=None, f3=None): if i3 is None: i3 = hs.coords2ToCoords3(initial) if f3 is None: f3 = hs.coords2ToCoords3(final) nspins = i3.size / 3 i3 = i3.reshape([-1,3]) f3 = f3.reshape([-1,3]) xnew = np.zeros(i3.shape) for i in xrange(nspins): xnew[i,:] = interpolate_spin(i3[i,:], f3[i,:], t) return hs.coords3ToCoords2(xnew.reshape(-1)).reshape(-1)
def interpolate_spins(initial, final, t, i3=None, f3=None): if i3 is None: i3 = hs.coords2ToCoords3(initial) if f3 is None: f3 = hs.coords2ToCoords3(final) nspins = old_div(i3.size, 3) i3 = i3.reshape([-1,3]) f3 = f3.reshape([-1,3]) xnew = np.zeros(i3.shape) for i in range(nspins): xnew[i,:] = interpolate_spin(i3[i,:], f3[i,:], t) return hs.coords3ToCoords2(xnew.reshape(-1)).reshape(-1)
def test(): pi = np.pi L = 4 nspins = L**2 #phases = np.zeros(nspins) pot = HeisenbergModelRA( dim = [L,L], field_disorder = 2. ) #, phases=phases) coords = np.zeros([nspins, 2]) for i in range(nspins): vec = rotations.vec_random() coords[i,:] = make2dVector(vec) coords = np.reshape(coords, [nspins*2]) if False: normfields = np.copy(pot.fields) for i in range(nspins): normfields[i,:] /= np.linalg.norm(normfields[i,:]) coords = coords3ToCoords2( np.reshape(normfields, [nspins*3] ) ) coords = np.reshape(coords, nspins*2) #print np.shape(coords) coordsinit = np.copy(coords) #print "fields", pot.fields print coords if False: coords3 = coords2ToCoords3(coords) coords2 = coords3ToCoords2(coords3) print np.reshape(coords, [nspins,2]) print coords2 coords3new = coords2ToCoords3(coords2) print coords3 print coords3new e = pot.getEnergy(coords) print "energy ", e if True: print "numerical gradient" ret = pot.getEnergyGradientNumerical(coords) print ret[1] if True: print "analytical gradient" ret2 = pot.getEnergyGradient(coords) print ret2[1] print ret[0] print ret2[0] #print "ratio" #print ret2[1] / ret[1] #print "inverse sin" #print 1./sin(coords) #print cos(coords) print "try a quench" from pele.optimize import mylbfgs ret = mylbfgs(coords, pot) print "quenched e = ", ret.energy, "funcalls", ret.nfev print ret.coords with open("out.spins", "w") as fout: s = coords2ToCoords3( ret.coords ) h = pot.fields c = coords2ToCoords3( coordsinit ) for node in pot.G.nodes(): i = pot.indices[node] fout.write( "%g %g %g %g %g %g %g %g %g %g %g\n" % (node[0], node[1], \ s[i,0], s[i,1], s[i,2], h[i,0], h[i,1], h[i,2], c[i,0], c[i,1], c[i,2] ) ) coords3 = coords2ToCoords3( ret.coords ) m = np.linalg.norm( coords3.sum(0) ) / nspins print "magnetization after quench", m test_basin_hopping(pot, coords)