当前位置: 首页>>代码示例>>Python>>正文


Python SolutionDirectory.cloneCase方法代码示例

本文整理汇总了Python中PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory.cloneCase方法的典型用法代码示例。如果您正苦于以下问题:Python SolutionDirectory.cloneCase方法的具体用法?Python SolutionDirectory.cloneCase怎么用?Python SolutionDirectory.cloneCase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory的用法示例。


在下文中一共展示了SolutionDirectory.cloneCase方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import cloneCase [as 别名]
    def run(self):
        if len(self.parser.getArgs())>2:
            error("Too many arguments:",self.parser.getArgs()[2:],"can not be used")

        sName=self.parser.getArgs()[0]
        dName=self.parser.getArgs()[1]

        if path.exists(dName):
            if self.parser.getOptions().force:
                warning("Replacing",dName,"(--force option)")
            elif path.exists(path.join(dName,"system","controlDict")):
                error("Destination",dName,"already existing and a Foam-Case")
            elif path.isdir(dName):
                dName=path.join(dName,path.basename(sName))
                if path.exists(dName) and not self.parser.getOptions().force:
                    error(dName,"already existing")
        elif not path.exists(path.dirname(dName)):
            warning("Directory",path.dirname(dName),"does not exist. Creating")

        sol=SolutionDirectory(sName,
                              archive=None,
                              paraviewLink=False,
                              addLocalConfig=True,
                              parallel=self.opts.parallel)

        if sol.determineVCS()!=None and self.opts.vcs:
            if self.opts.chemkin or self.opts.additional or self.opts.latest:
                self.error("Using an unimplemented option together with VCS")

            vcsInter=getVCS(sol.determineVCS(),
                            path=sol.name)
            vcsInter.clone(dName)
            return

        if self.parser.getOptions().chemkin:
            sol.addToClone("chemkin")

        if self.parser.getOptions().dopyfoam:
            sol.addToClone("customRegexp")

        for a in self.parser.getOptions().additional:
            sol.addToClone(a)

        if self.parser.getOptions().latest:
            sol.addToClone(sol.getLast())

        if self.opts.symlinkMode:
            sol.symlinkCase(
                dName,
                followSymlinks=self.parser.getOptions().followSymlinks,
                maxLevel=self.opts.symlinkLevel,
                relPath=self.opts.symlinkRelative
            )
        else:
            sol.cloneCase(
                dName,
                followSymlinks=self.parser.getOptions().followSymlinks
            )

        self.addToCaseLog(dName,"Cloned to",dName)
开发者ID:martinep,项目名称:foam-extend-svn,代码行数:62,代码来源:CloneCase.py

示例2: case_setup

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import cloneCase [as 别名]
def case_setup(ci):
    template_case = SolutionDirectory(
        "template", archive=None, paraviewLink=False)
    case = template_case.cloneCase(
        "{0}NC{1}".format(ci.name, ci.nr_classes)
    )

    phase_properties = ParsedParameterFile(
        path.join(template_case.name, "constant", "phaseProperties"))
    phase_properties["oil"]["PBEDiameterCoeffs"]["MOCCoeffs"]["numberOfClasses"] = ci.nr_classes
    phase_properties["oil"]["PBEDiameterCoeffs"]["MOCCoeffs"]["xi1"] = ci.dv

    # manually fix bad pyfoam parsing
    phase_properties["blending"]["default"]["type"] = "none"
    phase_properties["drag"][1]["swarmCorrection"]["type"] = "none"
    phase_properties.writeFileAs(path.join(
        case.name, "constant", "phaseProperties"
    ))

    n0 = ParsedParameterFile(path.join(template_case.name, "0", "n0"))
    for i in range(ci.nr_classes):
        n0.header["object"] = "n" + str(i)
        n0["internalField"].setUniform(ci.Ninit[i])
        n0.writeFileAs(path.join(case.name, "0", "n" + str(i)))

    controlDict = ParsedParameterFile(
        path.join(case.name, "system", "controlDict")
    )
    controlDict["functions"]["probes"]["fields"] = [
        "n{0}".format(n) for n in range(ci.nr_classes)]
    controlDict.writeFile()
开发者ID:Kojirion,项目名称:OpenPBE,代码行数:33,代码来源:setupCases.py

