COMP: access transformedElements by reference, not copy

- better code style and seems to avoid triggering a gcc warning about
  possibly uninitialized values

COMP: JSONformatter writeEntry missing a return value

STYLE: accept 'json' for checkMesh write format

- consistent with caseInfo functionObject
This commit is contained in:
Mark Olesen 2023-12-15 11:44:41 +01:00
parent 79993bba43
commit 0352a224b7
6 changed files with 49 additions and 54 deletions

View File

@ -8,6 +8,7 @@ const Enum<writeChecksFormatType> writeChecksFormatTypeNames
{
{ writeChecksFormatType::none, "none" },
{ writeChecksFormatType::dictionary, "dictionary" },
{ writeChecksFormatType::JSON, "json" },
{ writeChecksFormatType::JSON, "JSON" },
};
@ -15,7 +16,7 @@ writeChecksFormatType writeChecksFormat(writeChecksFormatType::none);
auto writeMeshChecks = [](const fvMesh& mesh, const writeChecksFormatType fmt)
{
if (Pstream::master())
if (UPstream::master())
{
switch (fmt)
{
@ -33,15 +34,14 @@ auto writeMeshChecks = [](const fvMesh& mesh, const writeChecksFormatType fmt)
)
);
Info<< "Writing mesh data to " << os.name() << nl << endl;
data.writeHeader(os);
mesh.data().meshDict().write(os, false);
IOobject::writeEndDivider(os);
Info<< "Writing mesh data to " << data.objectPath()
<< nl << endl;
break;
}
case writeChecksFormatType::JSON:

View File

@ -154,8 +154,8 @@ Foam::UPtrList<const Foam::mapDistributeBase> Foam::mapDistribute::extractBase
UPtrList<const mapDistributeBase> baseMaps(maps.size());
forAll(maps, i)
{
const mapDistributeBase& map = maps[i];
baseMaps.set(i, &map);
// Implicit cast to <const mapDistributeBase*>
baseMaps.set(i, maps.get(i));
}
return baseMaps;
}
@ -250,15 +250,13 @@ Foam::mapDistribute::mapDistribute
);
// Add all (non-local) transformed elements needed.
forAll(transformedElements, i)
for (const labelPair& elem : transformedElements)
{
labelPair elem = transformedElements[i];
label proci = globalTransforms.processor(elem);
if (proci != myRank)
{
label index = globalTransforms.index(elem);
label nCompact = compactMap[proci].size();
compactMap[proci].insert(index, nCompact);
compactMap[proci].insert(index, compactMap[proci].size());
}
}
@ -279,31 +277,32 @@ Foam::mapDistribute::mapDistribute
// Renumber the transformed elements
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Count per transformIndex
label nTrafo = globalTransforms.transformPermutations().size();
const label nTrafo = globalTransforms.transformPermutations().size();
labelList nPerTransform(nTrafo, Zero);
forAll(transformedElements, i)
for (const labelPair& elem : transformedElements)
{
labelPair elem = transformedElements[i];
label trafoI = globalTransforms.transformIndex(elem);
nPerTransform[trafoI]++;
}
// Offset per transformIndex
transformStart_.setSize(nTrafo);
transformElements_.setSize(nTrafo);
transformStart_.resize_nocopy(nTrafo);
transformElements_.resize_nocopy(nTrafo);
forAll(transformStart_, trafoI)
{
const label count = nPerTransform[trafoI];
transformStart_[trafoI] = constructSize();
constructSize() += nPerTransform[trafoI];
transformElements_[trafoI].setSize(nPerTransform[trafoI]);
transformElements_[trafoI].resize_nocopy(count);
constructSize() += count;
}
// Sort transformed elements into their new slot.
nPerTransform = 0;
transformedIndices.setSize(transformedElements.size());
transformedIndices.resize_nocopy(transformedElements.size());
forAll(transformedElements, i)
{
labelPair elem = transformedElements[i];
const labelPair& elem = transformedElements[i];
label proci = globalTransforms.processor(elem);
label index = globalTransforms.index(elem);
label trafoI = globalTransforms.transformIndex(elem);
@ -358,18 +357,15 @@ Foam::mapDistribute::mapDistribute
);
// Add all (non-local) transformed elements needed.
forAll(transformedElements, celli)
for (const labelPairList& elems : transformedElements)
{
const labelPairList& elems = transformedElements[celli];
forAll(elems, i)
for (const labelPair& elem : elems)
{
label proci = globalTransforms.processor(elems[i]);
label proci = globalTransforms.processor(elem);
if (proci != myRank)
{
label index = globalTransforms.index(elems[i]);
label nCompact = compactMap[proci].size();
compactMap[proci].insert(index, nCompact);
label index = globalTransforms.index(elem);
compactMap[proci].insert(index, compactMap[proci].size());
}
}
}
@ -391,36 +387,36 @@ Foam::mapDistribute::mapDistribute
// Renumber the transformed elements
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Count per transformIndex
label nTrafo = globalTransforms.transformPermutations().size();
const label nTrafo = globalTransforms.transformPermutations().size();
labelList nPerTransform(nTrafo, Zero);
forAll(transformedElements, celli)
for (const labelPairList& elems : transformedElements)
{
const labelPairList& elems = transformedElements[celli];
forAll(elems, i)
for (const labelPair& elem : elems)
{
label trafoI = globalTransforms.transformIndex(elems[i]);
label trafoI = globalTransforms.transformIndex(elem);
nPerTransform[trafoI]++;
}
}
// Offset per transformIndex
transformStart_.setSize(nTrafo);
transformElements_.setSize(nTrafo);
transformStart_.resize_nocopy(nTrafo);
transformElements_.resize_nocopy(nTrafo);
forAll(transformStart_, trafoI)
{
const label count = nPerTransform[trafoI];
transformStart_[trafoI] = constructSize();
constructSize() += nPerTransform[trafoI];
transformElements_[trafoI].setSize(nPerTransform[trafoI]);
transformElements_[trafoI].resize_nocopy(count);
constructSize() += count;
}
// Sort transformed elements into their new slot.
nPerTransform = 0;
transformedIndices.setSize(transformedElements.size());
transformedIndices.resize_nocopy(transformedElements.size());
forAll(transformedElements, celli)
{
const labelPairList& elems = transformedElements[celli];
transformedIndices[celli].setSize(elems.size());
transformedIndices[celli].resize_nocopy(elems.size());
forAll(elems, i)
{

View File

@ -425,8 +425,7 @@ void Foam::mapDistributeBase::calcCompactAddressing
{
label proci = globalNumbering.whichProcID(myRank, globalIdx);
label index = globalNumbering.toLocal(proci, globalIdx);
label nCompact = compactMap[proci].size();
compactMap[proci].insert(index, nCompact);
compactMap[proci].insert(index, compactMap[proci].size());
}
}
}
@ -478,8 +477,7 @@ void Foam::mapDistributeBase::calcCompactAddressing
{
label proci = globalNumbering.whichProcID(myRank, globalIdx);
label index = globalNumbering.toLocal(proci, globalIdx);
label nCompact = compactMap[proci].size();
compactMap[proci].insert(index, nCompact);
compactMap[proci].insert(index, compactMap[proci].size());
}
}
}

