void blockTemperature() { b = 1; for(g=1;g<=zNB;g++) { for (f=1;f<=yNB;f++) { for(e=1;e<=xNB;e++) { TEqnCoeff(); b += 1; } } } TemperatureBoundaryConditions(); b = 1; for(g=1;g<=zNB;g++) { for (f=1;f<=yNB;f++) { for(e=1;e<=xNB;e++) { TEqn(); b += 1; } } } }
void reactingOneDim::solveEnergy() { if (debug) { Info<< "reactingOneDim::solveEnergy()" << endl; } const volScalarField rhoCp(rho_*solidThermo_.Cp()); const surfaceScalarField phiQr(fvc::interpolate(Qr_)*nMagSf()); const surfaceScalarField phiGas(fvc::interpolate(phiHsGas_)); fvScalarMatrix TEqn ( fvm::ddt(rhoCp, T_) - fvm::laplacian(K_, T_) == chemistrySh_ + fvc::div(phiQr) + fvc::div(phiGas) ); if (moveMesh_) { surfaceScalarField phiMesh ( fvc::interpolate(rhoCp*T_)*regionMesh().phi() ); TEqn -= fvc::div(phiMesh); } TEqn.relax(); TEqn.solve(); Info<< "pyrolysis min/max(T) = " << min(T_).value() << ", " << max(T_).value() << endl; }
//--------------------------------------------------------------------------- void fun_TEqn( const surfaceScalarFieldHolder& phi, incompressible::RASModelHolder& turbulence, volScalarFieldHolder& kappat, const volScalarFieldHolder& T, volScalarFieldHolder& rhok, const dimensionedScalar& beta, const dimensionedScalar& TRef, const dimensionedScalar& Prt, const dimensionedScalar Pr ) { kappat = turbulence->nut() / Prt; kappat->correctBoundaryConditions(); volScalarField kappaEff("kappaEff", turbulence->nu()/Pr + kappat() ); smart_tmp< fvScalarMatrix > TEqn( fvm::div( phi(), T() ) - fvm::Sp(fvc::div( phi() ), T() ) - fvm::laplacian( kappaEff, T() ) ); TEqn->relax(); TEqn->solve(); rhok = 1.0 - beta * ( T() - TRef ); }
int main(int argc, char *argv[]) { Foam::argList::addBoolOption("explicit", "Run RK2 explicitly"); #include "setRootCase.H" const Switch implicit = !args.options().found("explicit"); #include "createTime.H" #include "createMesh.H" #define dt runTime.deltaT() #include "createFields.H" // Read the number of iterations each time-step const dictionary& itsDict = mesh.solutionDict().subDict("iterations"); const int nCorr = readLabel(itsDict.lookup("nCorr")); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Info<< "\nCalculating scalar transport\n" << endl; #include "CourantNo.H" while (runTime.loop()) { Info<< "Time = " << runTime.timeName() << endl; // Fixed number of iterations per time-step version for (int corr = 0; corr < nCorr; corr++) { fvScalarMatrix TEqn ( fvm::ddt(T) + 0.5*divPhiT.oldTime() ); if (implicit) { TEqn += 0.5*fvm::div(phi, T); } else { TEqn += 0.5*fvc::div(phi, T); } TEqn.solve(); } Info << "Max T = " << max(T) << " min T = " << min(T) << endl; /* // Keep doing iterations until converged version for(bool converged = false; !converged;) { fvScalarMatrix TEqn ( fvm::ddt(T) + 0.5*fvm::div(phi, T) + 0.5*divPhiT.oldTime() ); solverPerformance sp = TEqn.solve(); converged = sp.nIterations() <= 1; } */ divPhiT = fvc::div(phi, T); Info << " T goes from " << min(T.internalField()) << " to " << max(T.internalField()) << nl << endl; 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 "readDivSigmaExpMethod.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Info<< "\nStarting time loop\n" << endl; while(runTime.loop()) { Info<< "Time: " << runTime.timeName() << nl << endl; # include "readSolidMechanicsControls.H" int iCorr = 0; scalar initialResidual = 1.0; scalar relResT = 1.0; scalar relResU = 1.0; lduMatrix::solverPerformance solverPerfU; lduMatrix::solverPerformance solverPerfT; lduMatrix::debug = 0; // solve energy equation for temperature // the loop is for non-orthogonal corrections Info<< "Solving for " << T.name() << nl; do { T.storePrevIter(); fvScalarMatrix TEqn ( rhoC*fvm::ddt(T) == fvm::laplacian(k, T, "laplacian(k,T)") ); solverPerfT = TEqn.solve(); T.relax(); # include "calculateRelResT.H" if (iCorr % infoFrequency == 0) { Info<< "\tCorrector " << iCorr << ", residual = " << solverPerfT.initialResidual() << ", relative res = " << relResT << ", inner iters = " << solverPerfT.nIterations() << endl; } } while ( relResT > convergenceToleranceT && ++iCorr < nCorr ); Info<< "Solved for " << T.name() << " using " << solverPerfT.solverName() << " in " << iCorr << " iterations" << ", residual = " << solverPerfT.initialResidual() << ", relative res = " << relResT << nl << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << ", ClockTime = " << runTime.elapsedClockTime() << " s" << endl; // Solve momentum equation for displacement iCorr = 0; volVectorField gradThreeKalphaDeltaT = fvc::grad(threeKalpha*(T-T0), "grad(threeKalphaDeltaT)"); surfaceVectorField threeKalphaDeltaTf = mesh.Sf()*threeKalphaf*fvc::interpolate(T-T0, "deltaT"); Info<< "Solving for " << U.name() << nl; do { U.storePrevIter(); # include "calculateDivSigmaExp.H" // Linear momentum equaiton fvVectorMatrix UEqn ( rho*fvm::d2dt2(U) == fvm::laplacian(2*muf + lambdaf, U, "laplacian(DU,U)") + divSigmaExp ); solverPerfU = UEqn.solve(); if (aitkenRelax) { # include "aitkenRelaxation.H" } else { U.relax(); } gradU = fvc::grad(U); # include "calculateRelResU.H" if (iCorr == 0) { initialResidual = solverPerfU.initialResidual(); } if (iCorr % infoFrequency == 0) { Info<< "\tCorrector " << iCorr << ", residual = " << solverPerfU.initialResidual() << ", relative res = " << relResU; if (aitkenRelax) { Info << ", aitken = " << aitkenTheta; } Info<< ", inner iters = " << solverPerfU.nIterations() << endl; } } while ( iCorr++ == 0 || ( relResU > convergenceToleranceU && iCorr < nCorr ) ); Info<< "Solved for " << U.name() << " using " << solverPerfU.solverName() << " in " << iCorr << " iterations" << ", initial res = " << initialResidual << ", final res = " << solverPerfU.initialResidual() << ", final rel res = " << relResU << nl << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << ", ClockTime = " << runTime.elapsedClockTime() << " s" << endl; # include "calculateEpsilonSigma.H" # include "writeFields.H" Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s\n\n" << endl; } Info<< "End\n" << endl; return(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; }
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" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 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(); // 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; }