示例3: case_setup

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import cloneCase [as 别名]
def case_setup(ci):
    template_case = SolutionDirectory(
        "template", archive=None, paraviewLink=False)
    case = template_case.cloneCase(
        "{0}{1}".format(ci.name, ci.quadrature_order)
    )

    phase_properties = ParsedParameterFile(
        path.join("./diffs", ci.phase_properties_name))
    phase_properties["air"]["PBEDiameterCoeffs"]["QMOMCoeffs"]["quadratureOrder"] = ci.quadrature_order

    # manually fix bad pyfoam parsing
    phase_properties["blending"]["default"]["type"] = "none"
    phase_properties["drag"][1]["swarmCorrection"]["type"] = "none"
    phase_properties.writeFileAs(path.join(
        case.name, "constant", "phaseProperties"
    ))

    m0 = ParsedParameterFile(path.join(template_case.name, "0", "m0"))
    for i in range(ci.number_of_moments):
        m0.header["object"] = "m" + str(i)
        m0["internalField"].setUniform(ci.initial_moments[i])
        m0["dimensions"] = "[0 {0} 0 0 0 0 0]".format(3 * i)
        m0.writeFileAs(path.join(case.name, "0", "m" + str(i)))

    controlDict = ParsedParameterFile(
        path.join(case.name, "system", "controlDict")
    )
    controlDict["functions"]["probes"]["fields"] = [
        "m{0}".format(m) for m in range(ci.number_of_moments)]
    controlDict["endTime"] = ci.end_time
    controlDict["deltaT"] = ci.delta_t
    controlDict.writeFile()
开发者ID:Kojirion,项目名称:OpenPBE,代码行数:35,代码来源:setupCases.py

示例4: case_setup

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import cloneCase [as 别名]
def case_setup(ci):
    template_case = SolutionDirectory(
        "template", archive=None, paraviewLink=False)
    case = template_case.cloneCase("{0}".format(ci.name))

    stfproperties = ParsedParameterFile(path.join(
        case.name, "constant", "STFProperties"))

    stfproperties["apparentMass"] = ci.ma
    stfproperties["mass"] = ci.m
    stfproperties.writeFile()
开发者ID:robertsawko,项目名称:STFFoam,代码行数:13,代码来源:re_study.py

示例5: create_case

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import cloneCase [as 别名]
    def create_case(self, wind_dict, params):
        """
        0. cloning case
        1. creating snappyHexMeshDict and blockMeshdict according to flow direction and other parameters
        2. creating the blockMesh
        3. change the boundary conditions
        4. decomposing the domain
        5. creating the snappyHexMesh - running in parallel (sfoam.py or not - depending on user input)
        6. decomposing the created mesh
        """
        #--------------------------------------------------------------------------------------
        # cloning case
        #--------------------------------------------------------------------------------------
        target = params['case_dir']
        target = os.path.realpath(target)
        if not os.path.exists(target):
            makedirs(target)
        template = read_dict_string(wind_dict, 'template')
        self._r.debug("template = %r, target = %r" % (template, target))
        orig = SolutionDirectory(template,
                                archive=None,
                                paraviewLink=False)
        work = orig.cloneCase(target)

        #--
        # creating dictionaries
        #--
        if wind_dict['procnr'] > multiprocessing.cpu_count():
            self._r.warn('wind_dict contains a higher processor number then the machine has')
            wind_dict['procnr'] = min(wind_dict['procnr'], multiprocessing.cpu_count())
        phi = params['wind_dir'] * pi / 180
        params['phi'] = phi # - pi/180 * 90
        self._r.status('creating block mesh dictionary')
        self.create_block_mesh_dict(work, wind_dict, params)
        self._r.status('creating snappy hex mesh dictionary')
        self.create_SHM_dict(work, wind_dict, params)
        self._r.status('creating boundary conditions dictionary')
        self.create_boundary_conditions_dict(work, wind_dict, params)
        self._r.status('running block mesh')
        self.run_block_mesh(work)
        self._r.status('running decompose')
        self.run_decompose(work, wind_dict)
        self._r.status('running snappy hex mesh')
        self.run_SHM(work, wind_dict)
        self._r.status('running second decompose')
        self.run_decompose(work, wind_dict)
        return work
