PCG.C
Go to the documentation of this file.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 "PCG.H"
00028
00029
00030
00031 namespace Foam
00032 {
00033 defineTypeNameAndDebug(PCG, 0);
00034
00035 lduMatrix::solver::addsymMatrixConstructorToTable<PCG>
00036 addPCGSymMatrixConstructorToTable_;
00037 }
00038
00039
00040
00041
00042 Foam::PCG::PCG
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::PCG::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 wA(nCells);
00088 scalar* __restrict__ wAPtr = wA.begin();
00089
00090 scalar wArA = matrix_.great_;
00091 scalar wArAold = wArA;
00092
00093
00094 matrix_.Amul(wA, psi, interfaceBouCoeffs_, interfaces_, cmpt);
00095
00096
00097 scalarField rA(source - wA);
00098 scalar* __restrict__ rAPtr = rA.begin();
00099
00100
00101 scalar normFactor = this->normFactor(psi, source, wA, pA);
00102
00103 if (lduMatrix::debug >= 2)
00104 {
00105 Info<< " Normalisation factor = " << normFactor << endl;
00106 }
00107
00108
00109 solverPerf.initialResidual() = gSumMag(rA)/normFactor;
00110 solverPerf.finalResidual() = solverPerf.initialResidual();
00111
00112
00113 if (!solverPerf.checkConvergence(tolerance_, relTol_))
00114 {
00115
00116 autoPtr<lduMatrix::preconditioner> preconPtr =
00117 lduMatrix::preconditioner::New
00118 (
00119 *this,
00120 controlDict_
00121 );
00122
00123
00124 do
00125 {
00126
00127 wArAold = wArA;
00128
00129
00130 preconPtr->precondition(wA, rA, cmpt);
00131
00132
00133 wArA = gSumProd(wA, rA);
00134
00135 if (solverPerf.nIterations() == 0)
00136 {
00137 for (register label cell=0; cell<nCells; cell++)
00138 {
00139 pAPtr[cell] = wAPtr[cell];
00140 }
00141 }
00142 else
00143 {
00144 scalar beta = wArA/wArAold;
00145
00146 for (register label cell=0; cell<nCells; cell++)
00147 {
00148 pAPtr[cell] = wAPtr[cell] + beta*pAPtr[cell];
00149 }
00150 }
00151
00152
00153
00154 matrix_.Amul(wA, pA, interfaceBouCoeffs_, interfaces_, cmpt);
00155
00156 scalar wApA = gSumProd(wA, pA);
00157
00158
00159
00160 if (solverPerf.checkSingularity(mag(wApA)/normFactor)) break;
00161
00162
00163
00164
00165 scalar alpha = wArA/wApA;
00166
00167 for (register label cell=0; cell<nCells; cell++)
00168 {
00169 psiPtr[cell] += alpha*pAPtr[cell];
00170 rAPtr[cell] -= alpha*wAPtr[cell];
00171 }
00172
00173 solverPerf.finalResidual() = gSumMag(rA)/normFactor;
00174
00175 } while
00176 (
00177 solverPerf.nIterations()++ < maxIter_
00178 && !(solverPerf.checkConvergence(tolerance_, relTol_))
00179 );
00180 }
00181
00182 return solverPerf;
00183 }
00184
00185
00186
Copyright © 2000-2009 OpenCFD Ltd