ENH: redistributePar: single-step. See #1211

Support for DimensionedFields
This commit is contained in:
mattijs
2021-03-17 12:19:42 +00:00
parent 853f50f7da
commit 3299f9ac0d
6 changed files with 186 additions and 65 deletions

View File

@ -2407,9 +2407,12 @@ int main(int argc, char *argv[])
else else
{ {
// Directory does not exist. If this happens on master -> decompose mode // Directory does not exist. If this happens on master -> decompose mode
decompose = true; if (Pstream::master())
Info<< "No processor directories; switching on decompose mode" {
<< nl << endl; decompose = true;
Info<< "No processor directories; switching on decompose mode"
<< nl << endl;
}
} }
// If master changed to decompose mode make sure all nodes know about it // If master changed to decompose mode make sure all nodes know about it
Pstream::scatter(decompose); Pstream::scatter(decompose);
@ -2421,20 +2424,19 @@ int main(int argc, char *argv[])
// e.g. latestTime will pick up a different time (which causes createTime.H // e.g. latestTime will pick up a different time (which causes createTime.H
// to abort). So for now make sure to have master times on all // to abort). So for now make sure to have master times on all
// processors // processors
if (!procDir.empty())
{ {
Info<< "Creating time directories on all processors" << nl << endl; Info<< "Creating time directories on all processors" << nl << endl;
instantList timeDirs; instantList timeDirs;
if (Pstream::master()) if (Pstream::master())
{ {
const bool oldParRun = Pstream::parRun(false); const bool oldParRun = Pstream::parRun(false);
timeDirs = Time::findTimes(procDir, "constant"); timeDirs = Time::findTimes(args.path(), "constant");
Pstream::parRun(oldParRun); // Restore parallel state Pstream::parRun(oldParRun); // Restore parallel state
} }
Pstream::scatter(timeDirs); Pstream::scatter(timeDirs);
for (const instant& t : timeDirs) for (const instant& t : timeDirs)
{ {
mkDir(procDir/t.name()); mkDir(args.path()/t.name());
} }
} }

View File

@ -432,7 +432,11 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshAdder::add
constructFaceMap, constructFaceMap,
constructPointMap constructPointMap
); );
fvMeshAdder::MapDimFields<scalar>(fvMeshes, constructCellMap);
fvMeshAdder::MapDimFields<vector>(fvMeshes, constructCellMap);
fvMeshAdder::MapDimFields<sphericalTensor>(fvMeshes, constructCellMap);
fvMeshAdder::MapDimFields<symmTensor>(fvMeshes, constructCellMap);
fvMeshAdder::MapDimFields<tensor>(fvMeshes, constructCellMap);
// Swap returned data back to processor order // Swap returned data back to processor order
if (myProci != 0) if (myProci != 0)

View File

