mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: for-range, forAllIters() ... in applications/utilities
- reduced clutter when iterating over containers
This commit is contained in:
@ -74,7 +74,7 @@ if (doLagrangian)
|
||||
forAllConstIters(theseCloudFields, fieldIter)
|
||||
{
|
||||
const word& fieldName = fieldIter.key();
|
||||
const word& fieldType = fieldIter.object();
|
||||
const word& fieldType = fieldIter.val();
|
||||
|
||||
IOobject fieldObject
|
||||
(
|
||||
|
||||
@ -73,7 +73,7 @@ if (doLagrangian)
|
||||
forAllConstIters(theseCloudFields, fieldIter)
|
||||
{
|
||||
const word& fieldName = fieldIter.key();
|
||||
const word& fieldType = fieldIter.object();
|
||||
const word& fieldType = fieldIter.val();
|
||||
|
||||
IOobject fieldObject
|
||||
(
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
gmvFile << "tracers " << particles.size() << nl;
|
||||
forAllConstIter(Cloud<passiveParticle>, particles, iter)
|
||||
for (const passiveParticle& p : particles)
|
||||
{
|
||||
gmvFile << iter().position().x() << ' ';
|
||||
gmvFile << p.position().x() << ' ';
|
||||
}
|
||||
gmvFile << nl;
|
||||
|
||||
forAllConstIter(Cloud<passiveParticle>, particles, iter)
|
||||
for (const passiveParticle& p : particles)
|
||||
{
|
||||
gmvFile << iter().position().y() << ' ';
|
||||
gmvFile << p.position().y() << ' ';
|
||||
}
|
||||
gmvFile << nl;
|
||||
|
||||
forAllConstIter(Cloud<passiveParticle>, particles, iter)
|
||||
for (const passiveParticle& p : particles)
|
||||
{
|
||||
gmvFile << iter().position().z() << ' ';
|
||||
gmvFile << p.position().z() << ' ';
|
||||
}
|
||||
gmvFile << nl;
|
||||
|
||||
@ -36,9 +36,9 @@ for (const word& name : lagrangianScalarNames)
|
||||
{
|
||||
gmvFile << name << nl;
|
||||
|
||||
forAll(fld, n)
|
||||
for (const scalar& val : fld)
|
||||
{
|
||||
gmvFile << fld[n] << token::SPACE;
|
||||
gmvFile << val << token::SPACE;
|
||||
}
|
||||
gmvFile << nl;
|
||||
}
|
||||
|
||||
@ -1,48 +1,48 @@
|
||||
gmvFile << "tracers " << particles.size() << nl;
|
||||
forAllConstIter(discretePhase, particles, iter)
|
||||
for (const passiveParticle& p : particles)
|
||||
{
|
||||
gmvFile << iter().position().x() << " ";
|
||||
gmvFile << p.position().x() << " ";
|
||||
}
|
||||
gmvFile << nl;
|
||||
|
||||
forAllConstIter(discretePhase, particles, iter)
|
||||
for (const passiveParticle& p : particles)
|
||||
{
|
||||
gmvFile << iter().position().y() << " ";
|
||||
gmvFile << p.position().y() << " ";
|
||||
}
|
||||
gmvFile << nl;
|
||||
|
||||
forAllConstIter(discretePhase, particles, iter)
|
||||
for (const passiveParticle& p : particles)
|
||||
{
|
||||
gmvFile << iter().position().z() << " ";
|
||||
gmvFile << p.position().z() << " ";
|
||||
}
|
||||
gmvFile << nl;
|
||||
|
||||
gmvFile << "U" << nl;
|
||||
forAllConstIter(discretePhase, particles, iter)
|
||||
for (const passiveParticle& p : particles)
|
||||
{
|
||||
gmvFile << iter().velocity().x() << " ";
|
||||
gmvFile << p.velocity().x() << " ";
|
||||
}
|
||||
gmvFile << nl;
|
||||
|
||||
gmvFile << "V" << nl;
|
||||
forAllConstIter(discretePhase, particles, iter)
|
||||
for (const passiveParticle& p : particles)
|
||||
{
|
||||
gmvFile << iter().velocity().y() << " ";
|
||||
gmvFile << p.velocity().y() << " ";
|
||||
}
|
||||
gmvFile << nl;
|
||||
|
||||
gmvFile << "W" << nl;
|
||||
forAllConstIter(discretePhase, particles, iter)
|
||||
for (const passiveParticle& p : particles)
|
||||
{
|
||||
{
|
||||
gmvFile << iter().velocity().z() << " ";
|
||||
gmvFile << p.velocity().z() << " ";
|
||||
}
|
||||
gmvFile << nl;
|
||||
|
||||
gmvFile << "Diam" << nl;
|
||||
forAllConstIter(discretePhase, particles, iter)
|
||||
for (const passiveParticle& p : particles)
|
||||
{
|
||||
gmvFile << iter().d() << " ";
|
||||
gmvFile << p.d() << " ";
|
||||
}
|
||||
|
||||
gmvFile << "endtrace"<< nl;
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
gmvFile << "tracers " << particles.size() << nl;
|
||||
forAllConstIter(Cloud<passiveParticle>, particles, iter)
|
||||
for (const passiveParticle& p : particles)
|
||||
{
|
||||
gmvFile << iter().position().x() << " ";
|
||||
gmvFile << p.position().x() << " ";
|
||||
}
|
||||
gmvFile << nl;
|
||||
|
||||
forAllConstIter(Cloud<passiveParticle>, particles, iter)
|
||||
for (const passiveParticle& p : particles)
|
||||
{
|
||||
gmvFile << iter().position().y() << " ";
|
||||
gmvFile << p.position().y() << " ";
|
||||
}
|
||||
gmvFile << nl;
|
||||
|
||||
forAllConstIter(Cloud<passiveParticle>, particles, iter)
|
||||
for (const passiveParticle& p : particles)
|
||||
{
|
||||
gmvFile << iter().position().z() << " ";
|
||||
gmvFile << p.position().z() << " ";
|
||||
}
|
||||
gmvFile << nl;
|
||||
|
||||
|
||||
@ -118,7 +118,7 @@ Foam::label Foam::foamPvCore::addToSelection
|
||||
|
||||
if (iter.found())
|
||||
{
|
||||
return addToArray(select, prefix, iter.object().sortedToc());
|
||||
return addToArray(select, prefix, iter.val().sortedToc());
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -137,7 +137,7 @@ Foam::label Foam::foamPvCore::addToSelection
|
||||
|
||||
if (iter.found())
|
||||
{
|
||||
return addToArray(select, iter.object().sortedToc(), suffix);
|
||||
return addToArray(select, iter.val().sortedToc(), suffix);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@ -144,9 +144,9 @@ bool Foam::vtkPVFoam::addOutputBlock
|
||||
const word shortName = getFoamName(longName);
|
||||
|
||||
auto iter = cache.find(longName);
|
||||
if (iter.found() && iter.object().dataset)
|
||||
if (iter.found() && iter.val().dataset)
|
||||
{
|
||||
auto dataset = iter.object().dataset;
|
||||
auto dataset = iter.val().dataset;
|
||||
|
||||
if (singleDataset)
|
||||
{
|
||||
@ -540,13 +540,13 @@ void Foam::vtkPVFoam::Update
|
||||
// Eliminate cached values that would be unreliable
|
||||
forAllIters(cachedVtp_, iter)
|
||||
{
|
||||
iter.object().clearGeom();
|
||||
iter.object().clear();
|
||||
iter.val().clearGeom();
|
||||
iter.val().clear();
|
||||
}
|
||||
forAllIters(cachedVtu_, iter)
|
||||
{
|
||||
iter.object().clearGeom();
|
||||
iter.object().clear();
|
||||
iter.val().clearGeom();
|
||||
iter.val().clear();
|
||||
}
|
||||
}
|
||||
else if (oldDecomp != decomposePoly_)
|
||||
@ -554,8 +554,8 @@ void Foam::vtkPVFoam::Update
|
||||
// poly-decompose changed - dispose of cached values
|
||||
forAllIters(cachedVtu_, iter)
|
||||
{
|
||||
iter.object().clearGeom();
|
||||
iter.object().clear();
|
||||
iter.val().clearGeom();
|
||||
iter.val().clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,13 +91,13 @@ void Foam::vtkPVFoam::convertVolField
|
||||
const auto& longName = selectedPartIds_[partId];
|
||||
|
||||
auto iter = cachedVtp_.find(longName);
|
||||
if (!iter.found() || !iter.object().dataset)
|
||||
if (!iter.found() || !iter.val().dataset)
|
||||
{
|
||||
// Should not happen, but for safety require a vtk geometry
|
||||
continue;
|
||||
}
|
||||
|
||||
foamVtpData& vtpData = iter.object();
|
||||
foamVtpData& vtpData = iter.val();
|
||||
auto dataset = vtpData.dataset;
|
||||
|
||||
const labelUList& patchIds = vtpData.additionalIds();
|
||||
@ -195,13 +195,13 @@ void Foam::vtkPVFoam::convertVolField
|
||||
const word zoneName = getFoamName(longName);
|
||||
|
||||
auto iter = cachedVtp_.find(longName);
|
||||
if (!iter.found() || !iter.object().dataset)
|
||||
if (!iter.found() || !iter.val().dataset)
|
||||
{
|
||||
// Should not happen, but for safety require a vtk geometry
|
||||
continue;
|
||||
}
|
||||
|
||||
foamVtpData& vtpData = iter.object();
|
||||
foamVtpData& vtpData = iter.val();
|
||||
auto dataset = vtpData.dataset;
|
||||
|
||||
const faceZoneMesh& zMesh = mesh.faceZones();
|
||||
@ -236,12 +236,12 @@ void Foam::vtkPVFoam::convertVolField
|
||||
const word selectName = getFoamName(longName);
|
||||
|
||||
auto iter = cachedVtp_.find(longName);
|
||||
if (!iter.found() || !iter.object().dataset)
|
||||
if (!iter.found() || !iter.val().dataset)
|
||||
{
|
||||
// Should not happen, but for safety require a vtk geometry
|
||||
continue;
|
||||
}
|
||||
foamVtpData& vtpData = iter.object();
|
||||
foamVtpData& vtpData = iter.val();
|
||||
auto dataset = vtpData.dataset;
|
||||
|
||||
vtkSmartPointer<vtkFloatArray> cdata = convertFaceFieldToVTK
|
||||
@ -270,7 +270,7 @@ void Foam::vtkPVFoam::convertVolFields
|
||||
forAllConstIters(objects, iter)
|
||||
{
|
||||
// Restrict to GeometricField<Type, ...>
|
||||
const auto& ioobj = *(iter.object());
|
||||
const auto& ioobj = *(iter.val());
|
||||
|
||||
if (ioobj.headerClassName() == FieldType::typeName)
|
||||
{
|
||||
@ -320,7 +320,7 @@ void Foam::vtkPVFoam::convertDimFields
|
||||
forAllConstIters(objects, iter)
|
||||
{
|
||||
// Restrict to DimensionedField<Type, ...>
|
||||
const auto& ioobj = *(iter.object());
|
||||
const auto& ioobj = *(iter.val());
|
||||
|
||||
if (ioobj.headerClassName() != FieldType::typeName)
|
||||
{
|
||||
@ -404,13 +404,13 @@ void Foam::vtkPVFoam::convertVolFieldBlock
|
||||
const auto& longName = selectedPartIds_[partId];
|
||||
|
||||
auto iter = cachedVtu_.find(longName);
|
||||
if (!iter.found() || !iter.object().dataset)
|
||||
if (!iter.found() || !iter.val().dataset)
|
||||
{
|
||||
// Should not happen, but for safety require a vtk geometry
|
||||
continue;
|
||||
}
|
||||
|
||||
foamVtuData& vtuData = iter.object();
|
||||
foamVtuData& vtuData = iter.val();
|
||||
auto dataset = vtuData.dataset;
|
||||
|
||||
vtkSmartPointer<vtkFloatArray> cdata = convertVolFieldToVTK
|
||||
@ -459,7 +459,7 @@ void Foam::vtkPVFoam::convertAreaFields
|
||||
forAllConstIters(objects, iter)
|
||||
{
|
||||
// Restrict to GeometricField<Type, ...>
|
||||
const auto& ioobj = *(iter.object());
|
||||
const auto& ioobj = *(iter.val());
|
||||
|
||||
if (ioobj.headerClassName() == FieldType::typeName)
|
||||
{
|
||||
@ -478,14 +478,14 @@ void Foam::vtkPVFoam::convertAreaFields
|
||||
const auto& longName = selectedPartIds_[partId];
|
||||
|
||||
auto iter = cachedVtp_.find(longName);
|
||||
if (!iter.found() || !iter.object().dataset)
|
||||
if (!iter.found() || !iter.val().dataset)
|
||||
{
|
||||
// Should not happen, but for safety require a vtk
|
||||
// geometry
|
||||
continue;
|
||||
}
|
||||
|
||||
foamVtpData& vtpData = iter.object();
|
||||
foamVtpData& vtpData = iter.val();
|
||||
auto dataset = vtpData.dataset;
|
||||
|
||||
vtkSmartPointer<vtkFloatArray> cdata = convertFieldToVTK
|
||||
@ -535,7 +535,7 @@ void Foam::vtkPVFoam::convertPointFields
|
||||
forAllConstIters(objects, iter)
|
||||
{
|
||||
// Restrict to this GeometricField<Type, ...>
|
||||
const auto& ioobj = *(iter.object());
|
||||
const auto& ioobj = *(iter.val());
|
||||
|
||||
const word& fieldName = ioobj.name();
|
||||
if (ioobj.headerClassName() != FieldType::typeName)
|
||||
@ -568,13 +568,13 @@ void Foam::vtkPVFoam::convertPointFields
|
||||
const auto& longName = selectedPartIds_[partId];
|
||||
|
||||
auto iter = cachedVtp_.find(longName);
|
||||
if (!iter.found() || !iter.object().dataset)
|
||||
if (!iter.found() || !iter.val().dataset)
|
||||
{
|
||||
// Should not happen, but for safety require a vtk geometry
|
||||
continue;
|
||||
}
|
||||
|
||||
foamVtpData& vtpData = iter.object();
|
||||
foamVtpData& vtpData = iter.val();
|
||||
auto dataset = vtpData.dataset;
|
||||
|
||||
const labelUList& patchIds = vtpData.additionalIds();
|
||||
@ -605,13 +605,13 @@ void Foam::vtkPVFoam::convertPointFields
|
||||
const word zoneName = getFoamName(longName);
|
||||
|
||||
auto iter = cachedVtp_.find(longName);
|
||||
if (!iter.found() || !iter.object().dataset)
|
||||
if (!iter.found() || !iter.val().dataset)
|
||||
{
|
||||
// Should not happen, but for safety require a vtk geometry
|
||||
continue;
|
||||
}
|
||||
|
||||
foamVtpData& vtpData = iter.object();
|
||||
foamVtpData& vtpData = iter.val();
|
||||
auto dataset = vtpData.dataset;
|
||||
|
||||
const label zoneId = mesh.faceZones().findZoneID(zoneName);
|
||||
@ -673,13 +673,13 @@ void Foam::vtkPVFoam::convertPointFieldBlock
|
||||
const auto& longName = selectedPartIds_[partId];
|
||||
|
||||
auto iter = cachedVtu_.find(longName);
|
||||
if (!iter.found() || !iter.object().dataset)
|
||||
if (!iter.found() || !iter.val().dataset)
|
||||
{
|
||||
// Should not happen, but for safety require a vtk geometry
|
||||
continue;
|
||||
}
|
||||
|
||||
foamVtuData& vtuData = iter.object();
|
||||
foamVtuData& vtuData = iter.val();
|
||||
auto dataset = vtuData.dataset;
|
||||
|
||||
vtkSmartPointer<vtkFloatArray> pdata = convertPointField
|
||||
@ -794,7 +794,7 @@ void Foam::vtkPVFoam::convertLagrangianFields
|
||||
forAllConstIters(objects, iter)
|
||||
{
|
||||
// Restrict to IOField<Type>
|
||||
const auto& ioobj = *(iter.object());
|
||||
const auto& ioobj = *(iter.val());
|
||||
|
||||
if (ioobj.headerClassName() == IOField<Type>::typeName)
|
||||
{
|
||||
|
||||
@ -255,12 +255,12 @@ void Foam::vtkPVFoam::convertLagrangianFields()
|
||||
const word cloudName = getFoamName(longName);
|
||||
|
||||
auto iter = cachedVtp_.find(longName);
|
||||
if (!iter.found() || !iter.object().dataset)
|
||||
if (!iter.found() || !iter.val().dataset)
|
||||
{
|
||||
// Should not happen, but for safety require a vtk geometry
|
||||
continue;
|
||||
}
|
||||
auto dataset = iter.object().dataset;
|
||||
auto dataset = iter.val().dataset;
|
||||
|
||||
// Get the Lagrangian fields for this time and this cloud
|
||||
// but only keep selected fields
|
||||
|
||||
@ -80,9 +80,9 @@ vtkSmartPointer<vtkPolyData> Foam::vtkPVFoam::lagrangianVTKMesh
|
||||
vtkpoints->SetNumberOfPoints(parcels.size());
|
||||
|
||||
vtkIdType particleId = 0;
|
||||
forAllConstIters(parcels, iter)
|
||||
for (const passiveParticle& p : parcels)
|
||||
{
|
||||
vtkpoints->SetPoint(particleId, iter().position().v_);
|
||||
vtkpoints->SetPoint(particleId, p.position().v_);
|
||||
++particleId;
|
||||
}
|
||||
|
||||
|
||||
@ -276,7 +276,7 @@ void Foam::vtkPVFoam::updateInfoPatches
|
||||
forAllConstIters(groups, iter)
|
||||
{
|
||||
const auto& groupName = iter.key();
|
||||
const auto& patchIDs = iter.object();
|
||||
const auto& patchIDs = iter.val();
|
||||
|
||||
label nFaces = 0;
|
||||
for (auto patchId : patchIDs)
|
||||
@ -392,7 +392,7 @@ void Foam::vtkPVFoam::updateInfoPatches
|
||||
forAllConstIters(groups, iter)
|
||||
{
|
||||
const auto& groupName = iter.key();
|
||||
const auto& patchIDs = iter.object();
|
||||
const auto& patchIDs = iter.val();
|
||||
|
||||
const string dpyName = "group/" + groupName;
|
||||
displayNames.append(dpyName);
|
||||
@ -715,7 +715,7 @@ void Foam::vtkPVFoam::updateInfoLagrangianFields
|
||||
|
||||
forAllConstIters(localFields, iter)
|
||||
{
|
||||
fields(iter.key()) |= iter.object();
|
||||
fields(iter.key()) |= iter.val();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,12 +42,12 @@ int USERD_get_part_coords
|
||||
{
|
||||
label indx = 1;
|
||||
|
||||
forAllConstIter(Cloud<passiveParticle>, *sprayPtr, iter)
|
||||
forAllConstIters(*sprayPtr, iter)
|
||||
{
|
||||
coord_array[0][indx] = float(iter().position().x());
|
||||
coord_array[1][indx] = float(iter().position().y());
|
||||
coord_array[2][indx] = float(iter().position().z());
|
||||
indx++;
|
||||
++indx;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ int USERD_get_part_node_ids
|
||||
{
|
||||
label indx = 0;
|
||||
|
||||
forAllConstIter(Cloud<passiveParticle>, *sprayPtr, iter)
|
||||
forAllConstIters(*sprayPtr, iter)
|
||||
{
|
||||
nodeid_array[indx] = indx + 1;
|
||||
indx++;
|
||||
|
||||
@ -85,10 +85,10 @@ int main(int argc, char *argv[])
|
||||
Info<< " Read " << returnReduce(myCloud.size(), sumOp<label>())
|
||||
<< " particles" << endl;
|
||||
|
||||
forAllConstIter(passiveParticleCloud, myCloud, iter)
|
||||
for (const passiveParticle& p : myCloud)
|
||||
{
|
||||
label origId = iter().origId();
|
||||
label origProc = iter().origProc();
|
||||
const label origId = p.origId();
|
||||
const label origProc = p.origProc();
|
||||
|
||||
if (origProc >= maxIds.size())
|
||||
{
|
||||
@ -157,16 +157,16 @@ int main(int argc, char *argv[])
|
||||
myCloud.size(),
|
||||
point::zero
|
||||
);
|
||||
allOrigIds[Pstream::myProcNo()].setSize(myCloud.size(), 0);
|
||||
allOrigProcs[Pstream::myProcNo()].setSize(myCloud.size(), 0);
|
||||
allOrigIds[Pstream::myProcNo()].setSize(myCloud.size(), Zero);
|
||||
allOrigProcs[Pstream::myProcNo()].setSize(myCloud.size(), Zero);
|
||||
|
||||
label i = 0;
|
||||
forAllConstIter(passiveParticleCloud, myCloud, iter)
|
||||
for (const passiveParticle& p : myCloud)
|
||||
{
|
||||
allPositions[Pstream::myProcNo()][i] = iter().position();
|
||||
allOrigIds[Pstream::myProcNo()][i] = iter().origId();
|
||||
allOrigProcs[Pstream::myProcNo()][i] = iter().origProc();
|
||||
i++;
|
||||
allPositions[Pstream::myProcNo()][i] = p.position();
|
||||
allOrigIds[Pstream::myProcNo()][i] = p.origId();
|
||||
allOrigProcs[Pstream::myProcNo()][i] = p.origProc();
|
||||
++i;
|
||||
}
|
||||
|
||||
// Collect the track data on the master processor
|
||||
|
||||
@ -159,7 +159,7 @@ int main(int argc, char *argv[])
|
||||
particles.setSize(ppc.size());
|
||||
|
||||
label i = 0;
|
||||
forAllIter(passiveParticleCloud, ppc, iter)
|
||||
forAllIters(ppc, iter)
|
||||
{
|
||||
particles.set(i++, ppc.remove(&iter()));
|
||||
}
|
||||
@ -178,18 +178,19 @@ int main(int argc, char *argv[])
|
||||
const label origProc = particles[i].origProc();
|
||||
const label origId = particles[i].origId();
|
||||
|
||||
labelPairLookup::const_iterator iter =
|
||||
trackTable.find(labelPair(origProc, origId));
|
||||
const labelPair key(origProc, origId);
|
||||
|
||||
if (iter == trackTable.end())
|
||||
const auto iter = trackTable.cfind(key);
|
||||
|
||||
if (iter.found())
|
||||
{
|
||||
particleToTrack[i] = nTracks;
|
||||
trackTable.insert(labelPair(origProc, origId), nTracks);
|
||||
nTracks++;
|
||||
particleToTrack[i] = *iter;
|
||||
}
|
||||
else
|
||||
{
|
||||
particleToTrack[i] = iter();
|
||||
particleToTrack[i] = nTracks;
|
||||
trackTable.insert(key, nTracks);
|
||||
++nTracks;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -205,10 +206,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
// Determine length of each track
|
||||
labelList trackLengths(nTracks, Zero);
|
||||
forAll(particleToTrack, i)
|
||||
for (const label tracki : particleToTrack)
|
||||
{
|
||||
const label trackI = particleToTrack[i];
|
||||
trackLengths[trackI]++;
|
||||
++trackLengths[tracki];
|
||||
}
|
||||
|
||||
// Particle "age" property used to sort the tracks
|
||||
|
||||
Reference in New Issue
Block a user