示例#1
0
def _createFields(runTime, 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)

    ref.ext_Info() << "Reading field alpha1\n" << ref.nl
    man.interfaceProperties  # Load corresponding library to be able to use the following BC - "constantAlphaContactAngleFvPatchScalarField"
    alpha1 = man.volScalarField(
        man.IOobject(ref.word("alpha1"), 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)

    ref.ext_Info() << "Reading transportProperties\n" << ref.nl
    twoPhaseProperties = man.twoPhaseMixture(U, phi)

    rho1 = twoPhaseProperties.rho1()
    rho2 = twoPhaseProperties.rho2()

    # Need to store rho for ddt(rho, U)
    rho = man.volScalarField(
        man.IOobject(ref.word("rho"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.READ_IF_PRESENT),
        alpha1 * rho1 + (1.0 - alpha1) * rho2,
        alpha1.ext_boundaryField().types())
    rho.oldTime()

    # Mass flux
    # Initialisation does not matter because rhoPhi is reset after the
    # alpha1 solution before it is used in the U equation.
    rhoPhi = man.surfaceScalarField(
        man.IOobject(ref.word("rho*phi"), ref.fileName(runTime.timeName()),
                     mesh, ref.IOobject.NO_READ, ref.IOobject.NO_WRITE),
        rho1 * phi)

    # Construct interface from alpha1 distribution
    interface = man.interfaceProperties(alpha1, U, twoPhaseProperties)

    # Construct incompressible turbulence model
    turbulence = man.incompressible.turbulenceModel.New(
        U, phi, twoPhaseProperties)

    g = man.readGravitationalAcceleration(runTime, mesh)

    #dimensionedVector g0(g);

    #Read the data file and initialise the interpolation table
    #interpolationTable<vector> timeSeriesAcceleration( runTime.path()/runTime.caseConstant()/"acceleration.dat" );

    ref.ext_Info() << "Calculating field g.h\n" << ref.nl
    gh = man.volScalarField(ref.word("gh"),
                            g & man.volVectorField(mesh.C(), man.Deps(mesh)))
    ghf = man.surfaceScalarField(
        ref.word("ghf"), g & man.surfaceVectorField(mesh.Cf(), man.Deps(mesh)))

    p = man.volScalarField(
        man.IOobject(ref.word("p"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.NO_READ, ref.IOobject.AUTO_WRITE),
        p_rgh + rho * gh)

    pRefCell = 0
    pRefValue = 0.0

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

    if p_rgh.needReference():
        p += ref.dimensionedScalar(
            ref.word("p"), p.dimensions(),
            pRefValue - ref.getRefCellValue(p, pRefCell))
        p_rgh << p - rho * gh
        pass

    return p_rgh, p, alpha1, U, phi, rho1, rho2, rho, rhoPhi, twoPhaseProperties, pRefCell, pRefValue, interface, turbulence, g, gh, ghf
示例#2
0
def _createFields(runTime, 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,
    )

    ref.ext_Info() << "Reading field alpha1\n" << ref.nl
    alpha1 = man.volScalarField(
        man.IOobject(
            ref.word("alpha1"), 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)

    ref.ext_Info() << "Reading transportProperties\n" << ref.nl
    twoPhaseProperties = man.twoPhaseMixture(U, phi)

    rho1 = twoPhaseProperties.rho1()
    rho2 = twoPhaseProperties.rho2()

    # Need to store rho for ddt(rho, U)
    rho = man.volScalarField(
        man.IOobject(ref.word("rho"), ref.fileName(runTime.timeName()), mesh, ref.IOobject.READ_IF_PRESENT),
        alpha1 * rho1 + (1.0 - alpha1) * rho2,
        alpha1.ext_boundaryField().types(),
    )
    rho.oldTime()

    # Mass flux
    # Initialisation does not matter because rhoPhi is reset after the
    # alpha1 solution before it is used in the U equation.
    rhoPhi = man.surfaceScalarField(
        man.IOobject(
            ref.word("rho*phi"), ref.fileName(runTime.timeName()), mesh, ref.IOobject.NO_READ, ref.IOobject.NO_WRITE
        ),
        rho1 * phi,
    )

    # Construct interface from alpha1 distribution
    interface = man.interfaceProperties(alpha1, U, twoPhaseProperties)

    # Construct incompressible turbulence model
    turbulence = man.incompressible.turbulenceModel.New(U, phi, twoPhaseProperties)

    g = man.readGravitationalAcceleration(runTime, mesh)

    # dimensionedVector g0(g);

    # Read the data file and initialise the interpolation table
    # interpolationTable<vector> timeSeriesAcceleration( runTime.path()/runTime.caseConstant()/"acceleration.dat" );

    ref.ext_Info() << "Calculating field g.h\n" << ref.nl
    gh = man.volScalarField(ref.word("gh"), g & man.volVectorField(mesh.C(), man.Deps(mesh)))
    ghf = man.surfaceScalarField(ref.word("ghf"), g & man.surfaceVectorField(mesh.Cf(), man.Deps(mesh)))

    p = man.volScalarField(
        man.IOobject(
            ref.word("p"), ref.fileName(runTime.timeName()), mesh, ref.IOobject.NO_READ, ref.IOobject.AUTO_WRITE
        ),
        p_rgh + rho * gh,
    )

    pRefCell = 0
    pRefValue = 0.0

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

    if p_rgh.needReference():
        p += ref.dimensionedScalar(ref.word("p"), p.dimensions(), pRefValue - ref.getRefCellValue(p, pRefCell))
        p_rgh << p - rho * gh
        pass

    return (
        p_rgh,
        p,
        alpha1,
        U,
        phi,
        rho1,
        rho2,
        rho,
        rhoPhi,
        twoPhaseProperties,
        pRefCell,
        pRefValue,
        interface,
        turbulence,
        g,
        gh,
        ghf,
    )
def main_standalone( argc, argv ):

    args = ref.setRootCase( argc, argv )

    runTime = man.createTime( args )

    mesh = man.createMesh( runTime )
    
    g = man.readGravitationalAcceleration( runTime, mesh)
    
    pimple = ref.pimpleControl( mesh )
    
    adjustTimeStep, maxCo, maxDeltaT, nAlphaCorr, nAlphaSubCycles = read_controls( args, runTime, pimple )

    cumulativeContErr = ref.initContinuityErrs()

    p_rgh, alpha1, alpha2, U, phi, twoPhaseProperties, rho10, rho20, psi1, psi2, pMin, \
                      gh, ghf, p, rho1, rho2, rho, rhoPhi, dgdt, interface, turbulence = _createFields( runTime, mesh, g )
    
    CoNum, meanCoNum = ref.CourantNo( mesh, phi, runTime )
    
    runTime = ref.setInitialDeltaT( runTime, adjustTimeStep, maxCo, CoNum )

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

    while runTime.run():
        adjustTimeStep, maxCo, maxDeltaT, nAlphaCorr, nAlphaSubCycles = read_controls( args, runTime, pimple )

        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
        
        # --- Outer-corrector loop
        while pimple.loop():
            alphaEqnsSubCycle( runTime, pimple, mesh, phi, alpha1, alpha2, rho, rho1, rho2, rhoPhi, dgdt, interface )

            ref.solve( ref.fvm.ddt( rho ) + ref.fvc.div( rhoPhi ) )

            UEqn = fun_UEqn( mesh, alpha1, U, p, p_rgh, ghf, rho, rhoPhi, turbulence, g, twoPhaseProperties, interface, pimple )

            # --- Pressure corrector loop
            while pimple.correct(): 
                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 )
                pass
            if pimple.turbCorr():
                turbulence.correct()
                pass
            pass
        rho <<  alpha1 * rho1 + alpha2 * rho2

        runTime.write()

        ref.ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s\n\n" << ref.nl
        pass

    ref.ext_Info() << "End\n" << ref.nl 

    import os
    return os.EX_OK
def main_standalone(argc, argv):

    args = ref.setRootCase(argc, argv)

    runTime = man.createTime(args)

    mesh = man.createMesh(runTime)

    g = man.readGravitationalAcceleration(runTime, mesh)

    pimple = ref.pimpleControl(mesh)

    adjustTimeStep, maxCo, maxDeltaT, nAlphaCorr, nAlphaSubCycles = read_controls(
        args, runTime, pimple)

    cumulativeContErr = ref.initContinuityErrs()

    p_rgh, alpha1, alpha2, U, phi, twoPhaseProperties, rho10, rho20, psi1, psi2, pMin, \
                      gh, ghf, p, rho1, rho2, rho, rhoPhi, dgdt, interface, turbulence = _createFields( runTime, mesh, g )

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

    runTime = ref.setInitialDeltaT(runTime, adjustTimeStep, maxCo, CoNum)

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

    while runTime.run():
        adjustTimeStep, maxCo, maxDeltaT, nAlphaCorr, nAlphaSubCycles = read_controls(
            args, runTime, pimple)

        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

        # --- Outer-corrector loop
        pimple.start()
        while pimple.loop():
            alphaEqnsSubCycle(runTime, pimple, mesh, phi, alpha1, alpha2, rho,
                              rho1, rho2, rhoPhi, dgdt, interface)

            ref.solve(ref.fvm.ddt(rho) + ref.fvc.div(rhoPhi))

            UEqn = fun_UEqn(mesh, alpha1, U, p, p_rgh, ghf, rho, rhoPhi,
                            turbulence, g, twoPhaseProperties, interface,
                            pimple)

            # --- PISO loop
            for corr in range(pimple.nCorr()):
                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 )
                pass
            if pimple.turbCorr():
                turbulence.correct()
                pass

            pimple.increment()
            pass
        rho << alpha1 * rho1 + alpha2 * rho2

        runTime.write()

        ref.ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime(
        ) << " s\n\n" << ref.nl
        pass

    ref.ext_Info() << "End\n" << ref.nl

    import os
    return os.EX_OK
示例#5
0
def main_standalone( argc, argv ):

    args = ref.setRootCase( argc, argv )

    runTime = man.createTime( args )

    mesh = man.createMesh( runTime )
    
    g = man.readGravitationalAcceleration( runTime, mesh )

    cumulativeContErr = ref.initContinuityErrs()
    
    p_rgh, alpha1, U, phi, twoPhaseProperties, rho1, rho2, Dab, \
    alphatab, rho, rhoPhi, turbulence, gh, ghf, p, pRefCell, pRefValue = _createFields( runTime, mesh, g )

    adjustTimeStep, maxCo, maxDeltaT = ref.readTimeControls( runTime )
    
    CoNum, meanCoNum = ref.CourantNo( mesh, phi, runTime )
    
    runTime = ref.setInitialDeltaT( runTime, adjustTimeStep, maxCo, CoNum )
    
    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
        pimple.start()
        while pimple.loop():

            twoPhaseProperties.correct()

            alphaEqn( mesh, phi, alpha1, alphatab, Dab, rhoPhi, rho, rho1, rho2, turbulence )
            
            UEqn = fun_UEqn( mesh, U, p_rgh, ghf, rho, rhoPhi, turbulence, twoPhaseProperties, pimple )
            
            # --- PISO loop
            for corr in range( pimple.nCorr() ):
                cumulativeContErr = fun_pEqn( runTime, mesh, UEqn, U, p, p_rgh, gh, ghf, phi, rho, pimple, \
                                              corr, pRefCell, pRefValue, cumulativeContErr )
                pass

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