@ -292,8 +292,7 @@ void Foam::fvMeshAdder::MapVolFields
fldType& fld = const_cast<fldType&>(*fieldIter()); fldType& fld = const_cast<fldType&>(*fieldIter());
DebugPout DebugPout
<< "MapVolFields : Storing old time for " << fld.name() << "MapVolFields : Storing old time for " << fld.name() << endl;
<< endl;
fld.storeOldTimes(); fld.storeOldTimes();
} }
@ -317,8 +316,7 @@ void Foam::fvMeshAdder::MapVolFields
{ {
WarningInFunction WarningInFunction
<< "Not mapping field " << fld.name() << "Not mapping field " << fld.name()
<< " since not present on mesh to add" << " since not present on mesh to add" << endl;
<< endl;
} }
} }
} }
@ -604,8 +602,7 @@ void Foam::fvMeshAdder::MapSurfaceFields
fldType& fld = const_cast<fldType&>(*fieldIter()); fldType& fld = const_cast<fldType&>(*fieldIter());
DebugPout DebugPout
<< "MapSurfaceFields : Storing old time for " << "MapSurfaceFields : Storing old time for " << fld.name() << endl;
<< fld.name() << endl;
fld.storeOldTimes(); fld.storeOldTimes();
} }
@ -629,8 +626,7 @@ void Foam::fvMeshAdder::MapSurfaceFields
{ {
WarningInFunction WarningInFunction
<< "Not mapping field " << fld.name() << "Not mapping field " << fld.name()
<< " since not present on mesh to add" << " since not present on mesh to add" << endl;
<< endl;
} }
} }
} }
@ -697,8 +693,7 @@ void Foam::fvMeshAdder::MapDimFields
{ {
WarningInFunction WarningInFunction
<< "Not mapping field " << fld.name() << "Not mapping field " << fld.name()
<< " since not present on mesh to add" << " since not present on mesh to add" << endl;
<< endl;
} }
} }
} }
@ -717,7 +712,12 @@ void Foam::fvMeshAdder::MapDimField
// Add fields to fields[0] after adding the meshes to meshes[0]. // Add fields to fields[0] after adding the meshes to meshes[0].
// Mesh[0] is the sum of all meshes. Fields are not yet mapped. // Mesh[0] is the sum of all meshes. Fields are not yet mapped.
if (flds.size() == 0 || !flds.set(0)) if
(
flds.size() == 0
|| !flds.set(0)
|| cellProcAddressing.size() != flds.size()
)
{ {
FatalErrorInFunction << "Not valid field at element 0" FatalErrorInFunction << "Not valid field at element 0"
<< " in field list of size " << flds.size() << exit(FatalError); << " in field list of size " << flds.size() << exit(FatalError);
@ -729,10 +729,10 @@ void Foam::fvMeshAdder::MapDimField
{ {
// Store old internal field // Store old internal field
const Field<Type> oldInternalField(flds[0].primitiveField()); const Field<Type> oldInternalField(flds[0]);
// Modify internal field // Modify internal field
Field<Type>& intFld = flds[0].primitiveFieldRef(); Field<Type>& intFld = flds[0];
// Set to new mesh size // Set to new mesh size
intFld.setSize(flds[0].mesh().nCells()); intFld.setSize(flds[0].mesh().nCells());
@ -743,7 +743,7 @@ void Foam::fvMeshAdder::MapDimField
{ {
if (flds.set(meshi)) if (flds.set(meshi))
{ {
const Field<Type>& addFld = flds[meshi].primitiveFieldRef(); const Field<Type>& addFld = flds[meshi];
intFld.rmap(addFld, cellProcAddressing[meshi]); intFld.rmap(addFld, cellProcAddressing[meshi]);
} }
} }
@ -1174,6 +1174,7 @@ void Foam::fvMeshAdder::MapDimFields
) )
{ {
typedef DimensionedField<Type, volMesh> fldType; typedef DimensionedField<Type, volMesh> fldType;
typedef GeometricField<Type, fvPatchField, volMesh> excludeType;
if (meshes.size() == 0 || !meshes.set(0)) if (meshes.size() == 0 || !meshes.set(0))
{ {
@ -1190,23 +1191,31 @@ void Foam::fvMeshAdder::MapDimFields
for (const auto& fld : fields) for (const auto& fld : fields)
{ {
const word& name0 = fld->name(); if (!isA<excludeType>(*fld))
DebugPout
<< "MapDimFields : mapping " << name0 << endl;
UPtrList<fldType> meshToField(meshes.size());
forAll(meshes, meshi)
{ {
if (meshes.set(meshi)) const word& name0 = fld->name();
{
auto& meshFld = meshes[meshi].
objectRegistry::lookupObjectRef<fldType>(name0);
meshToField.set(meshi, &meshFld);
}
}
MapDimField(meshToField, cellProcAddressing, fullyMapped); DebugPout
<< "MapDimFields : mapping " << name0 << endl;
UPtrList<fldType> meshToField(meshes.size());
forAll(meshes, meshi)
{
if (meshes.set(meshi))
{
auto& meshFld = meshes[meshi].
objectRegistry::lookupObjectRef<fldType>(name0);
meshToField.set(meshi, &meshFld);
}
}
MapDimField(meshToField, cellProcAddressing, fullyMapped);
}
else
{
DebugPout
<< "MapDimFields : ignoring " << fld->name() << endl;
}
} }
} }

View File

@ -2017,11 +2017,36 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
getFieldNames<surfaceSymmTensorField>(mesh_, allFieldNames); getFieldNames<surfaceSymmTensorField>(mesh_, allFieldNames);
getFieldNames<surfaceTensorField>(mesh_, allFieldNames); getFieldNames<surfaceTensorField>(mesh_, allFieldNames);
getFieldNames<volScalarField::Internal>(mesh_, allFieldNames); getFieldNames<volScalarField::Internal>
getFieldNames<volVectorField::Internal>(mesh_, allFieldNames); (
getFieldNames<volSphericalTensorField::Internal>(mesh_, allFieldNames); mesh_,
getFieldNames<volSymmTensorField::Internal>(mesh_, allFieldNames); allFieldNames,
getFieldNames<volTensorField::Internal>(mesh_, allFieldNames); volScalarField::typeName
);
getFieldNames<volVectorField::Internal>
(
mesh_,
allFieldNames,
volVectorField::typeName
);
getFieldNames<volSphericalTensorField::Internal>
(
mesh_,
allFieldNames,
volSphericalTensorField::typeName
);
getFieldNames<volSymmTensorField::Internal>
(
mesh_,
allFieldNames,
volSymmTensorField::typeName
);
getFieldNames<volTensorField::Internal>
(
mesh_,
allFieldNames,
volTensorField::typeName
);
// Find patch to temporarily put exposed and processor faces into. // Find patch to temporarily put exposed and processor faces into.
@ -2072,6 +2097,11 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
printFieldInfo<surfaceSphericalTensorField>(mesh_); printFieldInfo<surfaceSphericalTensorField>(mesh_);
printFieldInfo<surfaceSymmTensorField>(mesh_); printFieldInfo<surfaceSymmTensorField>(mesh_);
printFieldInfo<surfaceTensorField>(mesh_); printFieldInfo<surfaceTensorField>(mesh_);
printIntFieldInfo<volScalarField::Internal>(mesh_);
printIntFieldInfo<volVectorField::Internal>(mesh_);
printIntFieldInfo<volSphericalTensorField::Internal>(mesh_);
printIntFieldInfo<volSymmTensorField::Internal>(mesh_);
printIntFieldInfo<volTensorField::Internal>(mesh_);
Pout<< nl << endl; Pout<< nl << endl;
} }
@ -2430,6 +2460,11 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
printFieldInfo<surfaceSphericalTensorField>(mesh_); printFieldInfo<surfaceSphericalTensorField>(mesh_);
printFieldInfo<surfaceSymmTensorField>(mesh_); printFieldInfo<surfaceSymmTensorField>(mesh_);
printFieldInfo<surfaceTensorField>(mesh_); printFieldInfo<surfaceTensorField>(mesh_);
printIntFieldInfo<volScalarField::Internal>(mesh_);
printIntFieldInfo<volVectorField::Internal>(mesh_);
printIntFieldInfo<volSphericalTensorField::Internal>(mesh_);
printIntFieldInfo<volSymmTensorField::Internal>(mesh_);
printIntFieldInfo<volTensorField::Internal>(mesh_);
Pout<< nl << endl; Pout<< nl << endl;
} }
@ -2804,6 +2839,11 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
printFieldInfo<surfaceSphericalTensorField>(mesh_); printFieldInfo<surfaceSphericalTensorField>(mesh_);
printFieldInfo<surfaceSymmTensorField>(mesh_); printFieldInfo<surfaceSymmTensorField>(mesh_);
printFieldInfo<surfaceTensorField>(mesh_); printFieldInfo<surfaceTensorField>(mesh_);
printIntFieldInfo<volScalarField::Internal>(mesh_);
printIntFieldInfo<volVectorField::Internal>(mesh_);
printIntFieldInfo<volSphericalTensorField::Internal>(mesh_);
printIntFieldInfo<volSymmTensorField::Internal>(mesh_);
printIntFieldInfo<volTensorField::Internal>(mesh_);
Pout<< nl << endl; Pout<< nl << endl;
} }
@ -2915,6 +2955,11 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
printFieldInfo<surfaceSphericalTensorField>(mesh_); printFieldInfo<surfaceSphericalTensorField>(mesh_);
printFieldInfo<surfaceSymmTensorField>(mesh_); printFieldInfo<surfaceSymmTensorField>(mesh_);
printFieldInfo<surfaceTensorField>(mesh_); printFieldInfo<surfaceTensorField>(mesh_);
printIntFieldInfo<volScalarField::Internal>(mesh_);
printIntFieldInfo<volVectorField::Internal>(mesh_);
printIntFieldInfo<volSphericalTensorField::Internal>(mesh_);
printIntFieldInfo<volSymmTensorField::Internal>(mesh_);
printIntFieldInfo<volTensorField::Internal>(mesh_);
Pout<< nl << endl; Pout<< nl << endl;
} }
@ -3000,6 +3045,11 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
printFieldInfo<surfaceSphericalTensorField>(mesh_); printFieldInfo<surfaceSphericalTensorField>(mesh_);
printFieldInfo<surfaceSymmTensorField>(mesh_); printFieldInfo<surfaceSymmTensorField>(mesh_);
printFieldInfo<surfaceTensorField>(mesh_); printFieldInfo<surfaceTensorField>(mesh_);
printIntFieldInfo<volScalarField::Internal>(mesh_);
printIntFieldInfo<volVectorField::Internal>(mesh_);
printIntFieldInfo<volSphericalTensorField::Internal>(mesh_);
printIntFieldInfo<volSymmTensorField::Internal>(mesh_);
printIntFieldInfo<volTensorField::Internal>(mesh_);
Pout<< nl << endl; Pout<< nl << endl;
} }

