def alphaEqnSubCycle(runTime, piso, mesh, phi, alpha1, rho, rhoPhi, rho1, rho2, interface): from Foam.OpenFOAM import word, readLabel nAlphaCorr = readLabel(piso.lookup(word("nAlphaCorr"))) nAlphaSubCycles = readLabel(piso.lookup(word("nAlphaSubCycles"))) if (nAlphaSubCycles > 1): totalDeltaT = runTime.deltaT() rhoPhiSum = 0.0 * rhoPhi from Foam.finiteVolume import subCycle_volScalarField alphaSubCycle = subCycle_volScalarField(alpha1, nAlphaSubCycles) for item in alphaSubCycle: alphaEqn(mesh, phi, alpha1, rhoPhi, rho1, rho2, interface, nAlphaCorr) rhoPhiSum.ext_assign(rhoPhiSum + (runTime.deltaT() / totalDeltaT) * rhoPhi) pass # To make sure that variable in the local scope will be destroyed # - during destruction of this variable it performs some important actions # - there is a difference between C++ and Python memory management, namely # if C++ automatically destroys stack variables when they exit the scope, # Python relay its memory management of some "garbage collection" algorithm # that do not provide predictable behavior on the "exit of scope" del alphaSubCycle rhoPhi.ext_assign(rhoPhiSum) else: alphaEqn(mesh, phi, alpha1, rhoPhi, rho1, rho2, interface, nAlphaCorr) pass interface.correct() rho == alpha1 * rho1 + (1.0 - alpha1) * rho2 pass
def alphaEqnSubCycle( runTime, piso, mesh, phi, alpha1, rho, rhoPhi, rho1, rho2, interface ): from Foam.OpenFOAM import word,readLabel nAlphaCorr = readLabel( piso.lookup( word( "nAlphaCorr" ) ) ) nAlphaSubCycles = readLabel( piso.lookup( word( "nAlphaSubCycles" ) ) ) if (nAlphaSubCycles > 1): totalDeltaT = runTime.deltaT() rhoPhiSum = 0.0 * rhoPhi from Foam.finiteVolume import subCycle_volScalarField alphaSubCycle = subCycle_volScalarField(alpha1, nAlphaSubCycles) for item in alphaSubCycle: alphaEqn( mesh, phi, alpha1, rhoPhi, rho1, rho2, interface, nAlphaCorr ) rhoPhiSum.ext_assign( rhoPhiSum + ( runTime.deltaT() / totalDeltaT ) * rhoPhi ) pass # To make sure that variable in the local scope will be destroyed # - during destruction of this variable it performs some important actions # - there is a difference between C++ and Python memory management, namely # if C++ automatically destroys stack variables when they exit the scope, # Python relay its memory management of some "garbage collection" algorithm # that do not provide predictable behavior on the "exit of scope" del alphaSubCycle rhoPhi.ext_assign( rhoPhiSum ) else: alphaEqn( mesh, phi, alpha1, rhoPhi, rho1, rho2, interface, nAlphaCorr ) pass interface.correct() rho == alpha1 * rho1 + ( 1.0 - alpha1 ) * rho2 pass
def _init__with_2_param( self, *args ): if len(args) != 2: raise AssertionError( "len( args ) != 2" ) argc = 0 from Foam.finiteVolume import fvMesh try: fvMesh.ext_isinstance( args[ argc ] ) except TypeError: raise AssertionError( "args[ argc ].__class__ != fvMesh" ) mesh = args[ argc ]; argc +=1 from Foam.OpenFOAM import dictionary try: dictionary.ext_isinstance( args[ argc ] ) except TypeError: raise AssertionError( "args[ argc ].__class__ != dictionary" ) dict_ = args[ argc ] PtrList_TypeBase.__init__( self ) from Foam.OpenFOAM import polyPatchID, word, readLabel, readScalar self.patchID_ = polyPatchID( dict_.lookup( word( "patch" ) ), mesh.boundaryMesh() ) self.faceIndex_ = readLabel( dict_.lookup( word( "face" ) ) ) self.dir_ = self.getDir( dict_ ) self.value_ = readScalar( dict_.lookup( word( "value" ) ) ) self.checkPatchFace(mesh)
def _init__with_2_param(self, *args): if len(args) != 2: raise AssertionError("len( args ) != 2") argc = 0 from Foam.finiteVolume import fvMesh try: fvMesh.ext_isinstance(args[argc]) except TypeError: raise AssertionError("args[ argc ].__class__ != fvMesh") mesh = args[argc] argc += 1 from Foam.OpenFOAM import dictionary try: dictionary.ext_isinstance(args[argc]) except TypeError: raise AssertionError("args[ argc ].__class__ != dictionary") dict_ = args[argc] PtrList_TypeBase.__init__(self) from Foam.OpenFOAM import polyPatchID, word, readLabel, readScalar self.patchID_ = polyPatchID(dict_.lookup(word("patch")), mesh.boundaryMesh()) self.faceIndex_ = readLabel(dict_.lookup(word("face"))) self.dir_ = self.getDir(dict_) self.value_ = readScalar(dict_.lookup(word("value"))) self.checkPatchFace(mesh)
def read_controls( args, runTime, mesh ): from Foam.finiteVolume.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh ) from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime ) from Foam.OpenFOAM import word, readLabel nAlphaCorr = readLabel( piso.lookup( word( "nAlphaCorr" ) ) ) nAlphaSubCycles = readLabel( piso.lookup( word( "nAlphaSubCycles" ) ) ) if nAlphaSubCycles > 1 and nOuterCorr != 1: from Foam.OpenFOAM import ext_Info, nl ext_Info() << args.executable() << "FATAL ERROR: Sub-cycling alpha is only allowed for PISO, i.e. when the number of outer-correctors = 1" << nl; import os; os_exit( 1 ) pass return piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr, adjustTimeStep, maxCo, maxDeltaT, nAlphaCorr, nAlphaSubCycles
def alphaEqnsSubCycle( runTime, piso, mesh, phi, alpha1, alpha2, rho, rho1, rho2, rhoPhi, dgdt, interface, oCorr ): from Foam.OpenFOAM import word,readLabel nAlphaCorr = readLabel( piso.lookup( word( "nAlphaCorr" ) ) ) nAlphaSubCycles = readLabel( piso.lookup( word( "nAlphaSubCycles" ) ) ) from Foam.finiteVolume import surfaceScalarField phic = ( phi / mesh.magSf() ).mag() phic.ext_assign( ( interface.cAlpha() * phic ).ext_min( phic.ext_max() ) ) from Foam import fvc divU = fvc.div( phi ) if nAlphaSubCycles > 1: totalDeltaT = runTime.deltaT() rhoPhiSum = 0.0 * rhoPhi from Foam.finiteVolume import subCycle_volScalarField alphaSubCycle = subCycle_volScalarField( alpha1, nAlphaSubCycles ) for item in alphaSubCycle: alphaEqns( runTime, mesh, rho1, rho2, rhoPhi, phic, dgdt, divU, alpha1, alpha2, phi, interface, nAlphaCorr ) rhoPhiSum.ext_assign( rhoPhiSum + ( runTime.deltaT() / totalDeltaT ) * rhoPhi ) pass # To make sure that variable in the local scope will be destroyed # - during destruction of this variable it performs some important actions # - there is a difference between C++ and Python memory management, namely # if C++ automatically destroys stack variables when they exit the scope, # Python relay its memory management of some "garbage collection" algorithm # that do not provide predictable behavior on the "exit of scope" del alphaSubCycle rhoPhi.ext_assign( rhoPhiSum ) pass else: alphaEqns( runTime, mesh, rho1, rho2, rhoPhi, phic, dgdt, divU, alpha1, alpha2, phi, interface, nAlphaCorr ) pass if oCorr == 0: interface.correct() pass pass