def __init__(self, ue, optimizer): #, energies self.opt = ue.opt self.hangle = ue.hangle [self.rmin, self.rmax], \ [self.phimin, self.phimax] = valminmax(ue.phys_surf) self.nr, self.nphi = ue.phys_surf.shape self.H = self.hangle*2*np.pi self.energies = deform_energies() self.optimizer = optimizer self.ue = ue
def test_prime_maps(u, final = False): ext_surf = make_periodic(u.ext_surf, 'surf', phi_period = u.phi_period) ext_umat = make_periodic(u.ext_umat, 'umat', sym_op = u.sym_op) [rmin, rmax], [phimin, phimax] = valminmax(ext_surf) rdev_max = 0 phidev_max = 0 iphidev, irdev = [], [] for ir, r_vec in np.ndenumerate(np.delete(ext_surf, -1, 1)): i, j = ir C = u.curve_Lphi[i]/u.phi_period #(phimax - phimin) drprimedphi = u.dudphipol[i,j][0] dphiprimedphi = 1 + u.dudphipol[i,j][1] #(u.phips[i, j + 1] - u.phips[ir]) / u.dphi_mat[ir] #(u.phips[i,dj] - u.phips[i,j])/dphi duzdphi = u.dudphipol[i,j][2] # u.du(r_vec, 'duz')[1] Ct = np.sqrt((r_vec[0] + ext_umat[ir][0])**2*dphiprimedphi**2 \ + drprimedphi**2 + duzdphi**2) if phidev_max < abs(Ct - C): phidev_max = abs(Ct - C) iphidev = [i,j] for iphi, phi_vec in np.ndenumerate(np.delete(ext_surf, -1, 0)): i, j = iphi K = u.curve_Lr[j]/(rmax - rmin) drprimedr = 1 + u.dudrpol[i,j][0] #(u.rps[i + 1, j] - u.rps[iphi]) / u.dr_mat[iphi] dphiprimedr = u.dudrpol[i,j][1] duzdr = u.dudrpol[i,j][2] # u.du(r_vec, 'duz')[1] rprime = phi_vec[0] + ext_umat[i, j][0] Kt = np.sqrt(drprimedr**2 + rprime**2*dphiprimedr**2 + duzdr**2) if rdev_max < abs(Kt - K) : rdev_max = abs(Kt - K) irdev = [i,j] if final and rdev_max > 1e-10: print 'screwed up: rdev_max = ' + str(rdev_max) if final and phidev_max > 1e-10: print 'screwed up: phidev_max = ' + str(phidev_max) return rdev_max, phidev_max, irdev, iphidev
def u(self): self.umat = np.empty(3, dtype = 'object') r_mat = self.ext_surf if self.system in ['spiral_w_wave_sqr', 'spiral_w_wave_str']: z_set = get_z_set(self.system, r_mat, self.hangle, self.consts, self.phi_period) #print z_set umat_b = np.empty(r_mat.shape, dtype = 'object') umat_cart_b = np.empty(r_mat.shape, dtype = 'object') [rmin, rmax] = valminmax(r_mat)[0] for index, r_vec in np.ndenumerate( r_mat ): umat_b[index] = np.zeros(3) umat_cart_b[index] = np.zeros(3) r, phi = r_vec[:2] # Map r -> r' if self.opt[0] == 0: ur = 0 elif self.opt[0] == 1: ur = self.consts[0] elif self.opt[0] == 2: ur = self.rps[index] - r else: print 'MIta shiivaddia' # Map phi -> phi' if self.opt[1] == 0: uphi = 0 elif self.opt[1] == 1: uphi = heaviside(r, self.consts[2])*((r - self.consts[2])/(rmax - self.consts[2]))**2* \ self.consts[3]*np.sin(phi/self.phi_period*2*pi) elif self.opt[1] == 2: uphi = self.consts[3] elif self.opt[1] == 3: uphi = self.phips[index] - phi else: print 'mita shiivaddia!' # Map z -> z' if self.opt[2] == 0: uz = self.hangle*phi elif self.opt[2] == 1: #print self.consts #curve_start = rmin + self.consts[2] # + self.consts[0] #uz = self.hangle*phi + heaviside(r, curve_start)*((r - curve_start)/ \ # (rmax - curve_start))**2 \ # *self.consts[1]*np.sin(phi/self.phi_period*2*pi*self.consts[4]) uz = z_set[index] elif self.opt[2] == 2: uz = self.consts[0]/2*r**2 elif self.opt[2] == 3: uz = self.hangle*phi + self.consts[0]*(r - rmin) elif self.opt[2] == 4: uz = self.consts[0] - np.sqrt(self.consts[0]**2 - r**2) elif self.opt[2] == 5: uz = self.hangle*phi + \ (r - rmin + self.consts[0])/(rmax - rmin) \ *self.consts[1]*np.sin(phi/self.phi_period*2*pi) elif self.opt[2] == 6: phase = 0 #-pi/2 uz = self.hangle*phi + heaviside(r, self.consts[2])*((r - self.consts[2])/ \ (rmax - self.consts[2]))**2 \ *self.consts[1]*np.cos(phi/self.phi_period*2*pi + phase) else: print 'mita shiivaddia!' umat_b[index][0] = ur umat_b[index][1] = uphi umat_b[index][2] = uz #self.ext_umat = make_periodic(umat_b, self.sym_op) self.ext_umat = umat_b self.phys_umat = make_periodic(np.delete(np.delete(self.ext_umat, 0, 0), -1, 0), 'umat', sym_op = self.sym_op) self.calc_umat = np.delete(np.delete(self.phys_umat, -1, 0), -1, 1)
def write_params(ue, energies, r, E_b, E_s): opt = ue.opt H = ue.hangle*2*np.pi nr, nphi = ue.phys_umat.shape [rmin, rmax], [phimin, phimax] = valminmax(ue.phys_surf) sigma = energies.sigma bend_module = energies.bm strech_module = energies.sm path_r = path + 'energies/H-passivation/teor/opt=[%i,%i,%i]/' %(opt[0],opt[1], opt[2]) # write u path_moldy = path_r + 'moldy/' if not exists(path_moldy): makedirs(path_moldy) umat_r, umat_phi, umat_z = ue.separate_mat(ue.ext_umat) init_r, init_phi, init_z = ue.separate_mat(ue.ext_surf) np.save(path_moldy + 'umat_pol_r_H=%.1f' %H, umat_r) np.save(path_moldy + 'umat_pol_phi_H=%.1f' %H, umat_phi) np.save(path_moldy + 'umat_pol_z_H=%.1f' %H, umat_z) np.save(path_moldy + 'init_pol_r_H=%.1f' %H, init_r) np.save(path_moldy + 'init_pol_phi_H=%.1f' %H, init_phi) np.save(path_moldy + 'init_pol_z_H=%.1f' %H, init_z) # def consts_string(consts): string_consts = '' for c in consts: string_consts += str(c) + ' ' return string_consts[:-1] if not exists(path_r): makedirs(path_r) if not exists(path_r + 'modules.data'): file_modules = open(path_r + 'modules.data', 'w') file_modules.write('# this is modules file: bend_module, strech_module, sigma \n' ) file_modules.write(str(bend_module) + ' ' + str(strech_module) + ' ' + str(sigma)) else: bend_module_read, strech_module_read, sigma_read = read_modules(opt) if bend_module_read != bend_module: print 'bend_modules differ we do not write!' return if strech_module_read != strech_module: print 'strech_modules differ we do not write!' return if sigma_read != sigma: print 'sigmas differ we do not write!' return if not exists(path_r + '%i-%i.data' %(r[0],r[1])): file_r = open(path_r + '%i-%i.data' %(r[0],r[1]), 'a') file_r.write('# Height, consts \n') else: file_r = open(path_r + '%i-%i.data' %(r[0],r[1]), 'a') file_r.write(str(H) + ' [' + consts_string(ue.consts) + '] ' + 'ebs: ' + str(E_b) + ' ' + str(E_s) \ + ' rs: ' + str(nr) + ' ' + str(rmin) + ' ' + str(rmax) + ' phis: ' + str(nphi) + ' ' + str(phimin) + ' ' + str(phimax) + ' \n') file_r.close()