View File

@ -137,9 +137,9 @@ class fvMeshDistribute
const typename GeoField::value_type& initVal const typename GeoField::value_type& initVal
); );
//- Call correctBoundaryConditions on fields ////- Call correctBoundaryConditions on fields
template<class GeoField> //template<class GeoField>
void correctBoundaryConditions(); //void correctBoundaryConditions();
//- Delete all processor patches. Move any processor faces into //- Delete all processor patches. Move any processor faces into
// patchi. // patchi.
@ -306,6 +306,7 @@ class fvMeshDistribute
( (
const fvMesh& mesh, const fvMesh& mesh,
HashTable<wordList>& allFieldNames, HashTable<wordList>& allFieldNames,
const word& excludeType = word::null,
const bool syncPar = true const bool syncPar = true
); );
@ -384,6 +385,10 @@ public:
const labelList& const labelList&
); );
//- Print some field info
template<class GeoField>
static void printIntFieldInfo(const fvMesh&);
//- Print some field info //- Print some field info
template<class GeoField> template<class GeoField>
static void printFieldInfo(const fvMesh&); static void printFieldInfo(const fvMesh&);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -30,10 +30,38 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class GeoField>
void Foam::fvMeshDistribute::printIntFieldInfo(const fvMesh& mesh)
{
typedef GeometricField
<
typename GeoField::value_type,
fvPatchField,
volMesh
> excludeType;
const HashTable<const GeoField*> flds
(
mesh.objectRegistry::lookupClass<GeoField>()
);
forAllConstIters(flds, iter)
{
const GeoField& fld = *iter();
if (!isA<excludeType>(fld))
{
Pout<< "Field:" << iter.key() << " internalsize:" << fld.size()
//<< " value:" << fld
<< endl;
}
}
}
template<class GeoField> template<class GeoField>
void Foam::fvMeshDistribute::printFieldInfo(const fvMesh& mesh) void Foam::fvMeshDistribute::printFieldInfo(const fvMesh& mesh)
{ {
HashTable<const GeoField*> flds const HashTable<const GeoField*> flds
( (
mesh.objectRegistry::lookupClass<GeoField>() mesh.objectRegistry::lookupClass<GeoField>()
); );
@ -270,22 +298,22 @@ void Foam::fvMeshDistribute::initPatchFields
} }
template<class GeoField> //template<class GeoField>
void Foam::fvMeshDistribute::correctBoundaryConditions() //void Foam::fvMeshDistribute::correctBoundaryConditions()
{ //{
// CorrectBoundaryConditions patch fields of certain type // // CorrectBoundaryConditions patch fields of certain type
//
HashTable<GeoField*> flds // HashTable<GeoField*> flds
( // (
mesh_.objectRegistry::lookupClass<GeoField>() // mesh_.objectRegistry::lookupClass<GeoField>()
); // );
//
forAllIters(flds, iter) // forAllIters(flds, iter)
{ // {
GeoField& fld = *iter(); // GeoField& fld = *iter();
fld.correctBoundaryConditions(); // fld.correctBoundaryConditions();
} // }
} //}
template<class GeoField> template<class GeoField>
@ -293,12 +321,32 @@ void Foam::fvMeshDistribute::getFieldNames
( (
const fvMesh& mesh, const fvMesh& mesh,
HashTable<wordList>& allFieldNames, HashTable<wordList>& allFieldNames,
const word& excludeType,
const bool syncPar const bool syncPar
) )
{ {
wordList& list = allFieldNames(GeoField::typeName); wordList& list = allFieldNames(GeoField::typeName);
list = mesh.sortedNames<GeoField>(); list = mesh.sortedNames<GeoField>();
if (!excludeType.empty())
{
const wordList& excludeList = allFieldNames(excludeType);
DynamicList<word> newList(list.size());
for(const auto& name : list)
{
if (!excludeList.found(name))
{
newList.append(name);
}
}
if (newList.size() < list.size())
{
list = std::move(newList);
}
}
// Check all procs have same names // Check all procs have same names
if (syncPar) if (syncPar)
{ {
@ -363,7 +411,8 @@ void Foam::fvMeshDistribute::sendFields
{ {
if (debug) if (debug)
{ {
Pout<< "Subsetting field " << fieldName Pout<< "Subsetting " << GeoField::typeName
<< " field " << fieldName
<< " for domain:" << domain << endl; << " for domain:" << domain << endl;
} }
@ -406,7 +455,8 @@ void Foam::fvMeshDistribute::receiveFields
if (debug) if (debug)
{ {
Pout<< "Receiving fields " << fieldNames Pout<< "Receiving:" << GeoField::typeName
<< " fields:" << fieldNames
<< " from domain:" << domain << endl; << " from domain:" << domain << endl;
} }
@ -417,7 +467,8 @@ void Foam::fvMeshDistribute::receiveFields
{ {
if (debug) if (debug)
{ {
Pout<< "Constructing field " << fieldName Pout<< "Constructing type:" << GeoField::typeName
<< " field:" << fieldName
<< " from domain:" << domain << endl; << " from domain:" << domain << endl;
} }