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
<< "(" << nl;
for (const auto& item : list1)

View File

@ -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;

View File

@ -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<class Type>
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>
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
\\/ 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<class T>
Foam::label Foam::Detail::PtrListDetail<T>::count() const noexcept
Foam::label Foam::Detail::PtrListDetail<T>::count_nonnull() const noexcept
{
label n = 0;

View File

@ -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;

View File

@ -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<T>::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)
{

View File

@ -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<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 |
-------------------------------------------------------------------------------
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<T>::capacity() const noexcept
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 |
-------------------------------------------------------------------------------
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
);
}
}
}