def alphaEqns(runTime, mesh, rho1, rho2, rhoPhi, phic, dgdt, divU, alpha1, alpha2, phi, interface, nAlphaCorr): alphaScheme = ref.word("div(phi,alpha)") alpharScheme = ref.word("div(phirb,alpha)") phir = phic * interface.nHatf() for gCorr in range(nAlphaCorr): Sp = ref.volScalarField.DimensionedInternalField( ref.IOobject(ref.word("Sp"), ref.fileName(runTime.timeName()), mesh), mesh, ref.dimensionedScalar(ref.word("Sp"), dgdt.dimensions(), 0.0)) Su = ref.volScalarField.DimensionedInternalField( ref.IOobject(ref.word("Su"), ref.fileName(runTime.timeName()), mesh), # Divergence term is handled explicitly to be # consistent with the explicit transport solution divU * alpha1.ext_min(1.0)) for celli in range(dgdt.size()): if dgdt[celli] > 0.0 and alpha1[celli] > 0.0: Sp[celli] -= dgdt[celli] * alpha1[celli] Su[celli] += dgdt[celli] * alpha1[celli] pass elif dgdt[celli] < 0.0 and alpha1[celli] < 1.0: Sp[celli] += dgdt[celli] * (1.0 - alpha1[celli]) pass pass phiAlpha1 = ref.fvc.flux(phi, alpha1, alphaScheme) + ref.fvc.flux( -ref.fvc.flux(-phir, alpha2, alpharScheme), alpha1, alpharScheme) ref.MULES.explicitSolve(ref.geometricOneField(), alpha1, phi, phiAlpha1, Sp, Su, 1.0, 0.0) rho1f = ref.fvc.interpolate(rho1) rho2f = ref.fvc.interpolate(rho2) rhoPhi << phiAlpha1 * (rho1f - rho2f) + phi * rho2f alpha2 << 1.0 - alpha1 pass from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Liquid phase volume fraction = " << alpha1.weightedAverage( mesh.V() ).value() \ << " Min(alpha1) = " << alpha1.ext_min().value() << " Min(alpha2) = " << alpha2.ext_min().value() << nl pass
def readGravitationalAcceleration(runTime, mesh): ref.ext_Info() << "\nReading g" << ref.nl g = ref.uniformDimensionedVectorField( ref.IOobject(ref.word("g"), ref.fileName(runTime.constant()), mesh, ref.IOobject.MUST_READ, ref.IOobject.NO_WRITE)) return g
def createDynamicFvMesh_020000(runTime): from Foam import ref ref.ext_Info() << "Create mesh for time = " << runTime.timeName( ) << ref.nl << ref.nl mesh = ref.dynamicFvMesh.New( ref.IOobject(ref.dynamicFvMesh.defaultRegion.fget(), ref.fileName(runTime.timeName()), runTime, ref.IOobject.MUST_READ)) return mesh
def write(runTime, mesh, T): if runTime.outputTime(): gradT = ref.fvc.grad(T) gradTx = ref.volScalarField( ref.IOobject(ref.word("gradTx"), ref.fileName(runTime.timeName()), mesh, ref.IOobject.NO_READ, ref.IOobject.AUTO_WRITE), gradT.component(ref.vector.X)) gradTy = ref.volScalarField( ref.IOobject(ref.word("gradTy"), ref.fileName(runTime.timeName()), mesh, ref.IOobject.NO_READ, ref.IOobject.AUTO_WRITE), gradT.component(ref.vector.Y)) gradTz = ref.volScalarField( ref.IOobject(ref.word("gradTz"), ref.fileName(runTime.timeName()), mesh, ref.IOobject.NO_READ, ref.IOobject.AUTO_WRITE), gradT.component(ref.vector.Z)) runTime.write() 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 _correctPhi(runTime, mesh, pimple, p, U, rAU, phi, pRefCell, pRefValue, cumulativeContErr): if mesh.changing(): for patchi in range(U.ext_boundaryField().size()): if U.ext_boundaryField()[patchi].fixesValue(): U.ext_boundaryField()[patchi].initEvaluate() pass pass for patchi in range(U.ext_boundaryField().size()): if U.ext_boundaryField()[patchi].fixesValue(): U.ext_boundaryField()[patchi].evaluate() phi.ext_boundaryField()[patchi] << ( U.ext_boundaryField()[patchi] & mesh.Sf().ext_boundaryField()[patchi]) pass pass pass pcorrTypes = ref.wordList(p.ext_boundaryField().size(), ref.zeroGradientFvPatchScalarField.typeName) for i in range(p.ext_boundaryField().size()): if p.ext_boundaryField()[i].fixesValue(): pcorrTypes[i] = ref.fixedValueFvPatchScalarField.typeName pass pass pcorr = ref.volScalarField( ref.IOobject(ref.word("pcorr"), ref.fileName(runTime.timeName()), mesh, ref.IOobject.NO_READ, ref.IOobject.NO_WRITE), mesh, ref.dimensionedScalar(ref.word("pcorr"), p.dimensions(), 0.0), pcorrTypes) while pimple.correctNonOrthogonal(): pcorrEqn = (ref.fvm.laplacian(rAU, pcorr) == ref.fvc.div(phi)) pcorrEqn.setReference(pRefCell, pRefValue) pcorrEqn.solve() if pimple.finalNonOrthogonalIter(): phi << phi() - pcorrEqn.flux() # mixed calculations pass pass cumulativeContErr = ref.ContinuityErrs(phi, runTime, mesh, cumulativeContErr) return cumulativeContErr
def correctPhi(runTime, mesh, phi, p, p_rgh, rho, U, cumulativeContErr, pimple, pRefCell, pRefValue): cumulativeContErr = ref.ContinuityErrs(phi, runTime, mesh, cumulativeContErr) pcorrTypes = ref.wordList(p_rgh.ext_boundaryField().size(), ref.zeroGradientFvPatchScalarField.typeName) for i in range(p.ext_boundaryField().size()): if p_rgh.ext_boundaryField()[i].fixesValue(): pcorrTypes[i] = ref.fixedValueFvPatchScalarField.typeName pass pass pcorr = ref.volScalarField( ref.IOobject(ref.word("pcorr"), ref.fileName(runTime.timeName()), mesh, ref.IOobject.NO_READ, ref.IOobject.NO_WRITE), mesh(), ref.dimensionedScalar(ref.word("pcorr"), p_rgh.dimensions(), 0.0), pcorrTypes) rAUf = ref.dimensionedScalar(ref.word("(1|A(U))"), ref.dimTime / rho.dimensions(), 1.0) ref.adjustPhi(phi, U, pcorr) while pimple.correctNonOrthogonal(): pcorrEqn = ref.fvm.laplacian(rAUf, pcorr) == ref.fvc.div(phi) pcorrEqn.setReference(pRefCell, pRefValue) pcorrEqn.solve() if pimple.finalNonOrthogonalIter(): phi -= pcorrEqn.flux() pass cumulativeContErr = ref.ContinuityErrs(phi, runTime, mesh, cumulativeContErr) return cumulativeContErr
def makeGraphs(runTime, mesh, U, turbulence, faceId, patchId, nWallFaces, wallNormal, cellId, flowDirection, y): R = ref.volSymmTensorField( ref.IOobject(ref.word("R"), ref.fileName(runTime.timeName()), mesh(), ref.IOobject.NO_READ, ref.IOobject.AUTO_WRITE), turbulence.R()) runTime.write() gFormat = runTime.graphFormat() ref.makeGraph(y, flowDirection & U(), ref.word("Uf"), gFormat) ref.makeGraph(y, turbulence.ext_nu(), gFormat) ref.makeGraph(y, turbulence.ext_k(), gFormat) ref.makeGraph(y, turbulence.ext_epsilon(), gFormat) ref.makeGraph(y, flowDirection & R & flowDirection, ref.word("Rff"), gFormat) ref.makeGraph(y, wallNormal & R & wallNormal, ref.word("Rww"), gFormat) ref.makeGraph(y, flowDirection & R & wallNormal, ref.word("Rfw"), gFormat) ref.makeGraph(y, R.component(ref.symmTensor.XX).mag().sqrt(), ref.word("u"), gFormat) ref.makeGraph(y, R.component(ref.symmTensor.YY).mag().sqrt(), ref.word("v"), gFormat) ref.makeGraph(y, R.component(ref.symmTensor.ZZ).mag().sqrt(), ref.word("w"), gFormat) ref.makeGraph(y, R.component(ref.symmTensor.XY), ref.word("uv"), gFormat) ref.makeGraph(y, ref.fvc.grad(U).mag(), ref.word("gammaDot"), gFormat) pass