/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "PBiCCCG.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
Foam::PBiCCCG::PBiCCCG
(
const word& fieldName,
const LduMatrix& matrix,
const dictionary& solverDict
)
:
LduMatrix::solver
(
fieldName,
matrix,
solverDict
)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
Foam::SolverPerformance
Foam::PBiCCCG::solve
(
Field& psi
) const
{
const word preconditionerName(this->controlDict_.getWord("preconditioner"));
// --- Setup class containing solver performance data
SolverPerformance solverPerf
(
preconditionerName + typeName,
this->fieldName_
);
label nIter = 0;
label nCells = psi.size();
Type* __restrict__ psiPtr = psi.begin();
Field pA(nCells);
Type* __restrict__ pAPtr = pA.begin();
Field pT(nCells, Zero);
Type* __restrict__ pTPtr = pT.begin();
Field wA(nCells);
Type* __restrict__ wAPtr = wA.begin();
Field wT(nCells);
Type* __restrict__ wTPtr = wT.begin();
scalar wArT = 1e15; //this->matrix_.great_;
scalar wArTold = wArT;
// --- Calculate A.psi and T.psi
this->matrix_.Amul(wA, psi);
this->matrix_.Tmul(wT, psi);
// --- Calculate initial residual and transpose residual fields
Field rA(this->matrix_.source() - wA);
Field rT(this->matrix_.source() - wT);
Type* __restrict__ rAPtr = rA.begin();
Type* __restrict__ rTPtr = rT.begin();
// --- Calculate normalisation factor
Type normFactor = this->normFactor(psi, wA, pA);
if ((this->log_ >= 2) || (LduMatrix::debug >= 2))
{
Info<< " Normalisation factor = " << normFactor << endl;
}
// --- Calculate normalised residual norm
solverPerf.initialResidual() = cmptDivide(gSumCmptMag(rA), normFactor);
solverPerf.finalResidual() = solverPerf.initialResidual();
// --- Check convergence, solve if not converged
if
(
this->minIter_ > 0
|| !solverPerf.checkConvergence
(
this->tolerance_,
this->relTol_,
this->log_
)
)
{
// --- Select and construct the preconditioner
autoPtr::preconditioner>
preconPtr = LduMatrix::preconditioner::New
(
*this,
this->controlDict_
);
// --- Solver iteration
do
{
// --- Store previous wArT
wArTold = wArT;
// --- Precondition residuals
preconPtr->precondition(wA, rA);
preconPtr->preconditionT(wT, rT);
// --- Update search directions:
wArT = gSumProd(wA, rT);
if (nIter == 0)
{
for (label cell=0; cellmatrix_.Amul(wA, pA);
this->matrix_.Tmul(wT, pT);
scalar wApT = gSumProd(wA, pT);
// --- Test for singularity
if
(
solverPerf.checkSingularity
(
cmptDivide(pTraits::one*mag(wApT), normFactor)
)
)
{
break;
}
// --- Update solution and residual:
scalar alpha = wArT/wApT;
for (label cell=0; cellmaxIter_
&& !solverPerf.checkConvergence
(
this->tolerance_,
this->relTol_,
this->log_
)
)
|| nIter < this->minIter_
);
}
solverPerf.nIterations() =
pTraits::labelType>::one*nIter;
return solverPerf;
}
// ************************************************************************* //