def main(): ffunc = [ set_fitfunc_from_fname(input_params(fbase + "/" + ifile[i], False)[0]) for i in range(Npot) ] param = [ input_params(fbase + "/" + ifile[i], False)[1] for i in range(Npot) ] Nconf = len(param[0][:, 0]) ### check #.conf for i in range(Npot): if (Nconf != len(param[i][:, 0])): print("\nERROR: Nconf is differ, exit\n") return -1 for r in frange(r_min, r_max, r_del): ipot = np.array( [[ffunc[i](r, *param[i][iconf, :]) for i in range(Npot)] for iconf in range(Nconf)]) rpot = np.array( [np.dot(rot_mat, ipot[iconf, :]) for iconf in range(Nconf)]) print("%lf %1.16e %1.16e %1.16e %1.16e %1.16e %1.16e %1.16e %1.16e" % (r, *make_mean_err(rpot[:, 0]), *make_mean_err(rpot[:, 1]), *make_mean_err(rpot[:, 2]), *make_mean_err(rpot[:, 3]))) return 0
def main(): Nadd = len(ifnames) if (Nadd == 0): print("\nERROR: No input files, exit.") return -1 func_names = [input_params(ifnames[i])[0] for i in range(Nadd)] iparams = np.array([input_params(ifnames[i])[1] for i in range(Nadd)]) Ngauss = np.array([len(iparams[i, 0, :]) // 2 for i in range(Nadd)]) Nconf = len(iparams[0, :, 0]) for i in range(Nadd): for c in range(Nconf): for k in range(Ngauss[i]): iparams[i, c, 2 * k] *= coeffs[i] oparam = iparams[0, :, :] for i in range(1, Nadd): oparam = np.append(oparam, iparams[i, :, :], axis=1) output_params(ofname, "12G", oparam) return 0
def input_NxN_params(a_iFname, verbose_flg=True): """ The function to input the initial-fit parameters. FORMAT: First line = '#.ch: [Number of channel]' FORMAT: Second line = [mass of ch.1-1] [mass of ch.1-2] ... [mass of ch.N-1] [mass of ch.N-2] FORMAT: From third line, [a name of parameter file] (for each line) FORMAT: The order of file name corresponds to jch+Nch*ich for params[ich, jch] FORMAT: A blank row and the row starting from '#' will be skippled return: (FuncName[#.ch, #.ch], Params [#.ch, #.ch, #.conf, #.param], mass [#.ch, 2]) """ with open(a_iFname, 'r') as ifile: lines = ifile.readlines() if (lines[0].split()[0].strip() != '#.ch:'): print( "\nERROR: Invalid NxN fit-parameters file (error at first line), exit.\n" ) return (None, None, None) l_Nch = int(lines[0].split()[1].strip()) if (len(lines[1].split()) != l_Nch * 2): print( "\nERROR: Invalid NxN fit-parameters file (error at second line), exit.\n" ) return (None, None, None) r_mass = array( [[float(lines[1].split()[j + 2 * i].strip()) for j in range(2)] for i in range(l_Nch)]) l_fparams = [] tmp_count = 0 for i in range(2, len(lines)): line = lines[i].split() if (len(line) == 0 or line[0][0].strip() == '#'): continue l_fparams.append(line[0]) tmp_count += 1 if (tmp_count == l_Nch**2): break if (len(l_fparams) != l_Nch**2): print( "\nERROR: Invalid NxN fit-parameters file (error at below third line), exit.\n" ) return (None, None, None) r_FuncName = array([[ input_params(l_fparams[jch + l_Nch * ich], verbose_flg=False)[0] for jch in range(l_Nch) ] for ich in range(l_Nch)]) r_Params = array([[ input_params(l_fparams[jch + l_Nch * ich], verbose_flg=False)[1] for jch in range(l_Nch) ] for ich in range(l_Nch)]) tmp_Nconf = len(r_Params[0, 0, :, 0]) for ich in range(l_Nch): for jch in range(l_Nch): if (tmp_Nconf != len(r_Params[ich, jch, :, 0])): print( "\nERROR: Invalid NxN fit-parameters file (different #.conf), exit.\n" ) return (None, None, None) if (verbose_flg): print("# Successful to input NxN fit parameters.") print("# N.ch =", l_Nch) print("# N.conf =", tmp_Nconf) for ich in range(l_Nch): print("# mass[%2d] =" % ich, r_mass[ich, :]) print("# Fit function (%dx%d):" % (l_Nch, l_Nch)) for ich in range(l_Nch): print("#", "%9s" * l_Nch % (*r_FuncName[ich, :], )) return (r_FuncName, r_Params, r_mass)
def main(): from multiprocessing import Pool from common.statistics import make_mean_err from fitting.io_params import input_params from fitting.fitfunc_type import set_fitfunc_from_fname from sch_diffeq.solve_diffeq_mixLS import solve_sch_diff_mixLS from Tmatrix.io_Tmatrix import output_Tmatrix from Tmatrix.convert_mat import convert_TtoS from Tmatrix.calc_phase_shift import calc_phase_Sii, within_one ### Input the potential func_type and parameters ### func_name_V_C, params_V_C = input_params(if_V_C) if (func_name_V_C is params_V_C is None): return -1 func_name_V_T, params_V_T = input_params(if_V_T) if (func_name_V_T is params_V_T is None): return -1 mass = (mass1 * mass2) / (mass1 + mass2) ### Set the potential func_type ### fit_func_V_C = set_fitfunc_from_fname(func_name_V_C) fit_func_V_T = set_fitfunc_from_fname(func_name_V_T) ### Set the energies to calculate ### if (ifengy is None): N_E = int((Emax - Emin) / Edel) Edata = np.array([Emin + i * Edel for i in range(N_E)]) else: Edata = np.array( [float(line.split()[0].strip()) for line in open(ifengy, 'r')]) N_E = len(Edata) ### T-matrix calculation ### Nconf = len(params_V_C[:, 0]) l_in = np.array([0, 2]) print("#\n# Calculate T-matrix...") if (Nproc == 1): Tmat = np.array([ fproc_wrapper( (iconf, fit_func_V_C, params_V_C[iconf, :], fit_func_V_T, params_V_T[iconf, :], mass, Edata, Rmax)) for iconf in range(Nconf) ]) else: args_procs = [(iconf, fit_func_V_C, params_V_C[iconf, :], fit_func_V_T, params_V_T[iconf, :], mass, Edata, Rmax) for iconf in range(Nconf)] with Pool(Nproc) as proc: Tmat = np.array(proc.map(fproc_wrapper, args_procs)) print("# Calculate T-matrix... all end\n#") ### Output T-matrix ### output_Tmatrix(ofname, Edata, Tmat) ### Output the Phase shift & Calculation of the Scattering length ### Smat = np.array( [[convert_TtoS(Tmat[iconf, iE, :, :]) for iE in range(N_E)] for iconf in range(Nconf)]) Edata[Edata == 0.0] = 1e-10 # To avoid zero-div phase = np.array([[ calc_phase_Sii(Smat[iconf, :, i, i], shift_disc=50) for i in range(2) ] for iconf in range(Nconf)]) MixAng = np.array([[ np.arccos(within_one(phase[iconf, 0, 1, iE])) * 90.0 / np.pi for iE in range(N_E) ] for iconf in range(Nconf)]) Edata[Edata == 1e-10] = 0.0 print("#\n# E, phs(S), phs_e(S), phs(D), phs_e(D), mix_ang, mix_ang_e") for iE in range(N_E): print("%lf %e %e %e %e %e %e" % (Edata[iE], *make_mean_err(phase[:, 0, 0, iE]), *make_mean_err( phase[:, 1, 0, iE]), *make_mean_err(MixAng[:, iE]))) # Scattering length for [fm] := T_ii(p)/p (p->0) ScatLength = np.array([ solve_sch_diff_mixLS(fit_func_V_C, params_V_C[iconf, :], fit_func_V_T, params_V_T[iconf, :], mass, np.array([1e-10]), Rmax)[0, :, :] for iconf in range(Nconf) ]) / np.sqrt(2.0 * mass * 1e-10) * hbar_c print("#\n# Scattering length for S-wave[fm] = %lf(%lf) + %lf(%lf) i" % (*make_mean_err(ScatLength[:, 0, 0].real), *make_mean_err(ScatLength[:, 0, 0].imag))) print("#\n# Scattering length for D-wave[fm] = %lf(%lf) + %lf(%lf) i" % (*make_mean_err(ScatLength[:, 1, 1].real), *make_mean_err(ScatLength[:, 1, 1].imag))) return 0
def main(): from multiprocessing import Pool from common.statistics import make_mean_err from fitting.io_params import input_params from fitting.fitfunc_type import set_fitfunc_from_fname from sch_diffeq.io_param_files import input_NxN_params from sch_diffeq.solve_diffeq import solve_sch_diff_NLO from Tmatrix.io_Tmatrix import output_Tmatrix from Tmatrix.convert_mat import convert_TtoS from Tmatrix.calc_phase_shift import calc_phase_Sii ### Input the potential func_type and parameters ### if (Nch == 1): TmpFuncName__LO, TmpParams__LO = input_params(if__LO) if (TmpFuncName__LO is TmpParams__LO is None): return -1 TmpFuncName_NLO, TmpParams_NLO = input_params(if_NLO) if (TmpFuncName_NLO is TmpParams_NLO is None): return -1 func_name__LO = np.array([[TmpFuncName__LO]]) func_name_NLO = np.array([[TmpFuncName_NLO]]) params__LO = np.array([[TmpParams__LO]]) params_NLO = np.array([[TmpParams_NLO]]) mass = np.array([[mass1, mass2]]) else: func_name__LO, params__LO, mass__LO = input_NxN_params(if__LO) if (func_name__LO is params__LO is mass__LO is None): return -1 func_name_NLO, params_NLO, mass_NLO = input_NxN_params(if_NLO) if (func_name_NLO is params_NLO is mass_NLO is None): return -1 if (Nch != len(params__LO[:, 0, 0, 0])): print( "\nERROR: Different #.ch in the NxN parameters file (for V_LO): " + "(%d != %d), exit." % (Nch, len(params__LO[:, 0, 0, 0]))) return -1 if (Nch != len(params_NLO[:, 0, 0, 0])): print( "\nERROR: Different #.ch in the NxN parameters file (for V_NLO): " + "(%d != %d), exit." % (Nch, len(params_NLO[:, 0, 0, 0]))) return -1 if (mass__LO != mass_NLO): print( "\nERROR: Different masses in two NxN parameters files (for V_LO and V_NLO): (", mass__LO, " != ", mass_NLO, "), exit.") return -1 mass = mass__LO ### Set the potential func_type ### fit_funcs__LO = np.array([[ set_fitfunc_from_fname(func_name__LO[ich][jch]) for jch in range(Nch) ] for ich in range(Nch)]) fit_funcs_NLO = np.array([[ set_fitfunc_from_fname(func_name_NLO[ich][jch]) for jch in range(Nch) ] for ich in range(Nch)]) ### Set the energies to calculate ### if (ifengy is None): N_E = int((Emax - Emin) / Edel) Edata = np.array([Emin + i * Edel for i in range(N_E)]) else: Edata = np.array( [float(line.split()[0].strip()) for line in open(ifengy, 'r')]) N_E = len(Edata) ### Set the initial wave functions ### iphi = np.zeros((Nch, 2 * Nch)) for ich in range(Nch): iphi[ich, ich + Nch] = 1.0 ### T-matrix calculation ### Nconf = len(params__LO[0, 0, :, 0]) l_in = np.zeros(Nch, dtype=int) print("#\n# Calculate T-matrix...") if (Nproc == 1): Tmat = np.array([ fproc_wrapper( (iconf, iphi, fit_funcs__LO, params__LO[:, :, iconf, :], fit_funcs_NLO, params_NLO[:, :, iconf, :], mass, Edata, l_in, 1e-6, Rmax)) for iconf in range(Nconf) ]) else: args_procs = [(iconf, iphi, fit_funcs__LO, params__LO[:, :, iconf, :], fit_funcs_NLO, params_NLO[:, :, iconf, :], mass, Edata, l_in, 1e-6, Rmax) for iconf in range(Nconf)] with Pool(Nproc) as proc: Tmat = np.array(proc.map(fproc_wrapper, args_procs)) print("# Calculate T-matrix... all end\n#") ### Output T-matrix ### output_Tmatrix(ofname, Edata, Tmat) if (Nch != 1): return 0 ### Output the Phase shift & Calculation of the Scattering length (For #.ch == 1) ### Smat = np.array( [[convert_TtoS(Tmat[iconf, iE, :, :]) for iE in range(N_E)] for iconf in range(Nconf)]) tmp_mu = (mass1 * mass2) / (mass1 + mass2) Edata[Edata == 0.0] = 1e-10 # To avoid zero-div PhaseShift = np.array( [calc_phase_Sii(Smat[iconf, :, 0, 0])[0] for iconf in range(Nconf)]) ScatLength = np.array([[(np.tan(PhaseShift[iconf] * np.pi / 180) / np.sqrt(2.0 * tmp_mu * Edata[iE]) * hbar_c) for iE in range(N_E)] for iconf in range(Nconf)]) Edata[Edata == 1e-10] = 0.0 print("#\n# E, phs, phs_e, scatt.len, scatt.len_e") for iE in range(N_E): print("%lf %e %e %e %e" % (Edata[iE], *make_mean_err(PhaseShift[:, iE]), *make_mean_err(ScatLength[:, iE]))) # Scattering length [fm] := T(p)/p (p->0) ScatLength = np.array([ solve_sch_diff_NLO(iphi, fit_funcs__LO, params__LO[:, :, iconf, :], fit_funcs_NLO, params_NLO[:, :, iconf, :], mass, np.array([1e-10]), l_in, 1e-6, Rmax)[0, 0, 0] for iconf in range(Nconf) ]) / np.sqrt(2.0 * tmp_mu * 1e-10) * hbar_c print("#\n# Scattering length [fm] = %lf(%lf) + %lf(%lf) i" % (*make_mean_err(ScatLength.real), *make_mean_err(ScatLength.imag))) return 0
def main(): from multiprocessing import Pool from fitting.io_params import input_params from sch_gauss_exp.print_eigen import print_eigen from sch_gauss_exp.solve_sch_GEM import solve_sch_GEM, make_Ham_mat, solve_sch_GEM_from_Ham_mat from sch_gauss_exp.io_Ham_mat import input_Ham_mat, output_Ham_mat ### Input parameters ### if (ifname != 'DEBUG'): if (from_Ham_mat): ### Calculation from Hamiltonian matrix max_r_in, ranges, Ham = input_Ham_mat(ifname) if (ranges is Ham is None): return -1 eigens = solve_sch_GEM_from_Ham_mat(Nstat, ranges, Ham, Np, eval_only, Nproc) print_eigen(eigens[0], eigens[1], ranges, max_r_in, 0.01, eval_only) return 0 else: func_name, params = input_params(ifname) if (func_name is params is None): return -1 Nconf = len(params[:,0]) else: ### For Debug from misc_QM.scattering_Idogata import Eb_Idogata3D_Swave global mass #Vzero = -50.0; Rzero = 2.0; mass = 500.0 Vzero = -100.0; Rzero = 4.0; mass = 1000.0 func_name = "SW" Nconf = 1 params = np.array([[Vzero, Rzero]]) print("# DEGUB MODE...") print("# V_0 (MeV) =", Vzero) print("# R_0 ( fm) =", Rzero) print("# mass(MeV) =", mass) print("# Func type = 3-dim Idogata") print("# Expect En =", Eb_Idogata3D_Swave(Vzero, Rzero, mass))) ### Construct the ranges ### if (not do_stochastic): ranges = np.array([max_r * pow(range_a, i) for i in range(Nbase)]) else: ### The stocastic variational method ranges = np.empty(0); tmp_eval = 1e+30 for i in range(Nbase): ranges = np.append(ranges, 0.0) while(True): ranges[i] = np.random.random() * max_r eval = solve_sch_GEM(1, ranges, params[0,:], mass, func_name, Np, True)[0] if (eval < tmp_eval): tmp_eval = eval break ### Solve the Schrodinger equation by GEM ### if (False): ### Two ways to solve GEM (first one will be deleted in future) print("#\n# Solve Schrodinger equation by GEM...") if (Nproc == 1): eigens = np.array([fproc_wrapper((iconf, Nstat, ranges, params[iconf,:], mass, func_name, Np, eval_only)) for iconf in range(Nconf)]) else: args_procs = [(iconf, Nstat, ranges, params[iconf,:], mass, func_name, Np, eval_only) for iconf in range(Nconf)] with Pool(Nproc) as proc: eigens = np.array(proc.map(fproc_wrapper, args_procs)) eigens = (np.array([eigens[iconf,0] for iconf in range(Nconf)]), np.array([eigens[iconf,1] for iconf in range(Nconf)])) print("# Solve Schrodinger equation by GEM... all end\n#")