Esempio n. 1
0
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void createFields( const TimeHolder& runTime, 
                   const fvMeshHolder& mesh,
                   volScalarFieldHolder& p,
                   volVectorFieldHolder& U,
                   surfaceScalarFieldHolder& phi,
                   singlePhaseTransportModelHolder& laminarTransport,
                   incompressible::RASModelHolder& turbulence,
                   label& pRefCell,
                   scalar& pRefValue )
{
  Info<< "Reading field p\n" << endl;
  p( volScalarFieldHolder( IOobjectHolder( "p",
                                            runTime->timeName(),
                                            mesh,
                                            IOobject::MUST_READ,
                                            IOobject::AUTO_WRITE ),
                            mesh ) );

  Info<< "Reading field U\n" << endl;
  U( volVectorFieldHolder( IOobjectHolder( "U",
                                            runTime->timeName(),
                                            mesh,
                                            IOobject::MUST_READ,
                                            IOobject::AUTO_WRITE ),
                            mesh ) );
  
  phi( createPhi( runTime, mesh, U ) );
  
  setRefCell( p, mesh->solutionDict().subDict("SIMPLE"), pRefCell, pRefValue );

  laminarTransport = singlePhaseTransportModelHolder( U, phi );

  turbulence = incompressible::RASModelHolder::New( U, phi, laminarTransport );

}
Esempio n. 2
0
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//---------------------------------------------------------------------------
void createFields( const TimeHolder& runTime, 
                   const fvMeshHolder& mesh,
                   singlePhaseTransportModelHolder& fluid,
                   volScalarFieldHolder& p,
                   volVectorFieldHolder& U,
                   surfaceScalarFieldHolder& phi,
                   label& pRefCell,
                   scalar& pRefValue )
{
  Info << "Reading field p\n" << endl;
  
  p( volScalarFieldHolder( IOobjectHolder( "p",
                                            runTime->timeName(),
                                            mesh,
                                            IOobject::MUST_READ,
                                            IOobject::AUTO_WRITE ), mesh ) );

  Info<< "Reading field U\n" << endl;
  U( volVectorFieldHolder( IOobjectHolder( "U",
                                            runTime->timeName(),
                                            mesh,
                                            IOobject::MUST_READ,
                                            IOobject::AUTO_WRITE ), mesh ) );

    
  phi( createPhi( runTime, mesh, U ) );
  
  fluid( singlePhaseTransportModelHolder( U, phi ) );
  
  setRefCell( p, mesh->solutionDict().subDict("PISO"), pRefCell, pRefValue);

} 
Esempio n. 3
0
 inline void setRefCell( const volScalarFieldHolder& field,
   const dictionary& dict,
   label& refCelli,
   scalar& refValue,
   const bool forceReference = false )
 {
   setRefCell( field(), dict, refCelli, refValue, forceReference );
 }
