def runFoamCase(testFile, testDir, testName, case,fenton=0): inpext = '.foam' os.chdir(testDir) caseName = testName+'-'+str(case) caseDir = os.path.join(testDir,caseName) if os.path.exists(caseDir): shutil.rmtree(caseDir) print 'Removed old directory',caseDir os.mkdir(caseDir) for f in ['0','system','constant','initialDisplacement','generateSolid.py']: if os.path.exists(f): subprocess.call('cp -r {0} {1}'.format(f,caseName),shell=True) shutil.copy(testFile,os.path.join(caseName,os.path.splitext(testName)[0]+'-'+str(case)+inpext)) mesh = open('constant/polyMesh/blockMeshDict').readlines() for i,l in enumerate(mesh): if l.split() and l.split()[0] == 'hex': params = re.split('[()]+', l)[3] paramsInt = [str(int(p)*2**(case-1)) if int(p)!=1 else p for p in params.split()] #the structure 'a if b else c' is called a 'ternary operator' mesh[i] = mesh[i].replace(params,' '.join(paramsInt)) print 'In mesh file, replaced line:' print l, print 'with:' print mesh[i], open(os.path.join(caseName,'constant/polyMesh/blockMeshDict'),'w').write(''.join(mesh)) foamDotFile = subprocess.check_output('. $HOME/.bashrc; echo $foamDotFile',shell=True).splitlines()[-1] if not foamDotFile: sys.exit('foamDotFile not defined in .bashrc') if not os.path.exists(foamDotFile): sys.exit('foamDotFile does not exist: {}'.format(foamDotFile)) os.chdir(caseName) for f in glob('constant/triSurface/*.stl'): subprocess.call('. '+foamDotFile+'; surfaceFeatureExtract -includedAngle 150 '+f+' features',shell=True) subprocess.call('cp ./0/alpha1.org ./0/alpha1; rm constant/polyMesh/[c-f,h-z]* -f; rm 0.* -rf; rm [1-9]* -rf',shell=True) subprocess.call('. '+foamDotFile+'; blockMesh',shell=True) if os.path.exists('./system/snappyHexMeshDict'): subprocess.call('. '+foamDotFile+'; snappyHexMesh -overwrite',shell=True) if os.path.exists('./generateSolid.py'): subprocess.call('. '+foamDotFile+'; ./generateSolid.py',shell=True) if os.path.exists('./initialDisplacement'): subprocess.call('. '+foamDotFile+'; cd initialDisplacement; ./run.sh; cd ..',shell=True) if 'runup' in testDir or 'propagation' in testDir: if fenton: subprocess.call('. '+foamDotFile+'; initializeFoamFenton',shell=True) else: soliton.initialize() elif glob('system/setFieldsDict'): subprocess.call('. '+foamDotFile+'; setFields',shell=True) t0=time() if subprocess.call('. '+foamDotFile+'; ' + chooseFoamSolver(),shell=True): sys.exit('runsolvers.py: Exiting because of the error of the solver') open(caseName+'_timing.dat','w').write(str(time()-t0)+'\n') if 'cylinder' in caseDir: subprocess.call('. '+foamDotFile+'; foamToVTK -excludePatches \'( \".*\" )\' -fields \'( alpha1 U p )\' ',shell=True) else: subprocess.call('. '+foamDotFile+'; foamToVTK -excludePatches \'( \".*\" )\' -fields \'( alpha1 U )\' ',shell=True) #-ascii #-noPointValues subprocess.call('mkdir timesteps; mv [1-9]* timesteps; mv 0.* timesteps; mv ./VTK/* ./; rm VTK -r',shell=True) return caseDir
def runGerrisCase(testFile, testDir, testName, case): os.chdir(testDir) caseDir = os.path.join(testDir, 'case' + str(case) + '-inProgress') caseName = testName + '-' + str(case) if os.path.exists(caseDir): shutil.rmtree(caseDir) os.mkdir(caseDir) mesh = open(testFile).readlines() for i, l in enumerate(mesh): l = l.split() if len(l) == 2 and l[0] in ['GfsRefine', 'Refine'] and l[1].isdigit(): print 'Changed Refine from', l[1], 'to', int(l[1]) + case - 1 l[1] = str(int(l[1]) + case - 1) + '\n' mesh[i] = ' '.join(l) if len(l) == 3 and l[0] == 'Define' and l[1] == 'REFLEVEL': print 'Changed REFLEVEL from', l[2], 'to', int(l[2]) + case - 1 l[2] = str(int(l[2]) + case - 1) + '\n' mesh[i] = ' '.join(l) if len(l) == 3 and l[0] == 'Define' and l[1] == 'NAME': l[2] = caseName + '\n' mesh[i] = ' '.join(l) open(os.path.join(caseDir, caseName + '.gfs'), 'w').write(''.join(mesh)) for f in glob('*.gts') + glob('*.cgd'): #copy additional input files shutil.copy(f, caseDir) os.chdir(caseDir) if '.cgd' in open(os.path.join( caseDir, caseName + '.gfs')).read() and ('propagation' in testDir or 'runup' in testDir): soliton.initialize() t0 = time() subprocess.call( 'gerris2D -m ' + caseName + '.gfs 2>&1 | tee ' + caseName + '.out', shell=True) #2>&1 streams stderr to stdout, so that tee can catch it open(caseName + '_timing.dat', 'w').write(str(time() - t0) + '\n') caseDir = updateCaseDir(caseDir) return caseDir
def runThetisCase(testFile, testDir, testName, case,fenton=0): inpext = '.don' os.chdir(testDir) caseDir = os.path.join(testDir,'case'+str(case)+'-inProgress') caseName = testName+'-'+str(case) if os.path.exists(caseDir): shutil.rmtree(caseDir) print 'Removed old directory',caseDir os.mkdir(caseDir) for file in ['caract.par','defaut.don','licence.dat']: shutil.copy(file,caseDir) mesh = open(testFile).readlines() for i,l in enumerate(mesh): l = re.split('[ ]+',l.strip()) if len(l)==3 and l[0] == 'MAILLAGE': Nx = str(int(l[1])*2**(case-1)) Ny = str(int(l[2])*2**(case-1)) mesh[i] = 'MAILLAGE '+Nx+' '+Ny+'\n' if len(l)==3 and l[0] == 'DIM_MAX': L = l[1].replace('D0','') H = str(float(l[2].replace('D0',''))+1) open(os.path.join(caseDir,caseName+inpext),'w').write(''.join(mesh)) open(os.path.join(caseDir,'thetis.dat'),'w').write('REPERTOIRE_DON ./\nFICHIER_DONNEE {file}.don\nFICHIER_DEFAUT defaut.don\nFICHIER_CARACT caract.par\n'.format(file=caseName)) os.chdir(caseDir) if not 'stillwater-flat' in testDir: if (not 'rotated' in testFile) and fenton: amp = pproc.determineAmplitude(testDir) subprocess.call('initialConditionThetis '+ str(amp) +' 15 '+ L +' '+ H +' '+ Nx +' '+ Ny,shell=True) else: soliton.initialize() t0=time() subprocess.call('thetis',shell=True) # | tee '+caseName+'.out' open(caseName+'_timing.dat','w').write(str(time()-t0)+'\n') caseDir = updateCaseDir(caseDir) return caseDir
def runTruchasCase(testFile, testDir, testName, case,fenton=0): os.chdir(testDir) caseDir = os.path.join(testDir,'case'+str(case)+'-inProgress') if os.path.exists(caseDir): shutil.rmtree(caseDir) print 'Removed old directory',caseDir os.mkdir(caseDir) caseName = testName+'-'+str(case) mesh = open(testFile).readlines() for i,l in enumerate(mesh): l = re.split('[ =,]+',l.strip()) if len(l)==4 and l[0] == 'Ncell': print 'In mesh file, replaced line:' print mesh[i], for j in range(1,len(l)): if int(l[j]) != 1: l[j] = str(int(l[j])*2**(case-1)) mesh[i] = ' Ncell = '+l[1]+', '+l[2]+', '+l[3]+'\n' print 'with:' print mesh[i] os.chdir(caseDir) open(caseName+'.inp','w').write(''.join(mesh)) #first located and computed in testDir, then moved to caseDir soliton.initialize() t0=time() subprocess.call('$SOLVERS/truchas-2.6.0/bin/t-linux.x86_64.g95.serial.opt-2.6.0 '+caseName+'.inp',shell=True) # | tee '+caseName+'.out' for f in glob(caseName+'_output/*'): shutil.move(f,caseDir) shutil.rmtree(caseName+'_output') open(caseName+'_timing.dat','w').write(str(time()-t0)+'\n') parseTruchasOutput() caseDir = updateCaseDir(caseDir) return caseDir
def runGerrisCase(testFile, testDir, testName, case): os.chdir(testDir) caseDir = os.path.join(testDir,'case'+str(case)+'-inProgress') caseName = testName+'-'+str(case) if os.path.exists(caseDir): shutil.rmtree(caseDir) os.mkdir(caseDir) mesh = open(testFile).readlines() for i,l in enumerate(mesh): l = l.split() if len(l)==2 and l[0] in ['GfsRefine', 'Refine'] and l[1].isdigit(): print 'Changed Refine from',l[1],'to',int(l[1])+case-1 l[1] = str(int(l[1])+case-1)+'\n' mesh[i] = ' '.join(l) if len(l)==3 and l[0] == 'Define' and l[1]== 'REFLEVEL': print 'Changed REFLEVEL from',l[2],'to',int(l[2])+case-1 l[2] = str(int(l[2])+case-1)+'\n' mesh[i] = ' '.join(l) if len(l)==3 and l[0] == 'Define' and l[1] == 'NAME': l[2] = caseName+'\n' mesh[i] = ' '.join(l) open(os.path.join(caseDir,caseName+'.gfs'),'w').write(''.join(mesh)) for f in glob('*.gts') + glob('*.cgd'): #copy additional input files shutil.copy(f,caseDir) os.chdir(caseDir) if '.cgd' in open(os.path.join(caseDir,caseName+'.gfs')).read() and ('propagation' in testDir or 'runup' in testDir): soliton.initialize() t0=time() subprocess.call('gerris2D -m '+caseName+'.gfs 2>&1 | tee '+caseName+'.out',shell=True) #2>&1 streams stderr to stdout, so that tee can catch it open(caseName+'_timing.dat','w').write(str(time()-t0)+'\n') caseDir = updateCaseDir(caseDir) return caseDir
subprocess.call('. ' + foamDotFile + '; snappyHexMesh -overwrite', shell=True) if os.path.exists('./generateSolid.py'): subprocess.call('. ' + foamDotFile + '; ./generateSolid.py', shell=True) if os.path.exists('./initialDisplacement'): subprocess.call('. ' + foamDotFile + '; cd initialDisplacement; ./run.sh; cd ..', shell=True) if 'runup' in testDir or 'propagation' in testDir: if fenton: subprocess.call('. ' + foamDotFile + '; initializeFoamFenton', shell=True) else: soliton.initialize() elif glob('system/setFieldsDict'): subprocess.call('. ' + foamDotFile + '; setFields', shell=True) t0 = time() if subprocess.call('. ' + foamDotFile + '; ' + chooseFoamSolver(), shell=True): sys.exit('runsolvers.py: Exiting because of the error of the solver') open(caseName + '_timing.dat', 'w').write(str(time() - t0) + '\n') if 'cylinder' in caseDir: subprocess.call( '. ' + foamDotFile + '; foamToVTK -excludePatches \'( \".*\" )\' -fields \'( alpha1 U p )\' ', shell=True) else: