diff --git a/src/functionObjects/field/externalCoupled/externalCoupled.C b/src/functionObjects/field/externalCoupled/externalCoupled.C index 96871a02cf..17a2be571d 100644 --- a/src/functionObjects/field/externalCoupled/externalCoupled.C +++ b/src/functionObjects/field/externalCoupled/externalCoupled.C @@ -277,21 +277,19 @@ void Foam::functionObjects::externalCoupled::writeGeometry labelList pointToGlobal; labelList uniquePointIDs; - forAll(meshes, meshi) + for (const fvMesh& mesh : meshes) { - const fvMesh& mesh = meshes[meshi]; - const labelList patchIDs ( mesh.boundaryMesh().patchSet ( - List(1, groupName) + List{groupName} ).sortedToc() ); - forAll(patchIDs, i) + for (const label patchi : patchIDs) { - const polyPatch& p = mesh.boundaryMesh()[patchIDs[i]]; + const polyPatch& p = mesh.boundaryMesh()[patchi]; mesh.globalData().mergePoints ( @@ -412,37 +410,38 @@ void Foam::functionObjects::externalCoupled::initCoupling() } // Write the geometry if not already there - forAll(regionGroupRegions_, i) + forAll(regionGroupNames_, regioni) { - const word& compName = regionGroupNames_[i]; - const wordList& regionNames = regionGroupRegions_[i]; + const word& compName = regionGroupNames_[regioni]; + const wordList& regionNames = regionGroupRegions_[regioni]; // Get the meshes for the region-group UPtrList meshes(regionNames.size()); - forAll(regionNames, j) + forAll(regionNames, regi) { - const word& regionName = regionNames[j]; - meshes.set(j, &time_.lookupObject(regionName)); + const word& regionName = regionNames[regi]; + meshes.set(regi, &time_.lookupObject(regionName)); } const labelList& groups = regionToGroups_[compName]; - forAll(groups, i) + for (const label groupi : groups) { - label groupi = groups[i]; const wordRe& groupName = groupNames_[groupi]; - bool exists = false; + bool geomExists = false; if (Pstream::master()) { fileName dir(groupDir(commDirectory(), compName, groupName)); - exists = + geomExists = isFile(dir/"patchPoints") || isFile(dir/"patchFaces"); } - if (!returnReduce(exists, orOp())) + Pstream::scatter(geomExists); + + if (!geomExists) { writeGeometry(meshes, commDirectory(), groupName); } @@ -596,7 +595,7 @@ bool Foam::functionObjects::externalCoupled::read(const dictionary& dict) regionToGroups_.insert ( regionGroupNames_.last(), - labelList(1, nGroups) + labelList{nGroups} ); } groupNames_.append(groupName); @@ -607,16 +606,12 @@ bool Foam::functionObjects::externalCoupled::read(const dictionary& dict) Info<< type() << ": Communicating with regions:" << endl; - forAll(regionGroupNames_, rgi) + for (const word& compName : regionGroupNames_) { - //const wordList& regionNames = regionGroupRegions_[rgi]; - const word& compName = regionGroupNames_[rgi]; - Info<< "Region: " << compName << endl << incrIndent; const labelList& groups = regionToGroups_[compName]; - forAll(groups, i) + for (const label groupi : groups) { - label groupi = groups[i]; const wordRe& groupName = groupNames_[groupi]; Info<< indent << "patchGroup: " << groupName << "\t" @@ -639,14 +634,11 @@ bool Foam::functionObjects::externalCoupled::read(const dictionary& dict) // should already be written - but just make sure if (Pstream::master()) { - forAll(regionGroupNames_, rgi) + for (const word& compName : regionGroupNames_) { - const word& compName = regionGroupNames_[rgi]; - const labelList& groups = regionToGroups_[compName]; - forAll(groups, i) + for (const label groupi : groups) { - label groupi = groups[i]; const wordRe& groupName = groupNames_[groupi]; fileName dir(groupDir(commDirectory(), compName, groupName)); @@ -682,48 +674,20 @@ void Foam::functionObjects::externalCoupled::readDataMaster() const labelList& groups = regionToGroups_[compName]; - forAll(groups, i) + for (const label groupi : groups) { - label groupi = groups[i]; const wordRe& groupName = groupNames_[groupi]; const wordList& fieldNames = groupReadFields_[groupi]; - forAll(fieldNames, fieldi) + for (const word& fieldName : fieldNames) { - const word& fieldName = fieldNames[fieldi]; - const bool ok = ( - readData - ( - meshes, - groupName, - fieldName - ) - || readData - ( - meshes, - groupName, - fieldName - ) - || readData - ( - meshes, - groupName, - fieldName - ) - || readData - ( - meshes, - groupName, - fieldName - ) - || readData - ( - meshes, - groupName, - fieldName - ) + readData(meshes, groupName, fieldName) + || readData(meshes, groupName, fieldName) + || readData(meshes, groupName, fieldName) + || readData(meshes, groupName, fieldName) + || readData(meshes, groupName, fieldName) ); if (!ok) @@ -755,48 +719,20 @@ void Foam::functionObjects::externalCoupled::writeDataMaster() const const labelList& groups = regionToGroups_[compName]; - forAll(groups, i) + for (const label groupi : groups) { - label groupi = groups[i]; const wordRe& groupName = groupNames_[groupi]; const wordList& fieldNames = groupWriteFields_[groupi]; - forAll(fieldNames, fieldi) + for (const word& fieldName : fieldNames) { - const word& fieldName = fieldNames[fieldi]; - const bool ok = ( - writeData - ( - meshes, - groupName, - fieldName - ) - || writeData - ( - meshes, - groupName, - fieldName - ) - || writeData - ( - meshes, - groupName, - fieldName - ) - || writeData - ( - meshes, - groupName, - fieldName - ) - || writeData - ( - meshes, - groupName, - fieldName - ) + writeData(meshes, groupName, fieldName) + || writeData(meshes, groupName, fieldName) + || writeData(meshes, groupName, fieldName) + || writeData(meshes, groupName, fieldName) + || writeData(meshes, groupName, fieldName) ); if (!ok) @@ -820,20 +756,17 @@ void Foam::functionObjects::externalCoupled::removeDataMaster() const Log << type() << ": removing data files written by master" << nl; - forAll(regionGroupNames_, regioni) + for (const word& compName : regionGroupNames_) { - const word& compName = regionGroupNames_[regioni]; - const labelList& groups = regionToGroups_[compName]; - forAll(groups, i) + for (const label groupi : groups) { - label groupi = groups[i]; const wordRe& groupName = groupNames_[groupi]; + const wordList& fieldNames = groupReadFields_[groupi]; - forAll(groupReadFields_[groupi], fieldi) + for (const word& fieldName : fieldNames) { - const word& fieldName = groupReadFields_[groupi][fieldi]; - rm + Foam::rm ( groupDir(commDirectory(), compName, groupName) / fieldName + ".out" @@ -853,20 +786,17 @@ void Foam::functionObjects::externalCoupled::removeDataSlave() const Log << type() << ": removing data files written by slave" << nl; - forAll(regionGroupNames_, regioni) + for (const word& compName : regionGroupNames_) { - const word& compName = regionGroupNames_[regioni]; - const labelList& groups = regionToGroups_[compName]; - forAll(groups, i) + for (const label groupi : groups) { - label groupi = groups[i]; const wordRe& groupName = groupNames_[groupi]; + const wordList& fieldNames = groupReadFields_[groupi]; - forAll(groupReadFields_[groupi], fieldi) + for (const word& fieldName : fieldNames) { - const word& fieldName = groupReadFields_[groupi][fieldi]; - rm + Foam::rm ( groupDir(commDirectory(), compName, groupName) / fieldName + ".in" diff --git a/src/functionObjects/field/externalCoupled/externalCoupledTemplates.C b/src/functionObjects/field/externalCoupled/externalCoupledTemplates.C index ee0bb19de7..504184bcf2 100644 --- a/src/functionObjects/field/externalCoupled/externalCoupledTemplates.C +++ b/src/functionObjects/field/externalCoupled/externalCoupledTemplates.C @@ -81,46 +81,40 @@ bool Foam::functionObjects::externalCoupled::readData label nFound = 0; - forAll(meshes, i) + for (const fvMesh& mesh : meshes) { - const fvMesh& mesh = meshes[i]; + const volFieldType* vfptr = + mesh.lookupObjectPtr(fieldName); - if (!mesh.foundObject(fieldName)) + if (!vfptr) { continue; } - nFound++; - const volFieldType& cvf = mesh.lookupObject(fieldName); - const typename volFieldType::Boundary& bf = cvf.boundaryField(); - + typename volFieldType::Boundary& bf = + const_cast(vfptr)->boundaryFieldRef(); // Get the patches const labelList patchIDs ( mesh.boundaryMesh().patchSet ( - List(1, groupName) + List{groupName} ).sortedToc() ); // Handle column-wise reading of patch data. Supports most easy types - forAll(patchIDs, i) + for (const label patchi : patchIDs) { - label patchi = patchIDs[i]; - if (isA(bf[patchi])) { // Explicit handling of externalCoupledMixed bcs - they // have specialised reading routines. - patchFieldType& pf = const_cast + patchFieldType& pf = refCast ( - refCast - ( - bf[patchi] - ) + bf[patchi] ); // Read from master into local stream @@ -141,6 +135,11 @@ bool Foam::functionObjects::externalCoupled::readData } else if (isA>(bf[patchi])) { + mixedFvPatchField& pf = refCast> + ( + bf[patchi] + ); + // Read columns from file for // value, snGrad, refValue, refGrad, valueFraction List data; @@ -152,15 +151,6 @@ bool Foam::functionObjects::externalCoupled::readData data ); - mixedFvPatchField& pf = - const_cast&> - ( - refCast> - ( - bf[patchi] - ) - ); - // Transfer read data to bc. // Skip value, snGrad direction columni = 2*pTraits::nComponents; @@ -193,6 +183,9 @@ bool Foam::functionObjects::externalCoupled::readData } else if (isA>(bf[patchi])) { + fixedGradientFvPatchField& pf = + refCast>(bf[patchi]); + // Read columns for value and gradient List data; readColumns @@ -203,15 +196,6 @@ bool Foam::functionObjects::externalCoupled::readData data ); - fixedGradientFvPatchField& pf = - const_cast&> - ( - refCast> - ( - bf[patchi] - ) - ); - // Transfer gradient to bc Field& gradient = pf.gradient(); for @@ -234,6 +218,9 @@ bool Foam::functionObjects::externalCoupled::readData } else if (isA>(bf[patchi])) { + fixedValueFvPatchField& pf = + refCast>(bf[patchi]); + // Read columns for value only List data; readColumns @@ -256,15 +243,6 @@ bool Foam::functionObjects::externalCoupled::readData value.replace(cmpt, data[cmpt]); } - fixedValueFvPatchField& pf = - const_cast&> - ( - refCast> - ( - bf[patchi] - ) - ); - pf == value; // Update the value from the read coefficicient. Bypass any @@ -379,35 +357,32 @@ bool Foam::functionObjects::externalCoupled::writeData label nFound = 0; - forAll(meshes, i) + for (const fvMesh& mesh : meshes) { - const fvMesh& mesh = meshes[i]; + const volFieldType* vfptr = + mesh.lookupObjectPtr(fieldName); - if (!mesh.foundObject(fieldName)) + if (!vfptr) { continue; } - nFound++; - const volFieldType& cvf = mesh.lookupObject(fieldName); - const typename volFieldType::Boundary& bf = cvf.boundaryField(); - + const typename volFieldType::Boundary& bf = + vfptr->boundaryField(); // Get the patches const labelList patchIDs ( mesh.boundaryMesh().patchSet ( - List(1, groupName) + List{groupName} ).sortedToc() ); // Handle column-wise writing of patch data. Supports most easy types - forAll(patchIDs, i) + for (const label patchi : patchIDs) { - label patchi = patchIDs[i]; - const globalIndex globalFaces(bf[patchi].size()); if (isA(bf[patchi]))