Ejemplo n.º 1
0
def _createFields(runTime, mesh):

    ref.ext_Info() << "Reading field U\n" << ref.nl
    U = man.volVectorField(
        man.IOobject(ref.word("U"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.AUTO_WRITE), mesh)

    ref.ext_Info() << "Creating face flux\n" << ref.nl
    phi = man.surfaceScalarField(
        man.IOobject(ref.word("phi"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.NO_READ, ref.IOobject.NO_WRITE), mesh,
        ref.dimensionedScalar(ref.word("zero"),
                              mesh.Sf().dimensions() * U.dimensions(), 0.0))

    laminarTransport = man.singlePhaseTransportModel(U, phi)

    turbulence = man.incompressible.RASModel.New(U, phi, laminarTransport)

    transportProperties = man.IOdictionary(
        man.IOobject(ref.word("transportProperties"),
                     ref.fileName(runTime.constant()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.NO_WRITE))
    Ubar = ref.dimensionedVector(transportProperties.lookup(ref.word("Ubar")))

    flowDirection = (Ubar / Ubar.mag()).ext_value()
    flowMask = flowDirection.sqr()

    gradP = ref.dimensionedVector(ref.word("gradP"),
                                  ref.dimensionSet(0.0, 1.0, -2.0, 0.0, 0.0),
                                  ref.vector(0.0, 0.0, 0.0))

    return U, phi, laminarTransport, turbulence, Ubar, gradP, flowDirection, flowMask
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
Ejemplo n.º 3
0
def _createFields(runTime, mesh):

    ref.ext_Info() << "Reading field p\n" << ref.nl
    p = man.volScalarField(
        man.IOobject(
            ref.word("p"), ref.fileName(runTime.timeName()), mesh, ref.IOobject.MUST_READ, ref.IOobject.AUTO_WRITE
        ),
        mesh,
    )

    ref.ext_Info() << "Reading field U\n" << ref.nl
    U = man.volVectorField(
        man.IOobject(
            ref.word("U"), ref.fileName(runTime.timeName()), mesh, ref.IOobject.MUST_READ, ref.IOobject.AUTO_WRITE
        ),
        mesh,
    )

    phi = man.createPhi(runTime, mesh, U)

    pRefCell = 0
    pRefValue = 0.0

    pRefCell, pRefValue = ref.setRefCell(p, mesh.solutionDict().subDict(ref.word("PISO")), pRefCell, pRefValue)

    laminarTransport = man.singlePhaseTransportModel(U, phi)

    turbulence = man.incompressible.turbulenceModel.New(U, phi, laminarTransport)

    return p, U, phi, turbulence, pRefCell, pRefValue, laminarTransport
Ejemplo n.º 4
0
def _createFields(runTime, mesh, potentialFlow, args):

    ref.ext_Info() << "Reading field p\n" << ref.nl
    p = man.volScalarField(
        man.IOobject(ref.word("p"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.NO_WRITE), mesh)

    p << ref.dimensionedScalar(ref.word("zero"), p.dimensions(), 0.0)

    ref.ext_Info() << "Reading field U\n" << ref.nl
    U = man.volVectorField(
        man.IOobject(ref.word("U"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.AUTO_WRITE), mesh)

    U << ref.dimensionedVector(ref.word("0"), U.dimensions(), ref.vector.zero)

    phi = man.surfaceScalarField(
        man.IOobject(ref.word("phi"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.NO_READ, ref.IOobject.AUTO_WRITE),
        man.fvc.interpolate(U)
        & man.surfaceVectorField(mesh.Sf(), man.Deps(mesh)))

    if args.optionFound(ref.word("initialiseUBCs")):
        U.correctBoundaryConditions()
        phi << (ref.fvc.interpolate(U) & mesh.Sf())
        pass

    pRefCell = 0
    pRefValue = 0.0

    pRefCell, pRefValue = ref.setRefCell(p, potentialFlow, pRefCell, pRefValue)

    return p, U, phi, pRefCell, pRefValue
Ejemplo n.º 5
0
def fun_pEqn( mesh, runTime, pimple, thermo, rho, p, h, psi, U, phi, mrfZones, turbulence, UEqn, dpdt, K, cumulativeContErr, rhoMax, rhoMin ):

    rho << thermo.rho()
    rho << rho().ext_max( rhoMin )
    rho << rho().ext_min( rhoMax )
    rho.relax()

    rAU = 1.0 / UEqn.A()
    U << rAU() * UEqn.H()

    if pimple.transonic():
        phid = ref.surfaceScalarField( ref.word( "phid" ), ref.fvc.interpolate( psi ) * ( ( ref.fvc.interpolate( U ) & mesh.Sf() ) \
                                                                                          + ref.fvc.ddtPhiCorr( rAU, rho, U, phi ) ) );
        mrfZones.relativeFlux( ref.fvc.interpolate( psi ), phid )
        
        while pimple.correctNonOrthogonal():
            pEqn = ref.fvm.ddt( psi, p) + ref.fvm.div( phid, p ) - ref.fvm.laplacian( rho() * rAU, p ) # mixed calculations
            
            pEqn.solve( mesh.solver( p.select( pimple.finalInnerIter() ) ) )

            if pimple.finalNonOrthogonalIter():
                phi == pEqn.flux()
                pass
            pass
        pass
    else:
        phi << ref.fvc.interpolate( rho ) * ( ( ref.fvc.interpolate( U ) & mesh.Sf() ) + ref.fvc.ddtPhiCorr( rAU, rho, U, phi ) )
        
        mrfZones.relativeFlux( ref.fvc.interpolate( rho ), phi )
        
        while pimple.correctNonOrthogonal():
            pEqn = ref.fvm.ddt( psi, p ) + ref.fvc.div( phi ) - ref.fvm.laplacian( rho()*rAU, p )  # mixed calculations
            
            pEqn.solve( mesh.solver( p.select( pimple.finalInnerIter() ) ) )
            
            if pimple.finalNonOrthogonalIter():
                phi += pEqn.flux()
                pass
            pass    
        pass

    ref.rhoEqn( rho, phi )
    cumulativeContErr = ref.compressibleContinuityErrs( rho(), thermo, cumulativeContErr ) # mixed calculations
    # Explicitly relax pressure for momentum corrector
    p.relax()
    
    # Recalculate density from the relaxed pressure
    rho << thermo.rho()
    rho << rho().ext_max( rhoMin )
    rho << rho().ext_min( rhoMax )
    rho.relax()
    ref.ext_Info()<< "rho max/min : " << rho.ext_max().value()  << " " << rho.ext_min().value() << ref.nl

    U -= rAU * ref.fvc.grad( p )
    U.correctBoundaryConditions()

    K << 0.5 * U.magSqr()
    dpdt << ref.fvc.ddt( p )
    
    return cumulativeContErr
Ejemplo n.º 6
0
def _createFields( runTime, mesh ):
        
    ref.ext_Info() << "Reading field p\n" << ref.nl
    p = man.volScalarField( man.IOobject( ref.word( "p" ),
                                          ref.fileName( runTime.timeName() ),
                                          mesh,
                                          ref.IOobject.MUST_READ,
                                          ref.IOobject.AUTO_WRITE ),
                            mesh )
    
    ref.ext_Info() << "Reading field U\n" << ref.nl
    U = man.volVectorField( man.IOobject( ref.word( "U" ),
                                          ref.fileName( runTime.timeName() ),
                                          mesh,
                                          ref.IOobject.MUST_READ,
                                          ref.IOobject.AUTO_WRITE ),
                            mesh )
    
    phi = man.createPhi( runTime, mesh, U )
    
    fluid = man.singlePhaseTransportModel( U, phi )
    
    pRefCell = 0
    pRefValue = 0.0
    
    pRefCell, pRefValue = ref.setRefCell( p, mesh.solutionDict().subDict( ref.word( "PISO" ) ), pRefCell, pRefValue )

        
    return p, U, phi, fluid, pRefCell, pRefValue
Ejemplo n.º 7
0
def _createFields(runTime, mesh, potentialFlow):

    ref.ext_Info() << "Reading field p\n" << ref.nl
    p = man.volScalarField(
        man.IOobject(
            ref.word("p"), ref.fileName(runTime.timeName()), mesh, ref.IOobject.MUST_READ, ref.IOobject.NO_WRITE
        ),
        mesh,
    )

    p << ref.dimensionedScalar(ref.word("zero"), p.dimensions(), 0.0)

    ref.ext_Info() << "Reading field U\n" << ref.nl
    U = man.volVectorField(
        man.IOobject(
            ref.word("U"), ref.fileName(runTime.timeName()), mesh, ref.IOobject.MUST_READ, ref.IOobject.AUTO_WRITE
        ),
        mesh,
    )

    U << ref.dimensionedVector(ref.word("0"), U.dimensions(), ref.vector.zero)

    phi = man.surfaceScalarField(
        man.IOobject(
            ref.word("phi"), ref.fileName(runTime.timeName()), mesh, ref.IOobject.NO_READ, ref.IOobject.AUTO_WRITE
        ),
        man.fvc.interpolate(U) & man.surfaceVectorField(mesh.Sf(), man.Deps(mesh)),
    )

    pRefCell = 0
    pRefValue = 0.0

    pRefCell, pRefValue = ref.setRefCell(p, potentialFlow, pRefCell, pRefValue)

    return p, U, phi, pRefCell, pRefValue
Ejemplo n.º 8
0
def CourantNo(runTime, mesh, h, phi, magg):
    CoNum = 0.0
    meanCoNum = 0.0
    waveCoNum = 0.0

    if mesh.nInternalFaces():
        phi_mag = ref.fvc.surfaceSum(phi.mag())
        sumPhi = phi_mag.internalField() / h.internalField()
        V = mesh.V()
        CoNum = 0.5 * (sumPhi / V.field()).gMax() * runTime.deltaTValue()
        V_field = V.field()
        meanCoNum = 0.5 * (sumPhi.gSum() /
                           V_field.gSum()) * runTime.deltaTValue()
        # Gravity wave Courant number
        waveCoNum = 0.25 * (
            ref.fvc.surfaceSum(
                ref.fvc.interpolate(h.sqrt()) * mesh.magSf()).internalField() /
            V.field()).gMax() * magg.sqrt().value() * runTime.deltaTValue()
        pass

    ref.ext_Info(
    ) << "Courant number mean: " << meanCoNum << " max: " << CoNum << ref.nl
    ref.ext_Info(
    ) << "Gravity wave Courant number max: " << waveCoNum << ref.nl

    return CoNum, meanCoNum, waveCoNum
Ejemplo n.º 9
0
def readGravitationalAcceleration(runTime, mesh):
    ref.ext_Info() << "\nReading gravitationalProperties" << ref.nl

    gravitationalProperties = man.IOdictionary(
        man.IOobject(
            ref.word("gravitationalProperties"),
            ref.fileName(runTime.constant()),
            mesh,
            ref.IOobject.MUST_READ_IF_MODIFIED,
            ref.IOobject.NO_WRITE,
        )
    )

    g = ref.dimensionedVector(gravitationalProperties.lookup(ref.word("g")))
    rotating = ref.Switch(gravitationalProperties.lookup(ref.word("rotating")))

    if rotating:
        Omega = ref.dimensionedVector(gravitationalProperties.lookup(ref.word("Omega")))
    else:
        Omega = ref.dimensionedVector(ref.word("Omega"), -ref.dimTime, ref.vector(0, 0, 0))

    magg = g.mag()
    gHat = g / magg

    return gravitationalProperties, g, rotating, Omega, magg, gHat
Ejemplo n.º 10
0
def createFields( runTime, mesh, rhoO, psi ):
    ref.ext_Info()<< "Reading field p\n" << ref.nl
    p = man.volScalarField( man.IOobject( ref.word( "p" ),
                                          ref.fileName( runTime.timeName() ),
                                          mesh,
                                          ref.IOobject.MUST_READ,
                                          ref.IOobject.AUTO_WRITE ),
                            mesh )


    ref.ext_Info()<< "Reading field U\n" << ref.nl
    U = man.volVectorField( man.IOobject( ref.word( "U" ),
                                          ref.fileName( runTime.timeName() ),
                                          mesh,
                                          ref.IOobject.MUST_READ,
                                          ref.IOobject.AUTO_WRITE ),
                            mesh )
    
    rho = man.volScalarField( man.IOobject( ref.word( "rho" ),
                                            ref.fileName( runTime.timeName() ),
                                            mesh,
                                            ref.IOobject.NO_READ,
                                            ref.IOobject.AUTO_WRITE ),
                              rhoO + psi * p )
  
    phi = man.compressibleCreatePhi( runTime, mesh, U, rho )
  
    return p, U, rho, phi
Ejemplo n.º 11
0
def fun_pEqn( mesh, runTime, simple, thermo, rho, p, h, psi, U, phi, turbulence, \
                      gh, ghf, p_rgh, UEqn, pRefCell, pRefValue, cumulativeContErr, initialMass):

    rho << thermo.rho()
    rho.relax()

    rAU = 1.0 / UEqn.A()
    rhorAUf = ref.surfaceScalarField(ref.word("(rho*(1|A(U)))"),
                                     ref.fvc.interpolate(rho() * rAU))

    U << rAU * UEqn.H()

    phi << ref.fvc.interpolate(rho) * (ref.fvc.interpolate(U()) & mesh.Sf())

    closedVolume = ref.adjustPhi(phi, U, p_rgh)

    buoyancyPhi = rhorAUf * ghf * ref.fvc.snGrad(rho) * mesh.magSf()
    phi -= buoyancyPhi

    while simple.correctNonOrthogonal():

        p_rghEqn = (ref.fvm.laplacian(rhorAUf, p_rgh) == ref.fvc.div(phi))
        p_rghEqn.setReference(pRefCell, ref.getRefCellValue(p_rgh, pRefCell))
        p_rghEqn.solve()

        if simple.finalNonOrthogonalIter():
            # Calculate the conservative fluxes
            phi -= p_rghEqn.flux()

            # Explicitly relax pressure for momentum corrector
            p_rgh.relax()

            # Correct the momentum source with the pressure gradient flux
            # calculated from the relaxed pressure
            U -= rAU * ref.fvc.reconstruct(
                (buoyancyPhi + p_rghEqn.flux()) / rhorAUf)
            U.correctBoundaryConditions()
            pass
        pass

    cumulativeContErr = ref.ContinuityErrs(phi, runTime, mesh,
                                           cumulativeContErr)

    p << p_rgh + rho * gh

    # For closed-volume cases adjust the pressure level
    # to obey overall mass continuity
    if closedVolume:
        p += (initialMass -
              ref.fvc.domainIntegrate(psi * p)) / ref.fvc.domainIntegrate(psi)
        p_rgh << p - rho * gh
        pass

    rho << thermo.rho()
    rho.relax()

    ref.ext_Info() << "rho max/min : " << rho.ext_max().value(
    ) << " " << rho.ext_min().value() << ref.nl

    return cumulativeContErr
Ejemplo n.º 12
0
def _createFields(runTime, mesh):

    ref.ext_Info() << "Reading field p\n" << ref.nl
    p = man.volScalarField(
        man.IOobject(ref.word("p"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.AUTO_WRITE), mesh)

    ref.ext_Info() << "Reading field U\n" << ref.nl

    U = man.volVectorField(
        man.IOobject(ref.word("U"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.AUTO_WRITE), mesh)

    phi = man.createPhi(runTime, mesh, U)

    pRefCell = 0
    pRefValue = 0.0

    pRefCell, pRefValue = ref.setRefCell(
        p,
        mesh.solutionDict().subDict(ref.word("PIMPLE")), pRefCell, pRefValue)

    laminarTransport = man.singlePhaseTransportModel(U, phi)

    turbulence = man.incompressible.turbulenceModel.New(
        U, phi, laminarTransport)

    return p, U, phi, turbulence, pRefCell, pRefValue, laminarTransport
Ejemplo n.º 13
0
def createFields(runTime, mesh, pimple):
    ref.ext_Info() << "Reading thermophysical properties\n" << ref.nl

    pThermo = man.basicPsiThermo.New(mesh)

    p = man.volScalarField(pThermo.p(), man.Deps(pThermo))
    h = man.volScalarField(pThermo.h(), man.Deps(pThermo))
    psi = man.volScalarField(pThermo.psi(), man.Deps(pThermo))

    rho = man.volScalarField(
        man.IOobject(ref.word("rho"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.READ_IF_PRESENT, ref.IOobject.AUTO_WRITE),
        man.volScalarField(pThermo.rho(), man.Deps(pThermo)))

    ref.ext_Info() << "Reading field U\n" << ref.nl
    U = man.volVectorField(
        man.IOobject(ref.word("U"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.AUTO_WRITE), mesh)

    phi = man.compressibleCreatePhi(runTime, mesh, U, rho)

    rhoMax = ref.dimensionedScalar(pimple.dict().lookup(ref.word("rhoMax")))
    rhoMin = ref.dimensionedScalar(pimple.dict().lookup(ref.word("rhoMin")))

    ref.ext_Info() << "Creating turbulence model\n" << ref.nl
    turbulence = man.compressible.turbulenceModel.New(rho, U, phi, pThermo)

    ref.ext_Info() << "Creating field dpdt\n" << ref.nl
    dpdt = man.volScalarField(ref.word("dpdt"), man.fvc.ddt(p))

    ref.ext_Info() << "Creating field kinetic energy K\n" << ref.nl
    K = man.volScalarField(ref.word("K"),
                           man.volScalarField(0.5 * U.magSqr(), man.Deps(U)))

    return pThermo, p, h, psi, rho, U, phi, rhoMax, rhoMin, turbulence, dpdt, K
Ejemplo n.º 14
0
def CourantNo(runTime, mesh, h, phi, magg):
    CoNum = 0.0
    meanCoNum = 0.0
    waveCoNum = 0.0

    if mesh.nInternalFaces():
        phi_mag = ref.fvc.surfaceSum(phi.mag())
        sumPhi = phi_mag.internalField() / h.internalField()
        V = mesh.V()
        CoNum = 0.5 * (sumPhi / V.field()).gMax() * runTime.deltaTValue()
        V_field = V.field()
        meanCoNum = 0.5 * (sumPhi.gSum() / V_field.gSum()) * runTime.deltaTValue()
        # Gravity wave Courant number
        waveCoNum = (
            0.25
            * (ref.fvc.surfaceSum(ref.fvc.interpolate(h.sqrt()) * mesh.magSf()).internalField() / V.field()).gMax()
            * magg.sqrt().value()
            * runTime.deltaTValue()
        )
        pass

    ref.ext_Info() << "Courant number mean: " << meanCoNum << " max: " << CoNum << ref.nl
    ref.ext_Info() << "Gravity wave Courant number max: " << waveCoNum << ref.nl

    return CoNum, meanCoNum, waveCoNum
Ejemplo n.º 15
0
def fun_pEqn( mesh, runTime, pimple, thermo, rho, p, h, psi, U, phi, mrfZones, turbulence, UEqn, DpDt, cumulativeContErr, corr, rhoMax, rhoMin ):

    rho << thermo.rho()
    rho << rho().ext_max( rhoMin )
    rho << rho().ext_min( rhoMax )
    rho.relax()

    rAU = 1.0 / UEqn.A()
    U << rAU() * UEqn.H()

    if pimple.transonic():
        phid = ref.surfaceScalarField( ref.word( "phid" ), ref.fvc.interpolate( psi ) * ( ( ref.fvc.interpolate( U ) & mesh.Sf() ) \
                                                                                          + ref.fvc.ddtPhiCorr( rAU, rho, U, phi ) ) );
        mrfZones.relativeFlux( ref.fvc.interpolate( psi ), phid )
        
        for nonOrth in range( pimple.nNonOrthCorr() + 1 ):
            pEqn = ref.fvm.ddt( psi, p) + ref.fvm.div( phid, p ) - ref.fvm.laplacian( rho() * rAU, p ) # mixed calculations
            
            pEqn.solve( mesh.solver( p.select( pimple.finalInnerIter( corr, nonOrth ) ) ) )

            if nonOrth == pimple.nNonOrthCorr():
                phi == pEqn.flux()
                pass
            pass
        pass
    else:
        phi << ref.fvc.interpolate( rho ) * ( ( ref.fvc.interpolate( U ) & mesh.Sf() ) + ref.fvc.ddtPhiCorr( rAU, rho, U, phi ) )
        
        mrfZones.relativeFlux( ref.fvc.interpolate( rho ), phi )
        
        for nonOrth in range( pimple.nNonOrthCorr() + 1 ):
            pEqn = ref.fvm.ddt( psi, p ) + ref.fvc.div( phi ) - ref.fvm.laplacian( rho()*rAU, p )  # mixed calculations
            
            pEqn.solve( mesh.solver( p.select( pimple.finalInnerIter( corr, nonOrth ) ) ) )
            
            if nonOrth == pimple.nNonOrthCorr():
                phi += pEqn.flux()
                pass
            pass    
        pass

    ref.rhoEqn( rho, phi )
    cumulativeContErr = ref.compressibleContinuityErrs( rho(), thermo, cumulativeContErr ) # mixed calculations
    # Explicitly relax pressure for momentum corrector
    p.relax()
    
    # Recalculate density from the relaxed pressure
    rho << thermo.rho()
    rho << rho().ext_max( rhoMin )
    rho << rho().ext_min( rhoMax )
    rho.relax()
    ref.ext_Info()<< "rho max/min : " << rho.ext_max().value()  << " " << rho.ext_min().value() << ref.nl

    U -= rAU * ref.fvc.grad( p )
    U.correctBoundaryConditions()

    DpDt << ref.fvc.DDt( ref.surfaceScalarField( ref.word( "phiU" ), phi() / ref.fvc.interpolate( rho ) ), p ) # mixed calculations
    
    return cumulativeContErr
Ejemplo n.º 16
0
def interrogateWallPatches( mesh ):
    # Search for wall patches faces and store normals
    
    faceId = -1
    patchId = -1
    nWallFaces = 0
    wallNormal = ref.vector.zero

    patches = mesh.boundary()
    
    for patchi in range( patches.size() ):
        currPatch = patches[ patchi ]
        
        if ref.wallFvPatch.ext_isA( currPatch ):
            nf = currPatch.nf()
            
            for facei in range( nf.size() ):
                nWallFaces = nWallFaces +1
                if nWallFaces == 1:
                    wallNormal = -nf()[ facei ]
                    faceId = facei
                    patchId = patchi
                    pass
                elif nWallFaces == 2:
                    wallNormal2 = -nf()[ facei ]
                    #- Check that wall faces are parallel
                    if ref.mag( wallNormal & wallNormal2 ) > 1.01 or ref.mag( wallNormal & wallNormal2 ) < 0.99:
                        ref.ext_Info() << "wall faces are not parallel for patches " << patches[ patchId ].name() << " and " \
                                       << currPatch.name() << nl
                        import os; os.abort()
                        pass
                    pass
                else:
                    ref.ext_Info() << "number of wall faces > 2"<< nl
                    import os; os.abort()
                    pass
                pass
            pass
        pass

    if nWallFaces == 0:
        ref.ext_Info() << "No wall patches identified"
        import os; os.abort()
        pass
    else:
        ref.ext_Info()<< "Generating wall data for patch: " << patches[ patchId ].name() << ref.nl
        pass
    pass


    # store local id of near-walll cell to process
    cellId = patches[ patchId ].faceCells()[ faceId ];

    # create position array for graph generation
    y = wallNormal & ( mesh.C().internalField() - mesh.C().ext_boundaryField()[ patchId ][ faceId ] )

    ref.ext_Info() << "    Height to first cell centre y0 = " << y[ cellId ] << ref.nl
    
    return faceId, patchId, nWallFaces, wallNormal, cellId, y
Ejemplo n.º 17
0
def main_standalone( argc, argv ):

    ref.argList.addBoolOption( ref.word( "writep" ), "write the final pressure field" )
    ref.argList.addBoolOption( ref.word( "initialiseUBCs" ), "initialise U boundary conditions" )
    
    args = ref.setRootCase( argc, argv )

    runTime = man.createTime( args )
    
    mesh = man.createMesh( runTime )
    
    potentialFlow, nNonOrthCorr = readControls( mesh )

    p, U, phi, pRefCell, pRefValue = _createFields( runTime, mesh, potentialFlow,args )

    ref.ext_Info() << ref.nl << "Calculating potential flow" << ref.nl
    
    # Since solver contains no time loop it would never execute
    # function objects so do it ourselves.
    runTime.functionObjects().start()
    
    ref.adjustPhi(phi, U, p)
    
    for nonOrth in range( nNonOrthCorr + 1):
        pEqn = ( ref.fvm.laplacian( ref.dimensionedScalar( ref.word( "1" ), ref.dimTime / p.dimensions() * ref.dimensionSet( 0.0, 2.0, -2.0, 0.0, 0.0 ), 1.0 ), p ) 
                == ref.fvc.div( phi ) )
        
        pEqn.setReference( pRefCell, pRefValue )
        pEqn.solve()

        if nonOrth == nNonOrthCorr:
           phi -= pEqn.flux()
           pass
        pass
    
    ref.ext_Info() << "continuity error = " << ref.fvc.div( phi ).mag().weightedAverage( mesh.V() ).value() << ref.nl

    U << ref.fvc.reconstruct( phi )
    U.correctBoundaryConditions()
    ref.ext_Info() << "Interpolated U error = " << ( ( ( ref.fvc.interpolate( U ) & mesh.Sf() ) - phi ).sqr().sum().sqrt()  /mesh.magSf().sum() ).value() << ref.nl

    # Force the write
    U.write()
    phi.write()
    
    if args.optionFound( ref.word( "writep" ) ):
       p.write()
       pass
       
    runTime.functionObjects().end()
    
    ref.ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \
              "  ClockTime = " << runTime.elapsedClockTime() << " s" << ref.nl << ref.nl
        
    ref.ext_Info() << "End\n" << ref.nl 

    import os
    return os.EX_OK
def fun_pEqn( mesh, runTime, simple, thermo, rho, p, h, psi, U, phi, turbulence, \
                      gh, ghf, p_rgh, UEqn, pRefCell, pRefValue, cumulativeContErr, initialMass):
      
      rho << thermo.rho()
      rho.relax()

      rAU = 1.0 / UEqn.A()
      rhorAUf = ref.surfaceScalarField( ref.word( "(rho*(1|A(U)))" ), ref.fvc.interpolate( rho() * rAU ) )
      
      U << rAU * UEqn.H()
      
      #UEqn.clear()
      
      phi << ref.fvc.interpolate( rho ) * ( ref.fvc.interpolate( U() ) & mesh.Sf() )
      
      closedVolume = ref.adjustPhi( phi, U, p_rgh )
      
      buoyancyPhi = rhorAUf * ghf * ref.fvc.snGrad( rho ) * mesh.magSf()
      
      phi -= buoyancyPhi

      for nonOrth in range( simple.nNonOrthCorr() + 1 ):

          p_rghEqn = ( ref.fvm.laplacian( rhorAUf, p_rgh ) == ref.fvc.div( phi ) )
          
          p_rghEqn.setReference( pRefCell, ref.getRefCellValue( p_rgh, pRefCell ) )
          p_rghEqn.solve()

          if nonOrth == simple.nNonOrthCorr():
              # Calculate the conservative fluxes
              phi -= p_rghEqn.flux()
              
              # Explicitly relax pressure for momentum corrector
              p_rgh.relax()
              
              # Correct the momentum source with the pressure gradient flux
              # calculated from the relaxed pressure
              U -= rAU * ref.fvc.reconstruct( ( buoyancyPhi + p_rghEqn.flux() ) / rhorAUf )
              U.correctBoundaryConditions()
              pass
          pass
  
      cumulativeContErr = ref.ContinuityErrs( phi, runTime, mesh, cumulativeContErr )
      
      p << p_rgh + rho * gh

      # For closed-volume cases adjust the pressure level
      # to obey overall mass continuity
      if closedVolume:
          p += ( initialMass - ref.fvc.domainIntegrate( psi * p ) ) / ref.fvc.domainIntegrate( psi ) 
          p_rgh << p - rho * gh
          pass
      rho << thermo.rho()
      rho.relax()
      
      ref.ext_Info() << "rho max/min : " <<  rho.ext_max().value() << " " << rho.ext_min().value() << ref.nl
      
      return cumulativeContErr
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
Ejemplo n.º 20
0
def main_standalone(argc, argv):

    args = ref.setRootCase(argc, argv)

    runTime = man.createTime(args)

    mesh = man.createMesh(runTime)

    U, phi, laminarTransport, turbulence, Ubar, gradP, flowDirection, flowMask = _createFields(
        runTime, mesh)

    faceId, patchId, nWallFaces, wallNormal, cellId, y = interrogateWallPatches(
        mesh)

    ref.ext_Info() << "\nStarting time loop\n" << ref.nl

    while runTime.loop():
        ref.ext_Info() << "Time = " << runTime.timeName() << ref.nl << ref.nl

        divR = turbulence.divDevReff(U)

        divR.source() << (flowMask & divR.source())

        UEqn = divR == gradP
        UEqn.relax()

        UEqn.solve()

        # Correct driving force for a constant mass flow rate

        UbarStar = flowMask & U.weightedAverage(mesh.V())

        U += Ubar - UbarStar
        gradP += (Ubar - UbarStar) / (1.0 / UEqn.A()).weightedAverage(mesh.V())

        turbulence.correct()

        ref.ext_Info() << "Uncorrected Ubar = " << ( flowDirection & UbarStar.value() ) << \
        ", pressure gradient = " << ( flowDirection & gradP.value() )<< ref.nl

        evaluateNearWall(turbulence, U, y, faceId, patchId, nWallFaces,
                         wallNormal, cellId, flowDirection)

        if runTime.outputTime():
            makeGraphs(runTime, mesh, U, turbulence, faceId, patchId,
                       nWallFaces, wallNormal, cellId, flowDirection, y)
            pass

        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 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
Ejemplo n.º 22
0
def setDeltaT(runTime, adjustTimeStep, maxCo, CoNum, maxAlphaCo, alphaCoNum, maxDeltaT):
    if adjustTimeStep:
        maxDeltaTFact = min(maxCo / (CoNum + ref.SMALL), maxAlphaCo / (alphaCoNum + ref.SMALL))
        deltaTFact = min(min(maxDeltaTFact, 1.0 + 0.1 * maxDeltaTFact), 1.2)

        runTime.setDeltaT(min(deltaTFact * runTime.deltaT().value(), maxDeltaT))
        ref.ext_Info() << "deltaT = " << runTime.deltaT().value() << ref.nl
        pass
    return runTime
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 createPhia(runTime, mesh, Ua):
    ref.ext_Info() << "Reading/calculating face flux field phia\n" << ref.nl

    phia = man.surfaceScalarField(
        man.IOobject(ref.word("phia"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.READ_IF_PRESENT, ref.IOobject.AUTO_WRITE),
        man.surfaceScalarField(
            ref.linearInterpolate(Ua) & mesh.Sf(), man.Deps(Ua, mesh)))

    return phia
Ejemplo n.º 25
0
def solveSolid(mesh, kappa, T, nNonOrthCorr):
    for index in range(nNonOrthCorr + 1):
        TEqn = -ref.fvm.laplacian(kappa, T)
        TEqn.relax()
        TEqn.solve()
        pass

    ref.ext_Info() << "Min/max T:" << T.ext_min().value() << " " << T.ext_max().value() << ref.nl

    pass
def adjointContinuityErrs(runTime, mesh, phia, cumulativeAdjointContErr):
    sumLocalContErr = runTime.deltaTValue() * ref.fvc.div(phia).mag().weightedAverage(mesh.V()).value()

    globalContErr = runTime.deltaTValue() * ref.fvc.div(phia).weightedAverage(mesh.V()).value()

    cumulativeAdjointContErr += globalContErr

    ref.ext_Info() << "Adjoint continuity errors : sum local = " << sumLocalContErr << ", global = " << globalContErr << ", cumulative = " << cumulativeAdjointContErr << ref.nl

    return cumulativeAdjointContErr
Ejemplo n.º 27
0
def writeGradP( runTime, gradP ):
    if runTime.outputTime():
       gradPFile = ref.OFstream( runTime.path()/ref.fileName( runTime.timeName() )/ref.fileName( "uniform" )/ref.fileName( "gradP.raw" ) )
       
       if gradPFile.good():
          gradPFile << gradP << ref.nl
          pass
       else:
          ref.ext_Info() << "Cannot open file " << runTime.path()/ref.fileName( runTime.timeName() )/ref.fileName( "uniform" )/ref.fileName( "gradP.raw" )
          import os
          os.abort()
Ejemplo n.º 28
0
def fun_pEqn( mesh, runTime, pimple, thermo, rho, p, h, psi, U, phi, turbulence, UEqn, rAU, DpDt, cumulativeContErr, corr, rhoMax, rhoMin ):

    rho << thermo.rho()
    rho << rho().ext_max( rhoMin )
    rho << rho().ext_min( rhoMax )
    rho.relax()

    U << rAU() * UEqn.H()

    if pimple.transonic():
        phid = ref.surfaceScalarField( ref.word( "phid" ), ref.fvc.interpolate( psi ) * ( ( ref.fvc.interpolate( U ) & mesh.Sf() ) \
                                                                                          + ref.fvc.ddtPhiCorr( rAU, rho, U, phi ) ) );
        for nonOrth in range( pimple.nNonOrthCorr() + 1 ):
            pEqn = ref.fvm.ddt( psi, p) + ref.fvm.div( phid, p ) - ref.fvm.laplacian( rho() * rAU, p ) # mixed calculations
            
            pEqn.solve( mesh.solver( p.select( pimple.finalInnerIter( corr, nonOrth ) ) ) )

            if nonOrth == pimple.nNonOrthCorr():
                phi == pEqn.flux()
                pass
            pass
        pass
    else:
        phi << ref.fvc.interpolate( rho ) * ( ( ref.fvc.interpolate( U ) & mesh.Sf() ) + ref.fvc.ddtPhiCorr( rAU, rho, U, phi ) )
        
        for nonOrth in range( pimple.nNonOrthCorr() + 1 ):
            pEqn = ref.fvm.ddt( psi, p ) + ref.fvc.div( phi ) - ref.fvm.laplacian( rho()*rAU, p )  # mixed calculations
            
            pEqn.solve( mesh.solver( p.select( pimple.finalInnerIter( corr, nonOrth ) ) ) )
            
            if nonOrth == pimple.nNonOrthCorr():
                phi += pEqn.flux()
                pass
            pass    
        pass

    ref.rhoEqn( rho, phi )
    cumulativeContErr = ref.compressibleContinuityErrs( rho(), thermo, cumulativeContErr ) # mixed calculations
    # Explicitly relax pressure for momentum corrector
    p.relax()
    
    # Recalculate density from the relaxed pressure
    rho << thermo.rho()
    rho << rho().ext_max( rhoMin )
    rho << rho().ext_min( rhoMax )
    rho.relax()
    ref.ext_Info()<< "rho max/min : " << rho.ext_max().value()  << " " << rho.ext_min().value() << ref.nl

    U -= rAU * ref.fvc.grad( p )
    U.correctBoundaryConditions()

    DpDt << ref.fvc.DDt( ref.surfaceScalarField( ref.word( "phiU" ), phi() / ref.fvc.interpolate( rho ) ), p ) # mixed calculations
    
    return cumulativeContErr
Ejemplo n.º 29
0
def createPhi( runTime, hU, mesh ):

    ref.ext_Info() << "Reading/calculating face flux field phi\n" << ref.nl
    
    phi = man.surfaceScalarField( man.IOobject( ref.word( "phi" ),
                                                ref.fileName( runTime.timeName() ),
                                                mesh,
                                                ref.IOobject.READ_IF_PRESENT,
                                                ref.IOobject.AUTO_WRITE ),
                                  man.linearInterpolate( hU ) & man.surfaceVectorField( mesh.Sf(), man.Deps( mesh ) ) )
    return phi
def createFields( runTime, mesh, g ):
    
    ref.ext_Info() << "Reading thermophysical properties\n" << ref.nl
    
    pThermo = man.basicPsiThermo.New( mesh );

    rho = man.volScalarField( man.IOobject( ref.word( "rho" ), 
                                            ref.fileName( runTime.timeName() ),
                                            mesh, 
                                            ref.IOobject.NO_READ, 
                                            ref.IOobject.NO_WRITE ),
                              man( pThermo.rho(), man.Deps( pThermo ) ) );
    
    p = man( pThermo.p(), man.Deps( pThermo ) )
    h = man( pThermo.h(), man.Deps( pThermo ) )
    psi = man( pThermo.psi(), man.Deps( pThermo ) )
    
    ref.ext_Info() << "Reading field U\n" << ref.nl
    U = man.volVectorField( man.IOobject( ref.word( "U" ),
                                          ref.fileName( runTime.timeName() ),
                                          mesh,
                                          ref.IOobject.MUST_READ,
                                          ref.IOobject.AUTO_WRITE ),
                              mesh )
    
    phi = man.compressibleCreatePhi( runTime, mesh, rho, U );

    ref.ext_Info() << "Creating turbulence model\n" << ref.nl
    turbulence = man.compressible.RASModel.New( rho, U,  phi, pThermo );

    ref.ext_Info()<< "Calculating field g.h\n" << ref.nl
    
    gh = man.volScalarField( ref.word( "gh" ), man( g & mesh.C(), man.Deps( mesh ) ) )
    ghf = man.surfaceScalarField( ref.word( "ghf" ), man( g & mesh.Cf(), man.Deps( mesh ) ) )
    
    ref.ext_Info() << "Reading field p_rgh\n" << ref.nl
    p_rgh = man.volScalarField( man.IOobject( ref.word( "p_rgh" ),
                                              ref.fileName( runTime.timeName() ),
                                              mesh,
                                              ref.IOobject.MUST_READ,
                                              ref.IOobject.AUTO_WRITE ),
                                mesh );
    # Force p_rgh to be consistent with p
    p_rgh << p - rho * gh
    
    pRefCell = 0
    pRefValue = 0.0
    
    pRefCell, pRefValue = ref.setRefCell( p, p_rgh, mesh.solutionDict().subDict( ref.word( "SIMPLE" ) ), pRefCell, pRefValue );

    initialMass = ref.fvc.domainIntegrate( rho )
    totalVolume = mesh.V().ext_sum()
    
    return pThermo, rho, p, h, psi, U, phi, turbulence, gh, ghf, p_rgh, pRefCell, pRefValue, initialMass, totalVolume
Ejemplo n.º 31
0
def setDeltaT(runTime, adjustTimeStep, maxCo, CoNum, maxAlphaCo, alphaCoNum,
              maxDeltaT):
    if adjustTimeStep:
        maxDeltaTFact = min(maxCo / (CoNum + ref.SMALL),
                            maxAlphaCo / (alphaCoNum + ref.SMALL))
        deltaTFact = min(min(maxDeltaTFact, 1.0 + 0.1 * maxDeltaTFact), 1.2)

        runTime.setDeltaT(min(deltaTFact * runTime.deltaT().value(),
                              maxDeltaT))
        ref.ext_Info() << "deltaT = " << runTime.deltaT().value() << ref.nl
        pass
    return runTime
Ejemplo n.º 32
0
def fun_pEqn( runTime, mesh, pimple, UEqn, p, p_rgh, phi, U, rho, rho1, rho2, rho10, rho20, gh, ghf, dgdt, pMin, \
              psi1, psi2, alpha1, alpha2, interface, corr ):
    rAU = 1.0 / UEqn.A()

    rAUf = ref.fvc.interpolate(rAU)

    p_rghEqnComp = None

    if pimple.transonic():
        p_rghEqnComp = ref.fvm.ddt(p_rgh) + ref.fvm.div(
            phi, p_rgh) - ref.fvm.Sp(ref.fvc.div(phi), p_rgh)
        pass
    else:
        p_rghEqnComp = ref.fvm.ddt(p_rgh) + ref.fvc.div(
            phi, p_rgh) - ref.fvc.Sp(ref.fvc.div(phi), p_rgh)
        pass

    U << rAU * UEqn.H()

    phiU = ref.surfaceScalarField(ref.word("phiU"),
                                  (ref.fvc.interpolate(U) & mesh.Sf()) +
                                  ref.fvc.ddtPhiCorr(rAU, rho, U, phi))

    phi << (phiU +
            (ref.fvc.interpolate(interface.sigmaK()) * ref.fvc.snGrad(alpha1) -
             ghf * ref.fvc.snGrad(rho)) * rAUf * mesh.magSf())

    for nonOrth in range(pimple.nNonOrthCorr() + 1):
        p_rghEqnIncomp = ref.fvc.div(phi) - ref.fvm.laplacian(rAUf, p_rgh)

        ref.solve(
            (alpha1.ext_max(0.0) * (psi1 / rho1) + alpha2.ext_max(0.0) *
             (psi2 / rho2)) * p_rghEqnComp() + p_rghEqnIncomp,  ##
            mesh.solver(p_rgh.select(pimple.finalInnerIter(corr, nonOrth))))

        if nonOrth == pimple.nNonOrthCorr():
            dgdt << (alpha2.pos() * (psi2 / rho2) - alpha1.pos() *
                     (psi1 / rho1)) * (p_rghEqnComp & p_rgh)
            phi += p_rghEqnIncomp.flux()
            pass

    U += rAU * ref.fvc.reconstruct((phi() - phiU) / rAUf)  # mixed calculations
    U.correctBoundaryConditions()

    p << ((p_rgh() + gh * (alpha1() * rho10 + alpha2 * rho20)) /
          (1.0 - gh * (alpha1() * psi1 + alpha2 * psi2))).ext_max(pMin)  #

    rho1 << rho10 + psi1 * p
    rho2 << rho20 + psi2 * p

    ref.ext_Info() << "max(U) " << U.mag().ext_max().value() << ref.nl
    ref.ext_Info() << "min(p_rgh) " << p_rgh.ext_min().value() << ref.nl
    pass
Ejemplo n.º 33
0
def readTransportProperties(runTime, mesh):
    ref.ext_Info() << "Reading transportProperties\n" << ref.nl

    transportProperties = man.IOdictionary(
        man.IOobject(ref.word("transportProperties"),
                     ref.fileName(runTime.constant()), mesh,
                     ref.IOobject.MUST_READ_IF_MODIFIED,
                     ref.IOobject.NO_WRITE))

    mu = ref.dimensionedScalar(transportProperties.lookup(ref.word("mu")))

    return transportProperties, mu
Ejemplo n.º 34
0
def createSolidField( solidRegions, runTime ):

    thermos = list()
    for index in range( solidRegions.__len__() ):
        ref.ext_Info() << "*** Reading solid mesh thermophysical properties for region " \
                       << solidRegions[ index ].name() << ref.nl << ref.nl

        ref.ext_Info() << "    Adding to thermos\n" << ref.nl
        thermos.append( man.basicSolidThermo.New( solidRegions[ index ] ) )
        pass
   
    return thermos
Ejemplo n.º 35
0
def main_standalone( argc, argv ):

    args = ref.setRootCase( argc, argv )

    runTime = man.createTime( args )

    mesh = man.createMesh( runTime )
    
    U, phi, laminarTransport, turbulence, Ubar, gradP, flowDirection, flowMask = _createFields( runTime, mesh )
    
    faceId, patchId, nWallFaces, wallNormal, cellId, y = interrogateWallPatches( mesh )
    
    ref.ext_Info() << "\nStarting time loop\n" << ref.nl 
    
    while runTime.loop() :
        ref.ext_Info() << "Time = " << runTime.timeName() << ref.nl << ref.nl
        
        divR = turbulence.divDevReff( U )

        divR.source()<<  ( flowMask & divR.source()  )
        
        UEqn = divR == gradP 
        UEqn.relax()

        UEqn.solve()
        
        # Correct driving force for a constant mass flow rate

        UbarStar = flowMask & U.weightedAverage(mesh.V())
        
        U +=  Ubar - UbarStar
        gradP += ( Ubar - UbarStar ) / ( 1.0 / UEqn.A() ).weightedAverage( mesh.V() )
        
        turbulence.correct()

        ref.ext_Info() << "Uncorrected Ubar = " << ( flowDirection & UbarStar.value() ) << \
        ", pressure gradient = " << ( flowDirection & gradP.value() )<< ref.nl
        
        evaluateNearWall( turbulence, U, y, faceId, patchId, nWallFaces, wallNormal, cellId, flowDirection )
        
        if runTime.outputTime():
            makeGraphs( runTime, mesh, U, turbulence, faceId, patchId, nWallFaces, wallNormal, cellId, flowDirection, y  )
            pass
    
        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
Ejemplo n.º 36
0
def compressibleCourantNo( mesh, amaxSf, runTime ):
    CoNum = 0.0
    meanCoNum = 0.0
    
    if mesh.nInternalFaces():
       amaxSfbyDelta = mesh.deltaCoeffs() * amaxSf
       CoNum = ( amaxSfbyDelta / mesh.magSf() ).ext_max().value() * runTime.deltaT().value()
       meanCoNum = ( amaxSfbyDelta.sum() / mesh.magSf().sum() ).value() * runTime.deltaTValue()
       pass
    ref.ext_Info() << "Mean and max Courant Numbers = " << meanCoNum << " " << CoNum << ref.nl
    
    return CoNum, meanCoNum
Ejemplo n.º 37
0
def readTransportProperties( runTime, mesh ):
    
    ref.ext_Info() << "Reading transportProperties\n" << ref.nl
    transportProperties = man.IOdictionary( man.IOobject( ref.word( "transportProperties" ),
                                                          ref.fileName( runTime.constant() ),
                                                           mesh,
                                                          ref.IOobject.MUST_READ_IF_MODIFIED,
                                                          ref.IOobject.NO_WRITE ) )

    nu = ref.dimensionedScalar( transportProperties.lookup( ref.word( "nu" ) ) )

    return transportProperties, nu
def adjointContinuityErrs(runTime, mesh, phia, cumulativeAdjointContErr):
    sumLocalContErr = runTime.deltaTValue() * ref.fvc.div(
        phia).mag().weightedAverage(mesh.V()).value()

    globalContErr = runTime.deltaTValue() * ref.fvc.div(phia).weightedAverage(
        mesh.V()).value()

    cumulativeAdjointContErr += globalContErr

    ref.ext_Info() << "Adjoint continuity errors : sum local = " << sumLocalContErr << ", global = " << globalContErr \
                   << ", cumulative = " << cumulativeAdjointContErr << ref.nl

    return cumulativeAdjointContErr
Ejemplo n.º 39
0
def solidRegionDiffNo( mesh, runTime, Cprho, kappa ):
    DiNum = 0.0
    meanDiNum = 0.0

    #- Take care: can have fluid domains with 0 cells so do not test for
    #  zero internal faces.
    kapparhoCpbyDelta = mesh.deltaCoeffs() * ref.fvc.interpolate( kappa ) / ref.fvc.interpolate(Cprho)
    DiNum = kapparhoCpbyDelta.internalField().gMax() * runTime.deltaT().value()
    meanDiNum = kapparhoCpbyDelta.average().value() * runTime.deltaT().value()
    
    ref.ext_Info() << "Region: " << mesh.name() << " Diffusion Number mean: " << meanDiNum << " max: " << DiNum << ref.nl

    return DiNum
Ejemplo n.º 40
0
def alphaEqn( mesh, phi, alpha1, alphatab, Dab, rhoPhi, rho, rho1, rho2, turbulence ):
    alpha1Eqn = ref.fvm.ddt( alpha1 ) + ref.fvm.div( phi, alpha1 ) - ref.fvm.laplacian( Dab + alphatab * turbulence.ext_nut(), alpha1, ref.word( "laplacian(Dab,alpha1)" ) )

    alpha1Eqn.solve()

    rhoPhi << alpha1Eqn.flux() * ( rho1 - rho2 ) + phi * rho2

    rho << alpha1 * rho1 + ( ref.scalar( 1 ) - alpha1 ) * rho2
    
    ref.ext_Info() << "Phase 1 volume fraction = " << alpha1.weightedAverage( mesh.V() ).value()  \
               << "  Min(alpha1) = " << alpha1.ext_min().value() << "  Max(alpha1) = " << alpha1.ext_max().value() << ref.nl
    
    pass
Ejemplo n.º 41
0
def setInitialMultiRegionDeltaT( adjustTimeStep, runTime, CoNum, DiNum, maxCo, maxDi, maxDeltaT ):
    if adjustTimeStep:
       if runTime.timeIndex() == 0 and ( CoNum > ref.SMALL or DiNum > ref.SMALL ) :
          if CoNum < ref.SMALL:
             CoNum = ref.SMALL
             pass
          if DiNum < ref.SMALL:
             DiNum = ref.SMALL
             pass
          runTime.setDeltaT( min( min( maxCo / CoNum, maxDi / DiNum ) * runTime.deltaT().value(), maxDeltaT ) )
          ref.ext_Info() << "deltaT = " <<  runTime.deltaT().value() << ref.nl
          pass
    return runTime, CoNum, DiNum
Ejemplo n.º 42
0
def _createFields( runTime, mesh ):
    ref.ext_Info() << "Reading field T\n" << ref.nl
    T = man.volScalarField( man.IOobject( ref.word( "T" ),
                                          ref.fileName( runTime.timeName() ),
                                          mesh,
                                          ref.IOobject.MUST_READ,
                                          ref.IOobject.AUTO_WRITE ),
                             mesh )

    ref.ext_Info() << "Reading field U\n" << ref.nl
    U = man.volVectorField( man.IOobject( ref.word( "U" ),
                                          ref.fileName( runTime.timeName() ),
                                          mesh,
                                          ref.IOobject.MUST_READ,
                                          ref.IOobject.AUTO_WRITE ),
                            mesh )


    ref.ext_Info() << "Reading transportProperties\n" << ref.nl
    transportProperties = man.IOdictionary( man.IOobject( ref.word( "transportProperties" ),
                                                          ref.fileName( runTime.constant() ),
                                                          mesh,
                                                          ref.IOobject.MUST_READ_IF_MODIFIED,
                                                          ref.IOobject.NO_WRITE ) )


    ref.ext_Info() << "Reading diffusivity D\n" << ref.nl

    DT = ref.dimensionedScalar( transportProperties.lookup( ref.word( "DT" ) ) )

    phi = man.createPhi( runTime, mesh, U )
           
    return T, U, transportProperties, DT, phi 
Ejemplo n.º 43
0
def createFluidMeshes( rp, runTime ) :
    
    fluidRegions = list()
    for index in range( rp.fluidRegionNames().size() ) :
        ref.ext_Info()<< "Create fluid mesh for region " << rp.fluidRegionNames()[ index ] \
                  << " for time = " << runTime.timeName() << ref.nl << ref.nl
        mesh = man.fvMesh( man.IOobject( rp.fluidRegionNames()[ index ],
                                         ref.fileName( runTime.timeName() ),
                                         runTime,
                                         ref.IOobject.MUST_READ ) )
        fluidRegions.append( mesh )
        pass
    
    return fluidRegions
Ejemplo n.º 44
0
def fun_hEqn( rho, h, phi, turb, DpDt, thermo, rad,  mesh, oCorr, nOuterCorr, finalIter ) :
    
    hEqn = ( ( ref.fvm.ddt( rho, h ) + ref.fvm.div( phi, h ) - ref.fvm.laplacian( turb.alphaEff(), h ) ) == DpDt() + rad.Sh( thermo() )  ) 
    
    hEqn.relax()
    hEqn.solve( mesh.solver( h.select( finalIter ) ) ) 
   
    thermo.correct()
    rad.correct()
    
    ref.ext_Info()<< "Min/max T:" << thermo.T().ext_min().value() << ' ' \
        << thermo.T().ext_max().value() << ref.nl
        
    pass
Ejemplo n.º 45
0
def readThermophysicalProperties(runTime, mesh):
    ref.ext_Info() << "Reading thermophysicalProperties\n" << ref.nl

    # Pr defined as a separate constant to enable calculation of k, currently
    # inaccessible through thermo
    thermophysicalProperties = man.IOdictionary(
        man.IOobject(ref.word("thermophysicalProperties"),
                     ref.fileName(runTime.constant()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.NO_WRITE))

    Pr = ref.dimensionedScalar.lookupOrDefault(ref.word("Pr"),
                                               thermophysicalProperties(), 1.0)

    return thermophysicalProperties, Pr
Ejemplo n.º 46
0
def _createFields(runTime, mesh):
    ref.ext_Info() << "Reading field T\n" << ref.nl
    T = man.volScalarField(
        man.IOobject(ref.word("T"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.AUTO_WRITE), mesh)

    ref.ext_Info() << "Reading field U\n" << ref.nl
    U = man.volVectorField(
        man.IOobject(ref.word("U"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.AUTO_WRITE), mesh)

    ref.ext_Info() << "Reading transportProperties\n" << ref.nl
    transportProperties = man.IOdictionary(
        man.IOobject(ref.word("transportProperties"),
                     ref.fileName(runTime.constant()), mesh,
                     ref.IOobject.MUST_READ_IF_MODIFIED,
                     ref.IOobject.NO_WRITE))

    ref.ext_Info() << "Reading diffusivity D\n" << ref.nl

    DT = ref.dimensionedScalar(transportProperties.lookup(ref.word("DT")))

    phi = man.createPhi(runTime, mesh, U)

    return T, U, transportProperties, DT, phi
Ejemplo n.º 47
0
def main_standalone( argc, argv ):

    args = ref.setRootCase( argc, argv )

    runTime = man.createTime( args )

    mesh = man.createMesh( runTime )
    
    T, transportProperties, DT = _createFields( runTime, mesh )
    
    simple = man.simpleControl( mesh )

    ref.ext_Info() << "\nCalculating temperature distribution\n" << ref.nl
    
    while runTime.loop() :
        ref.ext_Info() << "Time = " << runTime.timeName() << ref.nl << ref.nl
        
        for nonOrth in range( simple.nNonOrthCorr() + 1 ):
            ref.solve( ref.fvm.ddt( T ) - ref.fvm.laplacian( DT, T ) )
            pass
        
        write( runTime, mesh, T )
        
        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
Ejemplo n.º 48
0
def createFluidMeshes(rp, runTime):

    fluidRegions = list()
    for index in range(rp.fluidRegionNames().size()):
        ref.ext_Info()<< "Create fluid mesh for region " << rp.fluidRegionNames()[ index ] \
                  << " for time = " << runTime.timeName() << ref.nl << ref.nl
        mesh = man.fvMesh(
            man.IOobject(rp.fluidRegionNames()[index],
                         ref.fileName(runTime.timeName()), runTime,
                         ref.IOobject.MUST_READ))
        fluidRegions.append(mesh)
        pass

    return fluidRegions
Ejemplo n.º 49
0
def main_standalone(argc, argv):

    args = ref.setRootCase(argc, argv)

    runTime = man.createTime(args)

    mesh = man.createMesh(runTime)

    T, transportProperties, DT = _createFields(runTime, mesh)

    simple = man.simpleControl(mesh)

    ref.ext_Info() << "\nCalculating temperature distribution\n" << ref.nl

    while runTime.loop():
        ref.ext_Info() << "Time = " << runTime.timeName() << ref.nl << ref.nl

        while simple.correctNonOrthogonal():
            ref.solve(ref.fvm.ddt(T) - ref.fvm.laplacian(DT, T))
            pass

        write(runTime, mesh, T)

        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 createFields(runTime, mesh, g):

    ref.ext_Info() << "Reading thermophysical properties\n" << ref.nl

    pThermo = man.basicPsiThermo.New(mesh)

    rho = man.volScalarField(
        man.IOobject(ref.word("rho"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.NO_READ, ref.IOobject.NO_WRITE),
        man(pThermo.rho(), man.Deps(pThermo)))

    p = man(pThermo.p(), man.Deps(pThermo))
    h = man(pThermo.h(), man.Deps(pThermo))
    psi = man(pThermo.psi(), man.Deps(pThermo))

    ref.ext_Info() << "Reading field U\n" << ref.nl
    U = man.volVectorField(
        man.IOobject(ref.word("U"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.AUTO_WRITE), mesh)

    phi = man.compressibleCreatePhi(runTime, mesh, rho, U)

    ref.ext_Info() << "Creating turbulence model\n" << ref.nl
    turbulence = man.compressible.RASModel.New(rho, U, phi, pThermo)

    ref.ext_Info() << "Calculating field g.h\n" << ref.nl

    gh = man.volScalarField(ref.word("gh"), man(g & mesh.C(), man.Deps(mesh)))
    ghf = man.surfaceScalarField(ref.word("ghf"),
                                 man(g & mesh.Cf(), man.Deps(mesh)))

    ref.ext_Info() << "Reading field p_rgh\n" << ref.nl
    p_rgh = man.volScalarField(
        man.IOobject(ref.word("p_rgh"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.AUTO_WRITE), mesh)
    # Force p_rgh to be consistent with p
    p_rgh << p - rho * gh

    pRefCell = 0
    pRefValue = 0.0

    pRefCell, pRefValue = ref.setRefCell(
        p, p_rgh,
        mesh.solutionDict().subDict(ref.word("SIMPLE")), pRefCell, pRefValue)

    initialMass = ref.fvc.domainIntegrate(rho)
    totalVolume = mesh.V().ext_sum()

    return pThermo, rho, p, h, psi, U, phi, turbulence, gh, ghf, p_rgh, pRefCell, pRefValue, initialMass, totalVolume
Ejemplo n.º 51
0
def compressibleCourantNo( mesh, runTime, rho, phi ) :
    
    CoNum = 0.0
    meanCoNum = 0.0
    tmp = ref.fvc.surfaceSum( phi.mag() )
    sumPhi = tmp.internalField() / rho.internalField() 

    CoNum = 0.5 * ( sumPhi / mesh.V().field() ).gMax() * runTime.deltaTValue()

    meanCoNum = 0.5 * ( sumPhi.gSum() / mesh.V().field().gSum() ) * runTime.deltaTValue()

    ref.ext_Info() << "Region: " << mesh.name() << " Courant Number mean: " << meanCoNum \
        << " max: " << CoNum << ref.nl
    
    return  CoNum
Ejemplo n.º 52
0
def _createFields(runTime, mesh):

    ref.ext_Info() << "Reading field p\n" << ref.nl
    p = man.volScalarField(
        man.IOobject(ref.word("p"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.AUTO_WRITE), mesh)

    ref.ext_Info() << "Reading field U\n" << ref.nl
    U = man.volVectorField(
        man.IOobject(ref.word("U"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.AUTO_WRITE), mesh)

    phi = man.createPhi(runTime, mesh, U)

    return p, U, phi
Ejemplo n.º 53
0
def fun_hEqn( rho, h, phi, turb, K, dpdt, thermo, rad,  mesh, oCorr, nOuterCorr, finalIter ):
    
    hEqn = ( ( ref.fvm.ddt( rho, h ) + ref.fvm.div( phi, h ) - ref.fvm.laplacian( turb.alphaEff(), h ) ) \
               == dpdt() - ( ref.fvc.ddt( rho, K ) + ref.fvc.div( phi, K ) ) + rad.Sh( thermo() )  )  # mixed calculation
    
    hEqn.relax()
    hEqn.solve( mesh.solver( h.select( finalIter ) ) ) 
   
    thermo.correct()
    rad.correct()
    
    ref.ext_Info()<< "Min/max T:" << thermo.T().ext_min().value() << ' ' \
        << thermo.T().ext_max().value() << ref.nl
        
    pass
Ejemplo n.º 54
0
def readTurbulenceProperties(runTime, mesh, U):

    ref.ext_Info() << "Reading turbulenceProperties\n" << ref.nl
    turbulenceProperties = man.IOdictionary(
        man.IOobject(ref.word("turbulenceProperties"),
                     ref.fileName(runTime.constant()), mesh,
                     ref.IOobject.MUST_READ_IF_MODIFIED,
                     ref.IOobject.NO_WRITE))

    force = U / ref.dimensionedScalar(ref.word("dt"), ref.dimTime,
                                      runTime.deltaTValue())

    K = man.Kmesh(mesh)
    forceGen = man.UOprocess(K, runTime.deltaTValue(), turbulenceProperties)

    return turbulenceProperties, force, K, forceGen
Ejemplo n.º 55
0
def compressibleContinuityErrors( i, mesh, rho, thermo, cumulativeContErr ) :
    totalMass = ref.fvc.domainIntegrate(rho)
       
    sumLocalContErr =  ( ref.fvc.domainIntegrate( ( rho() - thermo.rho()  ).mag() )  / totalMass ).value() # mixed calculations
    
    globalContErr =  ( ref.fvc.domainIntegrate( rho() - thermo.rho() ) / totalMass ).value() # mixed calculations

    cumulativeContErr[i] = cumulativeContErr[i] + globalContErr
    
    ref.ext_Info()<< "time step continuity errors (" << mesh.name() << ")" \
        << ": sum local = " << sumLocalContErr \
        << ", global = " << globalContErr \
        << ", cumulative = " << cumulativeContErr[i] \
        << ref.nl
        
    return cumulativeContErr
Ejemplo n.º 56
0
def main_standalone(argc, argv):

    args = ref.setRootCase(argc, argv)

    runTime = man.createTime(args)

    mesh = man.createMesh(runTime)

    p, U, phi, turbulence, pRefCell, pRefValue, laminarTransport, sources = _createFields(
        runTime, mesh)

    cumulativeContErr = ref.initContinuityErrs()

    pimple = man.pimpleControl(mesh)

    ref.ext_Info() << "\nStarting time loop\n" << ref.nl

    while runTime.run():
        adjustTimeStep, maxCo, maxDeltaT = ref.readTimeControls(runTime)

        CoNum, meanCoNum = ref.CourantNo(mesh, phi, runTime)

        runTime = ref.setDeltaT(runTime, adjustTimeStep, maxCo, maxDeltaT,
                                CoNum)

        runTime.increment()

        ref.ext_Info() << "Time = " << runTime.timeName() << ref.nl << ref.nl

        # --- Pressure-velocity PIMPLE corrector loop
        while pimple.loop():

            UEqn, rAU = Ueqn(mesh, pimple, phi, U, p, turbulence, sources)

            # --- Pressure corrector loop
            while pimple.correct():
                cumulativeContErr = pEqn(runTime, mesh, pimple, U, rAU, UEqn,
                                         phi, p, pRefCell, pRefValue,
                                         cumulativeContErr, sources)
                pass

            if pimple.turbCorr():
                turbulence.correct()
                pass
            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