Commit 8760f6c9 authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: minor improvements to fvMeshDistribute (#1211)

- sorted field names for consistency, remove some local variables
parent 7da0b5be
......@@ -193,34 +193,6 @@ Foam::labelList Foam::fvMeshDistribute::select
}
void Foam::fvMeshDistribute::checkEqualWordList
(
const string& msg,
const wordList& lst
)
{
// Check all procs have same names and in exactly same order.
List<wordList> allNames(Pstream::nProcs());
allNames[Pstream::myProcNo()] = lst;
Pstream::gatherList(allNames);
Pstream::scatterList(allNames);
for (label proci = 1; proci < Pstream::nProcs(); proci++)
{
if (allNames[proci] != allNames[0])
{
FatalErrorInFunction
<< "When checking for equal " << msg.c_str() << " :" << endl
<< "processor0 has:" << allNames[0] << endl
<< "processor" << proci << " has:" << allNames[proci] << endl
<< msg.c_str() << " need to be synchronised on all processors."
<< exit(FatalError);
}
}
}
Foam::wordList Foam::fvMeshDistribute::mergeWordList(const wordList& procNames)
{
List<wordList> allNames(Pstream::nProcs());
......@@ -233,7 +205,7 @@ Foam::wordList Foam::fvMeshDistribute::mergeWordList(const wordList& procNames)
{
mergedNames.insert(allNames[proci]);
}
return mergedNames.toc();
return mergedNames.sortedToc();
}
......@@ -1851,71 +1823,32 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
mesh_.resetMotion();
// Get data to send. Make sure is synchronised
const wordList volScalars(mesh_.names(volScalarField::typeName));
checkEqualWordList("volScalarFields", volScalars);
const wordList volVectors(mesh_.names(volVectorField::typeName));
checkEqualWordList("volVectorFields", volVectors);
const wordList volSphereTensors
(
mesh_.names(volSphericalTensorField::typeName)
);
checkEqualWordList("volSphericalTensorFields", volSphereTensors);
const wordList volSymmTensors(mesh_.names(volSymmTensorField::typeName));
checkEqualWordList("volSymmTensorFields", volSymmTensors);
const wordList volTensors(mesh_.names(volTensorField::typeName));
checkEqualWordList("volTensorField", volTensors);
const wordList surfScalars(mesh_.names(surfaceScalarField::typeName));
checkEqualWordList("surfaceScalarFields", surfScalars);
const wordList surfVectors(mesh_.names(surfaceVectorField::typeName));
checkEqualWordList("surfaceVectorFields", surfVectors);
const wordList surfSphereTensors
(
mesh_.names(surfaceSphericalTensorField::typeName)
);
checkEqualWordList("surfaceSphericalTensorFields", surfSphereTensors);
const wordList surfSymmTensors
(
mesh_.names(surfaceSymmTensorField::typeName)
);
checkEqualWordList("surfaceSymmTensorFields", surfSymmTensors);
const wordList surfTensors(mesh_.names(surfaceTensorField::typeName));
checkEqualWordList("surfaceTensorFields", surfTensors);
typedef volScalarField::Internal dimScalType;
const wordList dimScalars(mesh_.names(dimScalType::typeName));
checkEqualWordList("volScalarField::Internal", dimScalars);
typedef volVectorField::Internal dimVecType;
const wordList dimVectors(mesh_.names(dimVecType::typeName));
checkEqualWordList("volVectorField::Internal", dimVectors);
HashTable<wordList> allFieldNames;
typedef volSphericalTensorField::Internal dimSphereType;
const wordList dimSphereTensors(mesh_.names(dimSphereType::typeName));
checkEqualWordList
(
"volSphericalTensorField::Internal",
dimSphereTensors
);
getFieldNames<volScalarField>(mesh_, allFieldNames);
getFieldNames<volVectorField>(mesh_, allFieldNames);
getFieldNames<volSphericalTensorField>(mesh_, allFieldNames);
getFieldNames<volSymmTensorField>(mesh_, allFieldNames);
getFieldNames<volTensorField>(mesh_, allFieldNames);
typedef volSymmTensorField::Internal dimSymmTensorType;
const wordList dimSymmTensors(mesh_.names(dimSymmTensorType::typeName));
checkEqualWordList
(
"volSymmTensorField::Internal",
dimSymmTensors
);
getFieldNames<surfaceScalarField>(mesh_, allFieldNames);
getFieldNames<surfaceVectorField>(mesh_, allFieldNames);
getFieldNames<surfaceSphericalTensorField>(mesh_, allFieldNames);
getFieldNames<surfaceSymmTensorField>(mesh_, allFieldNames);
getFieldNames<surfaceTensorField>(mesh_, allFieldNames);
typedef volTensorField::Internal dimTensorType;
const wordList dimTensors(mesh_.names(dimTensorType::typeName));
checkEqualWordList("volTensorField::Internal", dimTensors);
getFieldNames<volScalarField::Internal>(mesh_, allFieldNames);
getFieldNames<volVectorField::Internal>(mesh_, allFieldNames);
getFieldNames<volSphericalTensorField::Internal>(mesh_, allFieldNames);
getFieldNames<volSymmTensorField::Internal>(mesh_, allFieldNames);
getFieldNames<volTensorField::Internal>(mesh_, allFieldNames);
// Find patch to temporarily put exposed and processor faces into.
label oldInternalPatchi = findNonEmptyPatch();
// Delete processor patches, starting from the back. Move all faces into
// oldInternalPatchi.
labelList repatchFaceMap;
......@@ -2095,57 +2028,75 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
);
// volFields
sendFields<volScalarField>(recvProc, volScalars, subsetter, str);
sendFields<volVectorField>(recvProc, volVectors, subsetter, str);
sendFields<volScalarField>
(
recvProc,
allFieldNames,
subsetter,
str
);
sendFields<volVectorField>
(
recvProc,
allFieldNames,
subsetter,
str
);
sendFields<volSphericalTensorField>
(
recvProc,
volSphereTensors,
allFieldNames,
subsetter,
str
);
sendFields<volSymmTensorField>
(
recvProc,
volSymmTensors,
allFieldNames,
subsetter,
str
);
sendFields<volTensorField>
(
recvProc,
allFieldNames,
subsetter,
str
);
sendFields<volTensorField>(recvProc, volTensors, subsetter, str);
// surfaceFields
sendFields<surfaceScalarField>
(
recvProc,
surfScalars,
allFieldNames,
subsetter,
str
);
sendFields<surfaceVectorField>
(
recvProc,
surfVectors,
allFieldNames,
subsetter,
str
);
sendFields<surfaceSphericalTensorField>
(
recvProc,
surfSphereTensors,
allFieldNames,
subsetter,
str
);
sendFields<surfaceSymmTensorField>
(
recvProc,
surfSymmTensors,
allFieldNames,
subsetter,
str
);
sendFields<surfaceTensorField>
(
recvProc,
surfTensors,
allFieldNames,
subsetter,
str
);
......@@ -2154,35 +2105,35 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
sendFields<volScalarField::Internal>
(
recvProc,
dimScalars,
allFieldNames,
subsetter,
str
);
sendFields<volVectorField::Internal>
(
recvProc,
dimVectors,
allFieldNames,
subsetter,
str
);
sendFields<volSphericalTensorField::Internal>
(
recvProc,
dimSphereTensors,
allFieldNames,
subsetter,
str
);
sendFields<volSymmTensorField::Internal>
(
recvProc,
dimSymmTensors,
allFieldNames,
subsetter,
str
);
sendFields<volTensorField::Internal>
(
recvProc,
dimTensors,
allFieldNames,
subsetter,
str
);
......@@ -2391,142 +2342,126 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
receiveFields<volScalarField>
(
sendProc,
volScalars,
allFieldNames,
domainMesh,
vsf,
fieldDicts.subDict(volScalarField::typeName)
fieldDicts
);
receiveFields<volVectorField>
(
sendProc,
volVectors,
allFieldNames,
domainMesh,
vvf,
fieldDicts.subDict(volVectorField::typeName)
fieldDicts
);
receiveFields<volSphericalTensorField>
(
sendProc,
volSphereTensors,
allFieldNames,
domainMesh,
vsptf,
fieldDicts.subDict(volSphericalTensorField::typeName)
fieldDicts
);
receiveFields<volSymmTensorField>
(
sendProc,
volSymmTensors,
allFieldNames,
domainMesh,
vsytf,
fieldDicts.subDict(volSymmTensorField::typeName)
fieldDicts
);
receiveFields<volTensorField>
(
sendProc,
volTensors,
allFieldNames,
domainMesh,
vtf,
fieldDicts.subDict(volTensorField::typeName)
fieldDicts
);
// Surface fields
receiveFields<surfaceScalarField>
(
sendProc,
surfScalars,
allFieldNames,
domainMesh,
ssf,
fieldDicts.subDict(surfaceScalarField::typeName)
fieldDicts
);
receiveFields<surfaceVectorField>
(
sendProc,
surfVectors,
allFieldNames,
domainMesh,
svf,
fieldDicts.subDict(surfaceVectorField::typeName)
fieldDicts
);
receiveFields<surfaceSphericalTensorField>
(
sendProc,
surfSphereTensors,
allFieldNames,
domainMesh,
ssptf,
fieldDicts.subDict(surfaceSphericalTensorField::typeName)
fieldDicts
);
receiveFields<surfaceSymmTensorField>
(
sendProc,
surfSymmTensors,
allFieldNames,
domainMesh,
ssytf,
fieldDicts.subDict(surfaceSymmTensorField::typeName)
fieldDicts
);
receiveFields<surfaceTensorField>
(
sendProc,
surfTensors,
allFieldNames,
domainMesh,
stf,
fieldDicts.subDict(surfaceTensorField::typeName)
fieldDicts
);
// Dimensioned fields
receiveFields<volScalarField::Internal>
(
sendProc,
dimScalars,
allFieldNames,
domainMesh,
dsf,
fieldDicts.subDict
(
volScalarField::Internal::typeName
)
fieldDicts
);
receiveFields<volVectorField::Internal>
(
sendProc,
dimVectors,
allFieldNames,
domainMesh,
dvf,
fieldDicts.subDict
(
volVectorField::Internal::typeName
)
fieldDicts
);
receiveFields<volSphericalTensorField::Internal>
(
sendProc,
dimSphereTensors,
allFieldNames,
domainMesh,
dstf,
fieldDicts.subDict
(
volSphericalTensorField::Internal::
typeName
)
fieldDicts
);
receiveFields<volSymmTensorField::Internal>
(
sendProc,
dimSymmTensors,
allFieldNames,
domainMesh,
dsytf,
fieldDicts.subDict
(
volSymmTensorField::Internal::typeName
)
fieldDicts
);
receiveFields<volTensorField::Internal>
(
sendProc,
dimTensors,
allFieldNames,
domainMesh,
dtf,
fieldDicts.subDict
(
volTensorField::Internal::typeName
)
fieldDicts
);
}
const fvMesh& domainMesh = domainMeshPtr();
......
......@@ -100,9 +100,6 @@ class fvMeshDistribute
const label value
);
//- Check all procs have same names and in exactly same order.
static void checkEqualWordList(const string&, const wordList&);
//- Merge wordlists over all processors
static wordList mergeWordList(const wordList&);
......@@ -293,14 +290,25 @@ class fvMeshDistribute
const labelList& sourcePointMaster,
Ostream& toDomain
);
//- Get sorted names of GeoField, optionally test
//- that all procs have the same names.
template<class GeoField>
static void getFieldNames
(
const fvMesh& mesh,
HashTable<wordList>& allFieldNames,
const bool syncPar = true
);
//- Send subset of fields
template<class GeoField>
static void sendFields
(
const label domain,
const wordList& fieldNames,
const fvMeshSubset&,
Ostream& toNbr
const HashTable<wordList>& allFieldNames,
const fvMeshSubset& subsetter,
Ostream&
);
//- Receive mesh. Opposite of sendMesh
......@@ -324,10 +332,10 @@ class fvMeshDistribute
static void receiveFields
(
const label domain,
const wordList& fieldNames,
fvMesh&,
PtrList<GeoField>&,
const dictionary& fieldDicts
const HashTable<wordList>& allFieldNames,
fvMesh& mesh,
PtrList<GeoField>& fields,
const dictionary& allFieldsDict
);
//- No copy construct
......
......@@ -45,13 +45,13 @@ void Foam::fvMeshDistribute::printFieldInfo(const fvMesh& mesh)
//<< " value:" << fld
<< endl;
forAll(fld.boundaryField(), patchi)
for (const auto& patchFld : fld.boundaryField())
{
Pout<< " " << patchi
<< ' ' << fld.boundaryField()[patchi].patch().name()
<< ' ' << fld.boundaryField()[patchi].type()
<< ' ' << fld.boundaryField()[patchi].size()
<< endl;
Pout<< " " << patchFld.patch().index()
<< ' ' << patchFld.patch().name()
<< ' ' << patchFld.type()
<< ' ' << patchFld.size()
<< nl;
}
}
}
......@@ -287,11 +287,49 @@ void Foam::fvMeshDistribute::correctBoundaryConditions()
}
template<class GeoField>
void Foam::fvMeshDistribute::getFieldNames
(
const fvMesh& mesh,
HashTable<wordList>& allFieldNames,
const bool syncPar
)
{
wordList& list = allFieldNames(GeoField::typeName);
list = mesh.sortedNames<GeoField>();
// Check all procs have same names
if (syncPar)
{
List<wordList> allNames(Pstream::nProcs());
allNames[Pstream::myProcNo()] = list;
Pstream::gatherList(allNames);
Pstream::scatterList(allNames);
for (label proci = 1; proci < Pstream::nProcs(); proci++)
{
if (allNames[proci] != allNames[0])
{
FatalErrorInFunction
<< "When checking for equal "
<< GeoField::typeName
<< " :" << nl
<< "processor0 has:" << allNames[0] << endl
<< "processor" << proci << " has:" << allNames[proci] << nl
<< GeoField::typeName
<< " need to be synchronised on all processors."
<< exit(FatalError);
}
}
}
}
template<class GeoField>
void Foam::fvMeshDistribute::sendFields
(
const label domain,
const wordList& fieldNames,
const HashTable<wordList>& allFieldNames,
const fvMeshSubset& subsetter,
Ostream& toNbr
)
......@@ -315,24 +353,28 @@ void Foam::fvMeshDistribute::sendFields
// volVectorField {U {internalField ..; boundaryField ..;}}
const wordList& fieldNames =
allFieldNames.lookup(GeoField::typeName, wordList::null());
toNbr << GeoField::typeName << token::NL << token::BEGIN_BLOCK << token::NL;
forAll(fieldNames, i)
for (const word& fieldName : fieldNames)
{
if (debug)
{
Pout<< "Subsetting field " << fieldNames[i]
Pout<< "Subsetting field " << fieldName
<< " for domain:" << domain << endl;
}
// Send all fieldNames. This has to be exactly the same set as is
// being received!
const GeoField& fld =
subsetter.baseMesh().lookupObject<GeoField>(fieldNames[i]);
subsetter.baseMesh().lookupObject<GeoField>(fieldName);
tmp<GeoField> tsubfld = subsetter.interpolate(fld);
toNbr
<< fieldNames[i] << token::NL << token::BEGIN_BLOCK
<< fieldName << token::NL << token::BEGIN_BLOCK
<< tsubfld
<< token::NL << token::END_BLOCK << token::NL;
}
......@@ -344,45 +386,53 @@ template<class GeoField>
void Foam::fvMeshDistribute::receiveFields
(
const label domain,
const wordList& fieldNames,
const HashTable<wordList>& allFieldNames,
fvMesh& mesh,
PtrList<GeoField>& fields,
const dictionary& fieldDicts
const dictionary& allFieldsDict
)
{
// Opposite of sendFields
const wordList& fieldNames =
allFieldNames.lookup(GeoField::typeName, wordList::null());