From 4ff7ac3efefc80eedc65c0562ef5c10c25141625 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 26 Apr 2012 11:41:06 +0100 Subject: [PATCH] LduMatrix: Added support for both component-coupled and component-independent forms of PCG and PBiCG --- applications/test/PisoFoam/PisoFoam.C | 2 +- .../fields/Fields/Field/FieldFunctions.C | 4 ++-- .../fields/Fields/Field/FieldFunctions.H | 3 +-- .../fields/Fields/scalarField/scalarField.C | 18 ++++++++++++++ .../fields/Fields/scalarField/scalarField.H | 6 +++++ .../PBiCGScalarAlpha.C => PBiCCCG/PBiCCCG.C} | 13 +++++----- .../{PBiCG/TPBiCG.H => PBiCCCG/PBiCCCG.H} | 24 +++++++++---------- .../{PBiCG/TPBiCG.C => PBiCICG/PBiCICG.C} | 6 ++--- .../PBiCGScalarAlpha.H => PBiCICG/PBiCICG.H} | 24 +++++++++---------- .../Solvers/{PCG/TPCG.C => PCICG/PCICG.C} | 6 ++--- .../Solvers/{PCG/TPCG.H => PCICG/PCICG.H} | 24 +++++++++---------- .../matrices/LduMatrix/Solvers/lduSolvers.C | 19 ++++++++------- 12 files changed, 87 insertions(+), 62 deletions(-) rename src/OpenFOAM/matrices/LduMatrix/Solvers/{PBiCGScalarAlpha/PBiCGScalarAlpha.C => PBiCCCG/PBiCCCG.C} (95%) rename src/OpenFOAM/matrices/LduMatrix/Solvers/{PBiCG/TPBiCG.H => PBiCCCG/PBiCCCG.H} (90%) rename src/OpenFOAM/matrices/LduMatrix/Solvers/{PBiCG/TPBiCG.C => PBiCICG/PBiCICG.C} (97%) rename src/OpenFOAM/matrices/LduMatrix/Solvers/{PBiCGScalarAlpha/PBiCGScalarAlpha.H => PBiCICG/PBiCICG.H} (90%) rename src/OpenFOAM/matrices/LduMatrix/Solvers/{PCG/TPCG.C => PCICG/PCICG.C} (97%) rename src/OpenFOAM/matrices/LduMatrix/Solvers/{PCG/TPCG.H => PCICG/PCICG.H} (90%) diff --git a/applications/test/PisoFoam/PisoFoam.C b/applications/test/PisoFoam/PisoFoam.C index a6a4d6c5b7..a3ea54b568 100644 --- a/applications/test/PisoFoam/PisoFoam.C +++ b/applications/test/PisoFoam/PisoFoam.C @@ -102,7 +102,7 @@ int main(int argc, char *argv[]) "{" " /*solver SmoothSolver;*/" " smoother GaussSeidel;" - " solver PBiCG;" + " solver PBiCCCG;" " preconditioner DILU;" " tolerance (1e-7 1e-7 1);" " relTol (0 0 0);" diff --git a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C index 9397411ec4..c26227cd00 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C +++ b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C @@ -365,7 +365,7 @@ scalar sumProd(const UList& f1, const UList& f2) if (f1.size() && (f1.size() == f2.size())) { scalar SumProd = 0.0; - TFOR_ALL_S_OP_F_OP_F(scalar, SumProd, +=, Type, f1, *, Type, f2) + TFOR_ALL_S_OP_F_OP_F(scalar, SumProd, +=, Type, f1, &&, Type, f2) return SumProd; } else @@ -498,7 +498,7 @@ template scalar gSumProd(const UList& f1, const UList& f2) { scalar SumProd = sumProd(f1, f2); - reduce(SumProd, sumOp()); + reduce(SumProd, sumOp()); return SumProd; } diff --git a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H index e3fd66afaf..290fd07209 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H +++ b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.H @@ -23,8 +23,6 @@ License \*---------------------------------------------------------------------------*/ -#include "scalarField.H" - #define TEMPLATE template #include "FieldFunctionsM.H" @@ -332,5 +330,6 @@ PRODUCT_OPERATOR(scalarProduct, &&, dotdot) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #include "undefFieldFunctionsM.H" +#include "scalarField.H" // ************************************************************************* // diff --git a/src/OpenFOAM/fields/Fields/scalarField/scalarField.C b/src/OpenFOAM/fields/Fields/scalarField/scalarField.C index 9000bb533a..783eb15222 100644 --- a/src/OpenFOAM/fields/Fields/scalarField/scalarField.C +++ b/src/OpenFOAM/fields/Fields/scalarField/scalarField.C @@ -86,6 +86,24 @@ tmp stabilise(const tmp& tsf, const scalar s) } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template<> +scalar sumProd(const UList& f1, const UList& f2) +{ + if (f1.size() && (f1.size() == f2.size())) + { + scalar SumProd = 0.0; + TFOR_ALL_S_OP_F_OP_F(scalar, SumProd, +=, scalar, f1, *, scalar, f2) + return SumProd; + } + else + { + return 0.0; + } +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // BINARY_TYPE_OPERATOR(scalar, scalar, scalar, +, add) diff --git a/src/OpenFOAM/fields/Fields/scalarField/scalarField.H b/src/OpenFOAM/fields/Fields/scalarField/scalarField.H index 8d39528b9f..c18d1abfd1 100644 --- a/src/OpenFOAM/fields/Fields/scalarField/scalarField.H +++ b/src/OpenFOAM/fields/Fields/scalarField/scalarField.H @@ -72,6 +72,12 @@ tmp stabilise(const UList&, const scalar s); tmp stabilise(const tmp&, const scalar s); +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template<> +scalar sumProd(const UList& f1, const UList& f2); + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // BINARY_TYPE_OPERATOR(scalar, scalar, scalar, +, add) diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCGScalarAlpha/PBiCGScalarAlpha.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.C similarity index 95% rename from src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCGScalarAlpha/PBiCGScalarAlpha.C rename to src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.C index 955e6be440..45453ff1d0 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCGScalarAlpha/PBiCGScalarAlpha.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.C @@ -23,12 +23,12 @@ License \*---------------------------------------------------------------------------*/ -#include "TPBiCG.H" +#include "PBiCCCG.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -Foam::TPBiCG::TPBiCG +Foam::PBiCCCG::PBiCCCG ( const word& fieldName, const LduMatrix& matrix, @@ -48,7 +48,7 @@ Foam::TPBiCG::TPBiCG template typename Foam::LduMatrix::solverPerformance -Foam::TPBiCG::solve +Foam::PBiCCCG::solve ( Field& psi ) const @@ -125,8 +125,7 @@ Foam::TPBiCG::solve preconPtr->preconditionT(wT, rT); // --- Update search directions: - //wArT = gSumProd(wA, rT); - wArT = gSum(wA && rT); + wArT = gSumProd(wA, rT); if (solverPerf.nIterations() == 0) { @@ -152,14 +151,14 @@ Foam::TPBiCG::solve this->matrix_.Amul(wA, pA); this->matrix_.Tmul(wT, pT); - scalar wApT = gSum(wA && pT); + scalar wApT = gSumProd(wA, pT); // --- Test for singularity if ( solverPerf.checkSingularity ( - cmptDivide(Type::one*mag(wApT), normFactor) + cmptDivide(pTraits::one*mag(wApT), normFactor) ) ) { diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCG/TPBiCG.H b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.H similarity index 90% rename from src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCG/TPBiCG.H rename to src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.H index 736654cbeb..e5363dc651 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCG/TPBiCG.H +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.H @@ -22,19 +22,19 @@ License along with OpenFOAM. If not, see . Class - Foam::TPBiCG + Foam::PBiCCCG Description Preconditioned bi-conjugate gradient solver for asymmetric lduMatrices using a run-time selectable preconditiioner. SourceFiles - TPBiCG.C + PBiCCCG.C \*---------------------------------------------------------------------------*/ -#ifndef TPBiCG_H -#define TPBiCG_H +#ifndef PBiCCCG_H +#define PBiCCCG_H #include "LduMatrix.H" @@ -44,33 +44,33 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class TPBiCG Declaration + Class PBiCCCG Declaration \*---------------------------------------------------------------------------*/ template -class TPBiCG +class PBiCCCG : public LduMatrix::solver { // Private Member Functions //- Disallow default bitwise copy construct - TPBiCG(const TPBiCG&); + PBiCCCG(const PBiCCCG&); //- Disallow default bitwise assignment - void operator=(const TPBiCG&); + void operator=(const PBiCCCG&); public: //- Runtime type information - TypeName("PBiCG"); + TypeName("PBiCCCG"); // Constructors //- Construct from matrix components and solver data dictionary - TPBiCG + PBiCCCG ( const word& fieldName, const LduMatrix& matrix, @@ -80,7 +80,7 @@ public: // Destructor - virtual ~TPBiCG() + virtual ~PBiCCCG() {} @@ -101,7 +101,7 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository -# include "TPBiCG.C" +# include "PBiCCCG.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCG/TPBiCG.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.C similarity index 97% rename from src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCG/TPBiCG.C rename to src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.C index e36d1d6a37..b3665f0617 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCG/TPBiCG.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.C @@ -23,12 +23,12 @@ License \*---------------------------------------------------------------------------*/ -#include "TPBiCG.H" +#include "PBiCICG.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -Foam::TPBiCG::TPBiCG +Foam::PBiCICG::PBiCICG ( const word& fieldName, const LduMatrix& matrix, @@ -48,7 +48,7 @@ Foam::TPBiCG::TPBiCG template typename Foam::LduMatrix::solverPerformance -Foam::TPBiCG::solve(Field& psi) const +Foam::PBiCICG::solve(Field& psi) const { word preconditionerName(this->controlDict_.lookup("preconditioner")); diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCGScalarAlpha/PBiCGScalarAlpha.H b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.H similarity index 90% rename from src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCGScalarAlpha/PBiCGScalarAlpha.H rename to src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.H index dee183e10b..340ae48667 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCGScalarAlpha/PBiCGScalarAlpha.H +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.H @@ -22,19 +22,19 @@ License along with OpenFOAM. If not, see . Class - Foam::TPBiCG + Foam::PBiCICG Description Preconditioned bi-conjugate gradient solver for asymmetric lduMatrices using a run-time selectable preconditiioner. SourceFiles - TPBiCG.C + PBiCICG.C \*---------------------------------------------------------------------------*/ -#ifndef TPBiCG_H -#define TPBiCG_H +#ifndef PBiCICG_H +#define PBiCICG_H #include "LduMatrix.H" @@ -44,33 +44,33 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class TPBiCG Declaration + Class PBiCICG Declaration \*---------------------------------------------------------------------------*/ template -class TPBiCG +class PBiCICG : public LduMatrix::solver { // Private Member Functions //- Disallow default bitwise copy construct - TPBiCG(const TPBiCG&); + PBiCICG(const PBiCICG&); //- Disallow default bitwise assignment - void operator=(const TPBiCG&); + void operator=(const PBiCICG&); public: //- Runtime type information - TypeName("PBiCG"); + TypeName("PBiCICG"); // Constructors //- Construct from matrix components and solver data dictionary - TPBiCG + PBiCICG ( const word& fieldName, const LduMatrix& matrix, @@ -80,7 +80,7 @@ public: // Destructor - virtual ~TPBiCG() + virtual ~PBiCICG() {} @@ -101,7 +101,7 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository -# include "PBiCGScalarAlpha.C" +# include "PBiCICG.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PCG/TPCG.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.C similarity index 97% rename from src/OpenFOAM/matrices/LduMatrix/Solvers/PCG/TPCG.C rename to src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.C index 1226e65137..e6206e6116 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PCG/TPCG.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.C @@ -23,12 +23,12 @@ License \*---------------------------------------------------------------------------*/ -#include "TPCG.H" +#include "PCICG.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -Foam::TPCG::TPCG +Foam::PCICG::PCICG ( const word& fieldName, const LduMatrix& matrix, @@ -48,7 +48,7 @@ Foam::TPCG::TPCG template typename Foam::LduMatrix::solverPerformance -Foam::TPCG::solve(Field& psi) const +Foam::PCICG::solve(Field& psi) const { word preconditionerName(this->controlDict_.lookup("preconditioner")); diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PCG/TPCG.H b/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.H similarity index 90% rename from src/OpenFOAM/matrices/LduMatrix/Solvers/PCG/TPCG.H rename to src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.H index 779de7ec5e..250cc41b9a 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PCG/TPCG.H +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.H @@ -22,19 +22,19 @@ License along with OpenFOAM. If not, see . Class - Foam::TPCG + Foam::PCICG Description Preconditioned conjugate gradient solver for symmetric lduMatrices using a run-time selectable preconditiioner. SourceFiles - TPCG.C + PCICG.C \*---------------------------------------------------------------------------*/ -#ifndef TPCG_H -#define TPCG_H +#ifndef PCICG_H +#define PCICG_H #include "LduMatrix.H" @@ -44,33 +44,33 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class TPCG Declaration + Class PCICG Declaration \*---------------------------------------------------------------------------*/ template -class TPCG +class PCICG : public LduMatrix::solver { // Private Member Functions //- Disallow default bitwise copy construct - TPCG(const TPCG&); + PCICG(const PCICG&); //- Disallow default bitwise assignment - void operator=(const TPCG&); + void operator=(const PCICG&); public: //- Runtime type information - TypeName("PCG"); + TypeName("PCICG"); // Constructors //- Construct from matrix components and solver data dictionary - TPCG + PCICG ( const word& fieldName, const LduMatrix& matrix, @@ -80,7 +80,7 @@ public: // Destructor - virtual ~TPCG() + virtual ~PCICG() {} @@ -101,7 +101,7 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository -# include "TPCG.C" +# include "PCICG.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/lduSolvers.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/lduSolvers.C index 30159b4a48..6e36e525b8 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/lduSolvers.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/lduSolvers.C @@ -23,9 +23,9 @@ License \*---------------------------------------------------------------------------*/ -#include "TPCG.H" -//#include "TPBiCG.H" -#include "PBiCGScalarAlpha.H" +#include "PCICG.H" +#include "PBiCCCG.H" +#include "PBiCICG.H" #include "SmoothSolver.H" #include "fieldTypes.H" @@ -35,11 +35,14 @@ License makeLduSymSolver(DiagonalSolver, Type, DType, LUType); \ makeLduAsymSolver(DiagonalSolver, Type, DType, LUType); \ \ - makeLduSolver(TPCG, Type, DType, LUType); \ - makeLduSymSolver(TPCG, Type, DType, LUType); \ + makeLduSolver(PCICG, Type, DType, LUType); \ + makeLduSymSolver(PCICG, Type, DType, LUType); \ \ - makeLduSolver(TPBiCG, Type, DType, LUType); \ - makeLduAsymSolver(TPBiCG, Type, DType, LUType); \ + makeLduSolver(PBiCCCG, Type, DType, LUType); \ + makeLduAsymSolver(PBiCCCG, Type, DType, LUType); \ + \ + makeLduSolver(PBiCICG, Type, DType, LUType); \ + makeLduAsymSolver(PBiCICG, Type, DType, LUType); \ \ makeLduSolver(SmoothSolver, Type, DType, LUType); \ makeLduSymSolver(SmoothSolver, Type, DType, LUType); \ @@ -47,7 +50,7 @@ License namespace Foam { - //makeLduSolvers(scalar, scalar, scalar); + makeLduSolvers(scalar, scalar, scalar); makeLduSolvers(vector, scalar, scalar); makeLduSolvers(sphericalTensor, scalar, scalar); makeLduSolvers(symmTensor, scalar, scalar);