开发者ID:Involatum,项目名称:myOpenFOAMscripts,代码行数:49,代码来源:solvers.py

示例6: run

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import cloneCase [as 别名]
 def run(self):
     cName=self.parser.getArgs()[0]
     if self.opts.cloneCase:
         if self.opts.autoCasename:
             cName=path.join(cName,
                             path.basename(self.opts.cloneCase)+
                             buildFilenameExtension(self.opts.valuesDicts,
                                                    self.opts.values))
         if path.exists(cName):
             self.error(cName,"already existing (case should not exist when used with --clone-case)")
         if self.checkCase(self.opts.cloneCase,
                           fatal=self.opts.fatal,
                           verbose=not self.opts.noComplain):
             self.addLocalConfig(self.opts.cloneCase)
         orig=SolutionDirectory(self.opts.cloneCase,
                                archive=None,paraviewLink=False)
         sol=orig.cloneCase(cName)
     else:
         if self.checkCase(cName,
                           fatal=self.opts.fatal,
                           verbose=not self.opts.noComplain):
             self.addLocalConfig(cName)
         sol=SolutionDirectory(cName,archive=None,paraviewLink=False)
     self.prepare(sol,cName=cName)
开发者ID:mortbauer,项目名称:openfoam-extend-Breeder-other-scripting-PyFoam,代码行数:26,代码来源:PrepareCase.py

示例7: run

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import cloneCase [as 别名]

#.........这里部分代码省略.........
                self.error("Only",len(variations))
            start=self.opts.singleVariation
            end  =self.opts.singleVariation

        if end<start:
            self.error("Start value",start,"bigger than end value",end)

        if self.opts.listVariations:
            self.printPhase("Listing variations")
            for i in range(start,end+1):
                print_("Variation",i,":",variations[i])
            return

        if not hasDatabase or self.opts.noDatabaseWrite:
            if path.exists(self.opts.database) and self.opts.createDatabase:
                self.error("database-file",self.opts.database,"exists already.")
            elif not path.exists(self.opts.database) and not self.opts.createDatabase and not self.opts.autoCreateDatabase:
                self.error("database-file",self.opts.database,"does not exist")

        createDatabase=self.opts.createDatabase
        if self.opts.autoCreateDatabase and not path.exists(self.opts.database):
            createDatabase=True

        if not hasDatabase or self.opts.noDatabaseWrite:
            db=None
        else:
            db=RunDatabase(self.opts.database,
                           create=createDatabase,
                           verbose=self.opts.verbose)

        origCase=SolutionDirectory(origPath,archive=None)
        if self.opts.oneClonedCase:
            self.printPhase("Cloning work case")
            workCase=origCase.cloneCase(path.join(self.opts.cloneToDirectory,
                                              self.opts.clonedCasePrefix+"_"+path.basename(origPath)))

        self.printPhase("Starting actual variations")

        for i in range(start,end+1):
            self.printPhase("Variation",i,"of [",start,",",end,"]")

            usedVals=variations[i].copy()
            usedVals.update(fixed)

            self.prepareHooks()

            clone=False
            if self.opts.inplaceExecution:
                workCase=origCase
            elif self.opts.oneClonedCase:
                pass
            else:
                self.printPhase("Cloning work case")
                workCase=origCase.cloneCase(path.join(self.opts.cloneToDirectory,
                                                  self.opts.clonedCasePrefix+"_"+
                                                  ("%05d" % i)+"_"+path.basename(origPath)))

            self.processPlotLineOptions(autoPath=workCase.name)

            self.printPhase("Setting up the case")

            self.prepare(workCase,overrideParameters=usedVals)

            if self.opts.noExecuteSolver:
                self.printPhase("Not executing the solver")
                continue
开发者ID:LeeRuns,项目名称:PyFoam,代码行数:70,代码来源:RunParameterVariation.py

示例8: run

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import cloneCase [as 别名]

