mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -8,6 +8,7 @@ const Enum<writeChecksFormatType> writeChecksFormatTypeNames
|
|||||||
{
|
{
|
||||||
{ writeChecksFormatType::none, "none" },
|
{ writeChecksFormatType::none, "none" },
|
||||||
{ writeChecksFormatType::dictionary, "dictionary" },
|
{ writeChecksFormatType::dictionary, "dictionary" },
|
||||||
|
{ writeChecksFormatType::JSON, "json" },
|
||||||
{ writeChecksFormatType::JSON, "JSON" },
|
{ writeChecksFormatType::JSON, "JSON" },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ writeChecksFormatType writeChecksFormat(writeChecksFormatType::none);
|
|||||||
|
|
||||||
auto writeMeshChecks = [](const fvMesh& mesh, const writeChecksFormatType fmt)
|
auto writeMeshChecks = [](const fvMesh& mesh, const writeChecksFormatType fmt)
|
||||||
{
|
{
|
||||||
if (Pstream::master())
|
if (UPstream::master())
|
||||||
{
|
{
|
||||||
switch (fmt)
|
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);
|
data.writeHeader(os);
|
||||||
|
|
||||||
mesh.data().meshDict().write(os, false);
|
mesh.data().meshDict().write(os, false);
|
||||||
|
|
||||||
IOobject::writeEndDivider(os);
|
IOobject::writeEndDivider(os);
|
||||||
|
|
||||||
Info<< "Writing mesh data to " << data.objectPath()
|
|
||||||
<< nl << endl;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case writeChecksFormatType::JSON:
|
case writeChecksFormatType::JSON:
|
||||||
|
|||||||
@ -154,8 +154,8 @@ Foam::UPtrList<const Foam::mapDistributeBase> Foam::mapDistribute::extractBase
|
|||||||
UPtrList<const mapDistributeBase> baseMaps(maps.size());
|
UPtrList<const mapDistributeBase> baseMaps(maps.size());
|
||||||
forAll(maps, i)
|
forAll(maps, i)
|
||||||
{
|
{
|
||||||
const mapDistributeBase& map = maps[i];
|
// Implicit cast to <const mapDistributeBase*>
|
||||||
baseMaps.set(i, &map);
|
baseMaps.set(i, maps.get(i));
|
||||||
}
|
}
|
||||||
return baseMaps;
|
return baseMaps;
|
||||||
}
|
}
|
||||||
@ -250,15 +250,13 @@ Foam::mapDistribute::mapDistribute
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Add all (non-local) transformed elements needed.
|
// Add all (non-local) transformed elements needed.
|
||||||
forAll(transformedElements, i)
|
for (const labelPair& elem : transformedElements)
|
||||||
{
|
{
|
||||||
labelPair elem = transformedElements[i];
|
|
||||||
label proci = globalTransforms.processor(elem);
|
label proci = globalTransforms.processor(elem);
|
||||||
if (proci != myRank)
|
if (proci != myRank)
|
||||||
{
|
{
|
||||||
label index = globalTransforms.index(elem);
|
label index = globalTransforms.index(elem);
|
||||||
label nCompact = compactMap[proci].size();
|
compactMap[proci].insert(index, compactMap[proci].size());
|
||||||
compactMap[proci].insert(index, nCompact);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,31 +277,32 @@ Foam::mapDistribute::mapDistribute
|
|||||||
// Renumber the transformed elements
|
// Renumber the transformed elements
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
// Count per transformIndex
|
// Count per transformIndex
|
||||||
label nTrafo = globalTransforms.transformPermutations().size();
|
const label nTrafo = globalTransforms.transformPermutations().size();
|
||||||
labelList nPerTransform(nTrafo, Zero);
|
labelList nPerTransform(nTrafo, Zero);
|
||||||
forAll(transformedElements, i)
|
for (const labelPair& elem : transformedElements)
|
||||||
{
|
{
|
||||||
labelPair elem = transformedElements[i];
|
|
||||||
label trafoI = globalTransforms.transformIndex(elem);
|
label trafoI = globalTransforms.transformIndex(elem);
|
||||||
nPerTransform[trafoI]++;
|
nPerTransform[trafoI]++;
|
||||||
}
|
}
|
||||||
// Offset per transformIndex
|
// Offset per transformIndex
|
||||||
transformStart_.setSize(nTrafo);
|
transformStart_.resize_nocopy(nTrafo);
|
||||||
transformElements_.setSize(nTrafo);
|
transformElements_.resize_nocopy(nTrafo);
|
||||||
forAll(transformStart_, trafoI)
|
forAll(transformStart_, trafoI)
|
||||||
{
|
{
|
||||||
|
const label count = nPerTransform[trafoI];
|
||||||
|
|
||||||
transformStart_[trafoI] = constructSize();
|
transformStart_[trafoI] = constructSize();
|
||||||
constructSize() += nPerTransform[trafoI];
|
transformElements_[trafoI].resize_nocopy(count);
|
||||||
transformElements_[trafoI].setSize(nPerTransform[trafoI]);
|
constructSize() += count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort transformed elements into their new slot.
|
// Sort transformed elements into their new slot.
|
||||||
nPerTransform = 0;
|
nPerTransform = 0;
|
||||||
|
|
||||||
transformedIndices.setSize(transformedElements.size());
|
transformedIndices.resize_nocopy(transformedElements.size());
|
||||||
forAll(transformedElements, i)
|
forAll(transformedElements, i)
|
||||||
{
|
{
|
||||||
labelPair elem = transformedElements[i];
|
const labelPair& elem = transformedElements[i];
|
||||||
label proci = globalTransforms.processor(elem);
|
label proci = globalTransforms.processor(elem);
|
||||||
label index = globalTransforms.index(elem);
|
label index = globalTransforms.index(elem);
|
||||||
label trafoI = globalTransforms.transformIndex(elem);
|
label trafoI = globalTransforms.transformIndex(elem);
|
||||||
@ -358,18 +357,15 @@ Foam::mapDistribute::mapDistribute
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Add all (non-local) transformed elements needed.
|
// Add all (non-local) transformed elements needed.
|
||||||
forAll(transformedElements, celli)
|
for (const labelPairList& elems : transformedElements)
|
||||||
{
|
{
|
||||||
const labelPairList& elems = transformedElements[celli];
|
for (const labelPair& elem : elems)
|
||||||
|
|
||||||
forAll(elems, i)
|
|
||||||
{
|
{
|
||||||
label proci = globalTransforms.processor(elems[i]);
|
label proci = globalTransforms.processor(elem);
|
||||||
if (proci != myRank)
|
if (proci != myRank)
|
||||||
{
|
{
|
||||||
label index = globalTransforms.index(elems[i]);
|
label index = globalTransforms.index(elem);
|
||||||
label nCompact = compactMap[proci].size();
|
compactMap[proci].insert(index, compactMap[proci].size());
|
||||||
compactMap[proci].insert(index, nCompact);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -391,36 +387,36 @@ Foam::mapDistribute::mapDistribute
|
|||||||
// Renumber the transformed elements
|
// Renumber the transformed elements
|
||||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
// Count per transformIndex
|
// Count per transformIndex
|
||||||
label nTrafo = globalTransforms.transformPermutations().size();
|
const label nTrafo = globalTransforms.transformPermutations().size();
|
||||||
labelList nPerTransform(nTrafo, Zero);
|
labelList nPerTransform(nTrafo, Zero);
|
||||||
forAll(transformedElements, celli)
|
for (const labelPairList& elems : transformedElements)
|
||||||
{
|
{
|
||||||
const labelPairList& elems = transformedElements[celli];
|
for (const labelPair& elem : elems)
|
||||||
|
|
||||||
forAll(elems, i)
|
|
||||||
{
|
{
|
||||||
label trafoI = globalTransforms.transformIndex(elems[i]);
|
label trafoI = globalTransforms.transformIndex(elem);
|
||||||
nPerTransform[trafoI]++;
|
nPerTransform[trafoI]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Offset per transformIndex
|
// Offset per transformIndex
|
||||||
transformStart_.setSize(nTrafo);
|
transformStart_.resize_nocopy(nTrafo);
|
||||||
transformElements_.setSize(nTrafo);
|
transformElements_.resize_nocopy(nTrafo);
|
||||||
forAll(transformStart_, trafoI)
|
forAll(transformStart_, trafoI)
|
||||||
{
|
{
|
||||||
|
const label count = nPerTransform[trafoI];
|
||||||
|
|
||||||
transformStart_[trafoI] = constructSize();
|
transformStart_[trafoI] = constructSize();
|
||||||
constructSize() += nPerTransform[trafoI];
|
transformElements_[trafoI].resize_nocopy(count);
|
||||||
transformElements_[trafoI].setSize(nPerTransform[trafoI]);
|
constructSize() += count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort transformed elements into their new slot.
|
// Sort transformed elements into their new slot.
|
||||||
nPerTransform = 0;
|
nPerTransform = 0;
|
||||||
|
|
||||||
transformedIndices.setSize(transformedElements.size());
|
transformedIndices.resize_nocopy(transformedElements.size());
|
||||||
forAll(transformedElements, celli)
|
forAll(transformedElements, celli)
|
||||||
{
|
{
|
||||||
const labelPairList& elems = transformedElements[celli];
|
const labelPairList& elems = transformedElements[celli];
|
||||||
transformedIndices[celli].setSize(elems.size());
|
transformedIndices[celli].resize_nocopy(elems.size());
|
||||||
|
|
||||||
forAll(elems, i)
|
forAll(elems, i)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -425,8 +425,7 @@ void Foam::mapDistributeBase::calcCompactAddressing
|
|||||||
{
|
{
|
||||||
label proci = globalNumbering.whichProcID(myRank, globalIdx);
|
label proci = globalNumbering.whichProcID(myRank, globalIdx);
|
||||||
label index = globalNumbering.toLocal(proci, globalIdx);
|
label index = globalNumbering.toLocal(proci, globalIdx);
|
||||||
label nCompact = compactMap[proci].size();
|
compactMap[proci].insert(index, compactMap[proci].size());
|
||||||
compactMap[proci].insert(index, nCompact);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -478,8 +477,7 @@ void Foam::mapDistributeBase::calcCompactAddressing
|
|||||||
{
|
{
|
||||||
label proci = globalNumbering.whichProcID(myRank, globalIdx);
|
label proci = globalNumbering.whichProcID(myRank, globalIdx);
|
||||||
label index = globalNumbering.toLocal(proci, globalIdx);
|
label index = globalNumbering.toLocal(proci, globalIdx);
|
||||||
label nCompact = compactMap[proci].size();
|
compactMap[proci].insert(index, compactMap[proci].size());
|
||||||
compactMap[proci].insert(index, nCompact);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,8 +43,8 @@ SourceFiles
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef globalIndexAndTransform_H
|
#ifndef Foam_globalIndexAndTransform_H
|
||||||
#define globalIndexAndTransform_H
|
#define Foam_globalIndexAndTransform_H
|
||||||
|
|
||||||
#include "labelPair.H"
|
#include "labelPair.H"
|
||||||
#include "vectorTensorTransform.H"
|
#include "vectorTensorTransform.H"
|
||||||
@ -55,9 +55,9 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Forward Declarations
|
||||||
class polyMesh;
|
class polyMesh;
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class globalIndexAndTransform Declaration
|
Class globalIndexAndTransform Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -66,7 +66,7 @@ class globalIndexAndTransform
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Public classes
|
// Public Classes
|
||||||
|
|
||||||
//- Less function class used in sorting encoded transforms and indices
|
//- Less function class used in sorting encoded transforms and indices
|
||||||
// Minimum of:
|
// Minimum of:
|
||||||
@ -168,7 +168,7 @@ public:
|
|||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from components
|
//- Construct from components
|
||||||
globalIndexAndTransform(const polyMesh& mesh);
|
explicit globalIndexAndTransform(const polyMesh& mesh);
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
@ -282,7 +282,6 @@ public:
|
|||||||
const labelHashSet& patchIs,
|
const labelHashSet& patchIs,
|
||||||
const point& pt
|
const point& pt
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -130,7 +130,7 @@ Foam::Ostream& Foam::JSONformatter::writeDict(const dictionary& dict)
|
|||||||
const word& keyword = e.keyword();
|
const word& keyword = e.keyword();
|
||||||
|
|
||||||
os_ << indent;
|
os_ << indent;
|
||||||
writeKeyword(keyword) << " : ";
|
os_.writeQuoted(keyword) << " : ";
|
||||||
|
|
||||||
if (e.isDict())
|
if (e.isDict())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -82,7 +82,7 @@ public:
|
|||||||
virtual Ostream& write(const bool val);
|
virtual Ostream& write(const bool val);
|
||||||
virtual Ostream& write(const int32_t val);
|
virtual Ostream& write(const int32_t val);
|
||||||
virtual Ostream& write(const int64_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 double val);
|
||||||
virtual Ostream& write(const word& str);
|
virtual Ostream& write(const word& str);
|
||||||
virtual Ostream& write(const std::string& str);
|
virtual Ostream& write(const std::string& str);
|
||||||
@ -94,11 +94,13 @@ public:
|
|||||||
//- Write OpenFOAM dictionary to JSON dictionary
|
//- Write OpenFOAM dictionary to JSON dictionary
|
||||||
virtual Ostream& writeDict(const dictionary& dict);
|
virtual Ostream& writeDict(const dictionary& dict);
|
||||||
|
|
||||||
//- Write JSON keyword-value pair
|
//- Write JSON keyword-value pair (for primitive types)
|
||||||
template<class Type>
|
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_;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user