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