def testSolutionFileZippedReadWrite(self): test=SolutionFile(path.dirname(self.theFile),path.basename(self.theFile)) self.assertEqual(test.readInternalUniform(),"0") self.assertEqual(test.readBoundary("atmosphere"),"0") self.assertEqual(test.readDimension(),"0 0 0 0 0 0 0") test.replaceBoundary("atmosphere",2.3) self.assertEqual(test.readBoundary("atmosphere"),"2.3") test.replaceInternal(3.14) self.assertEqual(test.readInternalUniform(),"3.14")
if generate: os.chdir(studyPath) for pancackes in range(pancakesCenters.shape[0]): # toASCII() activator = 'funkySetFields -case '+refCase+' -field Ct -expression "0" -condition "1>0" -time "0"' subprocess.call(activator, shell=True) activator = 'funkySetFields -case '+refCase+' -field Ct -expression "1e-3" -condition "(pow(pos().x-'+str(pancakesCenters[pancackes,0])+',2) + pow(pos().y-'+str(pancakesCenters[pancackes,1])+',2) < pow('+str(radius)+',2) )&&(pos().z>0) && (pos().z<=(1e-6+0))" -time "0"' subprocess.call(activator, shell=True) dire=SolutionDirectory(refCase) sol=SolutionFile(dire.initialDir(),"Ct") sol.replaceBoundary("inlet","0") a= 'sh fixInlet.sh' subprocess.call(a, shell=True) # tobinary() # parallel decomposition if nproc > 1: args = ["--method=scotch", "--clear", refCase, nproc] Decomposer(args=args) run = BasicRunner( argv=[ solver, "-case", caseName], silent=True,
def main(): solver = 'simpleFoam' case_dir = '.' n_proc = 4 decompose_method = 'simple' decompose_coeffs = '(2 2 1)' log_file = 'log_' + solver mesh_points = 333329 turb_type = 'laminar' turb_model = 'no' ip.set_turbulence_mode( case_dir, turb_type, turb_model) #'laminar' or 'RAS', 'none' or 'kEpsilon' or 'kOmega' d_hyd = 4 * 0.02562 / 0.804201 nu = 0.00001 # SET IN FILE I = 0.05 Re_range = range(100, 1100, 100) glob_folders = [ case_dir + '/' + s for s in ['processor*', '0/cellLevel', '0/pointLevel'] ] glob_files = [case_dir + '/' + s for s in ['log*', 'PyFoam*']] for Re in Re_range: print("Re: {}".format(Re)) print("Remove folders from previous run.") dir = SolutionDirectory(case_dir) dir.clearResults() for glob_exp in glob_folders: ip.rm_folder(glob_exp) for glob_exp in glob_files: ip.rm_file(glob_exp) ip.rm_folder(case_dir + '/postProcessing') print("Set inlet velocity.") U_value = Re * nu / d_hyd U_file = SolutionFile(dir.initialDir(), "U") U_file.replaceBoundary("inlet", "(0 %f 0)" % (U_value)) ip.delete_line(case_dir + '/0/U', 'PyFoamRemoved') print("Set magUInf.") ip.change_line(case_dir + '/system/controlDict', 'magUInf', ' magUInf ' + str(U_value) + '; ') print("Set turbulent kinetic energy at inlet.") k_value = 1.5 * (U_value * I)**2 ip.set_turbulence_boundary(case_dir, 'k', ["inlet", "monkey"], k_value) print("Set turbulent dissipation at inlet.") epsilon_value = 0.09**(3 / 4) * k_value**(3 / 2) / (0.07 * d_hyd) ip.set_turbulence_boundary(case_dir, 'epsilon', ["inlet", "monkey"], epsilon_value) print("Set specific turbulent dissipation at inlet.") omega_value = epsilon_value / k_value ip.set_turbulence_boundary(case_dir, 'omega', ["inlet", "monkey"], omega_value) print("Decompose case.") ip.set_decomposition(case_dir, n_proc, decompose_method, decompose_coeffs) ip.bash_command('cd ' + case_dir + ' && decomposePar -force >> ' + case_dir + '/' + log_file) print("Renumber mesh for speedup.") ip.bash_command('cd ' + case_dir + ' && mpirun -np ' + str(n_proc) + ' renumberMesh -overwrite -parallel >> ' + case_dir + '/' + log_file) print(turb_type + " simulation using " + turb_model + " turbulence model on mesh with " + str(mesh_points) + " mesh points.") print("Run " + solver + " in parallel.") ip.bash_command('cd ' + case_dir + ' && mpirun -np ' + str(n_proc) + ' ' + solver + ' -parallel >> ' + case_dir + '/' + log_file) print("Reconstruct case.") ip.bash_command('cd ' + case_dir + ' && reconstructPar >> ' + case_dir + '/' + log_file) print("Copy results into results folder.") ip.make_folder(case_dir + '/Results') result_string = turb_type + '_' + turb_model + '_turbmodel_' + str( mesh_points) + '_meshpoints' ip.make_folder(case_dir + '/Results/forces_' + result_string) ip.make_folder(case_dir + '/Results/residuals_' + result_string) ip.copy_files( case_dir + '/postProcessing/forces/**/*.dat', case_dir + '/Results/forces_' + result_string + '/Re_' + str(Re) + '.dat', 9) ip.copy_files( case_dir + '/postProcessing/residuals/**/*.dat', case_dir + '/Results/residuals_' + result_string + '/Re_' + str(Re) + '.dat', 2)
dire.addBackup("PyFoamSolve.analyzed") dire.addBackup("Pressure.analyzed") dire.addBackup("MassFlow.analyzed") sol = SolutionFile(dire.initialDir(), "U") maximum = 1. nr = 10 f = dire.makeFile("InflowVariationResults") for i in range(nr + 1): # Set the boundary condition at the inlet val = (maximum * i) / nr print "Inlet velocity:", val sol.replaceBoundary("inlet", "(%f 0 0)" % (val)) # Run the solver run = ConvergenceRunner(BoundingLogAnalyzer(), argv=[solver, "-case", case], silent=True) run.start() print "Last Time = ", dire.getLast() # Get the pressure difference (Using an external utility) pUtil = UtilityRunner(argv=[pCmd, "-case", case], silent=True, logname="Pressure") pUtil.add("deltaP", "Pressure at .* Difference .*\] (.+)") pUtil.start()
dire.addBackup("PyFoamSolve.analyzed") dire.addBackup("Pressure.analyzed") dire.addBackup("MassFlow.analyzed") sol=SolutionFile(dire.initialDir(),"U") maximum=1. nr=10 f=dire.makeFile("InflowVariationResults") for i in range(nr+1): # Set the boundary condition at the inlet val=(maximum*i)/nr print "Inlet velocity:",val sol.replaceBoundary("inlet","(%f 0 0)" %(val)) # Run the solver run=ConvergenceRunner(BoundingLogAnalyzer(),argv=[solver,"-case",case],silent=True) run.start() print "Last Time = ",dire.getLast() # Get the pressure difference (Using an external utility) pUtil=UtilityRunner(argv=[pCmd,"-case",case],silent=True,logname="Pressure") pUtil.add("deltaP","Pressure at .* Difference .*\] (.+)") pUtil.start() deltaP=pUtil.get("deltaP")[0] # Get the mass flow
break print('toto') #loading sim files dire = SolutionDirectory(caseName) dire.clearResults() # writing CMC transprortPpties = ParsedParameterFile( caseName + '/constant/transportProperties') transprortPpties['Ccmc'][2] = Ccmc transprortPpties.writeFile() # writing Ct BC solCt = SolutionFile(dire.initialDir(), "Ct") solCt.replaceBoundary("inlet", "%f" % (Cbd)) # writing initial concentrations in the BC<y<BD c0 = 'funkySetFields -case ' + \ os.path.join(studyPath, caseName) + ' -field Ct -expression "pos().y <= 0.00010447667906605678 ? ' + \ str(Cbc) + ' : ' + str(Cbd) + '" -time 0' subprocess.call(c0, shell=True) print(c0) i += 1 if run: i = 0 for caseName in caseList: if i == 2: break
import sys file=sys.argv[1] name=sys.argv[2] bc =sys.argv[3] neu=sys.argv[4] dire=SolutionDirectory(file,archive="TestArchive") sol=SolutionFile(dire.initialDir(),name) print "Old internal",sol.readInternal() sol.replaceInternal(neu) print "New internal",sol.readInternal() sol.purgeFile() print "Reset internal",sol.readInternal() print "Old boundary",sol.readBoundary(bc) sol.replaceBoundary(bc,neu) print "New boundary",sol.readBoundary(bc) sol.purgeFile() print "Reset boundary",sol.readBoundary(bc)