diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.C b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.C index bf68dbc08a701837e2a1d35c5b331f28ba6f1d75..ef5e3e8eae31eb7eaf69030fcba4eff98e66b50b 100644 --- a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.C +++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.C @@ -58,6 +58,34 @@ bool Foam::SolverPerformance<Type>::singular() const } +template<class Type> +double Foam::SolverPerformance<Type>::timing() const +{ + double ret{0}; + + for (const double val : timing_) + { + ret += val; + } + + return ret; +} + + +template<class Type> +double Foam::SolverPerformance<Type>::maxTiming() const +{ + double ret{0}; + + for (const double val : timing_) + { + ret = Foam::max(ret, val); + } + + return ret; +} + + template<class Type> bool Foam::SolverPerformance<Type>::checkConvergence ( @@ -110,7 +138,7 @@ void Foam::SolverPerformance<Type>::print os << ", Initial residual = " << component(initialResidual_, cmpt) << ", Final residual = " << component(finalResidual_, cmpt) << ", No Iterations " << nIterations_ - ; + << ", Timing = " << timing_[cmpt]; } os << endl; } @@ -128,12 +156,13 @@ void Foam::SolverPerformance<Type>::replace finalResidual_.replace(cmpt, sp.finalResidual()); nIterations_.replace(cmpt, sp.nIterations()); singular_[cmpt] = sp.singular(); + timing_[cmpt] = sp.timing(); } template<class Type> Foam::SolverPerformance<typename Foam::pTraits<Type>::cmptType> -Foam::SolverPerformance<Type>::max() +Foam::SolverPerformance<Type>::max() const { return SolverPerformance<typename pTraits<Type>::cmptType> ( @@ -143,46 +172,49 @@ Foam::SolverPerformance<Type>::max() cmptMax(finalResidual_), cmptMax(nIterations_), converged_, - singular() + singular(), + maxTiming() ); } template<class Type> -bool Foam::SolverPerformance<Type>::operator!= +bool Foam::operator!= ( - const SolverPerformance<Type>& sp -) const + const SolverPerformance<Type>& a, + const SolverPerformance<Type>& b +) { return ( - solverName() != sp.solverName() - || fieldName() != sp.fieldName() - || initialResidual() != sp.initialResidual() - || finalResidual() != sp.finalResidual() - || nIterations() != sp.nIterations() - || converged() != sp.converged() - || singular() != sp.singular() + a.solverName() != b.solverName() + || a.fieldName() != b.fieldName() + || a.initialResidual() != b.initialResidual() + || a.finalResidual() != b.finalResidual() + || a.nIterations() != b.nIterations() + || a.converged() != b.converged() + || a.singular() != b.singular() ); } template<class Type> -typename Foam::SolverPerformance<Type> Foam::max +Foam::SolverPerformance<Type> Foam::max ( - const typename Foam::SolverPerformance<Type>& sp1, - const typename Foam::SolverPerformance<Type>& sp2 + const SolverPerformance<Type>& a, + const SolverPerformance<Type>& b ) { return SolverPerformance<Type> ( - sp1.solverName(), - sp1.fieldName_, - max(sp1.initialResidual(), sp2.initialResidual()), - max(sp1.finalResidual(), sp2.finalResidual()), - max(sp1.nIterations(), sp2.nIterations()), - sp1.converged() && sp2.converged(), - sp1.singular() || sp2.singular() + a.solverName(), + a.fieldName(), + max(a.initialResidual(), b.initialResidual()), + max(a.finalResidual(), b.finalResidual()), + max(a.nIterations(), b.nIterations()), + a.converged() && b.converged(), + a.singular() || b.singular(), + max(a.maxTiming(), b.maxTiming()) ); } @@ -201,7 +233,8 @@ Foam::Istream& Foam::operator>> >> sp.finalResidual_ >> sp.nIterations_ >> sp.converged_ - >> sp.singular_; + >> sp.singular_ + >> sp.timing_; is.readEnd("SolverPerformance"); return is; @@ -223,6 +256,7 @@ Foam::Ostream& Foam::operator<< << sp.nIterations_ << token::SPACE << sp.converged_ << token::SPACE << sp.singular_ << token::SPACE + << sp.timing_ << token::SPACE << token::END_LIST; return os; diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.H b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.H index 4d4ab648bb3dee4bc3dfac117f5f33598c55e87d..6d6450851d24cbb8544e7cf3d57efda1d3c58894 100644 --- a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.H +++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/SolverPerformance.H @@ -41,6 +41,7 @@ SourceFiles #include "word.H" #include "FixedList.H" +#include "clockValue.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -83,6 +84,7 @@ class SolverPerformance labelType nIterations_; bool converged_; FixedList<bool, pTraits<Type>::nComponents> singular_; + FixedList<double, pTraits<Type>::nComponents> timing_; public: @@ -114,7 +116,8 @@ public: finalResidual_(Zero), nIterations_(Zero), converged_(false), - singular_(false) + singular_(false), + timing_(Zero) {} @@ -127,7 +130,8 @@ public: const Type& fRes = pTraits<Type>::zero, const labelType& nIter = pTraits<labelType>::zero, const bool converged = false, - const bool singular = false + const bool singular = false, + const scalar timingValue = 0 ) : solverName_(solverName), @@ -136,8 +140,12 @@ public: finalResidual_(fRes), nIterations_(nIter), converged_(converged), - singular_(singular) - {} + singular_(singular), + timing_(Zero) + { + // Single-value assignment affects single component only + timing_.first() = timingValue; + } // Member Functions @@ -208,6 +216,24 @@ public: //- Is the matrix singular? bool singular() const; + //- Return total timing, the sum of all components + double timing() const; + + //- Add to single-component timing + void addTiming(double timingValue) + { + timing_.first() += timingValue; + } + + //- Set single-component timing + void setTiming(double timingValue) + { + timing_.first() = timingValue; + } + + //- Return the max timing + double maxTiming() const; + //- Check, store and return convergence bool checkConvergence ( @@ -230,23 +256,7 @@ public: //- Return the summary maximum of SolverPerformance<Type> // Effectively it will mostly return solverPerformanceScalar - SolverPerformance<typename pTraits<Type>::cmptType> max(); - - - // Member Operators - - //- Test for inequality - bool operator!=(const SolverPerformance<Type>&) const; - - - // Friend Functions - - //- Return the element-wise maximum of two SolverPerformance<Type>s - friend SolverPerformance<Type> Foam::max <Type> - ( - const SolverPerformance<Type>&, - const SolverPerformance<Type>& - ); + SolverPerformance<typename pTraits<Type>::cmptType> max() const; // Ostream Operator @@ -265,6 +275,28 @@ public: }; +// Global Operators + +//- Test for inequality +template<class Type> +bool operator!= +( + const SolverPerformance<Type>& a, + const SolverPerformance<Type>& b +); + + +// Global Functions + +//- Return element-wise maximum of SolverPerformance +template<class Type> +SolverPerformance<Type> max +( + const SolverPerformance<Type>& a, + const SolverPerformance<Type>& b +); + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/solverPerformance.C b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/solverPerformance.C index f7fe3bce9a5b1c26a642c6511db70b6eff3ed59b..62d4425ac3a990e5ab296f73919ab7d3bd090d8c 100644 --- a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/solverPerformance.C +++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/solverPerformance.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2015 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,10 +41,24 @@ namespace Foam template<> Foam::SolverPerformance<Foam::scalar> -Foam::SolverPerformance<Foam::scalar>::max() +Foam::SolverPerformance<Foam::scalar>::max() const { return *this; } +template<> +double Foam::SolverPerformance<Foam::scalar>::timing() const +{ + return timing_.first(); +} + + +template<> +double Foam::SolverPerformance<Foam::scalar>::maxTiming() const +{ + return timing_.first(); +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/solverPerformance.H b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/solverPerformance.H index 1231e169fa412cf6682254e3955ede19e866fed7..d11a8b5187cf49e186ec332454905a3fa205367a 100644 --- a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/solverPerformance.H +++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/solverPerformance.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2015 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -45,9 +46,17 @@ namespace Foam { typedef SolverPerformance<scalar> solverPerformance; - // Specialization of the max function for scalar object + // Specialize max() member function for scalar template<> - SolverPerformance<scalar> SolverPerformance<scalar>::max(); + SolverPerformance<scalar> SolverPerformance<scalar>::max() const; + + // Specialize timing() member function for scalar + template<> + double SolverPerformance<scalar>::timing() const; + + // Specialize maxTiming() member function for scalar + template<> + double SolverPerformance<scalar>::maxTiming() const; } diff --git a/src/finiteArea/faMatrices/faMatrix/faMatrixSolve.C b/src/finiteArea/faMatrices/faMatrix/faMatrixSolve.C index 73ee0de3d4dac202393df7b136da33faa3c340c7..7614229e6ae95230e9f805fb9954f0393bb283a4 100644 --- a/src/finiteArea/faMatrices/faMatrix/faMatrixSolve.C +++ b/src/finiteArea/faMatrices/faMatrix/faMatrixSolve.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016-2017 Wikki Ltd - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -129,10 +129,10 @@ Foam::SolverPerformance<Type> Foam::faMatrix<Type>::solve ); } - solverPerformance solverPerf; - // Solver call - solverPerf = lduMatrix::solver::New + const auto timing = clockValue::now(); + + solverPerformance solverPerf = lduMatrix::solver::New ( psi_.name() + pTraits<Type>::componentNames[cmpt], *this, @@ -142,6 +142,8 @@ Foam::SolverPerformance<Type> Foam::faMatrix<Type>::solve solverControls )->solve(psiCmpt, sourceCmpt, cmpt); + solverPerf.setTiming(timing.elapsedTime()); + if (SolverPerformance<Type>::debug) { solverPerf.print(Info); diff --git a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrixSolve.C b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrixSolve.C index 1bd117b28d9c7a76d65c8d0a4b855221bde54e7d..6ec2958fb590ae5fa5e56e1497bf3c2fb7ade1b6 100644 --- a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrixSolve.C +++ b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrixSolve.C @@ -203,10 +203,11 @@ Foam::SolverPerformance<Type> Foam::fvMatrix<Type>::solveSegregated ); } - solverPerformance solverPerf; // Solver call - solverPerf = lduMatrix::solver::New + const auto timing = clockValue::now(); + + solverPerformance solverPerf = lduMatrix::solver::New ( psi.name() + pTraits<Type>::componentNames[cmpt], *this, @@ -216,6 +217,8 @@ Foam::SolverPerformance<Type> Foam::fvMatrix<Type>::solveSegregated solverControls )->solve(psiCmpt, sourceCmpt, cmpt); + solverPerf.setTiming(timing.elapsedTime()); + if (SolverPerformance<Type>::debug) { solverPerf.print(Info.masterStream(this->mesh().comm()));