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 "smoothSolver.H"
00028
00029
00030
00031 namespace Foam
00032 {
00033 defineTypeNameAndDebug(smoothSolver, 0);
00034
00035 lduMatrix::solver::addsymMatrixConstructorToTable<smoothSolver>
00036 addsmoothSolverSymMatrixConstructorToTable_;
00037
00038 lduMatrix::solver::addasymMatrixConstructorToTable<smoothSolver>
00039 addsmoothSolverAsymMatrixConstructorToTable_;
00040 }
00041
00042
00043
00044
00045 Foam::smoothSolver::smoothSolver
00046 (
00047 const word& fieldName,
00048 const lduMatrix& matrix,
00049 const FieldField<Field, scalar>& interfaceBouCoeffs,
00050 const FieldField<Field, scalar>& interfaceIntCoeffs,
00051 const lduInterfaceFieldPtrsList& interfaces,
00052 const dictionary& solverControls
00053 )
00054 :
00055 lduMatrix::solver
00056 (
00057 fieldName,
00058 matrix,
00059 interfaceBouCoeffs,
00060 interfaceIntCoeffs,
00061 interfaces,
00062 solverControls
00063 )
00064 {
00065 readControls();
00066 }
00067
00068
00069
00070
00071 void Foam::smoothSolver::readControls()
00072 {
00073 lduMatrix::solver::readControls();
00074 nSweeps_ = controlDict_.lookupOrDefault<label>("nSweeps", 1);
00075 }
00076
00077
00078 Foam::lduMatrix::solverPerformance Foam::smoothSolver::solve
00079 (
00080 scalarField& psi,
00081 const scalarField& source,
00082 const direction cmpt
00083 ) const
00084 {
00085
00086 lduMatrix::solverPerformance solverPerf(typeName, fieldName_);
00087
00088
00089 if (nSweeps_ < 0)
00090 {
00091 autoPtr<lduMatrix::smoother> smootherPtr = lduMatrix::smoother::New
00092 (
00093 fieldName_,
00094 matrix_,
00095 interfaceBouCoeffs_,
00096 interfaceIntCoeffs_,
00097 interfaces_,
00098 controlDict_
00099 );
00100
00101 smootherPtr->smooth
00102 (
00103 psi,
00104 source,
00105 cmpt,
00106 -nSweeps_
00107 );
00108
00109 solverPerf.nIterations() -= nSweeps_;
00110 }
00111 else
00112 {
00113 scalar normFactor = 0;
00114
00115 {
00116 scalarField Apsi(psi.size());
00117 scalarField temp(psi.size());
00118
00119
00120 matrix_.Amul(Apsi, psi, interfaceBouCoeffs_, interfaces_, cmpt);
00121
00122
00123 normFactor = this->normFactor(psi, source, Apsi, temp);
00124
00125
00126 solverPerf.initialResidual() = gSumMag(source - Apsi)/normFactor;
00127 solverPerf.finalResidual() = solverPerf.initialResidual();
00128 }
00129
00130 if (lduMatrix::debug >= 2)
00131 {
00132 Info<< " Normalisation factor = " << normFactor << endl;
00133 }
00134
00135
00136
00137 if (!solverPerf.checkConvergence(tolerance_, relTol_))
00138 {
00139 autoPtr<lduMatrix::smoother> smootherPtr = lduMatrix::smoother::New
00140 (
00141 fieldName_,
00142 matrix_,
00143 interfaceBouCoeffs_,
00144 interfaceIntCoeffs_,
00145 interfaces_,
00146 controlDict_
00147 );
00148
00149
00150 do
00151 {
00152 smootherPtr->smooth
00153 (
00154 psi,
00155 source,
00156 cmpt,
00157 nSweeps_
00158 );
00159
00160
00161 solverPerf.finalResidual() = gSumMag
00162 (
00163 matrix_.residual
00164 (
00165 psi,
00166 source,
00167 interfaceBouCoeffs_,
00168 interfaces_,
00169 cmpt
00170 )
00171 )/normFactor;
00172 } while
00173 (
00174 (solverPerf.nIterations() += nSweeps_) < maxIter_
00175 && !(solverPerf.checkConvergence(tolerance_, relTol_))
00176 );
00177 }
00178 }
00179
00180 return solverPerf;
00181 }
00182
00183
00184