#.........这里部分代码省略.........

        for nr,description,solver,case,prepare,control,preControl,base,weight,additional,utilities,split,toRemove,setInit,decomposition in benchCases:
            #    control.append( ("endTime",-2000) )
            print "Running Benchmark: ",description
            print "Solver: ",solver
            print "Case: ",case
            caseName=solver+"_"+case+"_"+benchName+"."+uname()[1]+".case"
            print "Short name: ",caseName
            caseDir=caseName+".runDir"

            csv["description"]=description
            csv["solver"]=solver
            csv["case"]=case
            csv["caseDir"]=caseDir
            csv["base"]=base

            csv["benchmark"]=benchName
            csv["machine"]=uname()[1]
            csv["arch"]=uname()[4]
            if lam==None:
                csv["cpus"]=1
            else:
                csv["cpus"]=lam.cpuNr()
            csv["os"]=uname()[0]
            csv["version"]=uname()[2]
            
            workDir=path.realpath(path.curdir)

            orig=SolutionDirectory(path.join(casesDirectory,solver,case),
                                   archive=None,
                                   paraviewLink=False)
            for a in additional+utilities:
                orig.addToClone(a)
            orig.cloneCase(path.join(workDir,caseDir))

            if oldApp():
                argv=[solver,workDir,caseDir]
            else:
                argv=[solver,"-case",path.join(workDir,caseDir)]
                
            run=BasicRunner(silent=True,argv=argv,logname="BenchRunning",lam=lam)
            runDir=run.getSolutionDirectory()
            controlFile=ParameterFile(runDir.controlDict())

            for name,value in preControl:
                print "Setting parameter",name,"to",value,"in controlDict"
                controlFile.replaceParameter(name,value)

            for rm in toRemove:
                fn=path.join(caseDir,rm)
                print "Removing file",fn
                remove(fn)

            for field,bc,val in setInit:
                print "Setting",field,"on",bc,"to",val
                SolutionFile(runDir.initialDir(),field).replaceBoundary(bc,val)

            oldDeltaT=controlFile.replaceParameter("deltaT",0)

            for u in utilities:
                print "Building utility ",u
                execute("wmake 2>&1 >%s %s" % (path.join(caseDir,"BenchCompile."+u),path.join(caseDir,u)))

            print "Preparing the case: "
            if lam!=None:
                prepare=prepare+[("decomposePar","")]
开发者ID:floli,项目名称:tools,代码行数:70,代码来源:Benchmark.py