View File

@ -43,8 +43,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef globalIndexAndTransform_H
#define globalIndexAndTransform_H
#ifndef Foam_globalIndexAndTransform_H
#define Foam_globalIndexAndTransform_H
#include "labelPair.H"
#include "vectorTensorTransform.H"
@ -55,9 +55,9 @@ SourceFiles
namespace Foam
{
// Forward Declarations
class polyMesh;
/*---------------------------------------------------------------------------*\
Class globalIndexAndTransform Declaration
\*---------------------------------------------------------------------------*/
@ -66,7 +66,7 @@ class globalIndexAndTransform
{
public:
// Public classes
// Public Classes
//- Less function class used in sorting encoded transforms and indices
// Minimum of:
@ -168,7 +168,7 @@ public:
// Constructors
//- Construct from components
globalIndexAndTransform(const polyMesh& mesh);
explicit globalIndexAndTransform(const polyMesh& mesh);
// Member Functions
@ -282,7 +282,6 @@ public:
const labelHashSet& patchIs,
const point& pt
) const;
};

View File

@ -130,7 +130,7 @@ Foam::Ostream& Foam::JSONformatter::writeDict(const dictionary& dict)
const word& keyword = e.keyword();
os_ << indent;
writeKeyword(keyword) << " : ";
os_.writeQuoted(keyword) << " : ";
if (e.isDict())
{

View File

@ -82,7 +82,7 @@ public:
virtual Ostream& write(const bool val);
virtual Ostream& write(const int32_t val);
virtual Ostream& write(const int64_t val);
virtual Ostream& write(const float val );
virtual Ostream& write(const float val);
virtual Ostream& write(const double val);
virtual Ostream& write(const word& str);
virtual Ostream& write(const std::string& str);
@ -94,11 +94,13 @@ public:
//- Write OpenFOAM dictionary to JSON dictionary
virtual Ostream& writeDict(const dictionary& dict);
//- Write JSON keyword-value pair
//- Write JSON keyword-value pair (for primitive types)
template<class Type>
Ostream& writeEntry(const word& keyword, Type val)
Ostream& writeEntry(const word& keyword, const Type& val)
{
writeKeyword(keyword) << " : " << write(val);
os_.writeQuoted(keyword) << " : ";
write(val);
return os_;
}
};