예제 #1
0
    def run(self):
        cName = self.parser.casePath()

        self.checkCase(cName)

        sol = SolutionDirectory(cName, archive=None)

        print_("Clearing out old timesteps ....")

        sol.clearResults()

        self.checkAndCommit(SolutionDirectory(cName, archive=None))

        run = BasicRunner(argv=self.parser.getArgs(),
                          server=self.opts.server,
                          logname="PyFoamMeshUtility")

        self.addLibFunctionTrigger(run, sol)

        self.addToCaseLog(cName, "Starting")

        run.start()

        self.setData(run.data)

        sol.reread(force=True)

        self.addToCaseLog(cName, "Ending")

        if sol.latestDir() != sol.initialDir():
            for f in listdir(path.join(sol.latestDir(), "polyMesh")):
                system("mv -f " + path.join(sol.latestDir(), "polyMesh", f) +
                       " " + sol.polyMeshDir())

            print_("\nClearing out new timesteps ....")

            sol.clearResults()
        else:
            print_("\n\n  No new timestep. Utility propably failed")
예제 #2
0
    def run(self):
        cName=self.parser.casePath()

        self.checkCase(cName)

        sol=SolutionDirectory(cName,archive=None)

        print_("Clearing out old timesteps ....")

        sol.clearResults()

        self.checkAndCommit(SolutionDirectory(cName,archive=None))

        run=BasicRunner(argv=self.parser.getArgs(),
                        server=self.opts.server,
                        logname="PyFoamMeshUtility")

        self.addLibFunctionTrigger(run,sol)

        self.addToCaseLog(cName,"Starting")

        run.start()

        self.setData(run.data)

        sol.reread(force=True)

        self.addToCaseLog(cName,"Ending")

        if sol.latestDir()!=sol.initialDir():
            for f in listdir(path.join(sol.latestDir(),"polyMesh")):
                system("mv -f "+path.join(sol.latestDir(),"polyMesh",f)+" "+sol.polyMeshDir())

            print_("\nClearing out new timesteps ....")

            sol.clearResults()
        else:
            print_("\n\n  No new timestep. Utility propably failed")
예제 #3
0
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)
예제 #4
0
from PyFoam.Execution.AnalyzedRunner import AnalyzedRunner
from PyFoam.LogAnalysis.StandardLogAnalyzer import StandardLogAnalyzer
from PyFoam.Execution.BasicRunner import BasicRunner
from PyFoam.Execution.GnuplotRunner import GnuplotRunner

case = "polarStudy"
caseDir = SolutionDirectory(".",archive="polars")
caseDir.addBackup("postProcessing/forceCoeffs/0/forceCoeffs.dat")
caseDir.addBackup("PyFoamSolve.logfile")
caseDir.addBackup("PyFoamSolve.analyzed")
parameters = ParsedParameterFile("boundaryConditions",noHeader=True,preserveComments=False)

vRange =   np.arange(25,31,2.5)
alphaRange = np.arange(0,11,1)
print vRange
caseDir.clearResults()
caseDir.clear(functionObjectData=True)

valueList = []

for i in range(len(vRange)):
    for j in range(len(alphaRange)):
        valueList.append({'velocity':vRange[i],'alpha':alphaRange[j]})

valueList.append({'velocity':10,'alpha':4})
valueList.append({'velocity':5,'alpha':10})
valueList.append({'velocity':7.5,'alpha':10})
print valueList

for k in range(6,len(valueList)):
    vel = valueList[k]['velocity']
예제 #5
0
and after it has finished runs utilies that postprocess the output.
Collects some results"""

from PyFoam.Execution.ConvergenceRunner import ConvergenceRunner
from PyFoam.Execution.UtilityRunner import UtilityRunner
from PyFoam.LogAnalysis.BoundingLogAnalyzer import BoundingLogAnalyzer
from PyFoam.RunDictionary.SolutionFile import SolutionFile
from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory

solver="simpleFoam"
case="pitzDaily"
pCmd="calcPressureDifference"
mCmd="calcMassFlow"

dire=SolutionDirectory(case,archive="InletVariation")
dire.clearResults()
dire.addBackup("PyFoamSolve.logfile")
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
예제 #6
0
import sys

from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory

dName = sys.argv[1]

sd = SolutionDirectory(dName)

sd.lastToArchive("test")
sd.clearResults()
예제 #7
0
                    CloneCase(args=[refCase, caseName, '--force'])
                else:
                    try:
                        CloneCase(args=[refCase, caseName])
                    except BaseException:
                        print(
                            '\n' + caseName +
                            'already exist. Be careful or I\'ll destroy your data'
                            + '\n')
                        i += 1
                        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'
예제 #8
0
import sys

from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory

dName=sys.argv[1]

sd=SolutionDirectory(dName)

sd.lastToArchive("test")
sd.clearResults()