def run(self, the_number_iterations=5): """ Runs the solver execution The fvSolution dictionary must be manually edited before calling this function (see comments for createFvSolutionDict) """ pRes = [] # initial pressure residual uRes = [] # initial velocity residual it = [] iteration = [] iteration.append(0) for i in xrange(the_number_iterations): i += iteration[0] it.append(i) self.solver.step() pRes.append(self.solver.pressureRes()) uRes.append(self.solver.velocityRes()) pResTpl = tuple(pRes) uResTpl = tuple(uRes) self.run_time.writeNow() print_d("runTime.value() = %g" % (self.run_time.value())) self.post_processor.process(self.run_time.value()) pass iteration[0] += the_number_iterations return True
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