def fun_Urel(mesh, U): """ Calculate the relative velocity used to map the relative flux phi """ Urel = ref.volVectorField(ref.word("Urel"), U) if mesh.moving(): Urel -= ref.fvc.reconstruct(ref.fvc.meshPhi(U)) pass # Do any mesh changes mesh.update() pass
def main_standalone(argc, argv): args = ref.setRootCase(argc, argv) runTime = man.createTime(args) mesh = man.createMesh(runTime) p, Urel, phi, pRefCell, pRefValue, laminarTransport, turbulence, SRF, sources = createFields( runTime, mesh) cumulativeContErr = ref.initContinuityErrs() simple = man.simpleControl(mesh) # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * # ref.ext_Info() << "\nStarting time loop\n" << ref.nl while simple.loop(): ref.ext_Info() << "Time = " << runTime.timeName() << ref.nl << ref.nl # --- Pressure-velocity SIMPLE corrector UrelEqn = fun_UrelEqn(Urel, phi, turbulence, p, sources, SRF) cumulativeContErr = fun_pEqn(mesh, runTime, simple, Urel, phi, turbulence, p, UrelEqn, pRefCell, pRefValue, cumulativeContErr, sources) turbulence.correct() Uabs = None if runTime.outputTime(): Uabs = ref.volVectorField( ref.IOobject(ref.word("Uabs"), ref.fileName(runTime.timeName()), mesh, ref.IOobject.NO_READ, ref.IOobject.AUTO_WRITE), Urel() + SRF.U()) # mixed calculations pass runTime.write() ref.ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" \ << " ClockTime = " << runTime.elapsedClockTime() << " s" \ << ref.nl << ref.nl pass ref.ext_Info() << "End\n" << ref.nl import os return os.EX_OK
def main_standalone( argc, argv ): args = ref.setRootCase( argc, argv ) runTime = man.createTime( args ) mesh = man.createMesh( runTime ) p, Urel, phi, pRefCell, pRefValue, laminarTransport, turbulence, SRF, sources = createFields( runTime, mesh ) cumulativeContErr = ref.initContinuityErrs() simple = man.simpleControl (mesh) # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * # ref.ext_Info() << "\nStarting time loop\n" << ref.nl while simple.loop(): ref.ext_Info() << "Time = " << runTime.timeName() << ref.nl << ref.nl # --- Pressure-velocity SIMPLE corrector UrelEqn = fun_UrelEqn( Urel, phi, turbulence, p, sources, SRF ) cumulativeContErr = fun_pEqn( mesh, runTime, simple, Urel, phi, turbulence, p, UrelEqn, pRefCell, pRefValue, cumulativeContErr, sources ) turbulence.correct() Uabs = None if runTime.outputTime(): Uabs = ref.volVectorField( ref.IOobject( ref.word( "Uabs" ), ref.fileName( runTime.timeName() ), mesh, ref.IOobject.NO_READ, ref.IOobject.AUTO_WRITE ), Urel() + SRF.U() ) # mixed calculations pass runTime.write() ref.ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" \ << " ClockTime = " << runTime.elapsedClockTime() << " s" \ << ref.nl << ref.nl pass ref.ext_Info() << "End\n" << ref.nl import os return os.EX_OK
def __init__(self, the_case_dir, the_post_processor=None): """ Constructs instance of this class """ import os, os.path # To identify the canonical pathes of the specified filenames, # eliminating any symbolic links encountered in the pathes the_case_dir = os.path.realpath(the_case_dir) # Definiton of the "root" and OpenFOAM "case" a_root_dir, a_case = os.path.split(the_case_dir) print_d('a_root_dir = "%s", a_case = "%s"' % (a_root_dir, a_case)) a_controlDict = self._createControlDict() # Create time - without reading controlDict from file # Note - controlDict not written to file using this method self.run_time = ref.Time(a_controlDict, ref.fileName(a_root_dir), ref.fileName(a_case)) print_d("self.run_time.caseConstant() = %s" % self.run_time.caseConstant()) # Create transport properties self.transportProperties = ref.IOdictionary( ref.IOobject( ref.word("transportProperties"), self.run_time.caseConstant(), self.run_time, ref.IOobject.NO_READ, ref.IOobject.NO_WRITE, ) ) nu = ref.dimensionedScalar(ref.word("nu"), ref.dimensionSet(0.0, 2.0, -1.0, 0.0, 0.0, 0.0, 0.0), 1e-6) self.transportProperties.add(ref.word("nu"), nu) # Create fvSchemes and fvSolution dictionaries fvSchemesDict = self._createFvSchemesDict() fvSoln = self._createFvSolution() # Write all dictionaries to file # Note, we currently need fvSchemes and fvSolution to reside in the case directory # since it is used during the solution... so we now write them to file self.run_time.writeNow() # Clean up unused variables fvSchemesDict = 0 fvSoln = 0 # Create mesh self.mesh, self.patches = self._createFvMesh() # mesh.write() # Create pressure field pPatchTypes = pyWordList(["zeroGradient", "fixedValue", "fixedValue", "zeroGradient"]) a_value = ref.dimensionedScalar(ref.word(), ref.dimensionSet(0.0, 2.0, -2.0, 0.0, 0.0, 0.0, 0.0), 101.325) self.p = ref.volScalarField( ref.IOobject( ref.word("p"), ref.fileName(self.run_time.timeName()), self.mesh, ref.IOobject.NO_READ, ref.IOobject.AUTO_WRITE, ), self.mesh, a_value, pPatchTypes, ) self.p.ext_boundaryField()[1] << 101.325 self.p.ext_boundaryField()[2] << 101.325 # Create velocity field UPatchTypes = pyWordList(["fixedValue", "zeroGradient", "zeroGradient", "fixedValue"]) a_value = ref.dimensionedVector( ref.word(), ref.dimensionSet(0.0, 1.0, -1.0, 0.0, 0.0, 0.0, 0.0), ref.vector(0.0, 0.0, 0.0) ) self.U = ref.volVectorField( ref.IOobject( ref.word("U"), ref.fileName(self.run_time.timeName()), self.mesh, ref.IOobject.NO_READ, ref.IOobject.AUTO_WRITE, ), self.mesh, a_value, UPatchTypes, ) self.U.ext_boundaryField()[0] << ref.vector(0.0, 0.1, 0.0) self.U.ext_boundaryField()[3] << ref.vector(0.0, 0.0, 0.0) self.phi = ref.createPhi(self.run_time, self.mesh, self.U) # Write all dictionaries to file self.run_time.writeNow() # Define the post processor engine if the_post_processor == None: the_post_processor = TDummyPostProcessor pass # Construction of the post processor engine self.post_processor = the_post_processor(the_case_dir, a_case) # To dump controlDict to be able to run "foamToVTK" utility self._writeControlDict(a_controlDict) # Post processing of the first step self.post_processor.process(self.run_time.value()) # Initialization of the engine self.solver = icoFoam(self.run_time, self.U, self.p, self.phi, self.transportProperties) pass