Esempio n. 4
0
void Foam::setRefCell
(
    const volScalarField& field,
    const dictionary& dict,
    label& refCelli,
    scalar& refValue,
    const bool forceReference
)
{
    setRefCell(field, field, dict, refCelli, refValue, forceReference);
}
Esempio n. 5
0
//---------------------------------------------------------------------------
dimensionedScalar createFields( const TimeHolder& runTime,
                                const fvMeshHolder& mesh,
                                IOdictionaryHolder& transportProperties,
                                volScalarFieldHolder& p,
                                volVectorFieldHolder& U,
                                surfaceScalarFieldHolder& phi,
                                label& pRefCell,
                                scalar& pRefValue )
{
    Info<< "Reading transportProperties\n" << endl;

    transportProperties = IOdictionaryHolder( IOobjectHolder( "transportProperties",
                          runTime->constant(),
                          mesh,
                          IOobject::MUST_READ_IF_MODIFIED,
                          IOobject::NO_WRITE ) );

    dimensionedScalar nu ( transportProperties->lookup("nu") );

    Info << "Reading field p\n" << endl;

    p = volScalarFieldHolder( IOobjectHolder( "p",
                              runTime->timeName(),
                              mesh,
                              IOobject::MUST_READ,
                              IOobject::AUTO_WRITE ), mesh );

    Info<< "Reading field U\n" << endl;
    U = volVectorFieldHolder( IOobjectHolder( "U",
                              runTime->timeName(),
                              mesh,
                              IOobject::MUST_READ,
                              IOobject::AUTO_WRITE ), mesh );


    phi =createPhi( runTime, mesh, U );

    setRefCell( p, mesh->solutionDict().subDict("PISO"), pRefCell, pRefValue);

    return nu;
}
int main(int argc, char *argv[])
{

#   include "addTimeOptions.H"
#   include "setRootCase.H"

#   include "createTime.H"

    // Get times list
    instantList Times = runTime.times();

    // set startTime and endTime depending on -time and -latestTime options
#   include "checkTimeOptions.H"

    runTime.setTime(Times[startTime], startTime);

#   include "createMesh.H"
#   include "readGravitationalAcceleration.H"

    const dictionary& piso = mesh.solutionDict().subDict("PISO");

    label pRefCell = 0;
    scalar pRefValue = 0.0;

    int nNonOrthCorr = 0;
    if (piso.found("nNonOrthogonalCorrectors"))
    {
        nNonOrthCorr = readInt(piso.lookup("nNonOrthogonalCorrectors"));
    }

    for (label i = startTime; i < endTime; i++)
    {
        runTime.setTime(Times[i], i);

        Info<< "Time = " << runTime.timeName() << endl;

        IOobject pdHeader
        (
            "pd",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ
        );

        IOobject gammaHeader
        (
            "gamma",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ
        );

        IOobject Uheader
        (
            "U",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ
        );

        IOobject phiHeader
        (
            "phi",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ
        );

        // Check all fields exists
        if
        (
            pdHeader.headerOk()
         && gammaHeader.headerOk()
         && Uheader.headerOk()
         && phiHeader.headerOk()
        )
        {
            mesh.readUpdate();

            Info<< "    Reading pd" << endl;
            volScalarField pd(pdHeader, mesh);

            Info<< "    Reading gamma" << endl;
            volScalarField gamma(gammaHeader, mesh);

            Info<< "    Reading U" << endl;
            volVectorField U(Uheader, mesh);

            Info<< "    Reading phi" << endl;
            surfaceScalarField phi(phiHeader, mesh);

            Info<< "Reading transportProperties\n" << endl;
            twoPhaseMixture twoPhaseProperties(U, phi, "gamma");

            twoPhaseProperties.correct();

            // Construct interface from gamma distribution
            interfaceProperties interface(gamma, U, twoPhaseProperties);

            // Create momentum matrix

            const dimensionedScalar& rho1 = twoPhaseProperties.rho1();
            const dimensionedScalar& rho2 = twoPhaseProperties.rho2();

            volScalarField rho
            (
                IOobject
                (
                    "rho",
                    runTime.timeName(),
                    mesh,
                    IOobject::READ_IF_PRESENT
                ),
                gamma*rho1 + (scalar(1) - gamma)*rho2,
                gamma.boundaryField().types()
            );

            surfaceScalarField rhoPhi
            (
                IOobject
                (
                    "rho*phi",
                    runTime.timeName(),
                    mesh,
                    IOobject::NO_READ,
                    IOobject::NO_WRITE
                ),
                fvc::interpolate(rho)*phi
            );

            surfaceScalarField muf = twoPhaseProperties.muf();

            fvVectorMatrix UEqn
            (
                fvm::ddt(rho, U)
              + fvm::div(rhoPhi, U)
              - fvm::laplacian(muf, U)
              - (fvc::grad(U) & fvc::grad(muf))
             ==
                interface.sigmaK()*fvc::grad(gamma)
              + rho*g
            );

            // Solve for static pressure
            volScalarField p
            (
                IOobject
                (
                    "p",
                    runTime.timeName(),
                    mesh,
                    IOobject::READ_IF_PRESENT,
                    IOobject::NO_WRITE
                ),
                pd
            );

            setRefCell(p, piso, pRefCell, pRefValue);

            volScalarField rUA = 1.0/UEqn.A();
            surfaceScalarField rUAf = fvc::interpolate(rUA);

            U = rUA*UEqn.H();

            phi = fvc::interpolate(U) & mesh.Sf();

            for(int nonOrth = 0; nonOrth <= nNonOrthCorr; nonOrth++)
            {
                fvScalarMatrix pEqn
                (
                    fvm::laplacian(rUAf, p) == fvc::div(phi)
                );

                pEqn.setReference(pRefCell, pRefValue);
                pEqn.solve();
            }

            Info << "Writing p" << endl;
            p.write();
        }
        else
        {
            Info << "Not all fields are present.  " << endl;

            if (!pdHeader.headerOk())
            {
                Info << "pd ";
            }

            if (!gammaHeader.headerOk())
            {
                Info << "gamma ";
            }

            if (!Uheader.headerOk())
            {
                Info << "U ";
            }

            if (!phiHeader.headerOk())
            {
                Info << "phi ";
            }

            Info << "missing." << endl;
        }
    }

    Info<< "End\n" << endl;

    return(0);
}
Esempio n. 7
0
int main(int argc, char *argv[])
{
    argList::addOption
    (
        "pName",
        "pName",
        "Name of the pressure field"
    );

    argList::addBoolOption
    (
        "initialiseUBCs",
        "Initialise U boundary conditions"
    );

    argList::addBoolOption
    (
        "writePhi",
        "Write the velocity potential field"
    );

    argList::addBoolOption
    (
        "writep",
        "Calculate and write the pressure field"
    );

    argList::addBoolOption
    (
        "withFunctionObjects",
        "execute functionObjects"
    );

    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"

    pisoControl potentialFlow(mesh, "potentialFlow");

    #include "createFields.H"

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    Info<< nl << "Calculating potential flow" << endl;

    // Since solver contains no time loop it would never execute
    // function objects so do it ourselves
    runTime.functionObjects().start();

    MRF.makeRelative(phi);
    adjustPhi(phi, U, p);

    // Non-orthogonal velocity potential corrector loop
    while (potentialFlow.correctNonOrthogonal())
    {
        fvScalarMatrix PhiEqn
        (
            fvm::laplacian(dimensionedScalar("1", dimless, 1), Phi)
         ==
            fvc::div(phi)
        );

        PhiEqn.setReference(PhiRefCell, PhiRefValue);
        PhiEqn.solve();

        if (potentialFlow.finalNonOrthogonalIter())
        {
            phi -= PhiEqn.flux();
        }
    }

    MRF.makeAbsolute(phi);

    Info<< "Continuity error = "
        << mag(fvc::div(phi))().weightedAverage(mesh.V()).value()
        << endl;

    U = fvc::reconstruct(phi);
    U.correctBoundaryConditions();

    Info<< "Interpolated velocity error = "
        << (sqrt(sum(sqr(fvc::flux(U) - phi)))/sum(mesh.magSf())).value()
        << endl;

    // Write U and phi
    U.write();
    phi.write();

    // Optionally write Phi
    if (args.optionFound("writePhi"))
    {
        Phi.write();
    }

    // Calculate the pressure field
    if (args.optionFound("writep"))
    {
        Info<< nl << "Calculating approximate pressure field" << endl;

        label pRefCell = 0;
        scalar pRefValue = 0.0;
        setRefCell
        (
            p,
            potentialFlow.dict(),
            pRefCell,
            pRefValue
        );

        // Calculate the flow-direction filter tensor
        volScalarField magSqrU(magSqr(U));
        volSymmTensorField F(sqr(U)/(magSqrU + SMALL*average(magSqrU)));

        // Calculate the divergence of the flow-direction filtered div(U*U)
        // Filtering with the flow-direction generates a more reasonable
        // pressure distribution in regions of high velocity gradient in the
        // direction of the flow
        volScalarField divDivUU
        (
            fvc::div
            (
                F & fvc::div(phi, U),
                "div(div(phi,U))"
            )
        );

        // Solve a Poisson equation for the approximate pressure
        while (potentialFlow.correctNonOrthogonal())
        {
            fvScalarMatrix pEqn
            (
                fvm::laplacian(p) + divDivUU
            );

            pEqn.setReference(pRefCell, pRefValue);
            pEqn.solve();
        }

        p.write();
    }

    runTime.functionObjects().end();

    Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
        << "  ClockTime = " << runTime.elapsedClockTime() << " s"
        << nl << endl;

    Info<< "End\n" << endl;

    return 0;
}
//---------------------------------------------------------------------------
result_readTransportProperties createFields( const TimeHolder& runTime, 
                                             const fvMeshHolder& mesh,
                                             const uniformDimensionedVectorFieldHolder& g,
                                             volScalarFieldHolder& T,
                                             volScalarFieldHolder& p_rgh,
                                             volVectorFieldHolder& U,
                                             surfaceScalarFieldHolder& phi,
                                             singlePhaseTransportModelHolder& laminarTransport,
                                             incompressible::RASModelHolder& turbulence,
                                             volScalarFieldHolder& rhok,
                                             volScalarFieldHolder& kappat,
                                             volScalarFieldHolder& gh,
                                             surfaceScalarFieldHolder& ghf,
                                             volScalarFieldHolder& p,
                                             label& pRefCell,
                                             scalar& pRefValue )
{
  Info<< "Reading thermophysical properties\n" << endl;
  
  Info<< "Reading field T\n" << endl;
  T( volScalarFieldHolder( IOobjectHolder( "T",
                                            runTime->timeName(),
                                            mesh,
                                            IOobject::MUST_READ,
                                            IOobject::AUTO_WRITE ),
                            mesh ) );

  Info<< "Reading field p_rgh\n" << endl;
  p_rgh( volScalarFieldHolder( IOobjectHolder( "p_rgh",
                                                runTime->timeName(),
                                                mesh,
                                                IOobject::MUST_READ,
                                                IOobject::AUTO_WRITE ),
                                mesh ) );
  
  Info<< "Reading field U\n" << endl;
  U( volVectorFieldHolder( IOobjectHolder( "U",
                                            runTime->timeName(),
                                            mesh,
                                            IOobject::MUST_READ,
                                            IOobject::AUTO_WRITE ),
                            mesh ) );

  phi( createPhi( runTime, mesh, U ) );
    
  result_readTransportProperties result_readTransProp( readTransportProperties( U, phi, laminarTransport ) );
  
  dimensionedScalar beta = result_readTransProp.m_beta;
  dimensionedScalar TRef = result_readTransProp.m_TRef;
  
  Info<< "Creating turbulence model\n" << endl;
  turbulence = incompressible::RASModelHolder::New(U, phi, laminarTransport); 

  // Kinematic density for buoyancy force
  rhok( volScalarFieldHolder( IOobjectHolder( "rhok",
                                               runTime->timeName(),
                                               mesh ),
                               volScalarFieldHolder( 1.0 - beta * ( T() - TRef ), &T ) ) );
  
  // kinematic turbulent thermal thermal conductivity m2/s
  Info<< "Reading field kappat\n" << endl;
  kappat( volScalarFieldHolder( IOobjectHolder( "kappat",
                                                 runTime->timeName(),
                                                 mesh,
                                                 IOobject::MUST_READ,
                                                 IOobject::AUTO_WRITE ),
                                   mesh ) );

  Info<< "Calculating field g.h\n" << endl;
  gh( volScalarFieldHolder( "gh", g & volVectorFieldHolder( mesh->C(), Deps( &mesh ) ) ) );
  ghf(  surfaceScalarFieldHolder( "ghf", g & surfaceVectorFieldHolder( mesh->Cf(), Deps( &mesh ) ) ) );

  p( volScalarFieldHolder( IOobjectHolder( "p",
                                            runTime->timeName(),
                                            mesh,
                                            IOobject::NO_READ,
                                            IOobject::AUTO_WRITE ),
                            p_rgh + rhok*gh ) );

  setRefCell( p, p_rgh, mesh->solutionDict().subDict("SIMPLE"), pRefCell, pRefValue );

  if ( p_rgh->needReference() )
  {
    p += dimensionedScalar( "p",
                            p->dimensions(),
                            pRefValue - getRefCellValue( p, pRefCell ) );
  }
  
  return result_readTransProp;
}