diff --git a/src/petsc4Foam/utils/petscUtils.C b/src/petsc4Foam/utils/petscUtils.C index b0edd8f33b57a5447b0db7896929901a7e2ff3aa..d596d584c87bf1bdafe337041af3e7380fa0c77a 100644 --- a/src/petsc4Foam/utils/petscUtils.C +++ b/src/petsc4Foam/utils/petscUtils.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019 Simone Bna Copyright (C) 2020 Stefano Zampini ------------------------------------------------------------------------------- @@ -31,11 +31,10 @@ License #include "error.H" #include "petscUtils.H" #include "petscLinearSolverContext.H" -#include <algorithm> // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // -Foam::scalar Foam::gAverage(Vec input) +Foam::solveScalar Foam::gAverage(Vec input) { PetscInt len; VecGetSize(input, &len); @@ -51,11 +50,11 @@ Foam::scalar Foam::gAverage(Vec input) WarningInFunction << "Empty PETSc Vec, returning zero" << endl; - return Zero; + return 0; } -Foam::scalar Foam::gSum(Vec input) +Foam::solveScalar Foam::gSum(Vec input) { PetscScalar val; VecSum(input, &val); @@ -64,63 +63,6 @@ Foam::scalar Foam::gSum(Vec input) } -void Foam::PetscUtils::copyVector -( - Vec input, - List<scalar>& output, - const bool syncPar /* unused */ -) -{ - const PetscScalar *data; - VecGetArrayRead(input, &data); - - PetscInt len; - VecGetLocalSize(input, &len); - - output.resize(len); - - if (sizeof(PetscScalar) == sizeof(scalar)) - { - // Slight optimization - std::memcpy(output.data(), data, output.byteSize()); - } - else - { - std::copy(data, (data + len), output.begin()); - } - - VecRestoreArrayRead(input, &data); -} - - -void Foam::PetscUtils::copyVector -( - const UList<scalar>& input, - Vec output, - const bool syncPar -) -{ - if (syncPar) - { - VecSetSizes(output, input.size(), PETSC_DECIDE); - } - - PetscScalar *data; - VecGetArrayWrite(output, &data); - - if (sizeof(PetscScalar) == sizeof(scalar)) - { - // Slight optimization - std::memcpy(data, input.cdata(), input.byteSize()); - } - else - { - std::copy(input.cbegin(), input.cend(), data); - } - - VecRestoreArrayWrite(output, &data); -} - Foam::scalar Foam::PetscUtils::normFactor ( Vec AdotPsi, @@ -155,7 +97,7 @@ Foam::scalar Foam::PetscUtils::normFactor const PetscScalar* sourceValues; VecGetArrayRead(source, &sourceValues); - scalar normFactor = Zero; + scalar normFactor{0}; PetscInt len; VecGetLocalSize(psi, &len); @@ -183,6 +125,7 @@ Foam::scalar Foam::PetscUtils::normFactor ); } + PetscErrorCode Foam::PetscUtils::foamKSPMonitorFoam ( KSP ksp, @@ -238,6 +181,7 @@ PetscErrorCode Foam::PetscUtils::foamKSPMonitorFoam PetscFunctionReturn(0); } + PetscErrorCode Foam::PetscUtils::foamKSPMonitorRecordInit ( KSP ksp, @@ -254,6 +198,7 @@ PetscErrorCode Foam::PetscUtils::foamKSPMonitorRecordInit PetscFunctionReturn(0); } + PetscErrorCode Foam::PetscUtils::foamKSPConverge ( KSP ksp, diff --git a/src/petsc4Foam/utils/petscUtils.H b/src/petsc4Foam/utils/petscUtils.H index 28d7ce5172762d6a1ad30ec817038b7be639329e..b90c700f3c19ba8d3bac637177f62645cbf6156a 100644 --- a/src/petsc4Foam/utils/petscUtils.H +++ b/src/petsc4Foam/utils/petscUtils.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019 Simone Bna ------------------------------------------------------------------------------- License @@ -51,10 +51,10 @@ namespace Foam { //- Global average value in PETSc vector -scalar gAverage(Vec input); +solveScalar gAverage(Vec input); //- Global sum of PETSc vector -scalar gSum(Vec input); +solveScalar gSum(Vec input); namespace PetscUtils @@ -64,22 +64,6 @@ namespace PetscUtils Namespace PetscUtils \*---------------------------------------------------------------------------*/ -//- Copy a PETSc vector to an OpenFOAM List -void copyVector -( - Vec input, - List<scalar>& output, - const bool syncPar = false -); - -//- Copy an OpenFOAM List to a PETSc vector -void copyVector -( - const UList<scalar>& input, - Vec output, - const bool syncPar = false -); - //- Calculate the OpenFOAM normFactor (akin to an L1 norm) scalar normFactor (