def readParCom(): """function that read a 'par.com' file and return a parcom object """ try: parcomfile = open('par.com','r') except IOError: print("Warning: The file 'par.com' does not exist") return -1 lines = parcomfile.readlines() parcomfile.close() # En fortran on peut aussi noter les puissances de 10 via un "d", ce qui n'est pas accepté en python. lines = [line.split(':')[0].replace('d','e') for line in lines] [rmin, rmax] = map(float,lines[0].split()) [aspect_ratio, flaring_index] = map(float,lines[1].split()) [density, density_exponent] = map(float,lines[2].split()) [isIsothermal, adiabatic_index] = map(float,lines[3].split()) mean_molecular_weight = float(lines[4]) [viscosity_default, isViscosity, alpha] = map(float,lines[5].split()) isHeatingCoolingTerms = int(lines[6]) isRadiativeDiffusion = int(lines[7]) omega_frame = float(lines[8]) isFargo = int(lines[9]) # We must eval each value of boundary condition, else, we'll have "'C'" wich will not be valid [BoundaryConditionInner, BoundaryConditionOuter] = map(eval,lines[10].split()) [isWaveDamping, wd_rint, wd_rout] = map(float,lines[11].split()) [isLinearViscosity, linear_vicosity] = map(float,lines[12].split()) cfl_coeff = float(lines[13]) [isRestart, n_restart] = map(int,lines[14].split()) isRestartPlanets = float(lines[15]) dtprint = float(lines[16]) isTurbulence = int(lines[17]) turbulence_forcing = float(lines[18]) [mode_min, mode_max, mode_cut] = map(int,lines[19].split()) mode_timelife = float(lines[20]) [lengthUnit, massUnit] = map(float,lines[21].split()) # I don't remember how to modify them in a loop (because all changes in the list booleans do nothing on each variables that he contains) booleans = (isIsothermal, isViscosity, isHeatingCoolingTerms, isRadiativeDiffusion, isFargo, isWaveDamping, isLinearViscosity, isRestart, isRestartPlanets, isTurbulence) (isIsothermal, isViscosity, isHeatingCoolingTerms, isRadiativeDiffusion, isFargo, isWaveDamping, isLinearViscosity, isRestart, isRestartPlanets, isTurbulence)=map(bool,booleans) if not(isViscosity): alpha = None if not(isLinearViscosity): linear_viscosity = None if not(isTurbulence): turbulence_forcing = None if not(isRestart): n_restart = None parcomobject = parcom(rmin=rmin, rmax=rmax, aspect_ratio=aspect_ratio, flaring_index=flaring_index, density=density, density_exponent=density_exponent, wd_rint=wd_rint, wd_rout=wd_rout, lengthUnit=lengthUnit, massUnit=massUnit, omega_frame=omega_frame, alpha=alpha, linear_viscosity=linear_viscosity, turbulence_forcing=turbulence_forcing, isIsothermal=isIsothermal, adiabatic_index=adiabatic_index, mean_molecular_weight=mean_molecular_weight, viscosity_default=viscosity_default, isHeatingCoolingTerms=isHeatingCoolingTerms, isRadiativeDiffusion=isRadiativeDiffusion, isFargo=isFargo, isWaveDamping=isWaveDamping, cfl_coeff=cfl_coeff, n_restart=n_restart, isRestartPlanets=isRestartPlanets, dtprint=dtprint, isTurbulence=isTurbulence, mode_min=mode_min, mode_max=mode_max, mode_cut=mode_cut, mode_timelife=mode_timelife, BoundaryConditionInner=BoundaryConditionInner, BoundaryConditionOuter=BoundaryConditionOuter) return parcomobject
def readParCom(): """function that read a 'par.com' file and return a parcom object """ try: parcomfile = open('par.com', 'r') except IOError: print("Warning: The file 'par.com' does not exist") return -1 lines = parcomfile.readlines() parcomfile.close() # En fortran on peut aussi noter les puissances de 10 via un "d", ce qui n'est pas accepté en python. lines = [line.split(':')[0].replace('d', 'e') for line in lines] [rmin, rmax] = map(float, lines[0].split()) [aspect_ratio, flaring_index] = map(float, lines[1].split()) [density, density_exponent] = map(float, lines[2].split()) [isIsothermal, adiabatic_index] = map(float, lines[3].split()) mean_molecular_weight = float(lines[4]) [viscosity_default, isViscosity, alpha] = map(float, lines[5].split()) isHeatingCoolingTerms = int(lines[6]) isRadiativeDiffusion = int(lines[7]) omega_frame = float(lines[8]) isFargo = int(lines[9]) # We must eval each value of boundary condition, else, we'll have "'C'" wich will not be valid [BoundaryConditionInner, BoundaryConditionOuter] = map(eval, lines[10].split()) [isWaveDamping, wd_rint, wd_rout] = map(float, lines[11].split()) [isLinearViscosity, linear_vicosity] = map(float, lines[12].split()) cfl_coeff = float(lines[13]) [isRestart, n_restart] = map(int, lines[14].split()) isRestartPlanets = float(lines[15]) dtprint = float(lines[16]) isTurbulence = int(lines[17]) turbulence_forcing = float(lines[18]) [mode_min, mode_max, mode_cut] = map(int, lines[19].split()) mode_timelife = float(lines[20]) [lengthUnit, massUnit] = map(float, lines[21].split()) # I don't remember how to modify them in a loop (because all changes in the list booleans do nothing on each variables that he contains) booleans = (isIsothermal, isViscosity, isHeatingCoolingTerms, isRadiativeDiffusion, isFargo, isWaveDamping, isLinearViscosity, isRestart, isRestartPlanets, isTurbulence) (isIsothermal, isViscosity, isHeatingCoolingTerms, isRadiativeDiffusion, isFargo, isWaveDamping, isLinearViscosity, isRestart, isRestartPlanets, isTurbulence) = map(bool, booleans) if not (isViscosity): alpha = None if not (isLinearViscosity): linear_viscosity = None if not (isTurbulence): turbulence_forcing = None if not (isRestart): n_restart = None parcomobject = parcom(rmin=rmin, rmax=rmax, aspect_ratio=aspect_ratio, flaring_index=flaring_index, density=density, density_exponent=density_exponent, wd_rint=wd_rint, wd_rout=wd_rout, lengthUnit=lengthUnit, massUnit=massUnit, omega_frame=omega_frame, alpha=alpha, linear_viscosity=linear_viscosity, turbulence_forcing=turbulence_forcing, isIsothermal=isIsothermal, adiabatic_index=adiabatic_index, mean_molecular_weight=mean_molecular_weight, viscosity_default=viscosity_default, isHeatingCoolingTerms=isHeatingCoolingTerms, isRadiativeDiffusion=isRadiativeDiffusion, isFargo=isFargo, isWaveDamping=isWaveDamping, cfl_coeff=cfl_coeff, n_restart=n_restart, isRestartPlanets=isRestartPlanets, dtprint=dtprint, isTurbulence=isTurbulence, mode_min=mode_min, mode_max=mode_max, mode_cut=mode_cut, mode_timelife=mode_timelife, BoundaryConditionInner=BoundaryConditionInner, BoundaryConditionOuter=BoundaryConditionOuter) return parcomobject
int((parcom.rmax - parcom.rmin) / (x_s / CELL_NUMBER)) + 1) # We want to have square cells at the inner edge. It's not very important, # but if we care about azimuthal res, square cells at inner edge is important az_res.append( int(2 * pi / ((parcom.rmax - parcom.rmin) / (parcom.rmin * rad_res[-1]))) + 1) return zip(planetcom.m, zip(rad_res, az_res)) if __name__ == '__main__': parcom(rmin=0.6, rmax=2.5, aspect_ratio=0.05, flaring_index=0.e0, density=2.e-3, density_exponent=-0.5e0, wd_rint=0.75e0, wd_rout=2.3e0).write() test = readParCom() test.write() m = [2 * (i + 1) * 3e-6 for i in range(5)] a = [1 + i * 0.2 for i in range(5)] e = [0.01 for i in range(5)] I = [1. + 0.2 * i for i in range(5)] planetcom(m, a, e, I).write() test = readPlanetCom() test.write()
for (mi,ai) in zip(planetcom.m, planetcom.a): x_s = sqrt(1.7 * (mi / parcom.massUnit) / parcom.aspect_ratio * ai**2) corot_region.append(x_s) # we round the value to the next positive integer. rad_res.append(int((parcom.rmax - parcom.rmin) / (x_s / CELL_NUMBER)) + 1) # We want to have square cells at the inner edge. It's not very important, # but if we care about azimuthal res, square cells at inner edge is important az_res.append(int(2 * pi / ((parcom.rmax - parcom.rmin) / (parcom.rmin * rad_res[-1]))) + 1) return zip(planetcom.m, zip(rad_res,az_res)) if __name__=='__main__': parcom(rmin=0.6, rmax=2.5, aspect_ratio=0.05, flaring_index=0.e0, density=2.e-3, density_exponent=-0.5e0, wd_rint=0.75e0, wd_rout=2.3e0).write() test=readParCom() test.write() m = [2 * (i + 1) * 3e-6 for i in range(5)] a=[1 + i * 0.2 for i in range(5)] e=[0.01 for i in range(5)] I=[1. + 0.2*i for i in range(5)] planetcom(m, a, e, I).write() test = readPlanetCom() test.write() print(getResolution())