From ed293d3af1b757f30ac2b3fcf8684eb7c650f0c8 Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 27 Apr 2012 18:16:53 +0100 Subject: [PATCH] LduMatrix: coupled solvers are now run-time selectable for solving fvMatrices by conversion of the fvMatrix/lduMatrix to LduMatrix --- applications/test/PisoFoam/PisoFoam.C | 2 +- .../matrices/LduMatrix/LduMatrix/LduMatrix.C | 2 +- .../matrices/LduMatrix/LduMatrix/LduMatrix.H | 187 +------------ .../{LduMatrixTests.C => SolverPerformance.C} | 52 ++-- .../LduMatrix/LduMatrix/SolverPerformance.H | 258 ++++++++++++++++++ .../Solvers/DiagonalSolver/DiagonalSolver.C | 4 +- .../Solvers/DiagonalSolver/DiagonalSolver.H | 5 +- .../LduMatrix/Solvers/PBiCCCG/PBiCCCG.C | 4 +- .../LduMatrix/Solvers/PBiCCCG/PBiCCCG.H | 5 +- .../LduMatrix/Solvers/PBiCICG/PBiCICG.C | 4 +- .../LduMatrix/Solvers/PBiCICG/PBiCICG.H | 5 +- .../matrices/LduMatrix/Solvers/PCICG/PCICG.C | 4 +- .../matrices/LduMatrix/Solvers/PCICG/PCICG.H | 5 +- .../Solvers/SmoothSolver/SmoothSolver.C | 4 +- .../Solvers/SmoothSolver/SmoothSolver.H | 5 +- .../fvMatrices/fvMatrix/fvMatrix.H | 10 +- .../fvMatrices/fvMatrix/fvMatrixSolve.C | 100 ++++++- .../fvScalarMatrix/fvScalarMatrix.C | 5 +- .../fvScalarMatrix/fvScalarMatrix.H | 2 +- 19 files changed, 417 insertions(+), 246 deletions(-) rename src/OpenFOAM/matrices/LduMatrix/LduMatrix/{LduMatrixTests.C => SolverPerformance.C} (72%) create mode 100644 src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.H diff --git a/applications/test/PisoFoam/PisoFoam.C b/applications/test/PisoFoam/PisoFoam.C index 67f0084e71..1713e9747c 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 PBiCICG;" + " solver PBiCCCG;" " preconditioner none;" " tolerance (1e-7 1e-7 1);" " relTol (0 0 0);" diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrix.C b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrix.C index 97b2b2f40e..00782ac75b 100644 --- a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrix.C +++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrix.C @@ -382,7 +382,7 @@ Foam::Ostream& Foam::operator<< #include "LduMatrixOperations.C" #include "LduMatrixATmul.C" #include "LduMatrixUpdateMatrixInterfaces.C" -#include "LduMatrixTests.C" +#include "SolverPerformance.C" #include "LduMatrixPreconditioner.C" #include "LduMatrixSmoother.C" #include "LduMatrixSolver.C" diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrix.H b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrix.H index e0ce6d28ba..507fd40e94 100644 --- a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrix.H +++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrix.H @@ -54,6 +54,7 @@ SourceFiles #include "Field.H" #include "FieldField.H" #include "LduInterfaceFieldPtrsList.H" +#include "SolverPerformance.H" #include "typeInfo.H" #include "autoPtr.H" #include "runTimeSelectionTables.H" @@ -75,27 +76,6 @@ Ostream& operator<< const LduMatrix& ); -template -typename LduMatrix::solverPerformance max -( - const typename LduMatrix::solverPerformance&, - const typename LduMatrix::solverPerformance& -); - -template -Istream& operator>> -( - Istream&, - typename LduMatrix::solverPerformance& -); - -template -Ostream& operator<< -( - Ostream&, - const typename LduMatrix::solverPerformance& -); - /*---------------------------------------------------------------------------*\ Class LduMatrix Declaration @@ -127,168 +107,7 @@ class LduMatrix public: - //- Class returned by the solver - // containing performance statistics - class solverPerformance - { - word solverName_; - word fieldName_; - Type initialResidual_; - Type finalResidual_; - label noIterations_; - bool converged_; - FixedList::nComponents> singular_; - - - public: - - // Constructors - - solverPerformance() - : - initialResidual_(pTraits::zero), - finalResidual_(pTraits::zero), - noIterations_(0), - converged_(false), - singular_(false) - {} - - - solverPerformance - ( - const word& solverName, - const word& fieldName, - const Type& iRes = pTraits::zero, - const Type& fRes = pTraits::zero, - const label nIter = 0, - const bool converged = false, - const bool singular = false - ) - : - solverName_(solverName), - fieldName_(fieldName), - initialResidual_(iRes), - finalResidual_(fRes), - noIterations_(nIter), - converged_(converged), - singular_(singular) - {} - - - // Member functions - - //- Return solver name - const word& solverName() const - { - return solverName_; - } - - //- Return solver name - word& solverName() - { - return solverName_; - } - - - //- Return field name - const word& fieldName() const - { - return fieldName_; - } - - - //- Return initial residual - const Type& initialResidual() const - { - return initialResidual_; - } - - //- Return initial residual - Type& initialResidual() - { - return initialResidual_; - } - - - //- Return final residual - const Type& finalResidual() const - { - return finalResidual_; - } - - //- Return final residual - Type& finalResidual() - { - return finalResidual_; - } - - - //- Return number of iterations - label nIterations() const - { - return noIterations_; - } - - //- Return number of iterations - label& nIterations() - { - return noIterations_; - } - - - //- Has the solver converged? - bool converged() const - { - return converged_; - } - - //- Is the matrix singular? - bool singular() const; - - //- Check, store and return convergence - bool converged - ( - const Type& tolerance, - const Type& relTolerance - ); - - //- Singularity test - bool checkSingularity(const Type& residual); - - //- Print summary of solver performance to the given stream - void print(Ostream& os) const; - - - // Member Operators - - bool operator!=(const solverPerformance&) const; - - - // Friend functions - - //- Return the element-wise maximum of two solverPerformances - friend solverPerformance max - ( - const solverPerformance&, - const solverPerformance& - ); - - - // Ostream Operator - - friend Istream& operator>> - ( - Istream&, - solverPerformance& - ); - - friend Ostream& operator<< - ( - Ostream&, - const solverPerformance& - ); - }; - + friend class SolverPerformance; //- Abstract base-class for LduMatrix solvers class solver @@ -417,7 +236,7 @@ public: //- Read and reset the solver parameters from the given dictionary virtual void read(const dictionary& solverDict); - virtual solverPerformance solve + virtual SolverPerformance solve ( Field& psi ) const = 0; diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixTests.C b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.C similarity index 72% rename from src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixTests.C rename to src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.C index f5a675f044..a50a6e537f 100644 --- a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixTests.C +++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.C @@ -27,23 +27,24 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -template -bool Foam::LduMatrix::solverPerformance::checkSingularity +template +bool Foam::SolverPerformance::checkSingularity ( const Type& wApA ) { for(direction cmpt=0; cmpt::nComponents; cmpt++) { - singular_[cmpt] = component(wApA, cmpt) < vsmall_; + singular_[cmpt] = + component(wApA, cmpt) < LduMatrix::vsmall_; } return singular(); } -template -bool Foam::LduMatrix::solverPerformance::singular() const +template +bool Foam::SolverPerformance::singular() const { for(direction cmpt=0; cmpt::nComponents; cmpt++) { @@ -54,14 +55,14 @@ bool Foam::LduMatrix::solverPerformance::singular() const } -template -bool Foam::LduMatrix::solverPerformance::converged +template +bool Foam::SolverPerformance::converged ( const Type& Tolerance, const Type& RelTolerance ) { - if (debug >= 2) + if (LduMatrix::debug >= 2) { Info<< solverName_ << ": Iteration " << noIterations_ @@ -73,7 +74,8 @@ bool Foam::LduMatrix::solverPerformance::converged ( finalResidual_ < Tolerance || ( - RelTolerance > small_*pTraits::one + RelTolerance + > LduMatrix::small_*pTraits::one && finalResidual_ < cmptMultiply(RelTolerance, initialResidual_) ) ) @@ -89,8 +91,8 @@ bool Foam::LduMatrix::solverPerformance::converged } -template -void Foam::LduMatrix::solverPerformance::print +template +void Foam::SolverPerformance::print ( Ostream& os ) const @@ -115,10 +117,10 @@ void Foam::LduMatrix::solverPerformance::print } -template -bool Foam::LduMatrix::solverPerformance::operator!= +template +bool Foam::SolverPerformance::operator!= ( - const LduMatrix::solverPerformance& sp + const SolverPerformance& sp ) const { return @@ -134,14 +136,14 @@ bool Foam::LduMatrix::solverPerformance::operator!= } -template -typename Foam::LduMatrix::solverPerformance Foam::max +template +typename Foam::SolverPerformance Foam::max ( - const typename Foam::LduMatrix::solverPerformance& sp1, - const typename Foam::LduMatrix::solverPerformance& sp2 + const typename Foam::SolverPerformance& sp1, + const typename Foam::SolverPerformance& sp2 ) { - return lduMatrix::solverPerformance + return SolverPerformance ( sp1.solverName(), sp1.fieldName_, @@ -154,14 +156,14 @@ typename Foam::LduMatrix::solverPerformance Foam::max } -template +template Foam::Istream& Foam::operator>> ( Istream& is, - typename Foam::LduMatrix::solverPerformance& sp + typename Foam::SolverPerformance& sp ) { - is.readBeginList("LduMatrix::solverPerformance"); + is.readBeginList("SolverPerformance"); is >> sp.solverName_ >> sp.fieldName_ >> sp.initialResidual_ @@ -169,17 +171,17 @@ Foam::Istream& Foam::operator>> >> sp.noIterations_ >> sp.converged_ >> sp.singular_; - is.readEndList("LduMatrix::solverPerformance"); + is.readEndList("SolverPerformance"); return is; } -template +template Foam::Ostream& Foam::operator<< ( Ostream& os, - const typename Foam::LduMatrix::solverPerformance& sp + const typename Foam::SolverPerformance& sp ) { os << token::BEGIN_LIST diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.H b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.H new file mode 100644 index 0000000000..fdfd269e17 --- /dev/null +++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.H @@ -0,0 +1,258 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +Class + Foam::SolverPerformance + +Description + SolverPerformance is a general matrix class in which the coefficients are + stored as three arrays, one for the upper triangle, one for the + lower triangle and a third for the diagonal. + +SourceFiles + SolverPerformance.C + +\*---------------------------------------------------------------------------*/ + +#ifndef SolverPerformance_H +#define SolverPerformance_H + +#include "word.H" +#include "FixedList.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of friend functions and operators + +template +class SolverPerformance; + +template +SolverPerformance max +( + const SolverPerformance&, + const SolverPerformance& +); + +template +Istream& operator>> +( + Istream&, + SolverPerformance& +); + +template +Ostream& operator<< +( + Ostream&, + const SolverPerformance& +); + + + +/*---------------------------------------------------------------------------*\ + Class SolverPerformance Declaration +\*---------------------------------------------------------------------------*/ + +//- Class returned by the solver +// containing performance statistics +template +class SolverPerformance +{ + word solverName_; + word fieldName_; + Type initialResidual_; + Type finalResidual_; + label noIterations_; + bool converged_; + FixedList::nComponents> singular_; + + +public: + + // Constructors + + SolverPerformance() + : + initialResidual_(pTraits::zero), + finalResidual_(pTraits::zero), + noIterations_(0), + converged_(false), + singular_(false) + {} + + + SolverPerformance + ( + const word& solverName, + const word& fieldName, + const Type& iRes = pTraits::zero, + const Type& fRes = pTraits::zero, + const label nIter = 0, + const bool converged = false, + const bool singular = false + ) + : + solverName_(solverName), + fieldName_(fieldName), + initialResidual_(iRes), + finalResidual_(fRes), + noIterations_(nIter), + converged_(converged), + singular_(singular) + {} + + + // Member functions + + //- Return solver name + const word& solverName() const + { + return solverName_; + } + + //- Return solver name + word& solverName() + { + return solverName_; + } + + + //- Return field name + const word& fieldName() const + { + return fieldName_; + } + + + //- Return initial residual + const Type& initialResidual() const + { + return initialResidual_; + } + + //- Return initial residual + Type& initialResidual() + { + return initialResidual_; + } + + + //- Return final residual + const Type& finalResidual() const + { + return finalResidual_; + } + + //- Return final residual + Type& finalResidual() + { + return finalResidual_; + } + + + //- Return number of iterations + label nIterations() const + { + return noIterations_; + } + + //- Return number of iterations + label& nIterations() + { + return noIterations_; + } + + + //- Has the solver converged? + bool converged() const + { + return converged_; + } + + //- Is the matrix singular? + bool singular() const; + + //- Check, store and return convergence + bool converged + ( + const Type& tolerance, + const Type& relTolerance + ); + + //- Singularity test + bool checkSingularity(const Type& residual); + + //- Print summary of solver performance to the given stream + void print(Ostream& os) const; + + + // Member Operators + + bool operator!=(const SolverPerformance&) const; + + + // Friend functions + + //- Return the element-wise maximum of two SolverPerformances + friend SolverPerformance max + ( + const SolverPerformance&, + const SolverPerformance& + ); + + + // Ostream Operator + + friend Istream& operator>> + ( + Istream&, + SolverPerformance& + ); + + friend Ostream& operator<< + ( + Ostream&, + const SolverPerformance& + ); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +//# include "SolverPerformance.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/DiagonalSolver/DiagonalSolver.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/DiagonalSolver/DiagonalSolver.C index af128d249a..adbe9113a2 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/DiagonalSolver/DiagonalSolver.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/DiagonalSolver/DiagonalSolver.C @@ -55,7 +55,7 @@ void Foam::DiagonalSolver::read template -typename Foam::LduMatrix::solverPerformance +Foam::SolverPerformance Foam::DiagonalSolver::solve ( Field& psi @@ -63,7 +63,7 @@ Foam::DiagonalSolver::solve { psi = this->matrix_.source()/this->matrix_.diag(); - return typename LduMatrix::solverPerformance + return SolverPerformance ( typeName, this->fieldName_, diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/DiagonalSolver/DiagonalSolver.H b/src/OpenFOAM/matrices/LduMatrix/Solvers/DiagonalSolver/DiagonalSolver.H index 400891b977..b9dc537c08 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/DiagonalSolver/DiagonalSolver.H +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/DiagonalSolver/DiagonalSolver.H @@ -83,10 +83,7 @@ public: void read(const dictionary& solverDict); //- Solve the matrix with this solver - typename LduMatrix::solverPerformance solve - ( - Field& psi - ) const; + virtual SolverPerformance solve(Field& psi) const; }; diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.C index 45453ff1d0..ab0c1f4fc9 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.C @@ -47,7 +47,7 @@ Foam::PBiCCCG::PBiCCCG // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -typename Foam::LduMatrix::solverPerformance +Foam::SolverPerformance Foam::PBiCCCG::solve ( Field& psi @@ -56,7 +56,7 @@ Foam::PBiCCCG::solve word preconditionerName(this->controlDict_.lookup("preconditioner")); // --- Setup class containing solver performance data - typename LduMatrix::solverPerformance solverPerf + SolverPerformance solverPerf ( preconditionerName + typeName, this->fieldName_ diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.H b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.H index e5363dc651..39c0e56d44 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.H +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCCCG/PBiCCCG.H @@ -87,10 +87,7 @@ public: // Member Functions //- Solve the matrix with this solver - virtual typename LduMatrix::solverPerformance solve - ( - Field& psi - ) const; + virtual SolverPerformance solve(Field& psi) const; }; diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.C index b3665f0617..c92499c9fc 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.C @@ -47,13 +47,13 @@ Foam::PBiCICG::PBiCICG // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -typename Foam::LduMatrix::solverPerformance +Foam::SolverPerformance Foam::PBiCICG::solve(Field& psi) const { word preconditionerName(this->controlDict_.lookup("preconditioner")); // --- Setup class containing solver performance data - typename LduMatrix::solverPerformance solverPerf + SolverPerformance solverPerf ( preconditionerName + typeName, this->fieldName_ diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.H b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.H index 340ae48667..1265af2aac 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.H +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PBiCICG/PBiCICG.H @@ -87,10 +87,7 @@ public: // Member Functions //- Solve the matrix with this solver - virtual typename LduMatrix::solverPerformance solve - ( - Field& psi - ) const; + virtual SolverPerformance solve(Field& psi) const; }; diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.C index e6206e6116..83abd1f249 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.C @@ -47,13 +47,13 @@ Foam::PCICG::PCICG // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -typename Foam::LduMatrix::solverPerformance +typename Foam::SolverPerformance Foam::PCICG::solve(Field& psi) const { word preconditionerName(this->controlDict_.lookup("preconditioner")); // --- Setup class containing solver performance data - typename LduMatrix::solverPerformance solverPerf + SolverPerformance solverPerf ( preconditionerName + typeName, this->fieldName_ diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.H b/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.H index 250cc41b9a..cafeb7f61d 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.H +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/PCICG/PCICG.H @@ -87,10 +87,7 @@ public: // Member Functions //- Solve the matrix with this solver - virtual typename LduMatrix::solverPerformance solve - ( - Field& psi - ) const; + virtual SolverPerformance solve(Field& psi) const; }; diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/SmoothSolver/SmoothSolver.C b/src/OpenFOAM/matrices/LduMatrix/Solvers/SmoothSolver/SmoothSolver.C index e6f0241308..56ff3675e5 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/SmoothSolver/SmoothSolver.C +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/SmoothSolver/SmoothSolver.C @@ -58,11 +58,11 @@ void Foam::SmoothSolver::readControls() template -typename Foam::LduMatrix::solverPerformance +Foam::SolverPerformance Foam::SmoothSolver::solve(Field& psi) const { // --- Setup class containing solver performance data - typename LduMatrix::solverPerformance solverPerf + SolverPerformance solverPerf ( typeName, this->fieldName_ diff --git a/src/OpenFOAM/matrices/LduMatrix/Solvers/SmoothSolver/SmoothSolver.H b/src/OpenFOAM/matrices/LduMatrix/Solvers/SmoothSolver/SmoothSolver.H index 3d789420b3..54db11be8c 100644 --- a/src/OpenFOAM/matrices/LduMatrix/Solvers/SmoothSolver/SmoothSolver.H +++ b/src/OpenFOAM/matrices/LduMatrix/Solvers/SmoothSolver/SmoothSolver.H @@ -86,10 +86,7 @@ public: // Member Functions //- Solve the matrix with this solver - virtual typename LduMatrix::solverPerformance solve - ( - Field& psi - ) const; + virtual SolverPerformance solve(Field& psi) const; }; diff --git a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H index f567254f86..8b72617d04 100644 --- a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H +++ b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H @@ -387,10 +387,18 @@ public: // Solver controls read from fvSolution autoPtr solver(); - //- Solve returning the solution statistics. + //- Solve segregated or coupled returning the solution statistics. // Use the given solver controls lduMatrix::solverPerformance solve(const dictionary&); + //- Solve segregated returning the solution statistics. + // Use the given solver controls + lduMatrix::solverPerformance solveSegregated(const dictionary&); + + //- Solve coupled returning the solution statistics. + // Use the given solver controls + lduMatrix::solverPerformance solveCoupled(const dictionary&); + //- Solve returning the solution statistics. // Solver controls read from fvSolution lduMatrix::solverPerformance solve(); diff --git a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrixSolve.C b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrixSolve.C index bc3fc66d01..b37bfa2d5b 100644 --- a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrixSolve.C +++ b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrixSolve.C @@ -23,6 +23,9 @@ License \*---------------------------------------------------------------------------*/ +#include "LduMatrix.H" +#include "diagTensorField.H" + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template @@ -62,12 +65,51 @@ Foam::lduMatrix::solverPerformance Foam::fvMatrix::solve << endl; } + word type(solverControls.lookupOrDefault("type", "segregated")); + + if (type == "segregated") + { + return solveSegregated(solverControls); + } + else if (type == "coupled") + { + return solveCoupled(solverControls); + } + else + { + FatalIOErrorIn + ( + "fvMatrix::solve(const dictionary& solverControls)", + solverControls + ) << "Unknown type " << type + << "; currently supported solver types are segregated and coupled" + << exit(FatalIOError); + + return lduMatrix::solverPerformance(); + } +} + + +template +Foam::lduMatrix::solverPerformance Foam::fvMatrix::solveSegregated +( + const dictionary& solverControls +) +{ + if (debug) + { + Info<< "fvMatrix::solveSegregated" + "(const dictionary& solverControls) : " + "solving fvMatrix" + << endl; + } + GeometricField& psi = const_cast&>(psi_); lduMatrix::solverPerformance solverPerfVec ( - "fvMatrix::solve", + "fvMatrix::solveSegregated", psi.name() ); @@ -164,6 +206,62 @@ Foam::lduMatrix::solverPerformance Foam::fvMatrix::solve } +template +Foam::lduMatrix::solverPerformance Foam::fvMatrix::solveCoupled +( + const dictionary& solverControls +) +{ + if (debug) + { + Info<< "fvMatrix::solveCoupled" + "(const dictionary& solverControls) : " + "solving fvMatrix" + << endl; + } + + GeometricField& psi = + const_cast&>(psi_); + + LduMatrix coupledMatrix(psi.mesh()); + coupledMatrix.diag() = diag(); + coupledMatrix.upper() = upper(); + coupledMatrix.lower() = lower(); + coupledMatrix.source() = source(); + + addBoundaryDiag(coupledMatrix.diag(), 0); + addBoundarySource(coupledMatrix.source(), false); + + coupledMatrix.interfaces() = psi.boundaryField().interfaces(); + coupledMatrix.interfacesUpper() = boundaryCoeffs().component(0); + coupledMatrix.interfacesLower() = internalCoeffs().component(0); + + autoPtr::solver> + coupledMatrixSolver + ( + LduMatrix::solver::New + ( + psi.name(), + coupledMatrix, + solverControls + ) + ); + + SolverPerformance solverPerf + ( + coupledMatrixSolver->solve(psi) + ); + + solverPerf.print(Info); + + psi.correctBoundaryConditions(); + + // psi.mesh().setSolverPerformance(psi.name(), solverPerf); + + return lduMatrix::solverPerformance(); +} + + template Foam::autoPtr::fvSolver> Foam::fvMatrix::solver() diff --git a/src/finiteVolume/fvMatrices/fvScalarMatrix/fvScalarMatrix.C b/src/finiteVolume/fvMatrices/fvScalarMatrix/fvScalarMatrix.C index 23a259d574..aed610cd4c 100644 --- a/src/finiteVolume/fvMatrices/fvScalarMatrix/fvScalarMatrix.C +++ b/src/finiteVolume/fvMatrices/fvScalarMatrix/fvScalarMatrix.C @@ -130,14 +130,15 @@ Foam::lduMatrix::solverPerformance Foam::fvMatrix::fvSolver::solve template<> -Foam::lduMatrix::solverPerformance Foam::fvMatrix::solve +Foam::lduMatrix::solverPerformance Foam::fvMatrix::solveSegregated ( const dictionary& solverControls ) { if (debug) { - Info<< "fvMatrix::solve(const dictionary& solverControls) : " + Info<< "fvMatrix::solveSegregated" + "(const dictionary& solverControls) : " "solving fvMatrix" << endl; } diff --git a/src/finiteVolume/fvMatrices/fvScalarMatrix/fvScalarMatrix.H b/src/finiteVolume/fvMatrices/fvScalarMatrix/fvScalarMatrix.H index 072c9f2cd0..29c51a155b 100644 --- a/src/finiteVolume/fvMatrices/fvScalarMatrix/fvScalarMatrix.H +++ b/src/finiteVolume/fvMatrices/fvScalarMatrix/fvScalarMatrix.H @@ -68,7 +68,7 @@ lduMatrix::solverPerformance fvMatrix::fvSolver::solve ); template<> -lduMatrix::solverPerformance fvMatrix::solve +lduMatrix::solverPerformance fvMatrix::solveSegregated ( const dictionary& );