示例9: run3dHillBase

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import cloneCase [as 别名]
def run3dHillBase(template0, AR, z0, us, caseType):

	# loading other parameters from dictionary file
	inputDict = ParsedParameterFile("testZ0InfluenceDict")
	h		= inputDict["simParams"]["h"]
	yM 		= inputDict["simParams"]["yM"]
	# SHM parameters
	cell	= inputDict["SHMParams"]["cellSize"]["cell"] 
	Href = inputDict["SHMParams"]["domainSize"]["domZ"] 
	zz = inputDict["SHMParams"]["pointInDomain"]["zz"]
	# case definitions Martinez2DBump
	ks = 19.58 * z0 # [m] Martinez 2011
	k = inputDict["kEpsParams"]["k"]
	Cmu = inputDict["kEpsParams"]["Cmu"]	
	# yp/ks = 0.02 = x/ks
	hSample = inputDict["sampleParams"]["hSample"]
	procnr = multiprocessing.cpu_count()
	caseStr = "_z0_" + str(z0)
  	target = "runs/" + template0 + caseStr
  	x0, y0, phi = 	inputDict["SHMParams"]["centerOfDomain"]["x0"], inputDict["SHMParams"]["centerOfDomain"]["x0"], \
  					inputDict["SHMParams"]["flowOrigin"]["deg"]*pi/180
  	H = h
  	a = h*AR
	#--------------------------------------------------------------------------------------
	# cloning case
	#--------------------------------------------------------------------------------------
	orig = 	SolutionDirectory(template0,
			archive=None,
			paraviewLink=False)
	work = orig.cloneCase(target)
				  
	#--------------------------------------------------------------------------------------
	# changing inlet profile - - - - according to Martinez 2010
	#--------------------------------------------------------------------------------------
	# change inlet profile
	Uref = Utop = us/k*math.log(Href/z0)
	# calculating turbulentKE
	TKE = us*us/math.sqrt(Cmu)
	# 1: changing ABLConditions
	bmName = path.join(work.initialDir(),"include/ABLConditions")
	template = TemplateFile(bmName+".template")
	template.writeToFile(bmName,{'us':us,'Uref':Uref,'Href':Href,'z0':z0,'xDirection':sin(phi),'yDirection':cos(phi)})
	# 2: changing initialConditions
	bmName = path.join(work.initialDir(),"include/initialConditions")
	template = TemplateFile(bmName+".template")
	template.writeToFile(bmName,{'TKE':TKE})
	# 3: changing initial and boundary conditions for new z0
	# changing ks in nut, inside nutRoughWallFunction
	nutFile = ParsedParameterFile(path.join(work.initialDir(),"nut"))
	nutFile["boundaryField"]["ground"]["Ks"].setUniform(ks)
	nutFile["boundaryField"]["terrain_.*"]["Ks"].setUniform(ks)
	nutFile.writeFile()
	
	#--------------------------------------------------------------------------------------
	# changing sample file
	#--------------------------------------------------------------------------------------
	# 2: changing initialConditions
	bmName = path.join(work.systemDir(),"sampleDict")
	template = TemplateFile(bmName+".template")
	if AR>100:# flat terrain
		h=0
		template.writeToFile(bmName,{'hillTopY':0,'sampleHeightAbovePlain':50,'sampleHeightAboveHill':50,'inletX':3500})
	else:
		template.writeToFile(bmName,{'hillTopY':h,'sampleHeightAbovePlain':50,'sampleHeightAboveHill':h+50,'inletX':h*AR*4*0.9}) 
	
	# if SHM - create mesh
	if caseType.find("SHM")>0:
		phi = phi - pi/180 * 90	#--------------------------------------------------------------------------------------
		# creating blockMeshDict
		#--------------------------------------------------------------------------------------
		l, d = a*inputDict["SHMParams"]["domainSize"]["fX"], a*inputDict["SHMParams"]["domainSize"]["fY"]
		x1 = x0 - (l/2*sin(phi) + d/2*cos(phi))
		y1 = y0 - (l/2*cos(phi) - d/2*sin(phi))
		x2 = x0 - (l/2*sin(phi) - d/2*cos(phi))
		y2 = y0 - (l/2*cos(phi) + d/2*sin(phi))
		x3 = x0 + (l/2*sin(phi) + d/2*cos(phi))
		y3 = y0 + (l/2*cos(phi) - d/2*sin(phi))
		x4 = x0 + (l/2*sin(phi) - d/2*cos(phi))
		y4 = y0 + (l/2*cos(phi) + d/2*sin(phi))
		n = floor(d/(cell*inputDict["SHMParams"]["cellSize"]["cellYfactor"]))
		m = floor(l/(cell*inputDict["SHMParams"]["cellSize"]["cellYfactor"]))
		q = floor((Href+450)/cell) # -450 is the minimum of the blockMeshDict.template - since that is slightly lower then the lowest point on the planet

		bmName = path.join(work.constantDir(),"polyMesh/blockMeshDict")
		template = TemplateFile(bmName+".template")
		template.writeToFile(bmName,{'X0':x1,'X1':x2,'X2':x3,'X3':x4,'Y0':y1,'Y1':y2,'Y2':y3,'Y3':y4,'Z0':Href,'n':int(n),'m':int(m),'q':int(q)})
		
		#--------------------------------------------------------------------------------------
		# running blockMesh
		#--------------------------------------------------------------------------------------
		blockRun = BasicRunner(argv=["blockMesh",'-case',work.name],silent=True,server=False,logname="blockMesh")
		print "Running blockMesh"
		blockRun.start()
		if not blockRun.runOK(): error("there was an error with blockMesh")

		#--------------------------------------------------------------------------------------
		# running SHM
		#--------------------------------------------------------------------------------------
		print "calculating SHM parameters"
		# calculating refinement box positions
#.........这里部分代码省略.........
开发者ID:Involatum,项目名称:myOpenFOAMscripts,代码行数:103,代码来源:run3dHillBase.py

