From 732c8b3330ca976454f12b51269ee1fd79ab939c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 8 Feb 2024 15:52:48 +0100 Subject: [PATCH] STYLE: more explicit method name PtrList::count() -> count_nonnull() STYLE: use two-parameter shallowCopy --- applications/test/PtrList/Test-PtrList.C | 2 +- src/ODE/ODESolvers/ODESolver/ODESolver.H | 21 ++++++++-------- src/ODE/ODESolvers/ODESolver/ODESolverI.H | 25 +++---------------- .../PtrLists/PtrListDetail/PtrListDetail.C | 4 +-- .../PtrLists/PtrListDetail/PtrListDetail.H | 6 ++--- .../PtrLists/PtrListDetail/PtrListDetailIO.C | 6 ++--- .../containers/PtrLists/UPtrList/UPtrList.H | 10 +++++--- .../containers/PtrLists/UPtrList/UPtrListI.H | 6 ++--- .../matrices/LUscalarMatrix/procLduMatrix.C | 17 +++---------- 9 files changed, 36 insertions(+), 61 deletions(-) diff --git a/applications/test/PtrList/Test-PtrList.C b/applications/test/PtrList/Test-PtrList.C index b10794ffb0..2df2c5cbf0 100644 --- a/applications/test/PtrList/Test-PtrList.C +++ b/applications/test/PtrList/Test-PtrList.C @@ -412,7 +412,7 @@ int main(int argc, char *argv[]) } { - Info<< "range-for of list (" << list1.count() << '/' + Info<< "range-for of list (" << list1.count_nonnull() << '/' << list1.size() << ") non-null entries" << nl << "(" << nl; for (const auto& item : list1) diff --git a/src/ODE/ODESolvers/ODESolver/ODESolver.H b/src/ODE/ODESolvers/ODESolver/ODESolver.H index 066dc86483..b274234ea7 100644 --- a/src/ODE/ODESolvers/ODESolver/ODESolver.H +++ b/src/ODE/ODESolvers/ODESolver/ODESolver.H @@ -38,8 +38,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef ODESolver_H -#define ODESolver_H +#ifndef Foam_ODESolver_H +#define Foam_ODESolver_H #include "ODESystem.H" #include "typeInfo.H" @@ -56,10 +56,9 @@ namespace Foam class ODESolver { - protected: - // Protected data + // Protected Data //- Reference to ODESystem const ODESystem& odes_; @@ -106,7 +105,7 @@ public: class stepState { - public: + public: const bool forward; scalar dxTry; @@ -171,14 +170,14 @@ public: // Member Functions - //- Return the number of equations to solve - inline label nEqns() const; + //- The number of equations to solve + label nEqns() const noexcept { return n_; } - //- Return access to the absolute tolerance field - inline scalarField& absTol(); + //- Access to the absolute tolerance field + scalarField& absTol() noexcept { return absTol_; } - //- Return access to the relative tolerance field - inline scalarField& relTol(); + //- Access to the relative tolerance field + scalarField& relTol() noexcept { return relTol_; } //- Resize the ODE solver virtual bool resize() = 0; diff --git a/src/ODE/ODESolvers/ODESolver/ODESolverI.H b/src/ODE/ODESolvers/ODESolver/ODESolverI.H index acf77d7a50..bee196abbf 100644 --- a/src/ODE/ODESolvers/ODESolver/ODESolverI.H +++ b/src/ODE/ODESolvers/ODESolver/ODESolverI.H @@ -27,36 +27,19 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -inline Foam::label Foam::ODESolver::nEqns() const -{ - return n_; -} - - -inline Foam::scalarField& Foam::ODESolver::absTol() -{ - return absTol_; -} - - -inline Foam::scalarField& Foam::ODESolver::relTol() -{ - return relTol_; -} - - template inline void Foam::ODESolver::resizeField(UList& f, const label n) { - f.shallowCopy(UList(f.begin(), n)); + // shallowResize + f.shallowCopy(f.data(), n); } template inline void Foam::ODESolver::resizeField(UList& f) const { - resizeField(f, n_); + // shallowResize + f.shallowCopy(f.data(), n_); } diff --git a/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetail.C b/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetail.C index d3456228d3..c0917472a4 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetail.C +++ b/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetail.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2023 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,7 +30,7 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -Foam::label Foam::Detail::PtrListDetail::count() const noexcept +Foam::label Foam::Detail::PtrListDetail::count_nonnull() const noexcept { label n = 0; diff --git a/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetail.H b/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetail.H index faed8ae374..cc78942272 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetail.H +++ b/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetail.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2023 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -95,8 +95,8 @@ public: //- Return pointer to element or nullptr for out-of-range access. inline T* get(const label i); - //- Return the number of non-null entries - label count() const noexcept; + //- The number of non-nullptr entries in the list + label count_nonnull() const noexcept; //- FatalError if any null exists in the list inline void checkNonNull() const; diff --git a/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetailIO.C b/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetailIO.C index e17dfc320c..f3713841d9 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetailIO.C +++ b/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetailIO.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2023 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,8 +40,8 @@ Foam::Ostream& Foam::Detail::PtrListDetail::write { const label len = this->size(); - // The net length (after trimming any nullptr) - const label netLen = (trimNull ? this->count() : len); + // The net length, optionally after trimming any nullptr + const label netLen = (trimNull ? this->count_nonnull() : len); if (!netLen) { diff --git a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H index 3b180f3616..24c93e4a45 100644 --- a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H +++ b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2023 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -257,8 +257,8 @@ public: //- Size of the underlying storage. inline label capacity() const noexcept; - //- The number of non-null entries in the list - inline label count() const noexcept; + //- The number of non-nullptr entries in the list + inline label count_nonnull() const noexcept; //- Reference to the first element of the list inline T& front(); @@ -648,6 +648,10 @@ public: //- Move append another list to the end of this list. //FOAM_DEPRECATED_FOR(2022-10, "push_back()") void append(UPtrList&& other) { this->push_back(std::move(other)); } + + //- The number of non-nullptr entries in the list + FOAM_DEPRECATED_FOR(2024-01, "count_nonnull()") + label count() const noexcept { return count_nonnull(); } }; diff --git a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H index c7763cf9aa..681b6497ae 100644 --- a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H +++ b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2023 OpenCFD Ltd. + Copyright (C) 2018-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -124,9 +124,9 @@ inline Foam::label Foam::UPtrList::capacity() const noexcept template -inline Foam::label Foam::UPtrList::count() const noexcept +inline Foam::label Foam::UPtrList::count_nonnull() const noexcept { - return ptrs_.count(); + return ptrs_.count_nonnull(); } diff --git a/src/OpenFOAM/matrices/LUscalarMatrix/procLduMatrix.C b/src/OpenFOAM/matrices/LUscalarMatrix/procLduMatrix.C index 267a5c54c6..9670e99e14 100644 --- a/src/OpenFOAM/matrices/LUscalarMatrix/procLduMatrix.C +++ b/src/OpenFOAM/matrices/LUscalarMatrix/procLduMatrix.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation + Copyright (C) 2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,22 +43,11 @@ Foam::procLduMatrix::procLduMatrix lowerAddr_(ldum.lduAddr().lowerAddr()), diag_(ldum.diag()), upper_(ldum.upper()), - lower_(ldum.lower()) + lower_(ldum.lower()), + interfaces_(interfaces.count_nonnull()) { label nInterfaces = 0; - forAll(interfaces, i) - { - if (interfaces.set(i)) - { - nInterfaces++; - } - } - - interfaces_.setSize(nInterfaces); - - nInterfaces = 0; - forAll(interfaces, i) { if (interfaces.set(i)) @@ -73,7 +63,6 @@ Foam::procLduMatrix::procLduMatrix ); } } - }