def write( runTime, mesh, T ): if runTime.outputTime(): from Foam import fvc gradT = fvc.grad(T) from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField from Foam.OpenFOAM import vector gradTx = volScalarField( IOobject( word( "gradTx" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE ), gradT.component( vector.X ) ) gradTy = volScalarField( IOobject( word( "gradTy" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE ), gradT.component( vector.Y ) ) gradTz = volScalarField( IOobject( word( "gradTz" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE ), gradT.component( vector.Z ) ) runTime.write() pass
def _createFields( runTime, mesh, rhoO, psi ): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading field p\n" << nl from Foam.finiteVolume import volScalarField from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName p = volScalarField( IOobject( word( "p" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) rho = volScalarField( IOobject( word( "rho" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE ), rhoO + psi * p ) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi( runTime, mesh, rho, U ) return p, U, rho, phi
def _createFields( runTime, mesh, R, Cv ): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading field p\n" << nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField p = volScalarField( IOobject( word( "p" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Reading field T\n" << nl T = volScalarField( IOobject( word( "T" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) psi = volScalarField( IOobject( word( "psi" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.NO_WRITE ), 1.0 / ( R * T ) ) psi.oldTime() rho = volScalarField( IOobject( word( "rho" ), fileName( runTime.timeName() ), mesh ), psi * p, p.ext_boundaryField().types() ) rhoU = volVectorField( IOobject( word( "rhoU" ), fileName( runTime.timeName() ) , mesh, IOobject.NO_READ, IOobject.NO_WRITE ), rho * U, U.ext_boundaryField().types() ) rhoE = volScalarField( IOobject( word( "rhoE" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.NO_WRITE ), rho * Cv * T + 0.5 * rho * ( rhoU / rho ).magSqr(), T.ext_boundaryField().types() ) return p, T, U, psi, rho, rhoU, rhoE
def create_fields( runTime, mesh, g ): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicRhoThermo thermo = basicRhoThermo.New( mesh ) from Foam.OpenFOAM import IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject( word( "rho" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.NO_WRITE ), thermo.rho() ) p = thermo.p() h = thermo.h() psi = thermo.psi() ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi( runTime, mesh, rho, U ) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.turbulenceModel.New( rho, U, phi, thermo() ) ext_Info() << "Calculating field g.h\n" << nl gh = volScalarField( word( "gh" ), g & mesh.C() ) from Foam.finiteVolume import surfaceScalarField ghf = surfaceScalarField( word( "ghf" ), g & mesh.Cf() ) ext_Info() << "Reading field p_rgh\n" << nl p_rgh = volScalarField( IOobject( word( "p_rgh" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) # Force p_rgh to be consistent with p p_rgh.ext_assign( p - rho * gh ) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc DpDt = volScalarField( word( "DpDt" ), fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) ) return thermo, p, rho, h, psi, U, phi, turbulence, gh, ghf, p_rgh, DpDt
def createFields( runTime, mesh, g ): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField ext_Info() << "Reading thermophysical properties\n" << nl ext_Info() << "Reading field T\n" << nl T = volScalarField( IOobject( word( "T" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Reading field p\n" << nl p = volScalarField( IOobject( word( "p" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.finiteVolume.cfdTools.incompressible import createPhi phi = createPhi( runTime, mesh, U ) laminarTransport, beta, TRef,Pr, Prt = readTransportProperties( U, phi ) ext_Info() << "Creating turbulence model\n" << nl from Foam import incompressible turbulence = incompressible.RASModel.New( U, phi, laminarTransport ) ext_Info() << "Calculating field beta*(g.h)\n" << nl from Foam.finiteVolume import surfaceScalarField betaghf = surfaceScalarField( word( "betagh" ), beta * ( g & mesh.Cf() ) ) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "SIMPLE" ) ), pRefCell, pRefValue ) # Kinematic density for buoyancy force rhok = volScalarField( IOobject( word( "rhok" ), fileName( runTime.timeName() ), mesh ), 1.0 - beta * ( T - TRef ) ) return T, p, U, phi, laminarTransport, beta, TRef,Pr, Prt, turbulence, betaghf, pRefCell, pRefValue, rhok
def _createFields( runTime, mesh, R, Cv ): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading field p\n" << nl from Foam.finiteVolume import volScalarField from Foam.OpenFOAM import IOdictionary, IOobject, fileName, word p = volScalarField( IOobject( word( "p" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Reading field T\n" << nl T = volScalarField( IOobject( word( "T" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Calculating field e from T\n" << nl e = volScalarField( IOobject( word( "e" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.NO_WRITE ), Cv * T, T.ext_boundaryField().types() ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) psi = volScalarField( IOobject( word( "psi" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.NO_WRITE ), 1.0 / ( R * T ) ) psi.oldTime() rho = volScalarField( IOobject( word( "rho" ), fileName( runTime.timeName() ), mesh ), psi * p ) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi( runTime, mesh, rho, U ) return p, T, e, U, psi, rho, phi
def createSolidField( solidRegions, runTime ): #Initialise solid field pointer lists from Foam.finiteVolume import PtrList_volScalarField, volScalarField rhos = PtrList_volScalarField( solidRegions.size() ) cps = PtrList_volScalarField( solidRegions.size() ) rhosCps = PtrList_volScalarField( solidRegions.size() ) Ks = PtrList_volScalarField( solidRegions.size() ) Ts = PtrList_volScalarField( solidRegions.size() ) from Foam.OpenFOAM import ext_Info, nl #Populate solid field pointer lists from Foam.OpenFOAM import word, IOobject, fileName for index in range( solidRegions.size() ): ext_Info()<< "*** Reading solid mesh thermophysical properties for region " \ << solidRegions[ index ].name() << nl << nl ext_Info()<< " Adding to rhos\n" << nl rhos.ext_set( index, volScalarField( IOobject ( word( "rho" ), fileName( runTime.timeName() ), solidRegions[ index ], IOobject.MUST_READ, IOobject.AUTO_WRITE ), solidRegions[ index ] ) ) ext_Info()<< " Adding to cps\n" << nl cps.ext_set( index, volScalarField( IOobject( word( "cp" ), fileName( runTime.timeName() ), solidRegions[ index ], IOobject.MUST_READ, IOobject.AUTO_WRITE ), solidRegions[ index ] ) ) rhosCps.ext_set( index, volScalarField( word( "rhosCps" ), rhos[ index ] * cps[ index ] ) ) ext_Info()<< " Adding to Ks\n" << nl Ks.ext_set( index, volScalarField( IOobject( word( "K" ), fileName( runTime.timeName() ), solidRegions[ index ], IOobject.MUST_READ, IOobject.AUTO_WRITE ), solidRegions[ index ] ) ) ext_Info()<< " Adding to Ts\n" << nl Ts.ext_set( index, volScalarField( IOobject( word( "T" ), fileName( runTime.timeName() ), solidRegions[ index ], IOobject.MUST_READ, IOobject.AUTO_WRITE ), solidRegions[ index ] ) ) return rhos, cps, rhosCps, Ks, Ts
def _createFields( runTime, mesh, g ): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField ext_Info() << "Reading thermophysical properties\n" << nl ext_Info() << "Reading field T\n" << nl T = volScalarField( IOobject( word( "T" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Reading field p\n" << nl p = volScalarField( IOobject( word( "p" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.finiteVolume.cfdTools.incompressible import createPhi phi = createPhi( runTime, mesh, U ) laminarTransport, beta, TRef,Pr, Prt = readTransportProperties( U, phi ) ext_Info() << "Creating turbulence model\n" << nl from Foam import incompressible turbulence = incompressible.RASModel.New( U, phi, laminarTransport ) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "PISO" ) ), pRefCell, pRefValue ) # Kinematic density for buoyancy force rhok = volScalarField( IOobject( word( "rhok" ), fileName( runTime.timeName() ), mesh ), 1.0 - beta * ( T - TRef ) ) return T, p, U, phi, laminarTransport, beta, TRef,Pr, Prt, turbulence, pRefCell, pRefValue, rhok
def createSolidField(solidRegions, runTime): #Initialise solid field pointer lists from Foam.finiteVolume import PtrList_volScalarField, volScalarField rhos = PtrList_volScalarField(solidRegions.size()) cps = PtrList_volScalarField(solidRegions.size()) rhosCps = PtrList_volScalarField(solidRegions.size()) Ks = PtrList_volScalarField(solidRegions.size()) Ts = PtrList_volScalarField(solidRegions.size()) from Foam.OpenFOAM import ext_Info, nl #Populate solid field pointer lists from Foam.OpenFOAM import word, IOobject, fileName for index in range(solidRegions.size()): ext_Info()<< "*** Reading solid mesh thermophysical properties for region " \ << solidRegions[ index ].name() << nl << nl ext_Info() << " Adding to rhos\n" << nl rhos.ext_set( index, volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), solidRegions[index], IOobject.MUST_READ, IOobject.AUTO_WRITE), solidRegions[index])) ext_Info() << " Adding to cps\n" << nl cps.ext_set( index, volScalarField( IOobject(word("cp"), fileName(runTime.timeName()), solidRegions[index], IOobject.MUST_READ, IOobject.AUTO_WRITE), solidRegions[index])) rhosCps.ext_set( index, volScalarField(word("rhosCps"), rhos[index] * cps[index])) ext_Info() << " Adding to Ks\n" << nl Ks.ext_set( index, volScalarField( IOobject(word("K"), fileName(runTime.timeName()), solidRegions[index], IOobject.MUST_READ, IOobject.AUTO_WRITE), solidRegions[index])) ext_Info() << " Adding to Ts\n" << nl Ts.ext_set( index, volScalarField( IOobject(word("T"), fileName(runTime.timeName()), solidRegions[index], IOobject.MUST_READ, IOobject.AUTO_WRITE), solidRegions[index])) return rhos, cps, rhosCps, Ks, Ts
def createFields(runTime, mesh, g): ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import autoPtr_basicPsiThermo, basicPsiThermo thermo = basicPsiThermo.New(mesh) from Foam.finiteVolume import volScalarField from Foam.OpenFOAM import IOobject, word, fileName rho = volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), thermo.rho()) p = thermo.p() h = thermo.h() psi = thermo.psi() ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi(runTime, mesh, rho, U) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.RASModel.New(rho, U, phi, thermo()) ext_Info() << "Calculating field g.h\n" << nl gh = volScalarField(word("gh"), g & mesh.C()) from Foam.finiteVolume import surfaceScalarField ghf = surfaceScalarField(word("ghf"), g & mesh.Cf()) ext_Info() << "Reading field p_rgh\n" << nl p_rgh = volScalarField( IOobject(word("p_rgh"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) #Force p_rgh to be consistent with p p_rgh.ext_assign(p - rho * gh) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell( p, p_rgh, mesh.solutionDict().subDict(word("SIMPLE")), pRefCell, pRefValue) from Foam import fvc initialMass = fvc.domainIntegrate(rho) totalVolume = mesh.V().ext_sum() return thermo, rho, p, h, psi, U, phi, turbulence, gh, ghf, p_rgh, pRefCell, pRefValue, initialMass, totalVolume
def _createFields( runTime, mesh, Omega, gHat ): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField ext_Info() << "Reading field h\n" << nl h = volScalarField( IOobject( word( "h" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.OpenFOAM import dimLength, dimensionedScalar ext_Info() << "Reading field h0 if present\n" << nl h0 = volScalarField( IOobject( word( "h0" ), fileName( runTime.findInstance( fileName( word( "polyMesh" ) ), word( "points" ) ) ) , mesh, IOobject.READ_IF_PRESENT ), mesh, dimensionedScalar( word( "h0" ), dimLength, 0.0 ) ) from Foam.finiteVolume import volVectorField ext_Info() << "Reading field U\n" << nl U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Creating field hU\n" << nl hU = volVectorField( IOobject( word( "hU" ), fileName( runTime.timeName() ), mesh ), h * U, U.ext_boundaryField().types() ) ext_Info() << "Creating field hTotal for post processing\n" << nl hTotal = volScalarField( IOobject( word( "hTotal" ), fileName( runTime.timeName() ), mesh, IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE ), h + h0 ) hTotal.write() phi = createPhi( runTime, hU, mesh ) ext_Info() << "Creating Coriolis Force" << nl from Foam.OpenFOAM import dimensionedVector F = dimensionedVector( word( "F" ), ( ( 2.0 * Omega ) & gHat ) * gHat ) return h, h0, U, hU, hTotal, phi, F
def create_fields(runTime, mesh, g): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicRhoThermo thermo = basicRhoThermo.New(mesh) from Foam.OpenFOAM import IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), thermo.rho()) p = thermo.p() h = thermo.h() psi = thermo.psi() ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi(runTime, mesh, rho, U) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.turbulenceModel.New(rho, U, phi, thermo()) ext_Info() << "Calculating field g.h\n" << nl gh = volScalarField(word("gh"), g & mesh.C()) from Foam.finiteVolume import surfaceScalarField ghf = surfaceScalarField(word("ghf"), g & mesh.Cf()) ext_Info() << "Reading field p_rgh\n" << nl p_rgh = volScalarField( IOobject(word("p_rgh"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) # Force p_rgh to be consistent with p p_rgh.ext_assign(p - rho * gh) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc DpDt = volScalarField( word("DpDt"), fvc.DDt(surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)), p)) return thermo, p, rho, h, psi, U, phi, turbulence, gh, ghf, p_rgh, DpDt
def _createFields( runTime, mesh, g ): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicRhoThermo thermo = basicRhoThermo.New( mesh ) from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField rho= volScalarField( IOobject( word( "rho" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.NO_WRITE ), thermo.rho() ) p = thermo.p() h = thermo.h() psi = thermo.psi() ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi( runTime, mesh, rho, U ) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.turbulenceModel.New( rho, U, phi, thermo() ) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc from Foam.finiteVolume import surfaceScalarField DpDt = volScalarField( word( "DpDt" ), fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) ) thermo.correct() initialMass = fvc.domainIntegrate(rho); totalVolume = mesh.V().ext_sum() return thermo, p, h, psi, phi, rho, U, turbulence, DpDt, initialMass, totalVolume
def _createFields(runTime, mesh): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicPsiThermo thermo = basicPsiThermo.New(mesh) p = thermo.p() e = thermo.e() T = thermo.T() psi = thermo.psi() mu = thermo.mu() inviscid = True if mu.internalField().max() > 0.0: inviscid = False pass ext_Info() << "Reading field U\n" << nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) pbf, rhoBoundaryTypes = _rhoBoundaryTypes(p) from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE), thermo.rho(), rhoBoundaryTypes) rhoU = volVectorField( IOobject(word("rhoU"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), rho * U) rhoE = volScalarField( IOobject(word("rhoE"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), rho * (e + 0.5 * U.magSqr())) from Foam.OpenFOAM import dimensionedScalar, dimless from Foam.finiteVolume import surfaceScalarField pos = surfaceScalarField( IOobject(word("pos"), fileName(runTime.timeName()), mesh), mesh, dimensionedScalar(word("pos"), dimless, 1.0)) neg = surfaceScalarField( IOobject(word("neg"), fileName(runTime.timeName()), mesh), mesh, dimensionedScalar(word("neg"), dimless, -1.0)) return thermo, p, e, T, psi, mu, U, pbf, rhoBoundaryTypes, rho, rhoU, rhoE, pos, neg, inviscid
def _createFields( runTime, mesh ): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField ext_Info() << "Reading field p\n" << nl p = volScalarField( IOobject( word( "p" ), fileName( runTime.timeName() ), mesh(), IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh() ) from Foam.finiteVolume import volVectorField ext_Info() << "Reading field U\n" << nl U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh() , IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh() ) from Foam.finiteVolume.cfdTools.incompressible import createPhi phi = createPhi( runTime, mesh(), U ) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "PIMPLE" ) ), pRefCell, pRefValue ) from Foam.transportModels import singlePhaseTransportModel laminarTransport = singlePhaseTransportModel( U, phi ) from Foam import incompressible turbulence = incompressible.turbulenceModel.New( U, phi, laminarTransport ) from Foam.finiteVolume import zeroGradientFvPatchScalarField ext_Info() << "Reading field rAU if present\n" << nl rAU = volScalarField( IOobject( word( "rAU" ), fileName( runTime.timeName() ), mesh(), IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE ), mesh(), runTime.deltaT(), zeroGradientFvPatchScalarField.typeName ) return p, U, phi, laminarTransport, turbulence, rAU, pRefCell, pRefValue
def _createFields(runTime, mesh): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField ext_Info() << "Reading field p\n" << nl p = volScalarField( IOobject(word("p"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh ) from Foam.finiteVolume.cfdTools.incompressible import createPhi phi = createPhi(runTime, mesh, U) from Foam.transportModels import singlePhaseTransportModel fluid = singlePhaseTransportModel(U, phi) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell(p, mesh.solutionDict().subDict(word("PISO")), pRefCell, pRefValue) return p, U, phi, fluid, pRefCell, pRefValue
def nu( self, *args): if len(args) > 1: raise AttributeError("len(args) > 1") if len(args) == 1: try: arg = float(args[0]) except ValueError: raise AttributeError ("The arg is not float") from Foam.finiteVolume import volScalarField, zeroGradientFvPatchScalarField from Foam.OpenFOAM import word, fileName, IOobject, dimensionedScalar, dimless result = volScalarField( IOobject( word( "nu" ), fileName( self.mesh().time().timeName() ), self.mesh(), IOobject.NO_READ, IOobject.NO_WRITE ), self.mesh(), dimensionedScalar( word( "zeroE" ), dimless, 0.0 ), zeroGradientFvPatchScalarField.typeName ) #Accumulate data for all fields for lawI in self: # Python does not wait for evaluation of the closure expression, it destroys return values if it is no more in use lawI_nu =lawI.nu() result.internalField().ext_assign( result.internalField() + \ self.indicator( self.index( lawI ) ) * lawI_nu.internalField() ) result.correctBoundaryConditions() return result
def mu( self, *args ): if len(args) > 1: raise AttributeError("len(args) > 1") flag = False if len(args) == 1: try: t = float(args[0]) flag = True except ValueError: raise AttributeError ("The arg is not float") if flag: lawE = self.lawPtr_.E( t ) lawNu = self.lawPtr_.nu( t ) else: lawE = self.lawPtr_.E() lawNu = self.lawPtr_.nu() from Foam.finiteVolume import volScalarField from Foam.OpenFOAM import word, fileName, IOobject result = volScalarField( IOobject( word( "mu" ), fileName( self.sigma_.time().timeName() ), self.sigma_.db(), IOobject.NO_READ, IOobject.NO_WRITE ), lawE / ( 2.0 * ( 1.0 + lawNu ) ) ) return result
def rho(self, *args): if len(args) > 1: raise AttributeError("len(args) > 1") if len(args) == 1: try: arg = float(args[0]) except ValueError: raise AttributeError("The arg is not float") from Foam.finiteVolume import volScalarField, zeroGradientFvPatchScalarField from Foam.OpenFOAM import word, fileName, IOobject, dimensionedScalar, dimDensity result = volScalarField( IOobject(word("rho"), fileName(self.mesh().time().timeName()), self.mesh(), IOobject.NO_READ, IOobject.NO_WRITE), self.mesh(), dimensionedScalar(word("zeroRho"), dimDensity, 0.0), zeroGradientFvPatchScalarField.typeName) #Accumulate data for all fields from Foam.OpenFOAM import ext_Info for lawI in self: # Python does not wait for evaluation of the closure expression, it destroys return values if it is no more in use lawI_rho = lawI.rho() result.internalField().ext_assign( result.internalField() + self.indicator(self.index(lawI)) * lawI_rho.internalField()) result.correctBoundaryConditions() return result
def _createFields(runTime, mesh): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicPsiThermo, autoPtr_basicPsiThermo thermo = basicPsiThermo.New(mesh) p = thermo.p() e = thermo.e() psi = thermo.psi() rho = thermo.rho() from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), mesh), rho()) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi(runTime, mesh, rho, U) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.turbulenceModel.New(rho, U, phi, thermo()) return p, e, psi, rho, U, phi, turbulence, thermo
def _createFields(runTime, mesh): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField ext_Info() << "Reading field p\n" << nl p = volScalarField( IOobject(word("p"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) from Foam.finiteVolume.cfdTools.incompressible import createPhi phi = createPhi(runTime, mesh, U) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell(p, mesh.solutionDict().subDict(word("PISO")), pRefCell, pRefValue) from Foam.transportModels import singlePhaseTransportModel laminarTransport = singlePhaseTransportModel(U, phi) from Foam import incompressible turbulence = incompressible.turbulenceModel.New(U, phi, laminarTransport) return p, U, phi, turbulence, pRefCell, pRefValue, laminarTransport
def _createFields( runTime, mesh ): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField ext_Info() << "Reading field T\n" << nl T = volScalarField( IOobject( word( "T" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Reading transportProperties\n" << nl transportProperties = IOdictionary( IOobject( word( "transportProperties" ), fileName( runTime.constant() ), mesh, IOobject.MUST_READ, IOobject.NO_WRITE ) ) ext_Info() << "Reading diffusivity DT\n" << nl from Foam.OpenFOAM import dimensionedScalar DT = dimensionedScalar( transportProperties.lookup( word( "DT" ) ) ) return T, transportProperties, DT
def _createFields(runTime, mesh, g): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicRhoThermo thermo = basicRhoThermo.New(mesh) from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), thermo.rho()) p = thermo.p() h = thermo.h() psi = thermo.psi() ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi(runTime, mesh, rho, U) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.turbulenceModel.New(rho, U, phi, thermo()) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc from Foam.finiteVolume import surfaceScalarField DpDt = volScalarField( word("DpDt"), fvc.DDt(surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)), p)) thermo.correct() initialMass = fvc.domainIntegrate(rho) totalVolume = mesh.V().ext_sum() return thermo, p, h, psi, phi, rho, U, turbulence, DpDt, initialMass, totalVolume
def fun_pEqn(runTime, mesh, p, phi, U, UEqn, g, rhok, eqnResidual, maxResidual, nNonOrthCorr, cumulativeContErr, pRefCell, pRefValue): from Foam.finiteVolume import volScalarField, surfaceScalarField from Foam.OpenFOAM import word from Foam import fvc rUA = volScalarField(word("rUA"), 1.0 / UEqn().A()) rUAf = surfaceScalarField(word("(1|A(U))"), fvc.interpolate(rUA)) U.ext_assign(rUA * UEqn().H()) UEqn.clear() from Foam import fvc phi.ext_assign(fvc.interpolate(U) & mesh.Sf()) from Foam.finiteVolume import adjustPhi adjustPhi(phi, U, p) buoyancyPhi = rUAf * fvc.interpolate(rhok) * (g & mesh.Sf()) phi.ext_assign(phi + buoyancyPhi) for nonOrth in range(nNonOrthCorr + 1): from Foam import fvm, fvc pEqn = fvm.laplacian(rUAf, p) == fvc.div(phi) pEqn.setReference(pRefCell, pRefValue) # retain the residual from the first iteration if (nonOrth == 0): eqnResidual = pEqn.solve().initialResidual() maxResidual = max(eqnResidual, maxResidual) pass else: pEqn.solve() pass if (nonOrth == nNonOrthCorr): # Calculate the conservative fluxes phi.ext_assign(phi - pEqn.flux()) # Explicitly relax pressure for momentum corrector p.relax() # Correct the momentum source with the pressure gradient flux # calculated from the relaxed pressure U.ext_assign(U + rUA * fvc.reconstruct((buoyancyPhi - pEqn.flux()) / rUAf)) U.correctBoundaryConditions() pass pass from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs(mesh, phi, runTime, cumulativeContErr) return eqnResidual, maxResidual, cumulativeContErr
def create_fields( runTime, mesh ): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicPsiThermo, autoPtr_basicPsiThermo thermo = basicPsiThermo.New( mesh ) p = thermo.p() h = thermo.h() psi = thermo.psi() from Foam.OpenFOAM import IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject( word( "rho" ), fileName( runTime.timeName() ), mesh, IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE ), thermo.rho() ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi( runTime, mesh, rho, U ) from Foam.OpenFOAM import dimensionedScalar pMin = dimensionedScalar( mesh.solutionDict().subDict( word( "PIMPLE" ) ).lookup( word( "pMin" ) ) ) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.turbulenceModel.New( rho, U, phi, thermo() ) # initialMass = fvc.domainIntegrate(rho) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc from Foam.finiteVolume import surfaceScalarField DpDt = fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) from Foam.finiteVolume import MRFZones mrfZones = MRFZones( mesh ) mrfZones.correctBoundaryVelocity( U ) from Foam.finiteVolume import porousZones pZones = porousZones( mesh ) from Foam.OpenFOAM import Switch pressureImplicitPorosity = Switch( False ) return thermo, turbulence, p, h, psi, rho, U, phi, pMin, DpDt, mrfZones, pZones, pressureImplicitPorosity
def _createFields(runTime, mesh, Omega, gHat): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField ext_Info() << "Reading field h\n" << nl h = volScalarField( IOobject(word("h"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) from Foam.OpenFOAM import dimLength, dimensionedScalar ext_Info() << "Reading field h0 if present\n" << nl h0 = volScalarField( IOobject( word("h0"), fileName( runTime.findInstance(fileName(word("polyMesh")), word("points"))), mesh, IOobject.READ_IF_PRESENT), mesh, dimensionedScalar(word("h0"), dimLength, 0.0)) from Foam.finiteVolume import volVectorField ext_Info() << "Reading field U\n" << nl U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) ext_Info() << "Creating field hU\n" << nl hU = volVectorField( IOobject(word("hU"), fileName(runTime.timeName()), mesh), h * U, U.ext_boundaryField().types()) ext_Info() << "Creating field hTotal for post processing\n" << nl hTotal = volScalarField( IOobject(word("hTotal"), fileName(runTime.timeName()), mesh, IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE), h + h0) hTotal.write() phi = createPhi(runTime, hU, mesh) ext_Info() << "Creating Coriolis Force" << nl from Foam.OpenFOAM import dimensionedVector F = dimensionedVector(word("F"), ((2.0 * Omega) & gHat) * gHat) return h, h0, U, hU, hTotal, phi, F
def fun_pEqn( runTime, mesh, p, phi, U, UEqn, g, rhok, eqnResidual, maxResidual, nNonOrthCorr, cumulativeContErr, pRefCell, pRefValue ): from Foam.finiteVolume import volScalarField, surfaceScalarField from Foam.OpenFOAM import word from Foam import fvc rUA = volScalarField( word( "rUA" ), 1.0 / UEqn().A() ) rUAf = surfaceScalarField(word( "(1|A(U))" ), fvc.interpolate( rUA ) ) U.ext_assign( rUA * UEqn().H() ) UEqn.clear() from Foam import fvc phi.ext_assign( fvc.interpolate( U ) & mesh.Sf() ) from Foam.finiteVolume import adjustPhi adjustPhi( phi, U, p ) buoyancyPhi = rUAf * fvc.interpolate( rhok ) * ( g & mesh.Sf() ) phi.ext_assign( phi + buoyancyPhi ) for nonOrth in range( nNonOrthCorr+1 ): from Foam import fvm, fvc pEqn = fvm.laplacian(rUAf, p) == fvc.div(phi) pEqn.setReference( pRefCell, pRefValue ) # retain the residual from the first iteration if ( nonOrth == 0 ): eqnResidual = pEqn.solve().initialResidual() maxResidual = max( eqnResidual, maxResidual ) pass else: pEqn.solve() pass if ( nonOrth == nNonOrthCorr ): # Calculate the conservative fluxes phi.ext_assign( phi - pEqn.flux() ) # Explicitly relax pressure for momentum corrector p.relax() # Correct the momentum source with the pressure gradient flux # calculated from the relaxed pressure U.ext_assign( U + rUA * fvc.reconstruct( ( buoyancyPhi - pEqn.flux() ) / rUAf ) ) U.correctBoundaryConditions() pass pass from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr ) return eqnResidual, maxResidual, cumulativeContErr
def create_fields( runTime, mesh ): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading field p\n" << nl from Foam.OpenFOAM import IOobject, word, fileName from Foam.finiteVolume import volScalarField p = volScalarField( IOobject( word( "p" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.finiteVolume.cfdTools.incompressible import createPhi phi = createPhi( runTime, mesh, U ) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "SIMPLE" ) ), pRefCell, pRefValue ) from Foam.transportModels import singlePhaseTransportModel laminarTransport = singlePhaseTransportModel( U, phi ) from Foam import incompressible turbulence = incompressible.RASModel.New( U, phi, laminarTransport ) from Foam.finiteVolume import porousZones pZones = porousZones( mesh ) from Foam.OpenFOAM import Switch pressureImplicitPorosity = Switch( False ) nUCorr = 0 if pZones.size(): # nUCorrectors for pressureImplicitPorosity if (mesh.solutionDict().subDict( word( "SIMPLE" ) ).found( word( "nUCorrectors" ) ) ) : from Foam.OpenFOAM import readInt nUCorr = readInt( mesh.solutionDict().subDict( word( "SIMPLE" ) ).lookup( word( "nUCorrectors" ) ) ) pass if nUCorr > 0 : pressureImplicitPorosity = True pass pass return p, U, phi, pRefCell, pRefValue, laminarTransport, turbulence, pZones, pressureImplicitPorosity, nUCorr
def calculateStress( runTime, mesh, sigma, _lambda ): if (runTime.outputTime()): from Foam.finiteVolume import volScalarField from Foam.OpenFOAM import word, IOobject, fileName sigmaEq = volScalarField( IOobject( word( "sigmaEq" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE ), ( (3.0/2.0)*sigma.dev() .magSqr() ).sqrt() ) ext_Info() << "Max sigmaEq = " << sigmaEq.ext_max().value() << nl from Foam.OpenFOAM import symmTensor sigmaxx = volScalarField( IOobject( word( "sigmaxx" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE ), sigma.component(symmTensor.XX) ) sigmayy = volScalarField( IOobject( word( "sigmayy" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE ), sigma.component(symmTensor.YY) ) sigmazz = volScalarField( IOobject( word( "sigmazz" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE ), sigma.component(symmTensor.ZZ) ) ext_Info() << "Max sigmazz = " << sigmazz.ext_max().value() << nl sigmaxy = volScalarField( IOobject( word( "sigmaxy" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE ), sigma.component(symmTensor.XY) ) sigmaxz = volScalarField( IOobject( word( "sigmaxz" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE ), sigma.component(symmTensor.XZ) ) sigmayz = volScalarField( IOobject( word( "sigmayz" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE ), sigma.component(symmTensor.YZ) ) runTime.write() pass
def correctPhi(runTime, mesh, phi, pd, rho, U, cumulativeContErr, nNonOrthCorr, pdRefCell, pdRefValue): from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs(mesh, phi, runTime, cumulativeContErr) from Foam.OpenFOAM import wordList from Foam.finiteVolume import zeroGradientFvPatchScalarField pcorrTypes = wordList(pd.ext_boundaryField().size(), zeroGradientFvPatchScalarField.typeName) from Foam.finiteVolume import fixedValueFvPatchScalarField for i in range(pd.ext_boundaryField().size()): if pd.ext_boundaryField()[i].fixesValue(): pcorrTypes[i] = fixedValueFvPatchScalarField.typeName pass pass from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName, dimensionedScalar from Foam.finiteVolume import volScalarField pcorr = volScalarField( IOobject(word("pcorr"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), mesh, dimensionedScalar(word("pcorr"), pd.dimensions(), 0.0), pcorrTypes, ) from Foam.OpenFOAM import dimTime rUAf = dimensionedScalar(word("(1|A(U))"), dimTime / rho.dimensions(), 1.0) from Foam.finiteVolume import adjustPhi adjustPhi(phi, U, pcorr) from Foam import fvc, fvm for nonOrth in range(nNonOrthCorr + 1): pcorrEqn = fvm.laplacian(rUAf, pcorr) == fvc.div(phi) pcorrEqn.setReference(pdRefCell, pdRefValue) pcorrEqn.solve() if nonOrth == nNonOrthCorr: phi.ext_assign(phi - pcorrEqn.flux()) pass from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs(mesh, phi, runTime, cumulativeContErr) pass
def create_fields(runTime, mesh): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading field p\n" << nl from Foam.OpenFOAM import IOobject, word, fileName from Foam.finiteVolume import volScalarField p = volScalarField( IOobject(word("p"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) from Foam.finiteVolume.cfdTools.incompressible import createPhi phi = createPhi(runTime, mesh, U) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict(word("SIMPLE")), pRefCell, pRefValue) from Foam.transportModels import singlePhaseTransportModel laminarTransport = singlePhaseTransportModel(U, phi) from Foam import incompressible turbulence = incompressible.RASModel.New(U, phi, laminarTransport) from Foam.finiteVolume import porousZones pZones = porousZones(mesh) from Foam.OpenFOAM import Switch pressureImplicitPorosity = Switch(False) nUCorr = 0 if pZones.size(): # nUCorrectors for pressureImplicitPorosity if (mesh.solutionDict().subDict(word("SIMPLE")).found( word("nUCorrectors"))): from Foam.OpenFOAM import readInt nUCorr = readInt(mesh.solutionDict().subDict( word("SIMPLE")).lookup(word("nUCorrectors"))) pass if nUCorr > 0: pressureImplicitPorosity = True pass pass return p, U, phi, pRefCell, pRefValue, laminarTransport, turbulence, pZones, pressureImplicitPorosity, nUCorr
def create_fields(runTime, mesh): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicPsiThermo, autoPtr_basicPsiThermo thermo = basicPsiThermo.New(mesh) p = thermo.p() h = thermo.h() psi = thermo.psi() from Foam.OpenFOAM import IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), mesh, IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE), thermo.rho()) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi(runTime, mesh, rho, U) from Foam.OpenFOAM import dimensionedScalar pMin = dimensionedScalar(mesh.solutionDict().subDict( word("PIMPLE")).lookup(word("pMin"))) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.turbulenceModel.New(rho, U, phi, thermo()) # initialMass = fvc.domainIntegrate(rho) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc from Foam.finiteVolume import surfaceScalarField DpDt = fvc.DDt( surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)), p) from Foam.finiteVolume import MRFZones mrfZones = MRFZones(mesh) mrfZones.correctBoundaryVelocity(U) from Foam.finiteVolume import porousZones pZones = porousZones(mesh) from Foam.OpenFOAM import Switch pressureImplicitPorosity = Switch(False) return thermo, turbulence, p, h, psi, rho, U, phi, pMin, DpDt, mrfZones, pZones, pressureImplicitPorosity
def _createFields(runTime, mesh): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField ext_Info() << "Reading field p\n" << nl p = volScalarField( IOobject(word("p"), fileName(runTime.timeName()), mesh(), IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh()) from Foam.finiteVolume import volVectorField ext_Info() << "Reading field U\n" << nl U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh(), IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh()) from Foam.finiteVolume.cfdTools.incompressible import createPhi phi = createPhi(runTime, mesh(), U) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict(word("PIMPLE")), pRefCell, pRefValue) from Foam.transportModels import singlePhaseTransportModel laminarTransport = singlePhaseTransportModel(U, phi) from Foam import incompressible turbulence = incompressible.turbulenceModel.New(U, phi, laminarTransport) from Foam.finiteVolume import zeroGradientFvPatchScalarField ext_Info() << "Reading field rAU if present\n" << nl rAU = volScalarField( IOobject(word("rAU"), fileName(runTime.timeName()), mesh(), IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE), mesh(), runTime.deltaT(), zeroGradientFvPatchScalarField.typeName) return p, U, phi, laminarTransport, turbulence, rAU, pRefCell, pRefValue
def sigmaY(self): from Foam.finiteVolume import volScalarField, zeroGradientFvPatchScalarField from Foam.OpenFOAM import word, fileName, IOobject, dimensionedScalar, dimForce, dimArea, GREAT tresult = volScalarField( IOobject(word("sigmaY"), fileName(self.mesh().time().timeName()), self.mesh(), IOobject.NO_READ, IOobject.NO_WRITE), self.mesh(), dimensionedScalar(word("zeroSigmaY"), dimForce / dimArea, GREAT), zeroGradientFvPatchScalarField.typeName) tresult().correctBoundaryConditions() return tresult
def _createFields( runTime, mesh ): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicPsiThermo thermo = basicPsiThermo.New( mesh ) from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject( word( "rho" ), fileName( runTime.timeName() ), mesh, IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE ), thermo.rho() ) p = thermo.p() h = thermo.h() psi = thermo.psi() ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi( runTime, mesh, rho, U ) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "SIMPLE" ) ), pRefCell, pRefValue ) from Foam.OpenFOAM import dimensionedScalar pMin = dimensionedScalar( mesh.solutionDict().subDict( word( "SIMPLE" ) ).lookup( word( "pMin" ) ) ) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.RASModel.New( rho, U, phi, thermo() ) from Foam.OpenFOAM import dimensionedScalar from Foam import fvc initialMass = fvc.domainIntegrate( rho ) return thermo, rho, p, h, psi, U, phi, pRefCell, pRefValue, turbulence, initialMass, pMin
def _correctPhi( runTime, mesh, p, rAU, phi, nNonOrthCorr, pRefCell, pRefValue, cumulativeContErr ): if mesh.changing(): for patchi in range( U.boundaryField().size() ): if U.boundaryField()[patchi].fixesValue(): U.boundaryField()[patchi].initEvaluate() pass pass for patchi in range( U.boundaryField().size() ): if U.boundaryField()[patchi].fixesValue(): U.boundaryField()[patchi].evaluate() phi.boundaryField()[patchi].ext_assign( U.boundaryField()[patchi] & mesh.Sf().boundaryField()[patchi] ) pass pass pass from Foam.OpenFOAM import wordList from Foam.finiteVolume import zeroGradientFvPatchScalarField pcorrTypes = wordList( p.ext_boundaryField().size(), zeroGradientFvPatchScalarField.typeName ) from Foam.finiteVolume import fixedValueFvPatchScalarField for i in range( p.ext_boundaryField().size() ): if p.ext_boundaryField()[i].fixesValue(): pcorrTypes[i] = fixedValueFvPatchScalarField.typeName pass pass from Foam.finiteVolume import volScalarField from Foam.OpenFOAM import IOobject, word, fileName, dimensionedScalar pcorr = volScalarField( IOobject( word( "pcorr" ), fileName( runTime.timeName() ), mesh(), IOobject.NO_READ, IOobject.NO_WRITE ), mesh(), dimensionedScalar( word( "pcorr" ), p.dimensions(), 0.0), pcorrTypes ) for nonOrth in range( nNonOrthCorr + 1 ): from Foam import fvm,fvc pcorrEqn = ( fvm.laplacian( rAU, pcorr ) == fvc.div( phi ) ) pcorrEqn.setReference(pRefCell, pRefValue) pcorrEqn.solve() if nonOrth == nNonOrthCorr: phi.ext_assign( phi - pcorrEqn.flux() ) pass pass from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs cumulativeContErr = ContinuityErrs( phi, runTime, mesh, cumulativeContErr ) return cumulativeContErr
def _correctPhi(runTime, mesh, p, rAU, phi, nNonOrthCorr, pRefCell, pRefValue, cumulativeContErr): if mesh.changing(): for patchi in range(U.boundaryField().size()): if U.boundaryField()[patchi].fixesValue(): U.boundaryField()[patchi].initEvaluate() pass pass for patchi in range(U.boundaryField().size()): if U.boundaryField()[patchi].fixesValue(): U.boundaryField()[patchi].evaluate() phi.boundaryField()[patchi].ext_assign( U.boundaryField()[patchi] & mesh.Sf().boundaryField()[patchi]) pass pass pass from Foam.OpenFOAM import wordList from Foam.finiteVolume import zeroGradientFvPatchScalarField pcorrTypes = wordList(p.ext_boundaryField().size(), zeroGradientFvPatchScalarField.typeName) from Foam.finiteVolume import fixedValueFvPatchScalarField for i in range(p.ext_boundaryField().size()): if p.ext_boundaryField()[i].fixesValue(): pcorrTypes[i] = fixedValueFvPatchScalarField.typeName pass pass from Foam.finiteVolume import volScalarField from Foam.OpenFOAM import IOobject, word, fileName, dimensionedScalar pcorr = volScalarField( IOobject(word("pcorr"), fileName(runTime.timeName()), mesh(), IOobject.NO_READ, IOobject.NO_WRITE), mesh(), dimensionedScalar(word("pcorr"), p.dimensions(), 0.0), pcorrTypes) for nonOrth in range(nNonOrthCorr + 1): from Foam import fvm, fvc pcorrEqn = (fvm.laplacian(rAU, pcorr) == fvc.div(phi)) pcorrEqn.setReference(pRefCell, pRefValue) pcorrEqn.solve() if nonOrth == nNonOrthCorr: phi.ext_assign(phi - pcorrEqn.flux()) pass pass from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs cumulativeContErr = ContinuityErrs(phi, runTime, mesh, cumulativeContErr) return cumulativeContErr
def _createFields(runTime, mesh, R, Cv): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading field p\n" << nl from Foam.finiteVolume import volScalarField from Foam.OpenFOAM import IOdictionary, IOobject, fileName, word p = volScalarField( IOobject(word("p"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) ext_Info() << "Reading field T\n" << nl T = volScalarField( IOobject(word("T"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) ext_Info() << "Calculating field e from T\n" << nl e = volScalarField( IOobject(word("e"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), Cv * T, T.ext_boundaryField().types()) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) psi = volScalarField( IOobject(word("psi"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), 1.0 / (R * T)) psi.oldTime() rho = volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), mesh), psi * p) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi(runTime, mesh, rho, U) return p, T, e, U, psi, rho, phi
def threeK( self ): lawRho = self.lawPtr_.rho() lawE = self.lawPtr_.E() lawNu = self.lawPtr_.nu() from Foam.finiteVolume import volScalarField from Foam.OpenFOAM import word, fileName, IOobject if self.planeStress(): result = volScalarField( IOobject( word( "threeK" ), fileName( self.sigma_.time().timeName() ), self.sigma_.db(), IOobject.NO_READ, IOobject.NO_WRITE ), lawE / ( lawRho * ( 1 - lawNu ) ) ) else: result = volScalarField( IOobject( word( "threeK" ), fileName( self.sigma_.time().timeName() ), self.sigma_.db(), IOobject.NO_READ, IOobject.NO_WRITE ), lawE / ( lawRho * ( 1 - 2 * lawNu ) ) ) return result
def sigmaY( self ): from Foam.finiteVolume import volScalarField, zeroGradientFvPatchScalarField from Foam.OpenFOAM import word, fileName, IOobject, dimensionedScalar, dimForce, dimArea, GREAT tresult = volScalarField( IOobject( word( "sigmaY" ), fileName( self.mesh().time().timeName() ), self.mesh(), IOobject.NO_READ, IOobject.NO_WRITE ), self.mesh(), dimensionedScalar( word( "zeroSigmaY" ), dimForce/dimArea, GREAT), zeroGradientFvPatchScalarField.typeName ) tresult().correctBoundaryConditions() return tresult
def _createFields( runTime, mesh ): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicPsiThermo thermo = basicPsiThermo.New( mesh ) from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject( word( "rho" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.NO_WRITE ), thermo.rho() ) p = thermo.p() h = thermo.h() psi = thermo.psi() ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi( runTime, mesh, rho, U ) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.RASModel.New( rho, U, phi, thermo() ) thermo.correct() pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "SIMPLE" ) ), pRefCell, pRefValue ) from Foam import fvc initialMass = fvc.domainIntegrate(rho) return thermo, rho, p, h, psi, U, phi, turbulence, initialMass, pRefCell, pRefValue
def _TEqn( turbulence, T, phi, rhok, beta, TRef, Pr, Prt ): from Foam.OpenFOAM import word from Foam.finiteVolume import volScalarField kappaEff = volScalarField( word( "kappaEff" ), turbulence.nu() / Pr + turbulence.ext_nut() / Prt ) from Foam import fvc, fvm TEqn = fvm.ddt( T ) + fvm.div( phi, T ) - fvm.laplacian( kappaEff, T ) TEqn.relax() TEqn.solve() rhok.ext_assign( 1.0 - beta * ( T - TRef ) ) return TEqn, kappaEff
def _createFields(runTime, mesh, rhoO, psi): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading field p\n" << nl from Foam.finiteVolume import volScalarField from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName p = volScalarField( IOobject(word("p"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) rho = volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE), rhoO + psi * p) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi(runTime, mesh, rho, U) return p, U, rho, phi
def _createFields(runTime, mesh): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicPsiThermo, autoPtr_basicPsiThermo thermo = basicPsiThermo.New(mesh) p = thermo.p() h = thermo.h() psi = thermo.psi() from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), mesh, IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE), thermo.rho(), ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi(runTime, mesh, rho, U) from Foam.OpenFOAM import dimensionedScalar pMin = dimensionedScalar(mesh.solutionDict().subDict(word("PIMPLE")).lookup(word("pMin"))) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.turbulenceModel.New(rho, U, phi, thermo()) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc from Foam.finiteVolume import surfaceScalarField DpDt = fvc.DDt(surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)), p) return p, h, psi, rho, U, phi, turbulence, thermo, pMin, DpDt
def correctPhi( runTime, mesh, phi, p, rho, U, cumulativeContErr, nNonOrthCorr, pRefCell, pRefValue ): from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr ) from Foam.OpenFOAM import wordList from Foam.finiteVolume import zeroGradientFvPatchScalarField pcorrTypes = wordList( p.ext_boundaryField().size(), zeroGradientFvPatchScalarField.typeName ) from Foam.finiteVolume import fixedValueFvPatchScalarField for i in range( p.ext_boundaryField().size() ): if p.ext_boundaryField()[i].fixesValue(): pcorrTypes[i] = fixedValueFvPatchScalarField.typeName pass pass from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName, dimensionedScalar from Foam.finiteVolume import volScalarField pcorr = volScalarField( IOobject( word( "pcorr" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.NO_WRITE ), mesh, dimensionedScalar( word( "pcorr" ), p.dimensions(), 0.0 ), pcorrTypes ) from Foam.OpenFOAM import dimTime rUAf = dimensionedScalar( word( "(1|A(U))" ), dimTime / rho.dimensions(), 1.0) from Foam.finiteVolume import adjustPhi adjustPhi(phi, U, pcorr) from Foam import fvc, fvm for nonOrth in range( nNonOrthCorr + 1 ): pcorrEqn = fvm.laplacian( rUAf, pcorr ) == fvc.div( phi ) pcorrEqn.setReference(pRefCell, pRefValue) pcorrEqn.solve() if nonOrth == nNonOrthCorr: phi.ext_assign( phi - pcorrEqn.flux() ) pass from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr ) pass
def fun_TEqn( turbulence, phi, T, rhok, beta, TRef, Pr, Prt, eqnResidual, maxResidual ): from Foam.OpenFOAM import word from Foam.finiteVolume import volScalarField kappaEff = volScalarField( word( "kappaEff" ), turbulence.nu() / Pr + turbulence.ext_nut() / Prt ) from Foam import fvc, fvm TEqn = fvm.div( phi, T ) - fvm.Sp( fvc.div( phi ), T ) - fvm.laplacian( kappaEff, T ) TEqn.relax() eqnResidual = TEqn.solve().initialResidual() maxResidual = max(eqnResidual, maxResidual) rhok.ext_assign( 1.0 - beta * ( T - TRef ) ) return TEqn, kappaEff
def createFields( runTime, mesh ): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicThermo, autoPtr_basicThermo thermo = basicThermo.New( mesh ) p = thermo.p() h = thermo.h() psi = thermo.psi() rho = thermo.rho() from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject( word( "rho" ), fileName( runTime.timeName() ), mesh ), rho ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi( runTime, mesh, rho, U ) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.RASModel.New( rho, U, phi, thermo() ) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc from Foam.finiteVolume import surfaceScalarField DpDt = fvc.DDt( surfaceScalarField(word( "phiU" ), phi / fvc.interpolate( rho ) ), p ); return thermo, p, h, psi, rho, U, phi, turbulence, DpDt
def nu(self, *args): if len(args) > 1: raise AttributeError("len(args) > 1") if len(args) == 1: try: arg = float(args[0]) except ValueError: raise AttributeError("The args is not float") from Foam.finiteVolume import volScalarField, zeroGradientFvPatchScalarField from Foam.OpenFOAM import word, fileName, IOobject tresult = volScalarField( IOobject(word("nu"), fileName(self.mesh().time().timeName()), self.mesh(), IOobject.NO_READ, IOobject.NO_WRITE), self.mesh(), self.nu_, zeroGradientFvPatchScalarField.typeName) tresult.correctBoundaryConditions() return tresult
def _createFields( runTime, mesh ): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField ext_Info() << "Reading field p\n" << nl p = volScalarField( IOobject( word( "p" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.NO_WRITE ), mesh ) from Foam.OpenFOAM import dimensionedScalar p.ext_assign( dimensionedScalar( word( "zero" ), p.dimensions(), 0.0 ) ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.OpenFOAM import dimensionedVector, vector U.ext_assign( dimensionedVector( word( "0" ), U.dimensions(), vector.zero ) ) from Foam.finiteVolume import surfaceScalarField from Foam import fvc phi = surfaceScalarField( IOobject( word( "phi" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE ), fvc.interpolate( U ) & mesh.Sf() ) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "SIMPLE" ) ), pRefCell, pRefValue ) return p, U, phi, pRefCell, pRefValue
def __init__(self, name, sigma, dict_): from Foam.OpenFOAM import word, dictionary from Foam.finiteVolume import volSymmTensorField try: name = word(str(name)) except ValueError: raise AttributeError("The second arg is not string") try: volSymmTensorField.ext_isinstance(sigma) except TypeError: raise AssertionError("sigma != volSymmTensorField") from Foam.OpenFOAM import dictionary try: dictionary.ext_isinstance(dict_) except TypeError: raise AssertionError("dict_ != dictionary") rheologyLaw.__init__(self, name, sigma, dict_) from Foam.OpenFOAM import IOobject, fileName from Foam.finiteVolume import volScalarField self.materials_ = volScalarField( IOobject(word("materials"), fileName(self.mesh().time().timeName()), self.mesh(), IOobject.MUST_READ, IOobject.AUTO_WRITE), self.mesh()) from Foam.OpenFOAM import PtrList_entry lawEntries = PtrList_entry(dict_.lookup(word("laws"))) for lawI in range(lawEntries.size()): self.append( rheologyLaw.New(lawEntries[lawI].keyword(), sigma, lawEntries[lawI].dict())) from Foam.OpenFOAM import SMALL if self.materials_.ext_min().value() < 0 or self.materials_.ext_max( ).value() > (len(self) + SMALL): raise IOError(" Invalid definition of material indicator field.") pass
def calculateStress(runTime, mesh, sigma, _lambda): if (runTime.outputTime()): from Foam.finiteVolume import volScalarField from Foam.OpenFOAM import word, IOobject, fileName sigmaEq = volScalarField( IOobject(word("sigmaEq"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE), ((3.0 / 2.0) * sigma.dev().magSqr()).sqrt()) ext_Info() << "Max sigmaEq = " << sigmaEq.ext_max().value() << nl from Foam.OpenFOAM import symmTensor sigmaxx = volScalarField( IOobject(word("sigmaxx"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE), sigma.component(symmTensor.XX)) sigmayy = volScalarField( IOobject(word("sigmayy"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE), sigma.component(symmTensor.YY)) sigmazz = volScalarField( IOobject(word("sigmazz"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE), sigma.component(symmTensor.ZZ)) ext_Info() << "Max sigmazz = " << sigmazz.ext_max().value() << nl sigmaxy = volScalarField( IOobject(word("sigmaxy"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE), sigma.component(symmTensor.XY)) sigmaxz = volScalarField( IOobject(word("sigmaxz"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE), sigma.component(symmTensor.XZ)) sigmayz = volScalarField( IOobject(word("sigmayz"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE), sigma.component(symmTensor.YZ)) runTime.write() pass
def fun_TEqn(turbulence, phi, T, rhok, beta, TRef, Pr, Prt, eqnResidual, maxResidual): from Foam.OpenFOAM import word from Foam.finiteVolume import volScalarField kappaEff = volScalarField( word("kappaEff"), turbulence.nu() / Pr + turbulence.ext_nut() / Prt) from Foam import fvc, fvm TEqn = fvm.div(phi, T) - fvm.Sp(fvc.div(phi), T) - fvm.laplacian( kappaEff, T) TEqn.relax() eqnResidual = TEqn.solve().initialResidual() maxResidual = max(eqnResidual, maxResidual) rhok.ext_assign(1.0 - beta * (T - TRef)) return TEqn, kappaEff
def __init__( self, name, sigma, dict_ ): from Foam.OpenFOAM import word, dictionary from Foam.finiteVolume import volSymmTensorField try: name = word( str( name ) ) except ValueError: raise AttributeError("The second arg is not string") try: volSymmTensorField.ext_isinstance( sigma ) except TypeError: raise AssertionError( "sigma != volSymmTensorField" ) from Foam.OpenFOAM import dictionary try: dictionary.ext_isinstance( dict_ ) except TypeError: raise AssertionError( "dict_ != dictionary" ) rheologyLaw.__init__(self, name, sigma, dict_ ) from Foam.OpenFOAM import IOobject, fileName from Foam.finiteVolume import volScalarField self.materials_ = volScalarField( IOobject( word( "materials" ), fileName( self.mesh().time().timeName() ), self.mesh(), IOobject.MUST_READ, IOobject.AUTO_WRITE ), self.mesh() ) from Foam.OpenFOAM import PtrList_entry lawEntries = PtrList_entry( dict_.lookup( word("laws") ) ) for lawI in range( lawEntries.size() ): self.append( rheologyLaw.New( lawEntries[lawI].keyword(), sigma, lawEntries[lawI].dict() ) ) from Foam.OpenFOAM import SMALL if self.materials_.ext_min().value() < 0 or self.materials_.ext_max().value() > (len(self) + SMALL): raise IOError(" Invalid definition of material indicator field.") pass
def createFields( runTime, mesh ): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading transportProperties\n" from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName transportProperties = IOdictionary( IOobject( word( "transportProperties" ), fileName( runTime.constant() ), mesh, IOobject.MUST_READ, IOobject.NO_WRITE ) ) from Foam.OpenFOAM import dimensionedScalar nu = dimensionedScalar( transportProperties.lookup( word( "nu" ) ) ); ext_Info() << "Reading field p\n" << nl from Foam.finiteVolume import volScalarField p = volScalarField( IOobject( word( "p" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.finiteVolume.cfdTools.incompressible import createPhi phi = createPhi( runTime, mesh, U ) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "PISO" ) ), pRefCell, pRefValue ) return transportProperties, nu, p, U, phi, pRefCell, pRefValue