STYLE: more explicit method name PtrList::count() -> count_nonnull()

STYLE: use two-parameter shallowCopy
This commit is contained in:
Mark Olesen
2024-02-08 15:52:48 +01:00
parent ff567dbe71
commit 732c8b3330
9 changed files with 36 additions and 61 deletions

View File

@ -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 << list1.size() << ") non-null entries" << nl
<< "(" << nl; << "(" << nl;
for (const auto& item : list1) for (const auto& item : list1)

View File

@ -38,8 +38,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef ODESolver_H #ifndef Foam_ODESolver_H
#define ODESolver_H #define Foam_ODESolver_H
#include "ODESystem.H" #include "ODESystem.H"
#include "typeInfo.H" #include "typeInfo.H"
@ -56,10 +56,9 @@ namespace Foam
class ODESolver class ODESolver
{ {
protected: protected:
// Protected data // Protected Data
//- Reference to ODESystem //- Reference to ODESystem
const ODESystem& odes_; const ODESystem& odes_;
@ -171,14 +170,14 @@ public:
// Member Functions // Member Functions
//- Return the number of equations to solve //- The number of equations to solve
inline label nEqns() const; label nEqns() const noexcept { return n_; }
//- Return access to the absolute tolerance field //- Access to the absolute tolerance field
inline scalarField& absTol(); scalarField& absTol() noexcept { return absTol_; }
//- Return access to the relative tolerance field //- Access to the relative tolerance field
inline scalarField& relTol(); scalarField& relTol() noexcept { return relTol_; }
//- Resize the ODE solver //- Resize the ODE solver
virtual bool resize() = 0; virtual bool resize() = 0;

View File

@ -27,36 +27,19 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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<class Type> template<class Type>
inline void Foam::ODESolver::resizeField(UList<Type>& f, const label n) inline void Foam::ODESolver::resizeField(UList<Type>& f, const label n)
{ {
f.shallowCopy(UList<Type>(f.begin(), n)); // shallowResize
f.shallowCopy(f.data(), n);
} }
template<class Type> template<class Type>
inline void Foam::ODESolver::resizeField(UList<Type>& f) const inline void Foam::ODESolver::resizeField(UList<Type>& f) const
{ {
resizeField(f, n_); // shallowResize
f.shallowCopy(f.data(), n_);
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2023 OpenCFD Ltd. Copyright (C) 2018-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -30,7 +30,7 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T> template<class T>
Foam::label Foam::Detail::PtrListDetail<T>::count() const noexcept Foam::label Foam::Detail::PtrListDetail<T>::count_nonnull() const noexcept
{ {
label n = 0; label n = 0;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2023 OpenCFD Ltd. Copyright (C) 2018-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -95,8 +95,8 @@ public:
//- Return pointer to element or nullptr for out-of-range access. //- Return pointer to element or nullptr for out-of-range access.
inline T* get(const label i); inline T* get(const label i);
//- Return the number of non-null entries //- The number of non-nullptr entries in the list
label count() const noexcept; label count_nonnull() const noexcept;
//- FatalError if any null exists in the list //- FatalError if any null exists in the list
inline void checkNonNull() const; inline void checkNonNull() const;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2023 OpenCFD Ltd. Copyright (C) 2018-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -40,8 +40,8 @@ Foam::Ostream& Foam::Detail::PtrListDetail<T>::write
{ {
const label len = this->size(); const label len = this->size();
// The net length (after trimming any nullptr) // The net length, optionally after trimming any nullptr
const label netLen = (trimNull ? this->count() : len); const label netLen = (trimNull ? this->count_nonnull() : len);
if (!netLen) if (!netLen)
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2023 OpenCFD Ltd. Copyright (C) 2018-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -257,8 +257,8 @@ public:
//- Size of the underlying storage. //- Size of the underlying storage.
inline label capacity() const noexcept; inline label capacity() const noexcept;
//- The number of non-null entries in the list //- The number of non-nullptr entries in the list
inline label count() const noexcept; inline label count_nonnull() const noexcept;
//- Reference to the first element of the list //- Reference to the first element of the list
inline T& front(); inline T& front();
@ -648,6 +648,10 @@ public:
//- Move append another list to the end of this list. //- Move append another list to the end of this list.
//FOAM_DEPRECATED_FOR(2022-10, "push_back()") //FOAM_DEPRECATED_FOR(2022-10, "push_back()")
void append(UPtrList<T>&& other) { this->push_back(std::move(other)); } void append(UPtrList<T>&& 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(); }
}; };

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2023 OpenCFD Ltd. Copyright (C) 2018-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -124,9 +124,9 @@ inline Foam::label Foam::UPtrList<T>::capacity() const noexcept
template<class T> template<class T>
inline Foam::label Foam::UPtrList<T>::count() const noexcept inline Foam::label Foam::UPtrList<T>::count_nonnull() const noexcept
{ {
return ptrs_.count(); return ptrs_.count_nonnull();
} }

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -42,22 +43,11 @@ Foam::procLduMatrix::procLduMatrix
lowerAddr_(ldum.lduAddr().lowerAddr()), lowerAddr_(ldum.lduAddr().lowerAddr()),
diag_(ldum.diag()), diag_(ldum.diag()),
upper_(ldum.upper()), upper_(ldum.upper()),
lower_(ldum.lower()) lower_(ldum.lower()),
interfaces_(interfaces.count_nonnull())
{ {
label nInterfaces = 0; label nInterfaces = 0;
forAll(interfaces, i)
{
if (interfaces.set(i))
{
nInterfaces++;
}
}
interfaces_.setSize(nInterfaces);
nInterfaces = 0;
forAll(interfaces, i) forAll(interfaces, i)
{ {
if (interfaces.set(i)) if (interfaces.set(i))
@ -73,7 +63,6 @@ Foam::procLduMatrix::procLduMatrix
); );
} }
} }
} }