示例10: ParsedParameterFile

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import cloneCase [as 别名]
 # calculating ks according to Martinez 2011
 ks = 19.58 * z0
 print "ks = "+str(ks)
 # calculating ABLconditions - Ustar=$US according to logarithmic law
 k = 0.4
 Href = 700
 Uref = 17.4
 us = (Uref*k)/math.log((Href/z0));
 print "us = "+str(us)
 # calculating turbulentKE
 Cmu = 0.03
 TKE = us*us/math.sqrt(Cmu)
 print "TKE = "+str(TKE)
 
 # cloaning case
 work = orig.cloneCase(target)
 
 # changing initial and boundary conditions for new z0
 # changing ks in nut, inside nutRoughWallFunction
 nutFile = ParsedParameterFile(path.join(work.initialDir(),"nut"))
 nutFile["boundaryField"]["ground"]["Ks"].setUniform(ks)
 nutFile.writeFile()
 # changing ABLconditions
 bmName = path.join(work.initialDir(),"include/ABLconditions")
 template = TemplateFile(bmName+".template")
 template.writeToFile(bmName,{'z0':z0,'us':us})
 # changing initialConditions
 bmName = path.join(work.initialDir(),"include/initialConditions")
 template = TemplateFile(bmName+".template")
 template.writeToFile(bmName,{'TKE':TKE})
 
开发者ID:Involatum,项目名称:myOpenFOAMscripts,代码行数:32,代码来源:runZ0.py

示例11: execute

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import cloneCase [as 别名]
 def execute(self,para,log):
     print_("     Copy last result")
     sol=SolutionDirectory(para["case"],archive=None)
     sol.addToClone(sol.getLast())
     sol.cloneCase(path.join(para["results"],para["id"]))
     return True,None
开发者ID:Unofficial-Extend-Project-Mirror,项目名称:openfoam-extend-Breeder-other-scripting-PyFoam,代码行数:8,代码来源:Comparator.py

