STYLE: use newer forAll macros

This commit is contained in:
Mark Olesen
2017-05-30 12:44:13 +02:00
parent 5d60d7e15c
commit 6d26b40e8b
8 changed files with 74 additions and 76 deletions

View File

@ -57,6 +57,7 @@ public:
//- The second boundary //- The second boundary
label bnd1; label bnd1;
// Constructors // Constructors
//- Construct null //- Construct null
@ -194,7 +195,7 @@ public:
//- Scan available interface entries for one matching this boundary id //- Scan available interface entries for one matching this boundary id
bool isInterface(label bndId) bool isInterface(label bndId)
{ {
forAllConstIter(Map<interfaceEntry>, *this, iter) forAllConstIters(*this, iter)
{ {
if (iter().inInterface(bndId)) if (iter().inInterface(bndId))
{ {
@ -210,7 +211,7 @@ public:
word interfaceName(label bndId) word interfaceName(label bndId)
{ {
word ifname; word ifname;
forAllConstIter(Map<interfaceEntry>, *this, iter) forAllConstIters(*this, iter)
{ {
ifname = iter().canonicalName(bndId); ifname = iter().canonicalName(bndId);
if (!ifname.empty()) if (!ifname.empty())
@ -231,7 +232,7 @@ public:
const interfaceDefinitions& defs const interfaceDefinitions& defs
) )
{ {
os << static_cast<const Map<interfaceEntry>& >(defs) os << static_cast<const Map<interfaceEntry>&>(defs)
<< nl; << nl;
return os; return os;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -44,7 +44,7 @@ Foam::Map<Foam::word> Foam::ccm::reader::selectPorous
{ {
Map<word> lookup; Map<word> lookup;
forAllConstIter(Map<dictionary>, table, iter) forAllConstIters(table, iter)
{ {
if (iter().lookupOrDefault<label>("PorosityId", 0) != 0) if (iter().lookupOrDefault<label>("PorosityId", 0) != 0)
{ {
@ -70,21 +70,21 @@ void Foam::ccm::reader::warnDuplicates
const wordList& lst const wordList& lst
) )
{ {
HashTable<label> hashed(lst.size()); HashTable<label> hashed(2*lst.size());
bool duplicates = false; bool duplicates = false;
forAll(lst, elemI) for (const word& item : lst)
{ {
// Check duplicate name // Check duplicate names
HashTable<label>::iterator iter = hashed.find(lst[elemI]); auto iter = hashed.find(item);
if (iter != hashed.end()) if (iter.found())
{ {
(*iter)++; (*iter)++;
duplicates = true; duplicates = true;
} }
else else
{ {
hashed.insert(lst[elemI], 1); hashed.insert(item, 1);
} }
} }
@ -92,9 +92,9 @@ void Foam::ccm::reader::warnDuplicates
if (duplicates) if (duplicates)
{ {
Info << nl << "WARNING: " << context << " with identical names:"; Info << nl << "WARNING: " << context << " with identical names:";
forAllConstIter(HashTable<label>, hashed, iter) forAllConstIters(hashed, iter)
{ {
if (*iter > 1) if (iter.object() > 1)
{ {
Info << " " << iter.key(); Info << " " << iter.key();
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -479,8 +479,8 @@ void Foam::ccm::reader::readCells
info.setPatchName(ccmReadOptstr("Label", nodeId)); info.setPatchName(ccmReadOptstr("Label", nodeId));
// Lookup the name, type from boundary region info: // Lookup the name, type from boundary region info:
Map<dictionary>::iterator dictIter = boundaryRegion_.find(info.ccmIndex); auto dictIter = boundaryRegion_.find(info.ccmIndex);
if (dictIter != boundaryRegion_.end()) if (dictIter.found())
{ {
word patchName(dictIter()["Label"]); word patchName(dictIter()["Label"]);
word patchType(dictIter()["BoundaryType"]); word patchType(dictIter()["BoundaryType"]);
@ -576,8 +576,8 @@ void Foam::ccm::reader::readCells
if (option().combineBoundaries()) if (option().combineBoundaries())
{ {
// Check if patch name was already seen // Check if patch name was already seen
HashTable<label, std::string>::const_iterator citer = hashedNames.find(info.patchName); auto citer = hashedNames.cfind(info.patchName);
if (citer != hashedNames.end()) if (citer.found())
{ {
info.patchId = bndInfo[citer()].patchId; info.patchId = bndInfo[citer()].patchId;
} }
@ -775,7 +775,11 @@ void Foam::ccm::reader::readCells
kCCMIOStart, kCCMIOStart,
kCCMIOEnd kCCMIOEnd
); );
assertNoError("Error reading boundary face cells - index " + ::Foam::name(info.ccmIndex)); assertNoError
(
"Error reading boundary face cells - index "
+ ::Foam::name(info.ccmIndex)
);
// Copy into Foam list // Copy into Foam list
// ccmFaces are organized as [nVert vrt1 .. vrtN] // ccmFaces are organized as [nVert vrt1 .. vrtN]
@ -797,7 +801,11 @@ void Foam::ccm::reader::readCells
} }
else else
{ {
assertNoError("Error reading boundary faces - index " + ::Foam::name(info.ccmIndex)); assertNoError
(
"Error reading boundary faces - index "
+ ::Foam::name(info.ccmIndex)
);
} }
} }
@ -1106,11 +1114,10 @@ void Foam::ccm::reader::readMonitoring
<< "ccmRegionId: " << ccmRegionId << endl; << "ccmRegionId: " << ccmRegionId << endl;
#endif #endif
Map<dictionary>::const_iterator auto iter = boundaryRegion_.cfind(ccmRegionId);
iter = boundaryRegion_.find(ccmRegionId);
word zoneName; word zoneName;
if (iter != boundaryRegion_.end()) if (iter.found())
{ {
iter().lookup("Label") >> zoneName; iter().lookup("Label") >> zoneName;
} }
@ -1314,7 +1321,7 @@ void Foam::ccm::reader::removeUnwanted()
{ {
Map<word> keepMap; Map<word> keepMap;
forAllConstIter(Map<dictionary>, cellTable_, iter) forAllConstIters(cellTable_, iter)
{ {
const label tableId = iter.key(); const label tableId = iter.key();
if (!removeMap.found(tableId)) if (!removeMap.found(tableId))
@ -1326,17 +1333,19 @@ void Foam::ccm::reader::removeUnwanted()
Info<<"remove "<< nRemove << " cells in " Info<<"remove "<< nRemove << " cells in "
<< removeMap.size() << " unwanted cellZone(s)" << nl; << removeMap.size() << " unwanted cellZone(s)" << nl;
forAllConstIter(Map<word>, removeMap, iter) forAllConstIters(removeMap, iter)
{ {
Info<< " zone " << iter.key() << " : "<< iter() << nl; Info<< " zone "
<< iter.key() << " : " << iter.object() << nl;
} }
Info<<"retain "<< (nCells_ - nRemove) << " cells in " Info<<"retain "<< (nCells_ - nRemove) << " cells in "
<< keepMap.size() << " cellZone(s)" << nl; << keepMap.size() << " cellZone(s)" << nl;
forAllConstIter(Map<word>, keepMap, iter) forAllConstIters(keepMap, iter)
{ {
Info<< " zone " << iter.key() << " : "<< iter() << nl; Info<< " zone "
<< iter.key() << " : " << iter.object() << nl;
} }
} }
} }
@ -1821,7 +1830,7 @@ void Foam::ccm::reader::cleanupInterfaces()
// << SubList<label>(oldToNew, nFaces_ - nInternalFaces_, nInternalFaces_) // << SubList<label>(oldToNew, nFaces_ - nInternalFaces_, nInternalFaces_)
// << endl; // << endl;
forAllIter(HashTable<labelList>, monitoringSets_, iter) forAllIters(monitoringSets_, iter)
{ {
inplaceRenumber(oldToNew, iter()); inplaceRenumber(oldToNew, iter());
} }
@ -1903,7 +1912,12 @@ void Foam::ccm::reader::mergeInplaceInterfaces()
findIndex(origBndId_, ifentry.bnd1) findIndex(origBndId_, ifentry.bnd1)
); );
if (patchPair[0] == patchPair[1] || patchPair[0] < 0 || patchPair[1] < 0) if
(
patchPair[0] == patchPair[1]
|| patchPair[0] < 0
|| patchPair[1] < 0
)
{ {
// This should not happen // This should not happen
Info<<"Warning : bad interface " << interI << " " << ifentry Info<<"Warning : bad interface " << interI << " " << ifentry
@ -1985,7 +1999,7 @@ void Foam::ccm::reader::mergeInplaceInterfaces()
const UIndirectList<point> pointsToMerge(points_, addr); const UIndirectList<point> pointsToMerge(points_, addr);
Info<< " patch " << patch0 << ", " << patch1 << ": (" Info<< " patch " << patch0 << "," << patch1 << ": ("
<< nPatch0Faces << " and " << nPatch1Faces << " faces) " << flush; << nPatch0Faces << " and " << nPatch1Faces << " faces) " << flush;
label nMerged = mergePoints label nMerged = mergePoints
@ -2175,11 +2189,11 @@ void Foam::ccm::reader::mergeInplaceInterfaces()
// Note which one were successful // Note which one were successful
labelHashSet done(failed0.size()); labelHashSet done(failed0.size());
forAllConstIter(labelHashSet, failed0, iter0) forAllConstIters(failed0, iter0)
{ {
const label face0I = iter0.key(); const label face0I = iter0.key();
forAllConstIter(labelHashSet, failed1, iter1) forAllConstIters(failed1, iter1)
{ {
const label face1I = iter1.key(); const label face1I = iter1.key();
@ -2421,10 +2435,10 @@ void Foam::ccm::reader::reorderMesh()
inplaceReorder(oldToNew, faceNeighbour_); inplaceReorder(oldToNew, faceNeighbour_);
inplaceReorder(oldToNew, origFaceId_); inplaceReorder(oldToNew, origFaceId_);
forAllIter(HashTable<labelList>, monitoringSets_, iter) forAllIters(monitoringSets_, iter)
{ {
inplaceRenumber(oldToNew, iter()); labelList& lst = iter.object();
labelList &lst = iter(); inplaceRenumber(oldToNew, lst);
// disallow monitoring on boundaries // disallow monitoring on boundaries
label nElem = 0; label nElem = 0;
@ -2436,7 +2450,7 @@ void Foam::ccm::reader::reorderMesh()
{ {
lst[nElem] = lst[i]; lst[nElem] = lst[i];
} }
nElem++; ++nElem;
} }
} }
@ -2478,10 +2492,9 @@ void Foam::ccm::reader::addPatches
word patchName; word patchName;
word patchType; word patchType;
Map<dictionary>::const_iterator auto citer = boundaryRegion_.cfind(origBndId_[patchI]);
citer = boundaryRegion_.find(origBndId_[patchI]);
if (citer != boundaryRegion_.end()) if (citer.found())
{ {
citer().lookup("Label") >> patchName; citer().lookup("Label") >> patchName;
citer().lookup("BoundaryType") >> patchType; citer().lookup("BoundaryType") >> patchType;
@ -2593,7 +2606,7 @@ void Foam::ccm::reader::addFaceZones
} }
nZone = 0; nZone = 0;
forAllConstIter(HashTable<labelList>, monitoringSets_, iter) forAllConstIters(monitoringSets_, iter)
{ {
Info<< "faceZone " << nZone Info<< "faceZone " << nZone
<< " (size: " << iter().size() << ") name: " << " (size: " << iter().size() << ") name: "
@ -2612,7 +2625,7 @@ void Foam::ccm::reader::addFaceZones
) )
); );
nZone++; ++nZone;
} }
mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE; mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE;

View File

@ -622,7 +622,7 @@ Foam::ccm::reader::readField
// transcribe to output list // transcribe to output list
forAll(mapData, i) forAll(mapData, i)
{ {
label cellId = mapData[i]; const label cellId = mapData[i];
scalarData[cellId] = rawData[i]; scalarData[cellId] = rawData[i];
} }

View File

@ -50,8 +50,8 @@ class namesList
public SLList<T> public SLList<T>
{ {
public: public:
typedef typename SLList<T>::const_iterator const_iterator; using const_iterator = typename SLList<T>::const_iterator;
typedef typename SLList<T>::iterator iterator; using iterator = typename SLList<T>::iterator;
// Constructors // Constructors
@ -65,12 +65,7 @@ public:
//- Return true if a list element has a name that matches key //- Return true if a list element has a name that matches key
bool found(const word& key) const bool found(const word& key) const
{ {
for forAllConstIters(*this, iter)
(
const_iterator iter = SLList<T>::begin();
iter != SLList<T>::end();
++iter
)
{ {
if (iter().name() == key) if (iter().name() == key)
{ {
@ -85,12 +80,7 @@ public:
//- Find a list element has a name matching key //- Find a list element has a name matching key
iterator find(const word& key) iterator find(const word& key)
{ {
for forAllIters(*this, iter)
(
iterator iter = SLList<T>::begin();
iter != SLList<T>::end();
++iter
)
{ {
if (iter().name() == key) if (iter().name() == key)
{ {
@ -112,12 +102,7 @@ public:
List<word> matched(SLList<T>::size()); List<word> matched(SLList<T>::size());
label matchI = 0; label matchI = 0;
for forAllConstIters(*this, iter)
(
const_iterator iter = SLList<T>::begin();
iter != SLList<T>::end();
++iter
)
{ {
const word& name = iter().name(); const word& name = iter().name();
@ -382,15 +367,16 @@ public:
namesList<fieldEntry>() namesList<fieldEntry>()
{} {}
// Access // Access
//- The maximum cell Id referenced in the list //- The maximum cell Id referenced in the list
label maxCellId() const label maxCellId() const
{ {
label maxId = 0; label maxId = 0;
forAllConstIter(namesList<fieldEntry>, *this, iter) forAllConstIters(*this, iter)
{ {
label currMax = (iter()).maxCellId(); const label currMax = iter().maxCellId();
if (maxId < currMax) if (maxId < currMax)
{ {
@ -407,9 +393,9 @@ public:
{ {
label maxId = 0; label maxId = 0;
forAllConstIter(namesList<fieldEntry>, *this, iter) forAllConstIters(*this, iter)
{ {
label currMax = (iter()).maxFaceId(); const label currMax = iter().maxFaceId();
if (maxId < currMax) if (maxId < currMax)
{ {

View File

@ -95,7 +95,7 @@ void Foam::ccm::writer::writeBoundaryRegion
// Create dictionary lookup for constant/boundaryRegion // Create dictionary lookup for constant/boundaryRegion
dictionary typeDict; dictionary typeDict;
forAllConstIter(Map<dictionary>, boundaryRegion_, iter) forAllConstIters(boundaryRegion_, iter)
{ {
const dictionary& dict = iter(); const dictionary& dict = iter();
if if
@ -207,7 +207,7 @@ void Foam::ccm::writer::writeCellTable
ccmID nodeId; ccmID nodeId;
forAllConstIter(Map<dictionary>, cellTable_, iter) forAllConstIters(cellTable_, iter)
{ {
label intVal = iter.key(); label intVal = iter.key();
const dictionary& dict = iter(); const dictionary& dict = iter();

View File

@ -567,9 +567,9 @@ void Foam::ccm::writer::writeCells
tableId = cellTable_.append(dict); tableId = cellTable_.append(dict);
} }
forAll(cZone, i) for (auto id : cZone)
{ {
mapData[cZone[i]] = tableId; mapData[id] = tableId;
} }
} }
} }
@ -582,11 +582,11 @@ void Foam::ccm::writer::writeCells
dict.add("MaterialType", "fluid"); dict.add("MaterialType", "fluid");
label tableId = cellTable_.append(dict); label tableId = cellTable_.append(dict);
forAll(mapData, i) for (auto& id : mapData)
{ {
if (mapData[i] < 0) if (id < 0)
{ {
mapData[i] = tableId; id = tableId;
} }
} }
} }

View File

@ -463,8 +463,6 @@ void Foam::ccm::writer::writeSolution
&phaseNode &phaseNode
); );
forAllConstIter(IOobjectList, objects, iter) forAllConstIter(IOobjectList, objects, iter)
{ {
word fieldName = (*iter()).name(); word fieldName = (*iter()).name();