int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"
    #if defined(version30)
        pisoControl piso(mesh);
        #include "createTimeControls.H"
    #endif
    #include "createFields.H"
    #include "createFvOptions.H"
    #include "initContinuityErrs.H"

    // create cfdemCloud
    #include "readGravitationalAcceleration.H"
    #include "checkImCoupleM.H"
    #if defined(anisotropicRotation)
        cfdemCloudRotation particleCloud(mesh);
    #elif defined(superquadrics_flag)
        cfdemCloudRotationSuperquadric particleCloud(mesh);
    #else
        cfdemCloud particleCloud(mesh);
    #endif
    #include "checkModelType.H"

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    Info<< "\nStarting time loop\n" << endl;
    while (runTime.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        #if defined(version30)
            #include "readTimeControls.H"
            #include "CourantNo.H"
            #include "setDeltaT.H"
        #else
            #include "readPISOControls.H"
            #include "CourantNo.H"
        #endif

        // do particle stuff
        particleCloud.clockM().start(1,"Global");
        particleCloud.clockM().start(2,"Coupling");
        bool hasEvolved = particleCloud.evolve(voidfraction,Us,U);

        if(hasEvolved)
        {
            particleCloud.smoothingM().smoothenAbsolutField(particleCloud.forceM(0).impParticleForces());
        }
    
        Ksl = particleCloud.momCoupleM(particleCloud.registryM().getProperty("implicitCouple_index")).impMomSource();
        Ksl.correctBoundaryConditions();

        surfaceScalarField voidfractionf = fvc::interpolate(voidfraction);
        phi = voidfractionf*phiByVoidfraction;

        //Force Checks
        #include "forceCheckIm.H"

        #include "solverDebugInfo.H"
        particleCloud.clockM().stop("Coupling");

        particleCloud.clockM().start(26,"Flow");

        if(particleCloud.solveFlow())
        {
            // Pressure-velocity PISO corrector
            {
                // Momentum predictor
                fvVectorMatrix UEqn
                (
                    fvm::ddt(voidfraction,U) - fvm::Sp(fvc::ddt(voidfraction),U)
                  + fvm::div(phi,U) - fvm::Sp(fvc::div(phi),U)
//                + turbulence->divDevReff(U)
                  + particleCloud.divVoidfractionTau(U, voidfraction)
                  ==
                  - fvm::Sp(Ksl/rho,U)
                  + fvOptions(U)
                );

                UEqn.relax();
                fvOptions.constrain(UEqn);

                #if defined(version30)
                    if (piso.momentumPredictor())
                #else
                    if (momentumPredictor)
                #endif
                {
                    if (modelType=="B" || modelType=="Bfull")
                        solve(UEqn == - fvc::grad(p) + Ksl/rho*Us);
                    else
                        solve(UEqn == - voidfraction*fvc::grad(p) + Ksl/rho*Us);

                    fvOptions.correct(U);
                }

                // --- PISO loop
                #if defined(version30)
                    while (piso.correct())
                #else
                    for (int corr=0; corr<nCorr; corr++)
                #endif
                {
                    volScalarField rUA = 1.0/UEqn.A();

                    surfaceScalarField rUAf("(1|A(U))", fvc::interpolate(rUA));
                    volScalarField rUAvoidfraction("(voidfraction2|A(U))",rUA*voidfraction);
                    surfaceScalarField rUAfvoidfraction("(voidfraction2|A(U)F)", fvc::interpolate(rUAvoidfraction));

                    U = rUA*UEqn.H();

                    #ifdef version23
                        phi = ( fvc::interpolate(U) & mesh.Sf() )
                            + rUAfvoidfraction*fvc::ddtCorr(U, phiByVoidfraction);
                    #else
                        phi = ( fvc::interpolate(U) & mesh.Sf() )
                            + fvc::ddtPhiCorr(rUAvoidfraction, U, phiByVoidfraction);
                    #endif
                    surfaceScalarField phiS(fvc::interpolate(Us) & mesh.Sf());
                    phi += rUAf*(fvc::interpolate(Ksl/rho) * phiS);

                    if (modelType=="A")
                        rUAvoidfraction = volScalarField("(voidfraction2|A(U))",rUA*voidfraction*voidfraction);

                    // Update the fixedFluxPressure BCs to ensure flux consistency
                    #include "fixedFluxPressureHandling.H"
                    

                    // Non-orthogonal pressure corrector loop
                    #if defined(version30)
                        while (piso.correctNonOrthogonal())
                    #else
                        for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
                    #endif
                    {
                        // Pressure corrector
                        fvScalarMatrix pEqn
                        (
                            fvm::laplacian(rUAvoidfraction, p) == fvc::div(voidfractionf*phi) + particleCloud.ddtVoidfraction()
                        );
                        pEqn.setReference(pRefCell, pRefValue);

                        #if defined(version30)
                            pEqn.solve(mesh.solver(p.select(piso.finalInnerIter())));
                            if (piso.finalNonOrthogonalIter())
                            {
                                phiByVoidfraction = phi - pEqn.flux()/voidfractionf;
                            }
                        #else
                            if( corr == nCorr-1 && nonOrth == nNonOrthCorr )
                                #if defined(versionExt32)
                                    pEqn.solve(mesh.solutionDict().solver("pFinal"));
                                #else
                                    pEqn.solve(mesh.solver("pFinal"));
                                #endif
                            else
                                pEqn.solve();

                            if (nonOrth == nNonOrthCorr)
                            {
                                phiByVoidfraction = phi - pEqn.flux()/voidfractionf;
                            }
                        #endif

                    } // end non-orthogonal corrector loop

                    phi = voidfractionf*phiByVoidfraction;
                    #include "continuityErrorPhiPU.H"

                    if (modelType=="B" || modelType=="Bfull")
                        U -= rUA*fvc::grad(p) - Ksl/rho*Us*rUA;
                    else
                        U -= voidfraction*rUA*fvc::grad(p) - Ksl/rho*Us*rUA;

                    U.correctBoundaryConditions();
                    fvOptions.correct(U);

                } // end piso loop
            }
int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"
    #if defined(version30)
        pisoControl piso(mesh);
        #include "createTimeControls.H"
    #endif
    #include "createFields.H"
    #include "initContinuityErrs.H"

    // create cfdemCloud
    #include "readGravitationalAcceleration.H"
    #if defined(anisotropicRotation)
        cfdemCloudRotation particleCloud(mesh);
    #else
        cfdemCloud particleCloud(mesh);
    #endif
    #include "checkModelType.H"

    // create a scalarTransportModel
    autoPtr<scalarTransportModel> stm
    (
        scalarTransportModel::New(particleCloud.couplingProperties(),particleCloud)
    );

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    Info<< "\nStarting time loop\n" << endl;
    while (runTime.loop())
    {
        particleCloud.clockM().start(1,"Global");

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

        #if defined(version30)
            #include "readTimeControls.H"
            #include "CourantNo.H"
            #include "setDeltaT.H"
        #else
            #include "readPISOControls.H"
            #include "CourantNo.H"
        #endif

        // do particle stuff
        particleCloud.clockM().start(2,"Coupling");
        bool hasEvolved = particleCloud.evolve(voidfraction,Us,U);

        if(hasEvolved)
        {
            particleCloud.smoothingM().smoothen(particleCloud.forceM(0).impParticleForces());
        }
    
        Info << "update Ksl.internalField()" << endl;
        Ksl = particleCloud.momCoupleM(0).impMomSource();
        Ksl.correctBoundaryConditions();

        //Force Checks
        #include "forceCheckIm.H"

        #include "solverDebugInfo.H"
        particleCloud.clockM().stop("Coupling");

        particleCloud.clockM().start(26,"Flow");

        /*// get scalar source from DEM        
        particleCloud.forceM(1).manipulateScalarField(Tsource);
        Tsource.correctBoundaryConditions();*/

        stm().update();

        /*// solve scalar transport equation
        fvScalarMatrix TEqn
        (
           fvm::ddt(voidfraction,T) - fvm::Sp(fvc::ddt(voidfraction),T)
         + fvm::div(phi, T) - fvm::Sp(fvc::div(phi),T)
         - fvm::laplacian(DT*voidfraction, T)
         ==
           Tsource
        );
        TEqn.relax();
        TEqn.solve();*/

        particleCloud.clockM().start(26,"Flow");

        if(particleCloud.solveFlow())
        {
            // Pressure-velocity PISO corrector
            {
                // Momentum predictor
                fvVectorMatrix UEqn
                (
                    fvm::ddt(voidfraction,U) - fvm::Sp(fvc::ddt(voidfraction),U)
                  + fvm::div(phi,U) - fvm::Sp(fvc::div(phi),U)
//                + turbulence->divDevReff(U)
                  + particleCloud.divVoidfractionTau(U, voidfraction)
                  ==
                  - fvm::Sp(Ksl/rho,U)
                );

                UEqn.relax();

                #if defined(version30)
                    if (piso.momentumPredictor())
                #else
                    if (momentumPredictor)
                #endif
                {
                    if (modelType=="B" || modelType=="Bfull")
                        solve(UEqn == - fvc::grad(p) + Ksl/rho*Us);
                    else
                        solve(UEqn == - voidfraction*fvc::grad(p) + Ksl/rho*Us);
                }

                // --- PISO loop
                #if defined(version30)
                    while (piso.correct())
                #else
                    int nCorrSoph = nCorr + 5 * pow((1-particleCloud.dataExchangeM().timeStepFraction()),1);
                    for (int corr=0; corr<nCorrSoph; corr++)
                #endif
                {
                    volScalarField rUA = 1.0/UEqn.A();

                    surfaceScalarField rUAf("(1|A(U))", fvc::interpolate(rUA));
                    volScalarField rUAvoidfraction("(voidfraction2|A(U))",rUA*voidfraction);
                    surfaceScalarField rUAfvoidfraction("(voidfraction2|A(U)F)", fvc::interpolate(rUAvoidfraction));

                    U = rUA*UEqn.H();

                    #ifdef version23
                        phi = ( fvc::interpolate(U*voidfraction) & mesh.Sf() )
                            + rUAfvoidfraction*fvc::ddtCorr(U, phi);
                    #else
                        phi = ( fvc::interpolate(U*voidfraction) & mesh.Sf() )
                            + fvc::ddtPhiCorr(rUAvoidfraction, U, phi);
                    #endif
                    surfaceScalarField phiS(fvc::interpolate(Us*voidfraction) & mesh.Sf());
                    surfaceScalarField phiGes = phi + rUAf*(fvc::interpolate(Ksl/rho) * phiS);

                    if (modelType=="A")
                        rUAvoidfraction = volScalarField("(voidfraction2|A(U))",rUA*voidfraction*voidfraction);

                    // Update the fixedFluxPressure BCs to ensure flux consistency
                    #ifndef versionExt32
                        if (modelType=="A")
                        {
                            surfaceScalarField voidfractionf(fvc::interpolate(voidfraction));
                            setSnGrad<fixedFluxPressureFvPatchScalarField>
                            (
                                p.boundaryField(),
                                (
                                    phi.boundaryField()
                                  - (mesh.Sf().boundaryField() & U.boundaryField())
                                )/(mesh.magSf().boundaryField()*rUAf.boundaryField()*voidfractionf.boundaryField())
                            );
                        }else
                        {
                            setSnGrad<fixedFluxPressureFvPatchScalarField>
                            (
                                p.boundaryField(),
                                (
                                    phi.boundaryField()
                                  - (mesh.Sf().boundaryField() & U.boundaryField())
                                )/(mesh.magSf().boundaryField()*rUAf.boundaryField())
                            );
                        }
                    #endif

                    // Non-orthogonal pressure corrector loop
                    #if defined(version30)
                        while (piso.correctNonOrthogonal())
                    #else
                        for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
                    #endif
                    {
                        // Pressure corrector
                        fvScalarMatrix pEqn
                        (
                            fvm::laplacian(rUAvoidfraction, p) == fvc::div(phiGes) + particleCloud.ddtVoidfraction()
                        );
                        pEqn.setReference(pRefCell, pRefValue);

                        #if defined(version30)
                            pEqn.solve(mesh.solver(p.select(piso.finalInnerIter())));
                            if (piso.finalNonOrthogonalIter())
                            {
                                phiGes -= pEqn.flux();
                                phi = phiGes;
                            }
                        #else
                            if( corr == nCorr-1 && nonOrth == nNonOrthCorr )
                                #if defined(versionExt32)
                                    pEqn.solve(mesh.solutionDict().solver("pFinal"));
                                #else
                                    pEqn.solve(mesh.solver("pFinal"));
                                #endif
                            else
                                pEqn.solve();

                            if (nonOrth == nNonOrthCorr)
                            {
                                phiGes -= pEqn.flux();
                                phi = phiGes;
                            }
                        #endif

                    } // end non-orthogonal corrector loop

                    #include "continuityErrorPhiPU.H"

                    if (modelType=="B" || modelType=="Bfull")
                        U -= rUA*fvc::grad(p) - Ksl/rho*Us*rUA;
                    else
                        U -= voidfraction*rUA*fvc::grad(p) - Ksl/rho*Us*rUA;

                    U.correctBoundaryConditions();

                } // end piso loop
            }
Example #3
0
int main(int argc, char *argv[])
{
    #include "setRootCase.H"

    #include "createTime.H"
    #include "createMesh.H"
    #include "readMaterialProperties.H"
    #include "readPoroElasticControls.H"
    #include "createFields.H"

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

    Info<< "\nCalculating displacement field\n" << endl;

    while (runTime.loop())
    {
        Info<< "Iteration: " << runTime.value() << nl << endl;

        #include "readPoroElasticControls.H"

        int iCorr = 0;
        scalar DResidual = 1.0e10;
        scalar pResidual = 1.0e10;
		scalar residual = 1.0e10;

        do
        {
			
			fvScalarMatrix pEqn
			(
				fvm::ddt(p) == fvm::laplacian(Dp, p) - fvc::div(fvc::ddt(Dp2,D))
			);
			pResidual = pEqn.solve().initialResidual();
			
			fvVectorMatrix DEqn
			(
				fvm::laplacian(2*mu + lambda, D, "laplacian(DD,D)") + divSigmaExp == fvc::grad(p)
			);
			DResidual = DEqn.solve().initialResidual();
		
			volTensorField gradD = fvc::grad(D);
			sigmaD = mu*twoSymm(gradD) + (lambda*I)*tr(gradD);
			divSigmaExp = fvc::div(sigmaD - (2*mu + lambda)*gradD,"div(sigmaD)");
			
			residual = max(pResidual,DResidual);

        } while (residual > convergenceTolerance && ++iCorr < nCorr);

        #include "calculateStress.H"

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

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

    return 0;
}
Example #4
0
void demIcoFoam::run(double time_increment) {
  volVectorField        &U = *U_;
  volVectorField        &f = *f_;
  volScalarField        &n = *n_;
  volScalarField        &p = *p_;
  dimensionedScalar     &nu = *nu_;
  surfaceScalarField    &phi = *phi_;
  Foam::Time            &runTime = *runTime_;
  Foam::fvMesh          &mesh = *mesh_;
  scalar &cumulativeContErr = cumulativeContErr_;

  runTime.setEndTime(runTime.value() + time_increment);
  while (runTime.loop())
  {
    Info<< "Time = " << runTime.timeName() << nl << endl;
    #include "CourantNo.H"

    fvVectorMatrix UEqn
      (fvm::ddt(U) + fvm::div(phi, U) -
       fvm::laplacian(nu, U) - f/n);

    if (piso_->momentumPredictor())
      solve(UEqn == -fvc::grad(p));

    while (piso_->correct())
    {
      volScalarField rAU(1.0/UEqn.A());

      volVectorField HbyA("HbyA", U);
      HbyA = rAU*UEqn.H();
      surfaceScalarField phiHbyA
        ("phiHbyA", (fvc::interpolate(HbyA) & mesh_->Sf()));

      adjustPhi(phiHbyA, U, p);

      while (piso_->correctNonOrthogonal())
      {
        fvScalarMatrix pEqn
          (fvm::laplacian(rAU, p) ==
           fvc::div(phiHbyA) //+ dndt
            );
        pEqn.setReference(pRefCell_, pRefValue_);
        pEqn.solve(mesh.solver(p.select(piso_->finalInnerIter())));
        if (piso_->finalNonOrthogonalIter()) phi = phiHbyA - pEqn.flux();
      }


#include "continuityErrs.H"

      U = HbyA - rAU*fvc::grad(p);
      U.correctBoundaryConditions();
    }
    runTime.write();
    Info<< "ExecutionTime = " << runTime_->elapsedCpuTime() << " s"
        << "  ClockTime = " << runTime_->elapsedClockTime() << " s"
        << nl << endl;
  }
}
Example #5
0
//---------------------------------------------------------------------------
void fun_pEqn( const fvMeshHolder& mesh,
               const TimeHolder& runTime,
               const simpleControlHolder& simple,               
               volVectorFieldHolder& U, 
               surfaceScalarFieldHolder& phi, 
               incompressible::RASModelHolder& turbulence,
               volScalarFieldHolder& p,
               fvVectorMatrixHolder& UEqn,
               label& pRefCell,
               scalar& pRefValue,
               scalar& cumulativeContErr )
{
  p->boundaryField().updateCoeffs();

  smart_tmp< volScalarField > rAU(1.0/UEqn->A());
  U = rAU() * UEqn->H();

  phi = fvc::interpolate( U(), "interpolate(HbyA)") & mesh->Sf();
  adjustPhi(phi, U, p);

    // Non-orthogonal pressure corrector loop
  for (int nonOrth=0; nonOrth<=simple->nNonOrthCorr(); nonOrth++)
  {
    smart_tmp< fvScalarMatrix > pEqn( fvm::laplacian( rAU(), p() ) == fvc::div( phi() ) );

    pEqn->setReference(pRefCell, pRefValue);

    pEqn->solve();

    if (nonOrth == simple->nNonOrthCorr())
    {
      phi -= pEqn->flux();
    }
  }

  continuityErrors( runTime, mesh, phi, cumulativeContErr );

  // Explicitly relax pressure for momentum corrector
  p->relax();

  // Momentum corrector
  U -= rAU() * fvc::grad( p() );
  U->correctBoundaryConditions();
}
int main(int argc, char *argv[])
{

#   include "setRootCase.H"

#   include "createEngineTime.H"
#   include "createDynamicFvMesh.H"
#   include "initContinuityErrs.H"
#   include "createFields.H"

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

    Info<< "\nStarting time loop\n" << endl;

    while (runTime.run())
    {
#       include "readControls.H"
#       include "checkTotalVolume.H"
#       include "CourantNo.H"

        // Make the fluxes absolute
        fvc::makeAbsolute(phi, U);

#       include "setDeltaT.H"

        runTime++;

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

        bool meshChanged = mesh.update();
        reduce(meshChanged, orOp<bool>());

        if (meshChanged)
        {
#           include "checkTotalVolume.H"
#           include "correctPhi.H"
#           include "CourantNo.H"
        }

        // Make the fluxes relative to the mesh motion
        fvc::makeRelative(phi, U);

        if (checkMeshCourantNo)
        {
#           include "meshCourantNo.H"
        }

#       include "UEqn.H"

        // --- PISO loop
        for (int corr = 0; corr < nCorr; corr++)
        {
            rUA = 1.0/UEqn.A();

            U = rUA*UEqn.H();
            phi = (fvc::interpolate(U) & mesh.Sf());
              //+ fvc::ddtPhiCorr(rUA, U, phi);

            adjustPhi(phi, U, p);

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

                pEqn.setReference(pRefCell, pRefValue);

                if (corr == nCorr - 1 && nonOrth == nNonOrthCorr)
                {
                    pEqn.solve(mesh.solutionDict().solver(p.name() + "Final"));
                }
                else
                {
                    pEqn.solve(mesh.solutionDict().solver(p.name()));
                }

                if (nonOrth == nNonOrthCorr)
                {
                    phi -= pEqn.flux();
                }
            }

#           include "continuityErrs.H"

            // Make the fluxes relative to the mesh motion
            fvc::makeRelative(phi, U);

            U -= rUA*fvc::grad(p);
            U.correctBoundaryConditions();
        }

        turbulence->correct();

        runTime.write();

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

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

    return(0);
}
Example #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;
}
int main(int argc, char *argv[])
{

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

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

    Info<< "\nStarting time loop\n" << endl;

    while (runTime.loop())
    {
        Info<< "Time = " << runTime.value() << nl << endl;

#       include "readPISOControls.H"
        scalar HbyAblend = readScalar(piso.lookup("HbyAblend"));

#       include "readTimeControls.H"

        scalar CoNum = max
        (
            mesh.surfaceInterpolation::deltaCoeffs()
           *mag(phiv)/mesh.magSf()
        ).value()*runTime.deltaT().value();

        Info<< "Max Courant Number = " << CoNum << endl;

#       include "setDeltaT.H"

        for (int outerCorr = 0; outerCorr < nOuterCorr; outerCorr++)
        {
            magRhoU = mag(rhoU);
            H = (rhoE + p)/rho;

            fv::multivariateGaussConvectionScheme<scalar> mvConvection
            (
                mesh,
                fields,
                phiv,
                mesh.schemesDict().divScheme("div(phiv,rhoUH)")
            );

            solve
            (
                fvm::ddt(rho)
              + mvConvection.fvmDiv(phiv, rho)
            );

            surfaceScalarField rhoUWeights =
                mvConvection.interpolationScheme()()(magRhoU)()
               .weights(magRhoU);

            weighted<vector> rhoUScheme(rhoUWeights);

            fvVectorMatrix rhoUEqn
            (
                fvm::ddt(rhoU)
              + fv::gaussConvectionScheme<vector>(mesh, phiv, rhoUScheme)
                   .fvmDiv(phiv, rhoU)
            );

            solve(rhoUEqn == -fvc::grad(p));

            solve
            (
                fvm::ddt(rhoE)
              + mvConvection.fvmDiv(phiv, rhoE)
             ==
              - mvConvection.fvcDiv(phiv, p)
            );

            T = (rhoE - 0.5*rho*magSqr(rhoU/rho))/Cv/rho;
            psi = 1.0/(R*T);
            p = rho/psi;

            for (int corr = 0; corr < nCorr; corr++)
            {
                volScalarField rrhoUA = 1.0/rhoUEqn.A();
                surfaceScalarField rrhoUAf("rrhoUAf", fvc::interpolate(rrhoUA));
                volVectorField HbyA = rrhoUA*rhoUEqn.H();

                surfaceScalarField HbyAWeights =
                    HbyAblend*mesh.weights()
                  + (1.0 - HbyAblend)*
                    LimitedScheme
                        <vector, MUSCLLimiter<NVDTVD>, limitFuncs::magSqr>
                        (mesh, phi, IStringStream("HbyA")()).weights(HbyA);

                phi =
                    (
                        surfaceInterpolationScheme<vector>::interpolate
                        (HbyA, HbyAWeights) & mesh.Sf()
                    )
                  + HbyAblend*fvc::ddtPhiCorr(rrhoUA, rho, rhoU, phi);

                p.boundaryField().updateCoeffs();

                surfaceScalarField phiGradp =
                    rrhoUAf*mesh.magSf()*fvc::snGrad(p);

                phi -= phiGradp;

#               include "resetPhiPatches.H"

                surfaceScalarField rhof =
                    mvConvection.interpolationScheme()()(rho)()
                   .interpolate(rho);

                phiv = phi/rhof;

                fvScalarMatrix pEqn
                (
                    fvm::ddt(psi, p)
                  + mvConvection.fvcDiv(phiv, rho)
                  + fvc::div(phiGradp)
                  - fvm::laplacian(rrhoUAf, p)
                );

                pEqn.solve();

                phi += phiGradp + pEqn.flux();
                rho = psi*p;
                rhof =
                    mvConvection.interpolationScheme()()(rho)()
                   .interpolate(rho);
                phiv = phi/rhof;

                rhoU = HbyA - rrhoUA*fvc::grad(p);
                rhoU.correctBoundaryConditions();
            }
        }

        U = rhoU/rho;

        runTime.write();

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

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

    return 0;
}
int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"
    #include "createFields.H"
    #include "initContinuityErrs.H"

    // create cfdemCloud
    #include "readGravitationalAcceleration.H"
    cfdemCloud particleCloud(mesh);
    #include "checkModelType.H"

    // create a scalarTransportModel
    autoPtr<scalarTransportModel> stm
    (
        scalarTransportModel::New(particleCloud.couplingProperties(),particleCloud)
    );

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    Info<< "\nStarting time loop\n" << endl;
    while (runTime.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        #include "readPISOControls.H"
        #include "CourantNo.H"

        // do particle stuff
        bool hasEvolved = particleCloud.evolve(voidfraction,Us,U);

        if(hasEvolved)
        {
            particleCloud.smoothingM().smoothen(particleCloud.forceM(0).impParticleForces());
        }
    
        Info << "update Ksl.internalField()" << endl;
        Ksl = particleCloud.momCoupleM(0).impMomSource();
        Ksl.correctBoundaryConditions();


        #include "solverDebugInfo.H"

        /*// get scalar source from DEM        
        particleCloud.forceM(1).manipulateScalarField(Tsource);
        Tsource.correctBoundaryConditions();*/

        stm().update();

        /*// solve scalar transport equation
        fvScalarMatrix TEqn
        (
           fvm::ddt(voidfraction,T) - fvm::Sp(fvc::ddt(voidfraction),T)
         + fvm::div(phi, T) - fvm::Sp(fvc::div(phi),T)
         - fvm::laplacian(DT*voidfraction, T)
         ==
           Tsource
        );
        TEqn.relax();
        TEqn.solve();*/

        if(particleCloud.solveFlow())
        {
            // Pressure-velocity PISO corrector
            {
                // Momentum predictor
                fvVectorMatrix UEqn
                (
                    fvm::ddt(voidfraction,U) - fvm::Sp(fvc::ddt(voidfraction),U)
                  + fvm::div(phi,U) - fvm::Sp(fvc::div(phi),U)
//                + turbulence->divDevReff(U)
                  + particleCloud.divVoidfractionTau(U, voidfraction)
                  ==
                  - fvm::Sp(Ksl/rho,U)
                );

                UEqn.relax();
                if (momentumPredictor && (modelType=="B" || modelType=="Bfull"))
                    solve(UEqn == - fvc::grad(p) + Ksl/rho*Us);
                else if (momentumPredictor)
                    solve(UEqn == - voidfraction*fvc::grad(p) + Ksl/rho*Us);

                // --- PISO loop

                //for (int corr=0; corr<nCorr; corr++)
                int nCorrSoph = nCorr + 5 * pow((1-particleCloud.dataExchangeM().timeStepFraction()),1);

                for (int corr=0; corr<nCorrSoph; corr++)
                {
                    volScalarField rUA = 1.0/UEqn.A();

                    surfaceScalarField rUAf("(1|A(U))", fvc::interpolate(rUA));
                    volScalarField rUAvoidfraction("(voidfraction2|A(U))",rUA*voidfraction);
                    surfaceScalarField rUAfvoidfraction("(voidfraction2|A(U)F)", fvc::interpolate(rUAvoidfraction));

                    U = rUA*UEqn.H();

                    #ifdef version23
                    phi = ( fvc::interpolate(U*voidfraction) & mesh.Sf() )
                        + rUAfvoidfraction*fvc::ddtCorr(U, phi);
                    #else
                    phi = ( fvc::interpolate(U*voidfraction) & mesh.Sf() )
                        + fvc::ddtPhiCorr(rUAvoidfraction, U, phi);
                    #endif
                    surfaceScalarField phiS(fvc::interpolate(Us*voidfraction) & mesh.Sf());
                    surfaceScalarField phiGes = phi + rUAf*(fvc::interpolate(Ksl/rho) * phiS);

                    if (modelType=="A")
                        rUAvoidfraction = volScalarField("(voidfraction2|A(U))",rUA*voidfraction*voidfraction);

                    // Non-orthogonal pressure corrector loop
                    for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
                    {
                        // Pressure corrector
                        fvScalarMatrix pEqn
                        (
                            fvm::laplacian(rUAvoidfraction, p) == fvc::div(phiGes) + particleCloud.ddtVoidfraction()
                        );
                        pEqn.setReference(pRefCell, pRefValue);

                        if
                        (
                            corr == nCorr-1
                         && nonOrth == nNonOrthCorr
                        )
                        {
                            pEqn.solve(mesh.solver("pFinal"));
                        }
                        else
                        {
                            pEqn.solve();
                        }

                        if (nonOrth == nNonOrthCorr)
                        {
                            phiGes -= pEqn.flux();
                            phi = phiGes;
                        }

                    } // end non-orthogonal corrector loop

                    #include "continuityErrorPhiPU.H"

                    if (modelType=="B" || modelType=="Bfull")
                        U -= rUA*fvc::grad(p) - Ksl/rho*Us*rUA;
                    else
                        U -= voidfraction*rUA*fvc::grad(p) - Ksl/rho*Us*rUA;

                    U.correctBoundaryConditions();

                } // end piso loop
            }

            turbulence->correct();
        }// end solveFlow
        else
        {
            Info << "skipping flow solution." << endl;
        }

        runTime.write();

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

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

    return 0;
}
int main(int argc, char *argv[])
{
#   include "setRootCase.H"

#   include "createTime.H"
#   include "createMesh.H"
#   include "createFields.H"
#   include "initContinuityErrs.H"

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

    Info<< "\nStarting time loop\n" << endl;

    while (runTime.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

#       include "readPISOControls.H"
#       include "CourantNo.H"

        fvVectorMatrix UEqn
        (
            fvm::ddt(U)
          + fvm::div(phi, U)
          - fvm::laplacian(nu, U)
        );

        solve(UEqn == -fvc::grad(p));

        // --- PISO loop

        for (int corr = 0; corr < nCorr; corr++)
        {
            volScalarField rUA = 1.0/UEqn.A();

            U = rUA*UEqn.H();
            phi = (fvc::interpolate(U) & mesh.Sf())
                + fvc::ddtPhiCorr(rUA, U, phi);

            adjustPhi(phi, U, p);

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

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

                if (nonOrth == nNonOrthCorr)
                {
                    phi -= pEqn.flux();
                }
            }

#           include "continuityErrs.H"

            U -= rUA*fvc::grad(p);
            U.correctBoundaryConditions();
        }

        runTime.write();

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

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

    return 0;
}
Example #11
0
int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"
    #include "readTransportProperties.H"
    #include "createFields.H"
    #include "initContinuityErrs.H"
    #include "createGradP.H"

    Info<< "\nStarting time loop\n" << endl;

    while (runTime.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        #include "readPISOControls.H"

        #include "CourantNo.H"

        sgsModel->correct();

        fvVectorMatrix UEqn
        (
            fvm::ddt(U)
          + fvm::div(phi, U)
          + sgsModel->divDevBeff(U)
         ==
            flowDirection*gradP
        );

        if (momentumPredictor)
        {
            solve(UEqn == -fvc::grad(p));
        }


        // --- PISO loop

        volScalarField rUA = 1.0/UEqn.A();

        for (int corr=0; corr<nCorr; corr++)
        {
            U = rUA*UEqn.H();
            phi = (fvc::interpolate(U) & mesh.Sf())
                + fvc::ddtPhiCorr(rUA, U, phi);

            adjustPhi(phi, U, p);

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

                pEqn.setReference(pRefCell, pRefValue);

                if (corr == nCorr-1 && nonOrth == nNonOrthCorr)
                {
                    pEqn.solve(mesh.solver(p.name() + "Final"));
                }
                else
                {
                    pEqn.solve(mesh.solver(p.name()));
                }

                if (nonOrth == nNonOrthCorr)
                {
                    phi -= pEqn.flux();
                }
            }

            #include "continuityErrs.H"

            U -= rUA*fvc::grad(p);
            U.correctBoundaryConditions();
        }


        // Correct driving force for a constant mass flow rate

        // Extract the velocity in the flow direction
        dimensionedScalar magUbarStar =
            (flowDirection & U)().weightedAverage(mesh.V());

        // Calculate the pressure gradient increment needed to
        // adjust the average flow-rate to the correct value
        dimensionedScalar gragPplus =
            (magUbar - magUbarStar)/rUA.weightedAverage(mesh.V());

        U += flowDirection*rUA*gragPplus;

        gradP += gragPplus;

        Info<< "Uncorrected Ubar = " << magUbarStar.value() << tab
            << "pressure gradient = " << gradP.value() << endl;

        runTime.write();

        #include "writeGradP.H"

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

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

    return 0;
}
int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"
    #include "readThermodynamicProperties.H"
	//#include "readTransportProperties.H"
    #include "createFields.H"
	#include "createFvOptions.H"
    #include "initContinuityErrs.H"

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

    Info<< "\nStarting time loop\n" << endl;

    while (runTime.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        #include "readPISOControls.H"
        #include "compressibleCourantNo.H"

        #include "rhoEqn.H"
	dimensionedScalar period = dimensionedScalar("period", dimensionSet(0,0,1,0,0,0,0), 5000);
        extForceField = extForce * rho / molMass * sin(2*3.1415*runTime.time()/period) ;

        fvVectorMatrix UEqn
        (
            fvm::ddt(rho, U)
          + fvm::div(phi, U)
          - fvm::laplacian(mu, U)
	  - extForceField 
        );

        solve(UEqn == -fvc::grad(p));

        // --- PISO loop

        for (int corr=0; corr<nCorr; corr++)
        {

	 psi = (a0*pow(p,10) + a1*pow(p,9) + a2*pow(p,8) + a3*pow(p,7) + a4*pow(p,6) + a5*pow(p,5) 
		 + a6*pow(p,4) + a7*pow(p,3) + a8*pow(p,2)  + a9*p  + a10)/p;
	
	 rho =  psi*(p);
	
	 mu = mu6 * pow(rho,6) + mu5 * pow(rho,5) + mu4 * pow(rho,4) + mu3 * pow(rho,3) +  mu2 * pow(rho,2) + mu1 * rho + mu0;


            volScalarField rUA = 1.0/UEqn.A();
            U = rUA*UEqn.H();

            surfaceScalarField phid
            (
                "phid",
               fvc::interpolate(psi)
               *(
                    (fvc::interpolate(U) & mesh.Sf())
					+ fvc::ddtCorr(rho, U, phi)
                  //+ fvc::ddtPhiCorr(rUA, rho, U, phi)
                )
            );

            phi = (fvc::interpolate(rho0 - psi*p0)/fvc::interpolate(psi))*phid;

            fvScalarMatrix pEqn
            (
                fvm::ddt(psi, p)
              + fvc::div(phi)
              + fvm::div(phid, p)
              - fvm::laplacian(rho*rUA, p)
            );

            pEqn.solve();

            phi += pEqn.flux();

            #include "compressibleContinuityErrs.H"

            U -= rUA*fvc::grad(p);
            U.correctBoundaryConditions();

        }

//       rhoU =    ( rho*U.component(0) ) * (mesh.Sf()); //  fvc::snGrad(fvc::reconstruct(phi)); //   fvc::reconstruct(phi);


       runTime.write();
//	#include "binMassFluxNew.H"

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

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

    return 0;
}
Example #13
0
//---------------------------------------------------------------------------
int main(int argc, char *argv[])
{
    argList args = setRootCase( argc, argv );

    TimeHolder runTime=createTime( Time::controlDictName, args );

    fvMeshHolder mesh = createMesh( runTime );

    IOdictionaryHolder transportProperties;
    volScalarFieldHolder p;
    volVectorFieldHolder U;
    surfaceScalarFieldHolder phi;
    label pRefCell = 0;
    scalar pRefValue = 0.0;

    dimensionedScalar nu = createFields( runTime, mesh, transportProperties, p, U, phi, pRefCell, pRefValue );


    scalar cumulativeContErr = initContinuityErrs();

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

    Info<< "\nStarting time loop\n" << endl;

    while (runTime->loop())
    {

        Info<< "Time = " << runTime->timeName() << nl << endl;

        dictionary pisoDict;
        int nOuterCorr;
        int nCorr;
        int nNonOrthCorr;
        bool momentumPredictor;
        bool transonic;
        readPISOControls( mesh, pisoDict, nOuterCorr, nCorr, nNonOrthCorr, momentumPredictor, transonic);

        CourantNo( runTime, mesh, phi );

        fvVectorMatrixHolder UEqn
        (
            fvm::ddt( U )
            + fvm::div( phi, U )
            - fvm::laplacian( nu, U )
        );

        solve( UEqn == -fvc::grad( p ) );

        // --- PISO loop

        for (int corr=0; corr<nCorr; corr++)
        {

            volScalarFieldHolder rAU( 1.0 / volScalarFieldHolder( UEqn->A(), &UEqn ) );

            U = rAU * volVectorFieldHolder( UEqn->H(), &UEqn );

            phi = ( fvc::interpolate(U) & surfaceVectorFieldHolder( mesh->Sf(), &mesh ) ) + fvc::ddtPhiCorr(rAU, U, phi);


            adjustPhi(phi, U, p);

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

                pEqn->setReference(pRefCell, pRefValue);
                pEqn->solve();

                if (nonOrth == nNonOrthCorr)
                {
                    phi -= pEqn->flux();
                }
            }

            continuityErrors( runTime, mesh, phi, cumulativeContErr );

            U -= rAU * fvc::grad(p);
            U->correctBoundaryConditions();
        }

        runTime->write();

        Info<< "ExecutionTime = " << runTime->elapsedCpuTime() << " s"
            << "  ClockTime = " << runTime->elapsedClockTime() << " s"
            << nl << endl;
    }

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

    return 0;
}
Example #14
0
int main(int argc, char *argv[])
{
    #include "setRootCase.H"

    #include "createTime.H"
    #include "createMesh.H"
    #include "createFields.H"
    #include "initContinuityErrs.H"

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

    Info<< "\nStarting time loop\n" << endl;

    while (runTime.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        #include "readPISOControls.H"
        #include "CourantNo.H"


        fvVectorMatrix UEqn
        (
            fvm::ddt(U)
          + fvm::div(phi, U)
          - fvm::laplacian(nu, U)
        );

        solve(UEqn == -fvc::grad(p));

        // --- PISO loop

        for (int corr=0; corr<nCorr; corr++)
        {
            volScalarField rAU(1.0/UEqn.A());

            volVectorField HbyA("HbyA", U);
            HbyA = rAU*UEqn.H();
            surfaceScalarField phiHbyA
            (
                "phiHbyA",
                (fvc::interpolate(HbyA) & mesh.Sf())
              + fvc::interpolate(rAU)*fvc::ddtCorr(U, phi)
            );

            adjustPhi(phiHbyA, U, p);

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

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

                if (nonOrth == nNonOrthCorr)
                {
                    phi = phiHbyA - pEqn.flux();
                }
            }

            #include "continuityErrs.H"

            U = HbyA - rAU*fvc::grad(p);
            U.correctBoundaryConditions();
        }

        runTime.write();

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


    // Get index of patch
	const word w0("fixedWalls");
	const word w1("movingWall");
	const word w2("frontAndBack");
	// call size() of mother class fvPatchList
	label nb_fvPatch = mesh.boundaryMesh().size();
	// 
	const label w0PatchID = mesh.boundaryMesh().findPatchID(w0);
	const label w1PatchID = mesh.boundaryMesh().findPatchID(w1);
	const label w2PatchID = mesh.boundaryMesh().findPatchID(w2);
	Info<< "Size of fvBoundryMesh = " 
			<< nb_fvPatch << "\n"<< endl;
	Info<< "PatchID for "
			<< w0
			<< " is "
			<< w0PatchID << "\n" << endl;
	Info<< "PatchID for "
			<< w1
			<< " is "
			<< w1PatchID << "\n" << endl;
	Info<< "PatchID for "
			<< w2
			<< " is "
			<< w2PatchID << "\n" << endl;

    // Get reference to boundary value
	const fvsPatchVectorField& faceCentreshub = mesh.Cf().boundaryField()[w0PatchID];  // const fvsPatchVectorField
    fvPatchVectorField& U_b = U.boundaryField()[w1PatchID]; // fvPatchVectorField
    
    // get coordinate for cell centre
    const fvPatchVectorField& centre = mesh.C().boundaryField()[w0PatchID];
    scalarField y = centre.component(vector::Y);
    scalarField x = centre.component(vector::X);
    
    // calculate inlet velocity
    //U_b = y*0.75/0.0051*vector (1,0,0)+x*0.75/0.0051*vector(0,1,0)+7.5*vector(0,0,1);
    
    //inletU.write();
	forAll(U_b, faceI)
	{
		const double PI = 3.14;
		//get coordinate for face centre
		const vector& c = faceCentreshub[faceI];
		//vector p(0.5*(1+Foam::sin(40*PI*c[0]-PI/2)), 0, 0);
		//if (c[0]>0.025 & c[0]<0.075)
	    //vector p1 = vector(1, 0, 0); 
		//vector p1(1, 0, 0);
		
		//U_b[faceI] = p1;
		Info<< "faceI = " << faceI 
			<< "c = "<< c 
			<< "U = "<< U_b[faceI] 
			<< endl;
	}
    
    Info<< "ExecutionTime = "
    << runTime.elapsedCpuTime()
    << " s\n\n" << endl;

    }

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

    return 0;
}
Example #15
0
int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"

    simpleControl simple(mesh);

    #include "createFields.H"
    #include "initContinuityErrs.H"

    Info<< "\nStarting time loop\n" << endl;

    while (simple.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;
        curvature.correctBoundaryConditions();

        /** temperature equation */
        fvScalarMatrix TEqn(
            fvm::laplacian(0.5 * gamma2 * sqrt(T), T) == fvc::div(U)
        );
        TEqn.solve();

        /** SIMPLE algorithm for solving pressure-velocity equations */

        /** velocity predictor */
        tmp<fvVectorMatrix> tUEqn(
              fvm::div(phi, U)
            - fvm::laplacian(0.5 * gamma1 * sqrt(T), U) ==
              0.5 * gamma1 * fvc::div(sqrt(T) * dev2(::T(fvc::grad(U))))
        );
        fvVectorMatrix& UEqn = tUEqn.ref();
        UEqn.relax();
        solve(UEqn ==
            fvc::reconstruct((
                - fvc::snGrad(p2)
                + gamma7 * fvc::snGrad(T) * fvc::interpolate(
                    (U / gamma2 / sqrt(T) - 0.25*fvc::grad(T)) & fvc::grad(T)/T
                )
            ) * mesh.magSf())
        );

        /** pressure corrector */
        volScalarField rAU(1./UEqn.A());
        surfaceScalarField rAUbyT("rhorAUf", fvc::interpolate(rAU / T));
        volVectorField HbyA("HbyA", U);
        HbyA = rAU * UEqn.H();
        tUEqn.clear();

        surfaceScalarField phiHbyA("phiHbyA", fvc::interpolate(HbyA / T) & mesh.Sf());
        adjustPhi(phiHbyA, U, p2);
        surfaceScalarField phif(
            gamma7 * rAUbyT * fvc::snGrad(T) * mesh.magSf() * fvc::interpolate(
                (U / gamma2 / sqrt(T) - 0.25*fvc::grad(T)) & fvc::grad(T)/T
            )
        );
        phiHbyA += phif;

        // Update the fixedFluxPressure BCs to ensure flux consistency
        setSnGrad<fixedFluxPressureFvPatchScalarField>
        (
            p2.boundaryFieldRef(),
            phiHbyA.boundaryField()
            / (mesh.magSf().boundaryField() * rAUbyT.boundaryField())
        );

        while (simple.correctNonOrthogonal()) {
            fvScalarMatrix pEqn(
                fvm::laplacian(rAUbyT, p2) == fvc::div(phiHbyA)
            );
            pEqn.setReference(pRefCell, getRefCellValue(p2, pRefCell));
            pEqn.solve();
            if (simple.finalNonOrthogonalIter()) {
                // Calculate the conservative fluxes
                phi = phiHbyA - pEqn.flux();
                p2.relax();
                /** velocity corrector */
                U = HbyA + rAU * fvc::reconstruct((phif - pEqn.flux()) / rAUbyT);
                U.correctBoundaryConditions();
            }
        }
        #include "continuityErrs.H"

        // Pressure is defined up to a constant factor,
        // we adjust it to maintain the initial domainIntegrate
        p2 += (initialPressure - fvc::domainIntegrate(p2)) / totalVolume;

        runTime.write();

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

    Info<< "End\n" << endl;
    return 0;
}
Example #16
0
int main(int argc, char *argv[])
{

#   include <OpenFOAM/setRootCase.H>

#   include <OpenFOAM/createTime.H>
#   include <OpenFOAM/createMesh.H>
#   include "createFields.H"
#   include <finiteVolume/initContinuityErrs.H>

    //mesh.clearPrimitives();

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

    Info<< "\nStarting time loop\n" << endl;

    for (runTime++; !runTime.end(); runTime++)
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

#       include <finiteVolume/readSIMPLEControls.H>

        p.storePrevIter();

        // Pressure-velocity SIMPLE corrector
        {
            // Momentum predictor
            tmp<fvVectorMatrix> UrelEqn
            (
                fvm::div(phi, Urel)
              + turbulence->divDevReff(Urel)
              + SRF->Su()
            );

            UrelEqn().relax();

            solve(UrelEqn() == -fvc::grad(p));

            p.boundaryField().updateCoeffs();
            volScalarField AUrel = UrelEqn().A();
            Urel = UrelEqn().H()/AUrel;
            UrelEqn.clear();
            phi = fvc::interpolate(Urel) & mesh.Sf();
            adjustPhi(phi, Urel, p);

            // Non-orthogonal pressure corrector loop
            for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
            {
                fvScalarMatrix pEqn
                (
                    fvm::laplacian(1.0/AUrel, p) == fvc::div(phi)
                );

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

                if (nonOrth == nNonOrthCorr)
                {
                    phi -= pEqn.flux();
                }
            }

#           include <finiteVolume/continuityErrs.H>

            // Explicitly relax pressure for momentum corrector
            p.relax();

            // Momentum corrector
            Urel -= fvc::grad(p)/AUrel;
            Urel.correctBoundaryConditions();
        }

        turbulence->correct();


        if (runTime.outputTime())
        {
            volVectorField Uabs
            (
                IOobject
                (
                    "Uabs",
                    runTime.timeName(),
                    mesh,
                    IOobject::NO_READ,
                    IOobject::AUTO_WRITE
                ),
                Urel + SRF->U()
            );

            runTime.write();
        }

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

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

    return(0);
}
int main(int argc, char *argv[])
{
#   include "setRootCase.H"
#   include "createTime.H"
#   include "createDynamicFvMesh.H"
#   include "createFields.H"
#   include "initContinuityErrs.H"
#   include "createBubble.H"
#   include "createSurfactantConcentrationField.H"

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

    Info << "\nStarting time loop\n" << endl;

    for (runTime++; !runTime.end(); runTime++)
    {
        Info << "Time = " << runTime.value() << endl << endl;

#       include "readPISOControls.H"

        interface.moveMeshPointsForOldFreeSurfDisplacement();

        interface.updateDisplacementDirections();

        interface.predictPoints();

        Info<< "\nMax surface Courant Number = "
            << interface.maxCourantNumber() << endl << endl;

        for (int corr=0; corr<nOuterCorr; corr++)
        {
            // Update interface bc
            interface.updateBoundaryConditions();

            // Make the fluxes relative
            phi -= fvc::meshPhi(rho, U);

#           include "CourantNo.H"

            fvVectorMatrix UEqn
            (
                fvm::ddt(rho, U)
              + rho*aF
              + fvm::div(fvc::interpolate(rho)*phi, U, "div(phi,U)")
              - fvm::laplacian(mu, U)
            );

            solve(UEqn == -fvc::grad(p));

            // --- PISO loop
            for (int i=0; i<nCorr; i++)
            {
                volScalarField AU = UEqn.A();

                U = UEqn.H()/AU;

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

#               include "scalePhi.H"

#               include "scaleSpacePhi.H"

                // Non-orthogonal pressure corrector loop
                for (label nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
                {
                    fvScalarMatrix pEqn
                    (
                        fvm::laplacian(1.0/AU, p)
                     == fvc::div(phi)
                    );

#                   include "setReference.H"

                    pEqn.solve();

                    if (nonOrth == nNonOrthCorr)
                    {
                        phi -= pEqn.flux();
                    }
                }

#               include "continuityErrs.H"

                // Momentum corrector
                U -= fvc::grad(p)/AU;
                U.correctBoundaryConditions();
            }

#           include "solveBulkSurfactant.H"

            interface.correctPoints();

#           include "freeSurfaceContinuityErrs.H"
        }

#       include "updateMovingReferenceFrame.H"

#       include "volContinuity.H"

        Info << "Total surface tension force: "
            << interface.totalSurfaceTensionForce() << endl;

        vector totalForce =
            interface.totalViscousForce()
          + interface.totalPressureForce();

        Info << "Total force: " << totalForce << endl;

        runTime.write();

        Info << "ExecutionTime = "
            << scalar(runTime.elapsedCpuTime())
            << " s\n" << endl << endl;
    }

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

    return(0);
}
int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"
    #include "readThermodynamicProperties.H"
	//#include "readTransportProperties.H"
    #include "createFields.H"
	#include "createFvOptions.H"
    #include "initContinuityErrs.H"

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

//	dimensionedScalar period = dimensionedScalar("period", dimensionSet(0,0,1,0,0,0,0), 0.22e-9);
//dimensionedScalar tRed =  dimensionedScalar("tRed", dimensionSet(0,0,1,0,0,0,0), 2.16059e-12);

//% STARTING PERIOD
//dimensionedScalar P_S =  dimensionedScalar("P_S", dimensionSet(0,0,1,0,0,0,0), 100* 2.16059e-12);
scalar P_S = 100; // *2.16059e-12;
//scalar P_S = 100*2.16059e-12;
//% END PERIOD
//dimensionedScalar P_E =  dimensionedScalar("P_E", dimensionSet(0,0,1,0,0,0,0), 5000* 2.16059e-12);
scalar P_E = 5000; //*2.16059e-12;
//scalar P_E = 5000*2.16059e-12;
//dimensionedScalar endTime =  dimensionedScalar("endTime", dimensionSet(0,0,1,0,0,0,0), 10000* 2.16059e-12); 
scalar endTime = 10000; //*2.16059e-12;
//scalar endTime = 10000*2.16059e-12;
   // QUICKER TO BEGIN WITH AND HIGHER ORDER POLYNOMIAL
scalar n = 30; //*2.16059e-12;

//dimensionedScalar phase = 0; 
scalar phase = 0;
//scalar period = 0;

    Info<< "\nStarting time loop\n" << endl;

    while (runTime.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        #include "readPISOControls.H"
        #include "compressibleCourantNo.H"

        #include "rhoEqn.H"

scalar T = runTime.time().value() / 2.16059e-12;

   scalar temp = ( Foam::pow(( (T - endTime)/endTime), n));
Info << "temp = " << temp << endl;
//   dimensionedScalar freq =  dimensionedScalar("freq", dimensionSet(0,0,-1,0,0,0,0), 0); 
   scalar freq= ((1/P_E) - ( ( (1/P_E) - (1/P_S) ) * temp )) /2.16059e-12 ;
   
//   dimensionedScalar period = dimensionedScalar("period", dimensionSet(0,0,1,0,0,0,0), 1/freq);
//   dimensionedScalar period =  1/freq;
scalar  period = 1/freq;
//   phase +=  (freq * runTime.deltaT().value()/2.16059e-12)  ; // 0.0025*2.16059e-12;
Info << "phase = " << phase << endl;
   phase +=  ((freq) * runTime.deltaT().value())  ; // 0.0025*2.16059e-12;
Info << "freq = " << freq << endl;
Info << "phase = " << phase << endl;
Info << "period = " << period << endl;

   extForceField = extForce * rho / molMass * Foam::sin(2*3.1415*phase); //  *phase) ;


        fvVectorMatrix UEqn
        (
            fvm::ddt(rho, U)
          + fvm::div(phi, U)
          - fvm::laplacian(mu, U)
	  - extForceField 
        );

        solve(UEqn == -fvc::grad(p));

        // --- PISO loop

        for (int corr=0; corr<nCorr; corr++)
        {

	 psi = (a0*pow(p,10) + a1*pow(p,9) + a2*pow(p,8) + a3*pow(p,7) + a4*pow(p,6) + a5*pow(p,5) 
		 + a6*pow(p,4) + a7*pow(p,3) + a8*pow(p,2)  + a9*p  + a10)/p;
	
	 rho =  psi*(p);
	
	 mu = mu6 * pow(rho,6) + mu5 * pow(rho,5) + mu4 * pow(rho,4) + mu3 * pow(rho,3) +  mu2 * pow(rho,2) + mu1 * rho + mu0;


            volScalarField rUA = 1.0/UEqn.A();
            U = rUA*UEqn.H();

            surfaceScalarField phid
            (
                "phid",
               fvc::interpolate(psi)
               *(
                    (fvc::interpolate(U) & mesh.Sf())
					+ fvc::ddtCorr(rho, U, phi)
                  //+ fvc::ddtPhiCorr(rUA, rho, U, phi)
                )
            );

            phi = (fvc::interpolate(rho0 - psi*p0)/fvc::interpolate(psi))*phid;

            fvScalarMatrix pEqn
            (
                fvm::ddt(psi, p)
              + fvc::div(phi)
              + fvm::div(phid, p)
              - fvm::laplacian(rho*rUA, p)
            );

            pEqn.solve();

            phi += pEqn.flux();

            #include "compressibleContinuityErrs.H"

            U -= rUA*fvc::grad(p);
            U.correctBoundaryConditions();

        }

//       rhoU =    ( rho*U.component(0) ) * (mesh.Sf()); //  fvc::snGrad(fvc::reconstruct(phi)); //   fvc::reconstruct(phi);


       runTime.write();
//	#include "binMassFluxNew.H"

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

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

    return 0;
}
Example #19
0
int main(int argc, char *argv[])
{
    #include <OpenFOAM/setRootCase.H>

    #include <OpenFOAM/createTime.H>
    #include <OpenFOAM/createMeshNoClear.H>
    #include "readTransportProperties.H"
    #include "createFields.H"
    #include "readTurbulenceProperties.H"
    #include <finiteVolume/initContinuityErrs.H>

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

    Info<< nl << "Starting time loop" << endl;

    while (runTime.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        #include <finiteVolume/readPISOControls.H>

        force.internalField() = ReImSum
        (
            fft::reverseTransform
            (
                K/(mag(K) + 1.0e-6) ^ forceGen.newField(), K.nn()
            )
        );

        #include "globalProperties.H"

        fvVectorMatrix UEqn
        (
            fvm::ddt(U)
          + fvm::div(phi, U)
          - fvm::laplacian(nu, U)
         ==
            force
        );

        solve(UEqn == -fvc::grad(p));


        // --- PISO loop

        for (int corr=1; corr<=1; corr++)
        {
            volScalarField rUA = 1.0/UEqn.A();

            U = rUA*UEqn.H();
            phi = (fvc::interpolate(U) & mesh.Sf())
                + fvc::ddtPhiCorr(rUA, U, phi);

            fvScalarMatrix pEqn
            (
                fvm::laplacian(rUA, p) == fvc::div(phi)
            );

            pEqn.solve();

            phi -= pEqn.flux();

            #include <finiteVolume/continuityErrs.H>

            U -= rUA*fvc::grad(p);
            U.correctBoundaryConditions();
        }

        runTime.write();

        if (runTime.outputTime())
        {
            calcEk(U, K).write(runTime.timePath()/"Ek", runTime.graphFormat());
        }

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

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

    return 0;
}
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);
}
//---------------------------------------------------------------------------
void fun_pEqn( const fvMeshHolder& mesh,
               const TimeHolder& runTime,
               const pimpleControlHolder& pimple,
               basicPsiThermoHolder& thermo,
               volScalarFieldHolder& rho,
               volScalarFieldHolder& p,
               volScalarFieldHolder& h,
               volScalarFieldHolder& psi,
               volVectorFieldHolder& U,
               surfaceScalarFieldHolder& phi,
               compressible::turbulenceModelHolder& turbulence,
               fvVectorMatrixHolder& UEqn,
               MRFZonesHolder& mrfZones,
               volScalarFieldHolder& DpDt,
               scalar& cumulativeContErr,
               int& corr,
               dimensionedScalar& rhoMax,
               dimensionedScalar& rhoMin )
{
  rho = thermo->rho();
  rho = max( rho(), rhoMin );
  rho = min( rho(), rhoMax );
  rho->relax();

  smart_tmp< volScalarField >  rAU( 1.0 / UEqn->A() );
  U = rAU() * UEqn->H();

  if (pimple->nCorr() <= 1)
  {
    //UEqn->clear();
  }

  if (pimple->transonic())
  {
     surfaceScalarField phid( "phid", fvc::interpolate( psi() ) * ( ( fvc::interpolate( U() ) & mesh->Sf() )
                                                                    + fvc::ddtPhiCorr( rAU(), rho(), U(), phi() ) ) );

    mrfZones->relativeFlux( fvc::interpolate( psi() ), phid);
    
    for (int nonOrth=0; nonOrth <= pimple->nNonOrthCorr(); nonOrth++ )
    {
      smart_tmp< fvScalarMatrix > pEqn( fvm::ddt( psi(), p() ) + fvm::div( phid, p() ) - fvm::laplacian( rho() * rAU(), p() ) );

      pEqn->solve( mesh->solver( p->select( pimple->finalInnerIter( corr, nonOrth ) ) ) );

      if ( nonOrth == pimple->nNonOrthCorr() )
      {
        phi == pEqn->flux();
      }
    }
  }
  else
  {
    phi = fvc::interpolate( rho() ) * ( ( fvc::interpolate( U() ) & mesh->Sf() ) + fvc::ddtPhiCorr( rAU(), rho(), U(), phi() ) );
    
    mrfZones->relativeFlux( fvc::interpolate( rho() ), phi() );

    for (int nonOrth=0; nonOrth<=pimple->nNonOrthCorr(); nonOrth++)
    {
      // Pressure corrector
      smart_tmp< fvScalarMatrix > pEqn( fvm::ddt( psi(), p() ) + fvc::div( phi() ) - fvm::laplacian( rho()*rAU(), p() ) );

      pEqn->solve( mesh->solver( p->select( pimple->finalInnerIter( corr, nonOrth ) ) ) );

      if ( nonOrth == pimple->nNonOrthCorr() )
      {
        phi += pEqn->flux();
      }
    }
  }

  rhoEqn( rho, phi );
  compressibleContinuityErrs( thermo, rho, cumulativeContErr );

  // Explicitly relax pressure for momentum corrector
  p->relax();

  // Recalculate density from the relaxed pressure
  rho = thermo->rho();
  rho = max( rho(), rhoMin );
  rho = min( rho(), rhoMax );
  rho->relax();
  Info<< "rho max/min : " << max( rho() ).value()  << " " << min( rho() ).value() << endl;

  U -= rAU() * fvc::grad( p() );
  U->correctBoundaryConditions();

  DpDt = fvc::DDt(surfaceScalarField("phiU", phi() / fvc::interpolate( rho() ) ), p());
}
int main(int argc, char *argv[])
{

    argList::validOptions.insert("writep", "");

    #include "setRootCase.H"

    #include "createTime.H"
    #include "createMesh.H"
    #include "readControls.H"
    #include "createFields.H"
    

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

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

    adjustPhi(phi, U, p);

    for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
    {
        fvScalarMatrix pEqn
        (
            fvm::laplacian
            (
                dimensionedScalar
                (
                    "1",
                    dimTime/p.dimensions()*dimensionSet(0, 2, -2, 0, 0),
                    1
                ),
                p
            )
         ==
            fvc::div(phi)
        );

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

        if (nonOrth == nNonOrthCorr)
        {
            phi -= pEqn.flux();
        }
    }

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

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

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

    // Force the write
    U.write();
    p.write();
    
    Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
        << "  ClockTime = " << runTime.elapsedClockTime() << " s"
        << nl << endl;

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

    return 0;
}
int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"
    #include "readThermodynamicProperties.H"
    #include "readTransportProperties.H"
    #include "createFields.H"
    #include "initContinuityErrs.H"

    pimpleControl pimple(mesh);

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

    Info<< "\nStarting time loop\n" << endl;

    while (runTime.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        #include "readTimeControls.H"
        #include "compressibleCourantNo.H"

        #include "rhoEqn.H"

        // --- Pressure-velocity PIMPLE corrector loop
        while (pimple.loop())
        {
            fvVectorMatrix UEqn
            (
                fvm::ddt(rho, U)
              + fvm::div(phi, U)
              - fvm::laplacian(mu, U)
            );

            solve(UEqn == -fvc::grad(p));

            // --- Pressure corrector loop
            while (pimple.correct())
            {
                volScalarField rAU(1.0/UEqn.A());
                U = rAU*UEqn.H();

                surfaceScalarField phid
                (
                    "phid",
                    psi
                   *(
                       (fvc::interpolate(U) & mesh.Sf())
                     + fvc::ddtPhiCorr(rAU, rho, U, phi)
                   )
                );

                phi = (rhoO/psi)*phid;
                volScalarField Dp("Dp", rho*rAU);

                fvScalarMatrix pEqn
                (
                    fvm::ddt(psi, p)
                  + fvc::div(phi)
                  + fvm::div(phid, p)
                  - fvm::laplacian(Dp, p)
                );

                pEqn.solve();

                phi += pEqn.flux();

                #include "compressibleContinuityErrs.H"

                U -= rAU*fvc::grad(p);
                U.correctBoundaryConditions();
            }
        }

        rho = rhoO + psi*p;

        runTime.write();

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

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

    return 0;
}
Example #24
0
int main(int argc, char *argv[])
{

#   include "setRootCase.H"

#   include "createTime.H"
#   include "createMesh.H"
#   include "createFields.H"
#   include "initContinuityErrs.H"

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

    Info<< "\nStarting time loop\n" << endl;

    for (runTime++; !runTime.end(); runTime++)
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

#       include "readSIMPLEControls.H"

        p.storePrevIter();

        // Pressure-velocity SIMPLE corrector
        {
            // Momentum predictor

            tmp<fvVectorMatrix> UEqn
            (
                fvm::div(phi, U)
              + turbulence->divDevReff(U)
            );
            mrfZones.addCoriolis(UEqn());

            UEqn().relax();

            solve(UEqn() == -fvc::grad(p));

            p.boundaryField().updateCoeffs();
            volScalarField rAU = 1.0/UEqn().A();
            U = rAU*UEqn().H();
            UEqn.clear();

            phi = fvc::interpolate(U, "interpolate(HbyA)") & mesh.Sf();
            mrfZones.relativeFlux(phi);
            adjustPhi(phi, U, p);

            // Non-orthogonal pressure corrector loop
            for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
            {
                fvScalarMatrix pEqn
                (
                    fvm::laplacian(rAU, p) == fvc::div(phi)
                );

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

                if (nonOrth == nNonOrthCorr)
                {
                    phi -= pEqn.flux();
                }
            }

#           include "continuityErrs.H"

            // Explicitly relax pressure for momentum corrector
            p.relax();

            // Momentum corrector
            U -= rAU*fvc::grad(p);
            U.correctBoundaryConditions();
        }

        turbulence->correct();

        runTime.write();

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

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

    return(0);
}
Example #25
0
int main(int argc, char *argv[])
{
#   include "setRootCase.H"

#   include "createTime.H"
#   include "createMesh.H"
#   include "createFields.H"
#   include "initContinuityErrs.H"

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

    Info<< "\nStarting time loop\n" << endl;

    while (runTime.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

#       include "readPISOControls.H"
#       include "CourantNo.H"

        // Pressure-velocity PISO corrector
        {
            // Momentum predictor

            fvVectorMatrix UEqn
            (
                fvm::ddt(U)
              + fvm::div(phi, U)
              + turbulence->divDevReff(U)
            );

            UEqn.relax();

            if (momentumPredictor)
            {
                solve(UEqn == -fvc::grad(p));
            }

            // --- PISO loop

            for (int corr=0; corr<nCorr; corr++)
            {
                volScalarField rUA = 1.0/UEqn.A();

                U = rUA*UEqn.H();
                phi = (fvc::interpolate(U) & mesh.Sf())
                    + fvc::ddtPhiCorr(rUA, U, phi);

                adjustPhi(phi, U, p);

                // Non-orthogonal pressure corrector loop
                for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
                {
                    // Pressure corrector

                    fvScalarMatrix pEqn
                    (
                        fvm::laplacian(rUA, p) == fvc::div(phi)
                    );

                    pEqn.setReference(pRefCell, pRefValue);

                    if
                    (
                        corr == nCorr-1
                     && nonOrth == nNonOrthCorr
                    )
                    {
                        pEqn.solve(mesh.solver("pFinal"));
                    }
                    else
                    {
                        pEqn.solve();
                    }

                    if (nonOrth == nNonOrthCorr)
                    {
                        phi -= pEqn.flux();
                    }
                }

#               include "continuityErrs.H"

                U -= rUA*fvc::grad(p);
                U.correctBoundaryConditions();
            }
        }

        turbulence->correct();

        runTime.write();

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

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

    return 0;
}
Example #26
0
int main(int argc, char *argv[])
{
#   include "setRootCase.H"

#   include "createTime.H"
#   include "createMesh.H"
#   include "createFields.H"
#   include "immersedBoundaryInitContinuityErrs.H"

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

    Info<< "\nStarting time loop\n" << endl;

    while (runTime.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

#       include "readPIMPLEControls.H"
#       include "CourantNo.H"

        // Pressure-velocity corrector
        int oCorr = 0;
        do
        {
            fvVectorMatrix UEqn
            (
                fvm::ddt(U)
              + fvm::div(phi, U)
              - fvm::laplacian(nu, U)
            );

            UEqn.boundaryManipulate(U.boundaryField());
            solve(UEqn == -cellIbMask*fvc::grad(p));

            // --- PISO loop
            for (int corr = 0; corr < nCorr; corr++)
            {
                volScalarField rUA = 1.0/UEqn.A();

                U = rUA*UEqn.H();
                // Immersed boundary update
                U.correctBoundaryConditions();

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

                // Adjust immersed boundary fluxes
                immersedBoundaryAdjustPhi(phi, U);
                adjustPhi(phi, U, p);

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

                    pEqn.setReference(pRefCell, pRefValue);
                    pEqn.boundaryManipulate(p.boundaryField());
                    pEqn.solve();

                    if (nonOrth == nNonOrthCorr)
                    {
                        phi -= pEqn.flux();
                    }
                }

#               include "immersedBoundaryContinuityErrs.H"

                U -= rUA*fvc::grad(p);
                U.correctBoundaryConditions();
            }
        } while (++oCorr < nOuterCorr);

        runTime.write();

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

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

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

#   include "setRootCase.H"

#   include "createTime.H"
#   include "createMesh.H"
#   include "createFields.H"
#   include "initContinuityErrs.H"


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

    Info<< nl << "Starting time loop" << endl;

    for (runTime++; !runTime.end(); runTime++)
    {
#       include "readPISOControls.H"
#       include "readBPISOControls.H"

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

#       include "CourantNo.H"

        {
            fvVectorMatrix UEqn
            (
                fvm::ddt(U)
              + fvm::div(phi, U)
              - fvc::div(phiB, 2.0*DBU*B)
              - fvm::laplacian(nu, U)
              + fvc::grad(DBU*magSqr(B))
            );

            solve(UEqn == -fvc::grad(p));


            // --- PISO loop

            for (int corr=0; corr<nCorr; corr++)
            {
                volScalarField rUA = 1.0/UEqn.A();

                U = rUA*UEqn.H();

                phi = (fvc::interpolate(U) & mesh.Sf()) 
                    + fvc::ddtPhiCorr(rUA, U, phi);

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

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

                    if (nonOrth == nNonOrthCorr)
                    {
                        phi -= pEqn.flux();
                    }
                }

#               include "continuityErrs.H"

                U -= rUA*fvc::grad(p);
                U.correctBoundaryConditions();
            }
        }

        // --- B-PISO loop

        for (int Bcorr=0; Bcorr<nBcorr; Bcorr++)
        {
            fvVectorMatrix BEqn
            (
                fvm::ddt(B)
              + fvm::div(phi, B)
              - fvc::div(phiB, U)
              - fvm::laplacian(DB, B)
            );

            BEqn.solve();

            volScalarField rBA = 1.0/BEqn.A();

            phiB = (fvc::interpolate(B) & mesh.Sf())
                + fvc::ddtPhiCorr(rBA, B, phiB);

            fvScalarMatrix pBEqn
            (
                fvm::laplacian(rBA, pB) == fvc::div(phiB)
            );
            pBEqn.solve();

            phiB -= pBEqn.flux();

#           include "magneticFieldErr.H"
        }

        runTime.write();
    }

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

    return(0);
}
Example #28
0
int main(int argc, char *argv[])
{
    #include "setRootCase.H"

    #include "createTime.H"
    #include "createMesh.H"
    #include "createFields.H"
    #include "initContinuityErrs.H"

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

    Info<< nl << "Starting time loop" << endl;

    while (runTime.loop())
    {
        #include "readPISOControls.H"
        #include "readBPISOControls.H"

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

        #include "CourantNo.H"

        {
            fvVectorMatrix UEqn
            (
                fvm::ddt(U)
              + fvm::div(phi, U)
              - fvc::div(phiB, 2.0*DBU*B)
              - fvm::laplacian(nu, U)
              + fvc::grad(DBU*magSqr(B))
            );

            solve(UEqn == -fvc::grad(p));


            // --- PISO loop

            for (int corr=0; corr<nCorr; corr++)
            {
                volScalarField rAU(1.0/UEqn.A());
                surfaceScalarField rAUf("rAUf", fvc::interpolate(rAU));

                volVectorField HbyA("HbyA", U);
                HbyA = rAU*UEqn.H();

                surfaceScalarField phiHbyA
                (
                    "phiHbyA",
                    (fvc::interpolate(HbyA) & mesh.Sf())
                  + rAUf*fvc::ddtCorr(U, phi)
                );

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

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

                    if (nonOrth == nNonOrthCorr)
                    {
                        phi = phiHbyA - pEqn.flux();
                    }
                }

                #include "continuityErrs.H"

                U = HbyA - rAU*fvc::grad(p);
                U.correctBoundaryConditions();
            }
        }

        // --- B-PISO loop

        for (int Bcorr=0; Bcorr<nBcorr; Bcorr++)
        {
            fvVectorMatrix BEqn
            (
                fvm::ddt(B)
              + fvm::div(phi, B)
              - fvc::div(phiB, U)
              - fvm::laplacian(DB, B)
            );

            BEqn.solve();

            volScalarField rAB(1.0/BEqn.A());
            surfaceScalarField rABf("rABf", fvc::interpolate(rAB));

            phiB = (fvc::interpolate(B) & mesh.Sf())
                + rABf*fvc::ddtCorr(B, phiB);

            fvScalarMatrix pBEqn
            (
                fvm::laplacian(rABf, pB) == fvc::div(phiB)
            );
            pBEqn.solve();

            phiB -= pBEqn.flux();

            #include "magneticFieldErr.H"
        }

        runTime.write();
    }

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

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

#   include "setRootCase.H"

#   include "createTime.H"
#   include "createMesh.H"
#   include "createFields.H"
#   include "initContinuityErrs.H"

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

    Info<< "\nStarting time loop\n" << endl;

    for (runTime++; !runTime.end(); runTime++)
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

#       include "readPISOControls.H"
#       include "CourantNo.H"

        fvVectorMatrix UEqn
        (
            fvm::ddt(U)
          + fvm::div(phi, U)
          - fvm::laplacian(nu, U)
        );

        fvVectorMatrix UEqnp(UEqn == -fvc::grad(p));

        lduVectorMatrix U3Eqnp(mesh);
        U3Eqnp.diag() = UEqnp.diag();
        U3Eqnp.upper() = UEqnp.upper();
        U3Eqnp.lower() = UEqnp.lower();
        U3Eqnp.source() = UEqnp.source();

        UEqnp.addBoundaryDiag(U3Eqnp.diag(), 0);
        UEqnp.addBoundarySource(U3Eqnp.source(), false);

        autoPtr<lduVectorMatrix::solver> U3EqnpSolver =
            lduVectorMatrix::solver::New
            (
                U.name(),
                U3Eqnp,
                dictionary
                (
                    IStringStream
                    (
                        "{"
                        "    solver           PBiCG;"
                        "    preconditioner   DILU;"
                        "    tolerance        (1e-13 1e-13 1e-13);"
                        "    relTol           (0 0 0);"
                        "}"
                    )()
                )
            );

        U3EqnpSolver->solve(U).print(Info);

        // --- PISO loop

        for (int corr=0; corr<nCorr; corr++)
        {
            volScalarField rUA = 1.0/UEqn.A();

            U = rUA*UEqn.H();
            phi = (fvc::interpolate(U) & mesh.Sf()) 
                + fvc::ddtPhiCorr(rUA, U, phi);

            adjustPhi(phi, U, p);

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

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

                if (nonOrth == nNonOrthCorr)
                {
                    phi -= pEqn.flux();
                }
            }

#           include "continuityErrs.H"

            U -= rUA*fvc::grad(p);
            U.correctBoundaryConditions();
        }

        runTime.write();

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

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

    return(0);
}
int main(int argc, char *argv[])
{
    #include "setRootCase.H"

    #include "createTime.H"
    #include "createMesh.H"
    #include "createFields.H"
    #include "createFvOptions.H"
    #include "initContinuityErrs.H"

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

    Info<< "\nStarting time loop\n" << endl;

    while (runTime.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        #include "readPISOControls.H"
        #include "CourantNo.H"

        // Pressure-velocity PISO corrector
        {
            // Momentum predictor

            fvVectorMatrix UEqn
            (
                fvm::ddt(U)
              + fvm::div(phi, U)
              + turbulence->divDevReff(U)
            );

            UEqn.relax();

            if (momentumPredictor)
            {
                solve(UEqn == -fvc::grad(p));
            }

            // --- PISO loop

            for (int corr=0; corr<nCorr; corr++)
            {
                volScalarField rAU(1.0/UEqn.A());

                volVectorField HbyA("HbyA", U);
                HbyA = rAU*UEqn.H();
                surfaceScalarField phiHbyA
                (
                    "phiHbyA",
                    (fvc::interpolate(HbyA) & mesh.Sf())
                  + fvc::interpolate(rAU)*fvc::ddtCorr(U, phi)
                );

                adjustPhi(phiHbyA, U, p);

                // Non-orthogonal pressure corrector loop
                for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
                {
                    // Pressure corrector

                    fvScalarMatrix pEqn
                    (
                        fvm::laplacian(rAU, p) == fvc::div(phiHbyA)
                    );

                    pEqn.setReference(pRefCell, pRefValue);

                    if
                    (
                        corr == nCorr-1
                     && nonOrth == nNonOrthCorr
                    )
                    {
                        pEqn.solve(mesh.solver("pFinal"));
                    }
                    else
                    {
                        pEqn.solve();
                    }

                    if (nonOrth == nNonOrthCorr)
                    {
                        phi = phiHbyA - pEqn.flux();
                    }
                }

                #include "continuityErrs.H"

                U = HbyA - rAU*fvc::grad(p);
                U.correctBoundaryConditions();
            }
        }

        turbulence->correct();

        /*tmp<fvScalarMatrix> sEqn
        (
            fvm::ddt(s)
          + fvm::div(phi, s)
          - fvm::laplacian(Ds, s)
        );
        
        sources.constrain(sEqn());
        solve(sEqn() == sources(s));*/

	tmp<fv::convectionScheme<scalar> > mvConvection
	(
	    fv::convectionScheme<scalar>::New
	    (
		mesh,
		fields,
		phi,
		mesh.divScheme("div(phi,si_h)")
	    )
	);
	volScalarField kappaEff
	(
	    "kappaEff",
	    turbulence->nu()/Pr + turbulence->nut()/Prt
	);

	forAll(s, i)
    	{
	    volScalarField& si = s[i];

	    tmp<fvScalarMatrix> siEqn
	    (
		    fvm::ddt(si)
		  + mvConvection->fvmDiv(phi, si)
		  - fvm::laplacian(kappaEff, si)
		== fvOptions(si)
	    );

	    fvOptions.constrain(siEqn());
            solve(siEqn(),mesh.solver("si"));
	    fvOptions.correct(si);
    	}

	//create scalar Fields u*s for averaging
	forAll(us, i)
	{
    us[i]=U*s[i];
	}