tmp<volScalarField> Foam::voidFractionModel::voidFractionInterp() const { tmp<volScalarField> tsource ( new volScalarField ( IOobject ( "alpha_voidFractionModel", particleCloud_.mesh().time().timeName(), particleCloud_.mesh(), IOobject::NO_READ, IOobject::NO_WRITE ), particleCloud_.mesh(), dimensionedScalar ( "zero", dimensionSet(0, 0, 0, 0, 0), 0 ) ) ); scalar tsf = particleCloud_.dataExchangeM().timeStepFraction(); if(1-tsf < 1e-4 && particleCloud_.dataExchangeM().couplingStep() > 1) //tsf==1 { tsource() = voidfractionPrev_; } else { tsource() = (1 - tsf) * voidfractionPrev_ + tsf * voidfractionNext_; } return tsource; }
tmp<volScalarField> noCouple::impMomSource() const { tmp<volScalarField> tsource ( new volScalarField ( IOobject ( "Ksl_implicitCouple", particleCloud_.mesh().time().timeName(), particleCloud_.mesh(), IOobject::NO_READ, IOobject::NO_WRITE ), particleCloud_.mesh(), dimensionedScalar ( "zero", dimensionSet(1, -3, -1, 0, 0), // N/m3 / m/s 0 ) ) ); return tsource; }
tmp<volVectorField> noCouple::expMomSource() const { tmp<volVectorField> tsource ( new volVectorField ( IOobject ( "f_explicitCouple", particleCloud_.mesh().time().timeName(), particleCloud_.mesh(), IOobject::NO_READ, IOobject::NO_WRITE ), particleCloud_.mesh(), dimensionedVector ( "zero", dimensionSet(1, -2, -2, 0, 0), // N/m3 vector::zero ) ) ); return tsource; }
tmp<volVectorField> Foam::averagingModel::UsInterp() const { tmp<volVectorField> tsource ( new volVectorField ( IOobject ( "Us_averagingModel", particleCloud_.mesh().time().timeName(), particleCloud_.mesh(), IOobject::NO_READ, IOobject::NO_WRITE ), particleCloud_.mesh(), dimensionedVector ( "zero", dimensionSet(0, 1, -1, 0, 0), vector::zero ) ) ); if (particleCloud_.dataExchangeM().couplingStep() > 1) { tsource() = (1 - particleCloud_.dataExchangeM().timeStepFraction()) * UsPrev_ + particleCloud_.dataExchangeM().timeStepFraction() * UsNext_; } else { tsource() = UsNext_; } return tsource; }
Foam::solverPerformance Foam::smoothSolver::solve ( scalarField& psi_s, const scalarField& source, const direction cmpt ) const { FieldWrapper<solveScalar, scalar> tpsi(psi_s); solveScalarField& psi = tpsi.constCast(); // Setup class containing solver performance data solverPerformance solverPerf(typeName, fieldName_); // If the nSweeps_ is negative do a fixed number of sweeps if (nSweeps_ < 0) { addProfiling(solve, "lduMatrix::smoother." + fieldName_); autoPtr<lduMatrix::smoother> smootherPtr = lduMatrix::smoother::New ( fieldName_, matrix_, interfaceBouCoeffs_, interfaceIntCoeffs_, interfaces_, controlDict_ ); smootherPtr->smooth ( psi, source, cmpt, -nSweeps_ ); solverPerf.nIterations() -= nSweeps_; } else { solveScalar normFactor = 0; solveScalarField residual; ConstFieldWrapper<solveScalar, scalar> tsource(source); { solveScalarField Apsi(psi.size()); solveScalarField temp(psi.size()); // Calculate A.psi matrix_.Amul(Apsi, psi, interfaceBouCoeffs_, interfaces_, cmpt); // Calculate normalisation factor normFactor = this->normFactor(psi, source, Apsi, temp); residual = tsource() - Apsi; matrix().setResidualField ( ConstFieldWrapper<scalar, solveScalar>(residual)(), fieldName_, false ); // Calculate residual magnitude solverPerf.initialResidual() = gSumMag(residual, matrix().mesh().comm())/normFactor; solverPerf.finalResidual() = solverPerf.initialResidual(); } if (lduMatrix::debug >= 2) { Info.masterStream(matrix().mesh().comm()) << " Normalisation factor = " << normFactor << endl; } // Check convergence, solve if not converged if ( minIter_ > 0 || !solverPerf.checkConvergence(tolerance_, relTol_) ) { addProfiling(solve, "lduMatrix::smoother." + fieldName_); autoPtr<lduMatrix::smoother> smootherPtr = lduMatrix::smoother::New ( fieldName_, matrix_, interfaceBouCoeffs_, interfaceIntCoeffs_, interfaces_, controlDict_ ); // Smoothing loop do { smootherPtr->smooth ( psi, source, cmpt, nSweeps_ ); residual = matrix_.residual ( psi, source, interfaceBouCoeffs_, interfaces_, cmpt ); // Calculate the residual to check convergence solverPerf.finalResidual() = gSumMag(residual, matrix().mesh().comm())/normFactor; } while ( ( (solverPerf.nIterations() += nSweeps_) < maxIter_ && !solverPerf.checkConvergence(tolerance_, relTol_) ) || solverPerf.nIterations() < minIter_ ); } matrix().setResidualField ( ConstFieldWrapper<scalar, solveScalar>(residual)(), fieldName_, false ); } return solverPerf; }
Foam::solverPerformance Foam::PCG::solve ( scalarField& psi_s, const scalarField& source, const direction cmpt ) const { FieldWrapper<solveScalar, scalar> tpsi(psi_s); solveScalarField& psi = tpsi.constCast(); // --- Setup class containing solver performance data solverPerformance solverPerf ( lduMatrix::preconditioner::getName(controlDict_) + typeName, fieldName_ ); label nCells = psi.size(); solveScalar* __restrict__ psiPtr = psi.begin(); solveScalarField pA(nCells); solveScalar* __restrict__ pAPtr = pA.begin(); solveScalarField wA(nCells); solveScalar* __restrict__ wAPtr = wA.begin(); solveScalar wArA = solverPerf.great_; solveScalar wArAold = wArA; // --- Calculate A.psi matrix_.Amul(wA, psi, interfaceBouCoeffs_, interfaces_, cmpt); // --- Calculate initial residual field ConstFieldWrapper<solveScalar, scalar> tsource(source); solveScalarField rA(tsource() - wA); solveScalar* __restrict__ rAPtr = rA.begin(); matrix().setResidualField ( ConstFieldWrapper<scalar, solveScalar>(rA)(), fieldName_, false ); // --- Calculate normalisation factor solveScalar normFactor = this->normFactor(psi, source, wA, pA); if (lduMatrix::debug >= 2) { Info<< " Normalisation factor = " << normFactor << endl; } // --- Calculate normalised residual norm solverPerf.initialResidual() = gSumMag(rA, matrix().mesh().comm()) /normFactor; solverPerf.finalResidual() = solverPerf.initialResidual(); // --- Check convergence, solve if not converged if ( minIter_ > 0 || !solverPerf.checkConvergence(tolerance_, relTol_) ) { // --- Select and construct the preconditioner autoPtr<lduMatrix::preconditioner> preconPtr = lduMatrix::preconditioner::New ( *this, controlDict_ ); // --- Solver iteration do { // --- Store previous wArA wArAold = wArA; // --- Precondition residual preconPtr->precondition(wA, rA, cmpt); // --- Update search directions: wArA = gSumProd(wA, rA, matrix().mesh().comm()); if (solverPerf.nIterations() == 0) { for (label cell=0; cell<nCells; cell++) { pAPtr[cell] = wAPtr[cell]; } } else { solveScalar beta = wArA/wArAold; for (label cell=0; cell<nCells; cell++) { pAPtr[cell] = wAPtr[cell] + beta*pAPtr[cell]; } } // --- Update preconditioned residual matrix_.Amul(wA, pA, interfaceBouCoeffs_, interfaces_, cmpt); solveScalar wApA = gSumProd(wA, pA, matrix().mesh().comm()); // --- Test for singularity if (solverPerf.checkSingularity(mag(wApA)/normFactor)) break; // --- Update solution and residual: solveScalar alpha = wArA/wApA; for (label cell=0; cell<nCells; cell++) { psiPtr[cell] += alpha*pAPtr[cell]; rAPtr[cell] -= alpha*wAPtr[cell]; } solverPerf.finalResidual() = gSumMag(rA, matrix().mesh().comm()) /normFactor; } while ( ( ++solverPerf.nIterations() < maxIter_ && !solverPerf.checkConvergence(tolerance_, relTol_) ) || solverPerf.nIterations() < minIter_ ); } matrix().setResidualField ( ConstFieldWrapper<scalar, solveScalar>(rA)(), fieldName_, false ); return solverPerf; }