BUG: redistributePar -reconstruct lagrangian trashes fields (fixes #2494)

- the file removal cleanup, which makes reasonable sense for
  redistribute mode, always forced the removal of the reconstructed
  lagrangian fields (since all of the non-master fields are empty by
  definition)!

  Detect reconstruct mode (by using constructSize from the map) to
  circumvent this logic.
This commit is contained in:
Mark Olesen 2022-06-24 14:25:17 +02:00
parent 39d8964851
commit 3c64283364
2 changed files with 59 additions and 22 deletions

View File

@ -84,15 +84,32 @@ Foam::label Foam::parLagrangianDistributor::distributeFields
) )
); );
bool reconstruct = false;
label nFields = 0; label nFields = 0;
for (const word& objectName : fieldNames) for (const word& objectName : fieldNames)
{ {
if (!nFields) if (!nFields)
{ {
Info<< " Distributing lagrangian " // Performing an all-to-one (reconstruct)?
<< fieldType::typeName << "s\n" << endl; reconstruct = returnReduce
(
(!map.constructSize() || Pstream::master()),
andOp<bool>()
);
} }
Info<< " " << objectName << endl;
if (verbose_)
{
if (!nFields)
{
Info<< " Distributing lagrangian "
<< fieldType::typeName << "s\n" << nl;
}
Info<< " " << objectName << nl;
}
++nFields;
// Read if present // Read if present
IOField<Type> field IOField<Type> field
@ -128,7 +145,7 @@ Foam::label Foam::parLagrangianDistributor::distributeFields
{ {
IOField<Type>(fieldIO, std::move(field)).write(); IOField<Type>(fieldIO, std::move(field)).write();
} }
else else if (!reconstruct)
{ {
// When running with -overwrite it should also delete the old // When running with -overwrite it should also delete the old
// files. Below works but is not optimal. // files. Below works but is not optimal.
@ -138,6 +155,7 @@ Foam::label Foam::parLagrangianDistributor::distributeFields
} }
} }
if (nFields && verbose_) Info<< endl;
return nFields; return nFields;
} }
@ -174,9 +192,21 @@ Foam::label Foam::parLagrangianDistributor::distributeFieldFields
) )
); );
bool reconstruct = false;
label nFields = 0; label nFields = 0;
for (const word& objectName : fieldNames) for (const word& objectName : fieldNames)
{ {
if (!nFields)
{
// Performing an all-to-one (reconstruct)?
reconstruct = returnReduce
(
(!map.constructSize() || Pstream::master()),
andOp<bool>()
);
}
if (verbose_) if (verbose_)
{ {
if (!nFields) if (!nFields)
@ -227,7 +257,7 @@ Foam::label Foam::parLagrangianDistributor::distributeFieldFields
std::move(field) std::move(field)
).write(); ).write();
} }
else else if (!reconstruct)
{ {
// When running with -overwrite it should also delete the old // When running with -overwrite it should also delete the old
// files. Below works but is not optimal. // files. Below works but is not optimal.
@ -309,19 +339,31 @@ Foam::label Foam::parLagrangianDistributor::distributeStoredFields
cloud.lookupClass<Container>() cloud.lookupClass<Container>()
); );
bool reconstruct = false;
label nFields = 0; label nFields = 0;
forAllIters(fields, iter) forAllIters(fields, iter)
{ {
Container& field = *(iter.val()); Container& field = *(iter.val());
if (!nFields)
{
// Performing an all-to-one (reconstruct)?
reconstruct = returnReduce
(
(!map.constructSize() || Pstream::master()),
andOp<bool>()
);
}
if (verbose_) if (verbose_)
{ {
if (!nFields) if (!nFields)
{ {
Info<< " Distributing lagrangian " Info<< " Distributing lagrangian "
<< Container::typeName << "s\n" << endl; << Container::typeName << "s\n" << nl;
} }
Info<< " " << field.name() << endl; Info<< " " << field.name() << nl;
} }
++nFields; ++nFields;
@ -342,7 +384,7 @@ Foam::label Foam::parLagrangianDistributor::distributeStoredFields
{ {
Container(fieldIO, std::move(field)).write(); Container(fieldIO, std::move(field)).write();
} }
else else if (!reconstruct)
{ {
// When running with -overwrite it should also delete the old // When running with -overwrite it should also delete the old
// files. Below works but is not optimal. // files. Below works but is not optimal.

View File

@ -147,7 +147,7 @@ void createTimeDirs(const fileName& path)
//Pout<< "Time:" << t << nl //Pout<< "Time:" << t << nl
// << " raw :" << timePath << nl // << " raw :" << timePath << nl
// << endl; // << endl;
mkDir(timePath); Foam::mkDir(timePath);
} }
} }
@ -1141,18 +1141,13 @@ int main(int argc, char *argv[])
Info<< "Reconstructing case (like reconstructParMesh)" << nl << endl; Info<< "Reconstructing case (like reconstructParMesh)" << nl << endl;
} }
if ((decompose || reconstruct) && !overwrite)
if (decompose || reconstruct)
{ {
if (!overwrite)
{
WarningInFunction
<< "Working in decompose or reconstruction mode automatically"
<< " implies -overwrite" << nl << endl;
overwrite = true; overwrite = true;
WarningInFunction
<< "Working in -decompose or -reconstruct mode:"
" automatically implies -overwrite" << nl << endl;
} }
}
if (!Pstream::parRun()) if (!Pstream::parRun())
{ {
@ -1162,7 +1157,7 @@ int main(int argc, char *argv[])
} }
if (!isDir(args.rootPath())) if (!Foam::isDir(args.rootPath()))
{ {
FatalErrorInFunction FatalErrorInFunction
<< ": cannot open root directory " << args.rootPath() << ": cannot open root directory " << args.rootPath()
@ -1188,7 +1183,7 @@ int main(int argc, char *argv[])
// want to delay constructing runTime until we've synced all time // want to delay constructing runTime until we've synced all time
// directories... // directories...
const fileName procDir(fileHandler().filePath(args.path())); const fileName procDir(fileHandler().filePath(args.path()));
if (isDir(procDir)) if (Foam::isDir(procDir))
{ {
if (decompose) if (decompose)
{ {
@ -2446,7 +2441,7 @@ int main(int argc, char *argv[])
// Remove dummy mesh created by loadOrCreateMesh // Remove dummy mesh created by loadOrCreateMesh
const bool oldParRun = Pstream::parRun(false); const bool oldParRun = Pstream::parRun(false);
mesh.removeFiles(); mesh.removeFiles();
rmDir(mesh.objectRegistry::objectPath()); Foam::rmDir(mesh.objectRegistry::objectPath());
Pstream::parRun(oldParRun); // Restore parallel state Pstream::parRun(oldParRun); // Restore parallel state
} }
} }