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 readEnvironmentalProperties(runTime, mesh): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nReading environmentalProperties" << nl from Foam.OpenFOAM import IOdictionary, fileName, word, IOobject environmentalProperties = IOdictionary( IOobject(word("environmentalProperties"), fileName(runTime.constant()), mesh, IOobject.MUST_READ, IOobject.NO_WRITE)) from Foam.OpenFOAM import dimensionedVector g = dimensionedVector(environmentalProperties.lookup(word("g"))) return g, environmentalProperties
def readEnvironmentalProperties( runTime, mesh ): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nReading environmentalProperties" << nl from Foam.OpenFOAM import IOdictionary, fileName, word, IOobject environmentalProperties = IOdictionary( IOobject( word( "environmentalProperties" ), fileName( runTime.constant() ), mesh, IOobject.MUST_READ, IOobject.NO_WRITE ) ) from Foam.OpenFOAM import dimensionedVector g = dimensionedVector( environmentalProperties.lookup( word( "g" ) ) ) return g, environmentalProperties
def readGravitationalAcceleration(runTime, mesh): from Foam.OpenFOAM import IOdictionary, word, fileName, IOobject from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nReading gravitationalProperties" << nl gravitationalProperties = IOdictionary( IOobject(word("gravitationalProperties"), fileName(runTime.constant()), mesh, IOobject.MUST_READ, IOobject.NO_WRITE)) from Foam.OpenFOAM import dimensionedVector, Switch, dimTime g = dimensionedVector(gravitationalProperties.lookup(word("g"))) rotating = Switch(gravitationalProperties.lookup(word("rotating"))) if rotating: Omega = dimensionedVector(gravitationalProperties.lookup( word("Omega"))) else: Omega = dimensionedVector(word("Omega"), -dimTime, vector(0, 0, 0)) magg = g.mag() gHat = g / magg return gravitationalProperties, g, rotating, Omega, magg, gHat
def readGravitationalAcceleration( runTime, mesh ): from Foam.OpenFOAM import IOdictionary, word, fileName, IOobject from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nReading gravitationalProperties" << nl gravitationalProperties = IOdictionary( IOobject( word( "gravitationalProperties" ), fileName( runTime.constant() ), mesh, IOobject.MUST_READ, IOobject.NO_WRITE ) ) from Foam.OpenFOAM import dimensionedVector,Switch, dimTime g = dimensionedVector( gravitationalProperties.lookup( word( "g" ) ) ) rotating = Switch( gravitationalProperties.lookup( word( "rotating" ) ) ) if rotating: Omega = dimensionedVector( gravitationalProperties.lookup( word( "Omega" ) ) ) else: Omega = dimensionedVector( word( "Omega" ), -dimTime, vector( 0,0,0 ) ) magg = g.mag() gHat = g / magg return gravitationalProperties, g, rotating, Omega, magg, gHat
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 _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 readTransportProperties(runTime, mesh): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName ext_Info() << "\nReading transportProperties\n" << nl transportProperties = IOdictionary( IOobject(word("transportProperties"), fileName(runTime.constant()), mesh, IOobject.MUST_READ, IOobject.NO_WRITE, False)) from Foam.OpenFOAM import dimensionedScalar, dimensionedVector nu = dimensionedScalar(transportProperties.lookup(word("nu"))) # Read centerline velocity for channel simulations Ubar = dimensionedVector(transportProperties.lookup(word("Ubar"))) magUbar = Ubar.mag() from Foam.OpenFOAM import vector flowDirection = (Ubar / magUbar).ext_value() return transportProperties, nu, Ubar, magUbar, flowDirection
def readTransportProperties( runTime, mesh): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName ext_Info() << "\nReading transportProperties\n" << nl transportProperties = IOdictionary( IOobject( word( "transportProperties" ), fileName( runTime.constant() ), mesh, IOobject.MUST_READ, IOobject.NO_WRITE, False ) ) from Foam.OpenFOAM import dimensionedScalar, dimensionedVector nu = dimensionedScalar( transportProperties.lookup( word( "nu" ) ) ) # Read centerline velocity for channel simulations Ubar = dimensionedVector( transportProperties.lookup( word( "Ubar" ) ) ) magUbar = Ubar.mag() from Foam.OpenFOAM import vector flowDirection = ( Ubar / magUbar ).ext_value() return transportProperties, nu, Ubar, magUbar, flowDirection
def _createFields( runTime, mesh ): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName 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 face flux\n" << nl from Foam.OpenFOAM import dimensionedScalar from Foam.finiteVolume import surfaceScalarField phi = surfaceScalarField( IOobject( word( "phi" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.NO_WRITE ), mesh, dimensionedScalar( word( "zero" ), mesh.Sf().dimensions()*U.dimensions(), 0.0) ) from Foam.transportModels import singlePhaseTransportModel laminarTransport = singlePhaseTransportModel( U, phi ) from Foam import incompressible turbulence = incompressible.RASModel.New( U, phi, laminarTransport ) transportProperties = IOdictionary( IOobject( word( "transportProperties" ), fileName( runTime.constant() ), mesh, IOobject.MUST_READ, IOobject.NO_WRITE ) ) from Foam.OpenFOAM import dimensionedVector, vector Ubar = dimensionedVector( transportProperties.lookup( word( "Ubar" ) ) ) flowDirection = ( Ubar / Ubar.mag() ).ext_value() flowMask = flowDirection.sqr() nWallFaces = 0.0 from Foam.OpenFOAM import vector wallNormal = vector.zero patches = mesh.boundary() for patchi in range( mesh.boundary().size() ): currPatch = patches[patchi] from Foam.finiteVolume import wallFvPatch if wallFvPatch.ext_isType( currPatch ): for facei in range( currPatch.size() ): nWallFaces = nWallFaces +1 if nWallFaces == 1: wallNormal = - mesh.Sf().ext_boundaryField()[patchi][facei] / mesh.magSf().ext_boundaryField()[patchi][facei] pass elif nWallFaces == 2: wallNormal2 = mesh.Sf().ext_boundaryField()[patchi][facei] / mesh.magSf().ext_boundaryField()[patchi][facei] #- Check that wall faces are parallel from Foam.OpenFOAM import mag if mag(wallNormal & wallNormal2) > 1.01 or mag(wallNormal & wallNormal2) < 0.99: ext_Info() << "boundaryFoam: wall faces are not parallel" << nl import os os.abort() pass pass else: ext_Info() << "boundaryFoam: number of wall faces > 2" << nl import os os.abort() pass pass pass #- create position array for graph generation y = wallNormal & mesh.C().internalField() from Foam.OpenFOAM import dimensionSet, vector, word gradP = dimensionedVector( word( "gradP" ), dimensionSet( 0.0, 1.0, -2.0, 0.0, 0.0 ), vector( 0.0, 0.0, 0.0 ) ) return U, phi, laminarTransport, turbulence, Ubar, wallNormal, flowDirection, flowMask, y, gradP
ext_Info() << " Adding to turb\n" << nl from Foam import compressible turb.ext_set( index, compressible.RASModel.New( rhof[ index ], Uf[ index ], phif[ index ], thermof[ index ] ) ) ext_Info() << " Adding to DpDtf\n" << nl from Foam import fvc DpDtf.ext_set( index, volScalarField( fvc.DDt( surfaceScalarField( word( "phiU" ), phif[ index ] / fvc.interpolate( rhof[ index ] ) ), thermof[ index ].p() ) ) ) from Foam.OpenFOAM import IOdictionary environmentalProperties = IOdictionary.ext_lookupObject( fluidRegions[ index ], word( "environmentalProperties" ) ) from Foam.OpenFOAM import dimensionedVector g = dimensionedVector( environmentalProperties.lookup( word( "g" ) ) ) ext_Info() << " Adding to ghf\n" << nl ghf.ext_set( index, volScalarField( word( "gh" ), g & fluidRegions[ index ].C() ) ) ext_Info() << " Updating p from pd\n" << nl thermof[ index ].p() == pdf[ index ] + rhof[ index ] * ghf[ index ] + pRef thermof[ index ].correct() initialMassf[ index ] = fvc.domainIntegrate( rhof[ index ] ).value() return pdf, thermof, rhof, Kf, Uf, phif, turb, DpDtf, ghf, initialMassf, pRef #-----------------------------------------------------------------------------------------------------------------------