def run_SHM(self, work, wind_dict): if wind_dict["procnr"] > 1: self._r.status("Running SHM parallel") decomposeDict = ParsedParameterFile( path.join(work.systemDir(), "decomposeParDict")) decomposeDict["method"] = "ptscotch" decomposeDict.writeFile() self.mpirun(procnr=wind_dict['procnrSnappy'], argv=['snappyHexMesh', '-overwrite', '-case', work.name],output_file=path.join(work.name, 'SHM.log')) print 'running clearCase' ClearCase(args=work.name+' --processors-remove') else: SHMrun = BasicRunner(argv=["snappyHexMesh", '-overwrite','-case',work.name], server=False,logname="SHM") self._r.status("Running SHM uniprocessor") SHMrun.start()
def runCasesFiles(names, cases, runArg, n): start = os.getcwd() for case in cases: os.chdir(case) # change customeRegexp customRegexpName = "customRegexp.base" with open(os.path.join(case, 'customRegexp.base'), 'w+') as fd: fd.write(custom_reg_exp_contents) title = "Residuals for %s" %case customRegexpFile = ParsedParameterFile(customRegexpName) customRegexpFile["myFigure"]["theTitle"] = ('"'+title+'"') customRegexpFile.writeFile() # delete the header lines - ParsedParameterFile requires them, but the customRegexp dosen't seem to work when their around... lines = open(customRegexpName).readlines() open('customRegexp', 'w').writelines(lines[12:]) print n # if n>1 make sure case is decomposed into n processors if n > 1: print "decomposing %(case)s" % locals() ClearCase(" --processors-remove %(case)s" % locals()) Decomposer('--silent %(case)s %(n)s' % locals())
#!/usr/bin/python from PyFoam.Applications.ClearCase import ClearCase ClearCase()
def run_decompose(self, work, wind_dict): if wind_dict['procnr'] < 2: self._r.status('skipped decompose') return ClearCase(args=work.name+' --processors-remove') Decomposer(args=[work.name, wind_dict['procnr']])
def FOAM_model(xtr, y, ztr, Patient, Template): errorCode = True ## True when simulation has succesfully run ## Specify simulation folder Simulation = Patient + "/simulation" ## Clear case ClearCase(args=["--clear-history", Simulation]) print("Complete cleaning the case done") if not os.path.exists(Simulation): ## if simulation directory doesnt exist ## Clone template onto simulation folder CloneCase(args=[Template, Simulation]) print("Copied generic case to patient specific folder") ## copy betavSolid and actual skin temperature data onto the gland 0 folder shutil.copyfile(Template + "/0/gland/betavSolid", Simulation + "/0/gland/betavSolid") shutil.copyfile(Patient + "/actualSkinData", Simulation + "/0/gland/actualSkinData") ## define different cell zones using topoSetDict bmName = os.path.join(Simulation, 'system', "topoSetDict") template = TemplateFile(bmName + ".template", expressionDelimiter="$") template.writeToFile(bmName, { 'x': xtr, 'y': y, 'z': ztr, 'r': radius, 'gr': gr }) print("Setting template file for topoSet done") ## Run topoSet topoSetRun = BasicRunner(argv=["topoSet", "-case", Simulation], silent=True, server=False, logname='log.topoSet') topoSetRun.start() if not topoSetRun.runOK(): error("There was a problem with topoSet") print("topoSet done") print(xtr, y, ztr) ## Split mesh regions based on toposet splitMeshRegionsRun = BasicRunner( argv=["splitMeshRegions -cellZones -overwrite", "-case", Simulation], silent=True, server=False, logname='log.splitMeshRegions') splitMeshRegionsRun.start() if not splitMeshRegionsRun.runOK(): error("There was a problem with split mesh regions") print("split mesh regions done") ## Run change dictionary for gland region changeDictionaryGlandRun = BasicRunner( argv=[" changeDictionary -region gland", "-case", Simulation], silent=True, server=False, logname='log.changeDictionaryGland') changeDictionaryGlandRun.start() if not changeDictionaryGlandRun.runOK(): error("There was a problem with change dictionary for gland") print("change dictionary gland done") ## Run change dictionary for tumor region changeDictionaryTumorRun = BasicRunner( argv=[" changeDictionary -region tumor", "-case", Simulation], silent=True, server=False, logname='log.changeDictionaryTumor') changeDictionaryTumorRun.start() if not changeDictionaryTumorRun.runOK(): error("There was a problem with change dictionary for tumor") print("change dictionary tumor done") ## Run setFields for gland region setFieldsGlandRun = BasicRunner( argv=["setFields -region gland", "-case", Simulation], silent=True, server=False, logname='log.setFieldsGland') setFieldsGlandRun.start() if not setFieldsGlandRun.runOK(): error("There was a problem with setFields for gland") print("set fields for gland done") ## define gland anisotropic thermal conductivity bmName = os.path.join(Simulation, 'constant', 'gland', "thermophysicalProperties") template = TemplateFile(bmName + ".template", expressionDelimiter="$") template.writeToFile(bmName, {'x': xtr, 'y': y, 'z': ztr}) print("Setting anisotropic thermal conductivity for gland done") ## define tumor anisotropic thermal conductivity bmName = os.path.join(Simulation, 'constant', 'tumor', "thermophysicalProperties") template = TemplateFile(bmName + ".template", expressionDelimiter="$") template.writeToFile(bmName, {'x': xtr, 'y': y, 'z': ztr}) print("Setting anisotropic thermal conductivity for tumor done") ## removing fvoptions if benign tumor if state == 'benign': if not os.path.exists(Simulation + "/constant/tumor/fvOptions"): print("Removing heat sources for benign tumors done") else: os.remove(Simulation + "/constant/tumor/fvOptions") print("Removing heat sources for benign tumors done") ## multi region simple foam with two heat sources specified for tumor region print("Running") theRun = BasicRunner( argv=["chtMultiRegionSimpleFoam", "-case", Simulation], silent=True, server=False, logname='log.solver') #"-postProcess", "-func", "surfaces" theRun.start() errorCode = theRun.endSeen if not theRun.runOK(): error("There was a problem while running the solver") print("Solver run done") ## converting latest simulation step to VTK- gland print("Converting gland region to VTK") VTKGlandRun = BasicRunner(argv=[ "foamToVTK -fields '(T)' -latestTime -ascii -region gland", "-case", Simulation ], silent=True, server=False, logname='log.VTKGland') VTKGlandRun.start() if not VTKGlandRun.runOK(): error( "There was a problem while converting the gland region to VTK for post-processing" ) print("Conversion of Gland region to VTK done") ## converting latest simulation step to VTK- tumor print("Converting tumor region to VTK") VTKTumorRun = BasicRunner(argv=[ "foamToVTK -fields '(T)' -latestTime -ascii -region tumor", "-case", Simulation ], silent=True, server=False, logname='log.VTKTumor') VTKTumorRun.start() if not VTKTumorRun.runOK(): error( "There was a problem while converting the tumor region to VTK for post-processing" ) print("Conversion of Tumor region to VTK done") ## Moving VTK for post processing by rounding off to two decimal places if ((y * 100) % 1) == 0: y_str = str(round(y * 100) / 100) + '0' else: y_str = str(y) shutil.move(Simulation + "/VTK", Patient + "/VTK" + "/VTK" + y_str) return errorCode