00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "PBiCG.H"
00028
00029
00030
00031 namespace Foam
00032 {
00033 defineTypeNameAndDebug(PBiCG, 0);
00034
00035 lduMatrix::solver::addasymMatrixConstructorToTable<PBiCG>
00036 addPBiCGAsymMatrixConstructorToTable_;
00037 }
00038
00039
00040
00041
00042 Foam::PBiCG::PBiCG
00043 (
00044 const word& fieldName,
00045 const lduMatrix& matrix,
00046 const FieldField<Field, scalar>& interfaceBouCoeffs,
00047 const FieldField<Field, scalar>& interfaceIntCoeffs,
00048 const lduInterfaceFieldPtrsList& interfaces,
00049 const dictionary& solverControls
00050 )
00051 :
00052 lduMatrix::solver
00053 (
00054 fieldName,
00055 matrix,
00056 interfaceBouCoeffs,
00057 interfaceIntCoeffs,
00058 interfaces,
00059 solverControls
00060 )
00061 {}
00062
00063
00064
00065
00066 Foam::lduMatrix::solverPerformance Foam::PBiCG::solve
00067 (
00068 scalarField& psi,
00069 const scalarField& source,
00070 const direction cmpt
00071 ) const
00072 {
00073
00074 lduMatrix::solverPerformance solverPerf
00075 (
00076 lduMatrix::preconditioner::getName(controlDict_) + typeName,
00077 fieldName_
00078 );
00079
00080 register label nCells = psi.size();
00081
00082 scalar* __restrict__ psiPtr = psi.begin();
00083
00084 scalarField pA(nCells);
00085 scalar* __restrict__ pAPtr = pA.begin();
00086
00087 scalarField pT(nCells, 0.0);
00088 scalar* __restrict__ pTPtr = pT.begin();
00089
00090 scalarField wA(nCells);
00091 scalar* __restrict__ wAPtr = wA.begin();
00092
00093 scalarField wT(nCells);
00094 scalar* __restrict__ wTPtr = wT.begin();
00095
00096 scalar wArT = matrix_.great_;
00097 scalar wArTold = wArT;
00098
00099
00100 matrix_.Amul(wA, psi, interfaceBouCoeffs_, interfaces_, cmpt);
00101 matrix_.Tmul(wT, psi, interfaceIntCoeffs_, interfaces_, cmpt);
00102
00103
00104 scalarField rA(source - wA);
00105 scalarField rT(source - wT);
00106 scalar* __restrict__ rAPtr = rA.begin();
00107 scalar* __restrict__ rTPtr = rT.begin();
00108
00109
00110 scalar normFactor = this->normFactor(psi, source, wA, pA);
00111
00112 if (lduMatrix::debug >= 2)
00113 {
00114 Info<< " Normalisation factor = " << normFactor << endl;
00115 }
00116
00117
00118 solverPerf.initialResidual() = gSumMag(rA)/normFactor;
00119 solverPerf.finalResidual() = solverPerf.initialResidual();
00120
00121
00122 if (!solverPerf.checkConvergence(tolerance_, relTol_))
00123 {
00124
00125 autoPtr<lduMatrix::preconditioner> preconPtr =
00126 lduMatrix::preconditioner::New
00127 (
00128 *this,
00129 controlDict_
00130 );
00131
00132
00133 do
00134 {
00135
00136 wArTold = wArT;
00137
00138
00139 preconPtr->precondition(wA, rA, cmpt);
00140 preconPtr->preconditionT(wT, rT, cmpt);
00141
00142
00143 wArT = gSumProd(wA, rT);
00144
00145 if (solverPerf.nIterations() == 0)
00146 {
00147 for (register label cell=0; cell<nCells; cell++)
00148 {
00149 pAPtr[cell] = wAPtr[cell];
00150 pTPtr[cell] = wTPtr[cell];
00151 }
00152 }
00153 else
00154 {
00155 scalar beta = wArT/wArTold;
00156
00157 for (register label cell=0; cell<nCells; cell++)
00158 {
00159 pAPtr[cell] = wAPtr[cell] + beta*pAPtr[cell];
00160 pTPtr[cell] = wTPtr[cell] + beta*pTPtr[cell];
00161 }
00162 }
00163
00164
00165
00166 matrix_.Amul(wA, pA, interfaceBouCoeffs_, interfaces_, cmpt);
00167 matrix_.Tmul(wT, pT, interfaceIntCoeffs_, interfaces_, cmpt);
00168
00169 scalar wApT = gSumProd(wA, pT);
00170
00171
00172
00173 if (solverPerf.checkSingularity(mag(wApT)/normFactor)) break;
00174
00175
00176
00177
00178 scalar alpha = wArT/wApT;
00179
00180 for (register label cell=0; cell<nCells; cell++)
00181 {
00182 psiPtr[cell] += alpha*pAPtr[cell];
00183 rAPtr[cell] -= alpha*wAPtr[cell];
00184 rTPtr[cell] -= alpha*wTPtr[cell];
00185 }
00186
00187 solverPerf.finalResidual() = gSumMag(rA)/normFactor;
00188
00189 } while
00190 (
00191 solverPerf.nIterations()++ < maxIter_
00192 && !(solverPerf.checkConvergence(tolerance_, relTol_))
00193 );
00194 }
00195
00196 return solverPerf;
00197 }
00198
00199
00200