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
{
// Directory does not exist. If this happens on master -> decompose mode
decompose = true;
Info<< "No processor directories; switching on decompose mode"
<< nl << endl;
if (Pstream::master())
{
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
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
// to abort). So for now make sure to have master times on all
// processors
if (!procDir.empty())
{
Info<< "Creating time directories on all processors" << nl << endl;
instantList timeDirs;
if (Pstream::master())
{
const bool oldParRun = Pstream::parRun(false);
timeDirs = Time::findTimes(procDir, "constant");
timeDirs = Time::findTimes(args.path(), "constant");
Pstream::parRun(oldParRun); // Restore parallel state
}
Pstream::scatter(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,
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
if (myProci != 0)

View File

@ -292,8 +292,7 @@ void Foam::fvMeshAdder::MapVolFields
fldType& fld = const_cast<fldType&>(*fieldIter());
DebugPout
<< "MapVolFields : Storing old time for " << fld.name()
<< endl;
<< "MapVolFields : Storing old time for " << fld.name() << endl;
fld.storeOldTimes();
}
@ -317,8 +316,7 @@ void Foam::fvMeshAdder::MapVolFields
{
WarningInFunction
<< "Not mapping field " << fld.name()
<< " since not present on mesh to add"
<< endl;
<< " since not present on mesh to add" << endl;
}
}
}
@ -604,8 +602,7 @@ void Foam::fvMeshAdder::MapSurfaceFields
fldType& fld = const_cast<fldType&>(*fieldIter());
DebugPout
<< "MapSurfaceFields : Storing old time for "
<< fld.name() << endl;
<< "MapSurfaceFields : Storing old time for " << fld.name() << endl;
fld.storeOldTimes();
}
@ -629,8 +626,7 @@ void Foam::fvMeshAdder::MapSurfaceFields
{
WarningInFunction
<< "Not mapping field " << fld.name()
<< " since not present on mesh to add"
<< endl;
<< " since not present on mesh to add" << endl;
}
}
}
@ -697,8 +693,7 @@ void Foam::fvMeshAdder::MapDimFields
{
WarningInFunction
<< "Not mapping field " << fld.name()
<< " since not present on mesh to add"
<< endl;
<< " since not present on mesh to add" << endl;
}
}
}
@ -717,7 +712,12 @@ void Foam::fvMeshAdder::MapDimField
// 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.
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"
<< " in field list of size " << flds.size() << exit(FatalError);
@ -729,10 +729,10 @@ void Foam::fvMeshAdder::MapDimField
{
// Store old internal field
const Field<Type> oldInternalField(flds[0].primitiveField());
const Field<Type> oldInternalField(flds[0]);
// Modify internal field
Field<Type>& intFld = flds[0].primitiveFieldRef();
Field<Type>& intFld = flds[0];
// Set to new mesh size
intFld.setSize(flds[0].mesh().nCells());
@ -743,7 +743,7 @@ void Foam::fvMeshAdder::MapDimField
{
if (flds.set(meshi))
{
const Field<Type>& addFld = flds[meshi].primitiveFieldRef();
const Field<Type>& addFld = flds[meshi];
intFld.rmap(addFld, cellProcAddressing[meshi]);
}
}
@ -1174,6 +1174,7 @@ void Foam::fvMeshAdder::MapDimFields
)
{
typedef DimensionedField<Type, volMesh> fldType;
typedef GeometricField<Type, fvPatchField, volMesh> excludeType;
if (meshes.size() == 0 || !meshes.set(0))
{
@ -1190,23 +1191,31 @@ void Foam::fvMeshAdder::MapDimFields
for (const auto& fld : fields)
{
const word& name0 = fld->name();
DebugPout
<< "MapDimFields : mapping " << name0 << endl;
UPtrList<fldType> meshToField(meshes.size());
forAll(meshes, meshi)
if (!isA<excludeType>(*fld))
{
if (meshes.set(meshi))
{
auto& meshFld = meshes[meshi].
objectRegistry::lookupObjectRef<fldType>(name0);
meshToField.set(meshi, &meshFld);
}
}
const word& name0 = fld->name();
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<surfaceTensorField>(mesh_, allFieldNames);
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);
getFieldNames<volScalarField::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.
@ -2072,6 +2097,11 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
printFieldInfo<surfaceSphericalTensorField>(mesh_);
printFieldInfo<surfaceSymmTensorField>(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;
}
@ -2430,6 +2460,11 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
printFieldInfo<surfaceSphericalTensorField>(mesh_);
printFieldInfo<surfaceSymmTensorField>(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;
}
@ -2804,6 +2839,11 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
printFieldInfo<surfaceSphericalTensorField>(mesh_);
printFieldInfo<surfaceSymmTensorField>(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;
}
@ -2915,6 +2955,11 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
printFieldInfo<surfaceSphericalTensorField>(mesh_);
printFieldInfo<surfaceSymmTensorField>(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;
}
@ -3000,6 +3045,11 @@ Foam::autoPtr<Foam::mapDistributePolyMesh> Foam::fvMeshDistribute::distribute
printFieldInfo<surfaceSphericalTensorField>(mesh_);
printFieldInfo<surfaceSymmTensorField>(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;
}

View File

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

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -30,10 +30,38 @@ License
// * * * * * * * * * * * * * 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>
void Foam::fvMeshDistribute::printFieldInfo(const fvMesh& mesh)
{
HashTable<const GeoField*> flds
const HashTable<const GeoField*> flds
(
mesh.objectRegistry::lookupClass<GeoField>()
);
@ -270,22 +298,22 @@ void Foam::fvMeshDistribute::initPatchFields
}
template<class GeoField>
void Foam::fvMeshDistribute::correctBoundaryConditions()
{
// CorrectBoundaryConditions patch fields of certain type
HashTable<GeoField*> flds
(
mesh_.objectRegistry::lookupClass<GeoField>()
);
forAllIters(flds, iter)
{
GeoField& fld = *iter();
fld.correctBoundaryConditions();
}
}
//template<class GeoField>
//void Foam::fvMeshDistribute::correctBoundaryConditions()
//{
// // CorrectBoundaryConditions patch fields of certain type
//
// HashTable<GeoField*> flds
// (
// mesh_.objectRegistry::lookupClass<GeoField>()
// );
//
// forAllIters(flds, iter)
// {
// GeoField& fld = *iter();
// fld.correctBoundaryConditions();
// }
//}
template<class GeoField>
@ -293,12 +321,32 @@ void Foam::fvMeshDistribute::getFieldNames
(
const fvMesh& mesh,
HashTable<wordList>& allFieldNames,
const word& excludeType,
const bool syncPar
)
{
wordList& list = allFieldNames(GeoField::typeName);
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
if (syncPar)
{
@ -363,7 +411,8 @@ void Foam::fvMeshDistribute::sendFields
{
if (debug)
{
Pout<< "Subsetting field " << fieldName
Pout<< "Subsetting " << GeoField::typeName
<< " field " << fieldName
<< " for domain:" << domain << endl;
}
@ -406,7 +455,8 @@ void Foam::fvMeshDistribute::receiveFields
if (debug)
{
Pout<< "Receiving fields " << fieldNames
Pout<< "Receiving:" << GeoField::typeName
<< " fields:" << fieldNames
<< " from domain:" << domain << endl;
}
@ -417,7 +467,8 @@ void Foam::fvMeshDistribute::receiveFields
{
if (debug)
{
Pout<< "Constructing field " << fieldName
Pout<< "Constructing type:" << GeoField::typeName
<< " field:" << fieldName
<< " from domain:" << domain << endl;
}