STYLE: Use C++11 and OpenFOAM-1706 methods in externalCoupled

This commit is contained in:
Mark Olesen
2017-07-17 13:41:14 +02:00
parent 7a408c713b
commit 454ad5162c
2 changed files with 74 additions and 169 deletions

View File

@ -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<wordRe>(1, groupName)
List<wordRe>{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<const fvMesh> meshes(regionNames.size());
forAll(regionNames, j)
forAll(regionNames, regi)
{
const word& regionName = regionNames[j];
meshes.set(j, &time_.lookupObject<fvMesh>(regionName));
const word& regionName = regionNames[regi];
meshes.set(regi, &time_.lookupObject<fvMesh>(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<bool>()))
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<scalar>
(
meshes,
groupName,
fieldName
)
|| readData<vector>
(
meshes,
groupName,
fieldName
)
|| readData<sphericalTensor>
(
meshes,
groupName,
fieldName
)
|| readData<symmTensor>
(
meshes,
groupName,
fieldName
)
|| readData<tensor>
(
meshes,
groupName,
fieldName
)
readData<scalar>(meshes, groupName, fieldName)
|| readData<vector>(meshes, groupName, fieldName)
|| readData<sphericalTensor>(meshes, groupName, fieldName)
|| readData<symmTensor>(meshes, groupName, fieldName)
|| readData<tensor>(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<scalar>
(
meshes,
groupName,
fieldName
)
|| writeData<vector>
(
meshes,
groupName,
fieldName
)
|| writeData<sphericalTensor>
(
meshes,
groupName,
fieldName
)
|| writeData<symmTensor>
(
meshes,
groupName,
fieldName
)
|| writeData<tensor>
(
meshes,
groupName,
fieldName
)
writeData<scalar>(meshes, groupName, fieldName)
|| writeData<vector>(meshes, groupName, fieldName)
|| writeData<sphericalTensor>(meshes, groupName, fieldName)
|| writeData<symmTensor>(meshes, groupName, fieldName)
|| writeData<tensor>(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"

View File

@ -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<volFieldType>(fieldName);
if (!mesh.foundObject<volFieldType>(fieldName))
if (!vfptr)
{
continue;
}
nFound++;
const volFieldType& cvf = mesh.lookupObject<volFieldType>(fieldName);
const typename volFieldType::Boundary& bf = cvf.boundaryField();
typename volFieldType::Boundary& bf =
const_cast<volFieldType*>(vfptr)->boundaryFieldRef();
// Get the patches
const labelList patchIDs
(
mesh.boundaryMesh().patchSet
(
List<wordRe>(1, groupName)
List<wordRe>{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<patchFieldType>(bf[patchi]))
{
// Explicit handling of externalCoupledMixed bcs - they
// have specialised reading routines.
patchFieldType& pf = const_cast<patchFieldType&>
(
refCast<const patchFieldType>
patchFieldType& pf = refCast<patchFieldType>
(
bf[patchi]
)
);
// Read from master into local stream
@ -141,6 +135,11 @@ bool Foam::functionObjects::externalCoupled::readData
}
else if (isA<mixedFvPatchField<Type>>(bf[patchi]))
{
mixedFvPatchField<Type>& pf = refCast<mixedFvPatchField<Type>>
(
bf[patchi]
);
// Read columns from file for
// value, snGrad, refValue, refGrad, valueFraction
List<scalarField> data;
@ -152,15 +151,6 @@ bool Foam::functionObjects::externalCoupled::readData
data
);
mixedFvPatchField<Type>& pf =
const_cast<mixedFvPatchField<Type>&>
(
refCast<const mixedFvPatchField<Type>>
(
bf[patchi]
)
);
// Transfer read data to bc.
// Skip value, snGrad
direction columni = 2*pTraits<Type>::nComponents;
@ -193,6 +183,9 @@ bool Foam::functionObjects::externalCoupled::readData
}
else if (isA<fixedGradientFvPatchField<Type>>(bf[patchi]))
{
fixedGradientFvPatchField<Type>& pf =
refCast<fixedGradientFvPatchField<Type>>(bf[patchi]);
// Read columns for value and gradient
List<scalarField> data;
readColumns
@ -203,15 +196,6 @@ bool Foam::functionObjects::externalCoupled::readData
data
);
fixedGradientFvPatchField<Type>& pf =
const_cast<fixedGradientFvPatchField<Type>&>
(
refCast<const fixedGradientFvPatchField<Type>>
(
bf[patchi]
)
);
// Transfer gradient to bc
Field<Type>& gradient = pf.gradient();
for
@ -234,6 +218,9 @@ bool Foam::functionObjects::externalCoupled::readData
}
else if (isA<fixedValueFvPatchField<Type>>(bf[patchi]))
{
fixedValueFvPatchField<Type>& pf =
refCast<fixedValueFvPatchField<Type>>(bf[patchi]);
// Read columns for value only
List<scalarField> data;
readColumns
@ -256,15 +243,6 @@ bool Foam::functionObjects::externalCoupled::readData
value.replace(cmpt, data[cmpt]);
}
fixedValueFvPatchField<Type>& pf =
const_cast<fixedValueFvPatchField<Type>&>
(
refCast<const fixedValueFvPatchField<Type>>
(
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<volFieldType>(fieldName);
if (!mesh.foundObject<volFieldType>(fieldName))
if (!vfptr)
{
continue;
}
nFound++;
const volFieldType& cvf = mesh.lookupObject<volFieldType>(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<wordRe>(1, groupName)
List<wordRe>{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<patchFieldType>(bf[patchi]))