示例12: prepareCase_2dHill

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import cloneCase [as 别名]
def prepareCase_2dHill(template0, targetDir, target0, hillName, AR, r, x, Ls, L, L1, H, x0, z0, us, yM, h, caseType):

    # case definitions Martinez2DBump
    ks = 19.58 * z0 # [m] Martinez 2011
    k = 0.4
    Cmu = 0.03     # Castro 96
    Htop = Href = H    # [m]

    # yp/ks = 0.02 = x/ks
    funky = 0
    plotMartinez = 1
    hSample = 10
    fac = 10 # currecting calculation of number of cells and Rx factor to get a smooth transition 
             # from the inner refined cell and the outer less refined cells of the blockMesh Mesh
    procnr = 4

    caseStr = "_AR_" + str(AR) + "_z0_" + str(z0)
    if caseType=="Crude":
        caseStr = caseStr + "Crude"
    target = os.path.join(targetDir, target0 + caseStr)
    if not os.path.exists(template0):
        print "there is no %r directory in the current directory %r" % (template0, os.getcwd())
        raise SystemExit
    orig = SolutionDirectory(template0,
              archive=None,
              paraviewLink=False)
    #--------------------------------------------------------------------------------------
    # clonning case
    #--------------------------------------------------------------------------------------
    if not os.path.exists(targetDir):
        os.mkdir(targetDir)
    work = orig.cloneCase(target)

    #--------------------------------------------------------------------------------------
    # creating mesh
    #--------------------------------------------------------------------------------------
    y0 =  2 * x * z0 # setting first cell according to Martinez 2011 p. 25
    ny = int(round(math.log(H/y0*(r-1)+1)/math.log(r)))    # number of cells in the y direction of the hill block
    Ry  = r**(ny-1.)
    nx = int(L/x0-1)
    rx = max(r,1.1)
    ns = int(round(math.log((Ls-L)/x0*(rx-1)/rx**fac+1)/math.log(rx)))    # number of cells in the x direction of the hill block
    Rx = rx**(ns-1)
    # changing blockMeshDict - from template file
    bmName = path.join(work.constantDir(),"polyMesh/blockMeshDict")
    if AR==1000: # if flat terrain
        template = TemplateFile(bmName+"_flat_3cell.template")
    else:
        template = TemplateFile(bmName+"_3cell.template")
    template.writeToFile(bmName,{'H':H,'ny':ny,'Ry':Ry,'nx':nx,'L':L,'L1':L1,'Ls':Ls,'Rx':Rx,'Rx_one_over':1/Rx,'ns':ns})
    # writing ground shape (hill, or whatever you want - equation in function writeGroundShape.py)
    # sample file is changed as well - for sampling h=10 meters above ground
    sampleName = path.join(work.systemDir(),"sampleDict.template")
    write2dShape(bmName,H,L,sampleName,hSample,hillName,AR)
    # changing Y line limits
    bmName = path.join(work.systemDir(),"sampleDict")
    template = TemplateFile(bmName + ".template")
    if AR==1000: # if flat terrain
        template.writeToFile(bmName,{'hillTopY':0,'maxY':yM*2.5})
    else:
        template.writeToFile(bmName,{'hillTopY':h,'maxY':yM*2.5+h})

    # running blockMesh
    print "running blockMesh"
    blockRun = BasicRunner(argv=["blockMesh",'-case',work.name],silent=True,server=False,logname="blockMesh")
    blockRun.start()
    if not blockRun.runOK():
        error("there was an error with blockMesh")

    #--------------------------------------------------------------------------------------
    # changing inlet profile - - - - according to Martinez 2010
    #--------------------------------------------------------------------------------------
    # change inlet profile
    Uref = Utop = us/k*math.log(Href/z0)
    # calculating turbulentKE
    TKE = us*us/math.sqrt(Cmu)
    # 1: changing ABLConditions
    bmName = path.join(work.initialDir(),"include/ABLConditions")
    template = TemplateFile(bmName+".template")
    template.writeToFile(bmName,{'us':us,'Uref':Uref,'Href':Href,'z0':z0})
    # 2: changing initialConditions
    bmName = path.join(work.initialDir(),"include/initialConditions")
    template = TemplateFile(bmName+".template")
    template.writeToFile(bmName,{'TKE':TKE})

    if funky:    
        # 3: changing U (inserting variables into groovyBC for inlet profile)
        bmName = path.join(work.initialDir(),"U")
        template = TemplateFile(bmName + ".template")
        template.writeToFile(bmName,{'us':us,'z0':z0,'K':k,'Utop':Utop})
        # 4: changing k (inserting variables into groovyBC for inlet profile)
        bmName = path.join(work.initialDir(),"k")
        template = TemplateFile(bmName + ".template")
        template.writeToFile(bmName,{'us':us,'z0':z0,'K':k,'Utop':Utop,'Cmu':Cmu})
        # 5: changing epsilon (inserting variables into groovyBC for inlet profile)
        bmName = path.join(work.initialDir(),"epsilon")
        template = TemplateFile(bmName + ".template")
        template.writeToFile(bmName,{'us':us,'z0':z0,'K':k,'Utop':Utop,'Cmu':Cmu})

    # 6: changing initial and boundary conditions for new z0
#.........这里部分代码省略.........
开发者ID:Involatum,项目名称:myOpenFOAMscripts,代码行数:103,代码来源:prepareCase_2dHill.py

示例13: gamma

# 需要导入模块: from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory [as 别名]
# 或者: from PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory import cloneCase [as 别名]
from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory
from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile
from scipy.stats import gamma

class_number = 160
vmax = 1
dv = vmax / class_number
m0 = 2
prob = gamma(a=50, scale=1.0e-2)
v = dv + dv * arange(class_number)

if __name__ == "__main__":
    template_case = SolutionDirectory(
        "MOC-template", archive=None, paraviewLink=False)
    case = template_case.cloneCase(
        "{0}{1}".format("MOC", class_number)
    )

    n0 = ParsedParameterFile(path.join(template_case.name, "0", "n0"))
    for i in range(class_number):
        n0.header["object"] = "n" + str(i)
        n0["internalField"].setUniform(
            m0 * (prob.cdf(v[i]) - prob.cdf(v[i] - dv))
        )
        n0.writeFileAs(path.join(case.name, "0", "n" + str(i)))

    phase_properties = ParsedParameterFile(
        path.join(case.name, "constant", "phaseProperties")
    )

    phase_properties["air"]["PBEDiameterCoeffs"]["MOCCoeffs"]["numberOfClasses"] = class_number
开发者ID:Kojirion,项目名称:OpenPBE,代码行数:33,代码来源:setupIC.py


注:本文中的PyFoam.RunDictionary.SolutionDirectory.SolutionDirectory.cloneCase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。