Commit e23bd3bb authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: use Zero when zero-initializing types

- makes the intent clearer and avoids the need for additional
  constructor casting. Eg,

      labelList(10, Zero)    vs.  labelList(10, 0)
      scalarField(10, Zero)  vs.  scalarField(10, scalar(0))
      vectorField(10, Zero)  vs.  vectorField(10, vector::zero)
parent 2ad36438
......@@ -119,7 +119,7 @@ Foam::label Foam::Distribution<Type>::index
// Underflow of this List, storage increase and remapping
// required
List<scalar> newCmptDistribution(2*cmptDistribution.size(), 0.0);
List<scalar> newCmptDistribution(2*cmptDistribution.size(), Zero);
label sOld = cmptDistribution.size();
......
......@@ -70,7 +70,7 @@ Foam::labelListList Foam::invertOneToMany
const labelUList& map
)
{
labelList sizes(len, 0);
labelList sizes(len, Zero);
for (const label newIdx : map)
{
......
......@@ -695,7 +695,7 @@ void Foam::invertManyToMany
)
{
// The output list sizes
labelList sizes(len, 0);
labelList sizes(len, Zero);
for (const InputIntListType& sublist : input)
{
......
......@@ -42,6 +42,13 @@ inline Foam::SortableList<T>::SortableList(const label size)
{}
template<class T>
inline Foam::SortableList<T>::SortableList(const label size, const zero)
:
List<T>(size, zero())
{}
template<class T>
inline Foam::SortableList<T>::SortableList(const label size, const T& val)
:
......
......@@ -71,7 +71,11 @@ public:
// The indices remain empty until the list is sorted
inline explicit SortableList(const label size);
//- Construct given size and initial value. Sort later on
//- Construct zero-initialized with given size, sort later.
// The indices remain empty until the list is sorted
inline SortableList(const label size, const zero);
//- Construct given size and initial value, sorting later.
// The indices remain empty until the list is sorted
inline SortableList(const label size, const T& val);
......
......@@ -796,7 +796,7 @@ Foam::label Foam::decomposedBlockData::calcNumProcs
(
reinterpret_cast<const char*>(&nSendProcs),
List<int>(nProcs, sizeof(nSendProcs)),
List<int>(nProcs, 0),
List<int>(nProcs, Zero),
reinterpret_cast<char*>(&n),
sizeof(n),
comm
......
......@@ -58,7 +58,7 @@ void Foam::UPstream::setParRun(const label nProcs, const bool haveThreads)
haveThreads_ = haveThreads;
freeCommunicator(UPstream::worldComm);
label comm = allocateCommunicator(-1, labelList(1, label(0)), false);
label comm = allocateCommunicator(-1, labelList(1, Zero), false);
if (comm != UPstream::worldComm)
{
FatalErrorInFunction
......@@ -382,7 +382,7 @@ Foam::UPstream::treeCommunication_(10);
Foam::UPstream::communicator serialComm
(
-1,
Foam::labelList(1, Foam::label(0)),
Foam::labelList(1, Foam::Zero),
false
);
......
......@@ -275,9 +275,9 @@ void Foam::Pstream::exchange
List<char*> charRecvBufs(sendBufs.size());
labelList nRecv(sendBufs.size());
labelList startRecv(sendBufs.size(), 0);
labelList startRecv(sendBufs.size(), Zero);
labelList nSend(sendBufs.size());
labelList startSend(sendBufs.size(), 0);
labelList startSend(sendBufs.size(), Zero);
for (label iter = 0; iter < nIter; iter++)
{
......
......@@ -25,7 +25,7 @@ Class
Foam::geometricZeroField
Description
A class representing the concept of a GeometricField of 1 used to avoid
A class representing the concept of a GeometricField of 0 used to avoid
unnecessary manipulations for objects which are known to be zero at
compile-time.
......@@ -57,6 +57,14 @@ class geometricZeroField
public:
// Public typedefs
typedef zeroField Internal;
typedef zeroField Patch;
typedef zeroFieldField Boundary;
typedef zero cmptType;
// Constructors
//- Construct null
......
......@@ -35,7 +35,7 @@ Foam::curve::curve
const label l
)
:
scalarField(l, 0.0),
scalarField(l, Zero),
name_(name),
style_(style)
{}
......
......@@ -54,7 +54,7 @@ Foam::uniformInterpolationTable<Type>::uniformInterpolationTable
)
:
IOobject(io),
List<scalar>(2, 0.0),
List<scalar>(2, Zero),
x0_(0.0),
dx_(1.0),
log10_(false),
......@@ -93,7 +93,7 @@ Foam::uniformInterpolationTable<Type>::uniformInterpolationTable
IOobject::NO_WRITE,
false // if used in BCs, could be used by multiple patches
),
List<scalar>(2, 0.0),
List<scalar>(2, Zero),
x0_(dict.get<scalar>("x0")),
dx_(dict.get<scalar>("dx")),
log10_(dict.lookupOrDefault<Switch>("log10", false)),
......
......@@ -41,7 +41,7 @@ void Foam::lduAddressing::calcLosort() const
// Scan the neighbour list to find out how many times the cell
// appears as a neighbour of the face. Done this way to avoid guessing
// and resizing list
labelList nNbrOfFace(size(), 0);
labelList nNbrOfFace(size(), Zero);
const labelUList& nbr = upperAddr();
......@@ -136,7 +136,7 @@ void Foam::lduAddressing::calcLosortStart() const
<< abort(FatalError);
}
losortStartPtr_ = new labelList(size() + 1, 0);
losortStartPtr_ = new labelList(size() + 1, Zero);
labelList& lsrtStart = *losortStartPtr_;
......@@ -259,7 +259,7 @@ Foam::Tuple2<Foam::label, Foam::scalar> Foam::lduAddressing::band() const
const labelUList& owner = lowerAddr();
const labelUList& neighbour = upperAddr();
labelList cellBandwidth(size(), 0);
labelList cellBandwidth(size(), Zero);
forAll(neighbour, facei)
{
......
......@@ -178,7 +178,7 @@ Foam::scalarField& Foam::lduMatrix::lower()
}
else
{
lowerPtr_ = new scalarField(lduAddr().lowerAddr().size(), 0.0);
lowerPtr_ = new scalarField(lduAddr().lowerAddr().size(), Zero);
}
}
......@@ -190,7 +190,7 @@ Foam::scalarField& Foam::lduMatrix::diag()
{
if (!diagPtr_)
{
diagPtr_ = new scalarField(lduAddr().size(), 0.0);
diagPtr_ = new scalarField(lduAddr().size(), Zero);
}
return *diagPtr_;
......@@ -207,7 +207,7 @@ Foam::scalarField& Foam::lduMatrix::upper()
}
else
{
upperPtr_ = new scalarField(lduAddr().lowerAddr().size(), 0.0);
upperPtr_ = new scalarField(lduAddr().lowerAddr().size(), Zero);
}
}
......@@ -225,7 +225,7 @@ Foam::scalarField& Foam::lduMatrix::lower(const label nCoeffs)
}
else
{
lowerPtr_ = new scalarField(nCoeffs, 0.0);
lowerPtr_ = new scalarField(nCoeffs, Zero);
}
}
......@@ -237,7 +237,7 @@ Foam::scalarField& Foam::lduMatrix::diag(const label size)
{
if (!diagPtr_)
{
diagPtr_ = new scalarField(size, 0.0);
diagPtr_ = new scalarField(size, Zero);
}
return *diagPtr_;
......@@ -254,7 +254,7 @@ Foam::scalarField& Foam::lduMatrix::upper(const label nCoeffs)
}
else
{
upperPtr_ = new scalarField(nCoeffs, 0.0);
upperPtr_ = new scalarField(nCoeffs, Zero);
}
}
......
......@@ -295,7 +295,7 @@ Foam::tmp<Foam::scalarField > Foam::lduMatrix::H1() const
{
tmp<scalarField > tH1
(
new scalarField(lduAddr().size(), 0.0)
new scalarField(lduAddr().size(), Zero)
);
if (lowerPtr_ || upperPtr_)
......
......@@ -70,7 +70,7 @@ void Foam::GAMGAgglomeration::agglomerateLduAddressing
label maxNnbrs = 10;
// Number of faces for each coarse-cell
labelList cCellnFaces(nCoarseCells, 0);
labelList cCellnFaces(nCoarseCells, Zero);
// Setup initial packed storage for coarse-cell faces
labelList cCellFaces(maxNnbrs*nCoarseCells);
......@@ -260,7 +260,11 @@ void Foam::GAMGAgglomeration::agglomerateLduAddressing
// Get reference to fine-level interfaces
const lduInterfacePtrsList& fineInterfaces = interfaceLevel(fineLevelIndex);
nPatchFaces_.set(fineLevelIndex, new labelList(fineInterfaces.size(), 0));
nPatchFaces_.set
(
fineLevelIndex,
new labelList(fineInterfaces.size(), Zero)
);
labelList& nPatchFaces = nPatchFaces_[fineLevelIndex];
patchFaceRestrictAddressing_.set
......
......@@ -135,7 +135,7 @@ Foam::tmp<Foam::labelField> Foam::pairGAMGAgglomeration::agglomerate
// memory management
{
labelList nNbrs(nFineCells, 0);
labelList nNbrs(nFineCells, Zero);
forAll(upperAddr, facei)
{
......
......@@ -95,7 +95,7 @@ bool Foam::masterCoarsestGAMGProcAgglomeration::agglomerate()
if (nProcs > 1)
{
// Processor restriction map: per processor the coarse processor
labelList procAgglomMap(nProcs, 0);
labelList procAgglomMap(nProcs, Zero);
// Master processor
labelList masterProcs;
......
......@@ -150,7 +150,7 @@ Foam::procFacesGAMGProcAgglomeration::processorAgglomeration
label singleCellMeshComm = UPstream::allocateCommunicator
(
mesh.comm(),
labelList(1, label(0)) // only processor 0
labelList(1, Zero) // only processor 0
);
scalarField faceWeights;
......
......@@ -253,7 +253,7 @@ void Foam::GAMGSolver::agglomerateInterfaceCoefficients
coarseInterfaceBouCoeffs.set
(
inti,
new scalarField(nPatchFaces[inti], 0.0)
new scalarField(nPatchFaces[inti], Zero)
);
agglomeration_.restrictField
(
......@@ -265,7 +265,7 @@ void Foam::GAMGSolver::agglomerateInterfaceCoefficients
coarseInterfaceIntCoeffs.set
(
inti,
new scalarField(nPatchFaces[inti], 0.0)
new scalarField(nPatchFaces[inti], Zero)
);
agglomeration_.restrictField
(
......
......@@ -80,7 +80,7 @@ Foam::tmp<Foam::scalarField> Foam::GAMGInterface::agglomerateCoeffs
const scalarField& fineCoeffs
) const
{
tmp<scalarField> tcoarseCoeffs(new scalarField(size(), 0.0));
tmp<scalarField> tcoarseCoeffs(new scalarField(size(), Zero));
scalarField& coarseCoeffs = tcoarseCoeffs.ref();
if (fineCoeffs.size() != faceRestrictAddressing_.size())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment