diff --git a/src/petsc4Foam/solvers/petscSolver.C b/src/petsc4Foam/solvers/petscSolver.C index 690d45a4405f5f421744af83182795a23e2784bc..77fb3d6d18d697eee0a5c49cbee5951eec8aa570 100644 --- a/src/petsc4Foam/solvers/petscSolver.C +++ b/src/petsc4Foam/solvers/petscSolver.C @@ -184,8 +184,8 @@ Foam::solverPerformance Foam::petscSolver::scalarSolve buildKsp(Amat, ksp); } - bool matup = ctx.caching.needsMatrixUpdate(); - bool pcup = ctx.caching.needsPrecondUpdate(); + const bool matup = ctx.caching.needsMatrixUpdate(); + const bool pcup = ctx.caching.needsPrecondUpdate(); if (matup) { PetscLogStagePush(ctx.matstage); diff --git a/src/petsc4Foam/utils/petscCacheManager.H b/src/petsc4Foam/utils/petscCacheManager.H index f6d5cdd05305c023d3c4225b09328d35a76debb7..8238127252879e988dbf61abec388b7db55843a7 100644 --- a/src/petsc4Foam/utils/petscCacheManager.H +++ b/src/petsc4Foam/utils/petscCacheManager.H @@ -162,8 +162,10 @@ class petscCacheManager { // Private Data - //- The current (relative) iterations for matrix and preconditioner + //- The current (relative) iterations for matrix label miter; + + //- The current (relative) iterations for preconditioner label piter; PetscUtils::Caching matrixCaching; @@ -246,7 +248,6 @@ public: { ++miter; } - } @@ -255,7 +256,8 @@ private: bool needsUpdate(const PetscUtils::Caching& caching, label& iter) const { // Default: Always update - bool need = true; + bool need = true; + switch (caching.updateType_) { case PetscUtils::Caching::Never: @@ -271,7 +273,6 @@ private: case PetscUtils::Caching::Periodic: { - need = false; if ( caching.updateFreq_ <= 1 @@ -279,7 +280,10 @@ private: ) { iter = 0; - need = true; + } + else + { + need = false; } break; } @@ -288,7 +292,6 @@ private: { if (iter > 3) // we need at least three times { - need = false; const double ratio0 = caching.time0 / caching.timeIter; @@ -301,12 +304,16 @@ private: if (iter >= nsteps) { iter = 0; - need = true; + } + else + { + need = false; } } break; } } + return need; } }; diff --git a/src/petsc4Foam/utils/petscLinearSolverContext.H b/src/petsc4Foam/utils/petscLinearSolverContext.H index 21b4873ebe85d82277923da8861daf13e761c35d..ef6145a2494f1375e8419efea4c77d29389df452 100644 --- a/src/petsc4Foam/utils/petscLinearSolverContext.H +++ b/src/petsc4Foam/utils/petscLinearSolverContext.H @@ -69,9 +69,9 @@ public: Mat Amat; KSP ksp; - PetscLogStage matstage; - PetscLogStage pcstage; - PetscLogStage kspstage; + // Auxiliary vectors for the OpenFOAM-PETSc L1-norm + Vec ArowsSum; + Vec *res_l1_w; solverPerformance performance; petscCacheManager caching; @@ -79,12 +79,12 @@ public: List<PetscInt> lowNonZero; label maxLowNonZeroPerRow; - // Auxiliary vectors for the OpenFOAM-PETSc L1-norm - Vec ArowsSum; - Vec *res_l1_w; - PetscScalar normFactor; + PetscLogStage matstage; + PetscLogStage pcstage; + PetscLogStage kspstage; + // Constructors @@ -92,13 +92,12 @@ public: petscLinearSolverContext() : init_(false), - init_aux_vectors_(false) - { - Amat = NULL; - ksp = NULL; - ArowsSum = NULL; - res_l1_w = NULL; - } + init_aux_vectors_(false), + Amat(nullptr), + ksp(nullptr), + ArowsSum(nullptr), + res_l1_w(nullptr) + {} //- Destructor @@ -130,9 +129,9 @@ public: { if (!init_aux_vectors_) { + init_aux_vectors_ = true; VecDuplicate(psi, &ArowsSum); VecDuplicateVecs(psi, 2, &res_l1_w); - init_aux_vectors_ = true; } } @@ -150,6 +149,7 @@ public: void computeNormFactor(Mat A, Vec psi, Vec source) { if (!init_aux_vectors_) return; + MatMult(A, psi, res_l1_w[1]); normFactor =