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

View File

@ -147,7 +147,7 @@ void createTimeDirs(const fileName& path)
//Pout<< "Time:" << t << nl
// << " raw :" << timePath << nl
// << endl;
mkDir(timePath);
Foam::mkDir(timePath);
}
}
@ -1141,19 +1141,14 @@ int main(int argc, char *argv[])
Info<< "Reconstructing case (like reconstructParMesh)" << nl << endl;
}
if (decompose || reconstruct)
if ((decompose || reconstruct) && !overwrite)
{
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())
{
FatalErrorInFunction
@ -1162,7 +1157,7 @@ int main(int argc, char *argv[])
}
if (!isDir(args.rootPath()))
if (!Foam::isDir(args.rootPath()))
{
FatalErrorInFunction
<< ": 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
// directories...
const fileName procDir(fileHandler().filePath(args.path()));
if (isDir(procDir))
if (Foam::isDir(procDir))
{
if (decompose)
{
@ -2446,7 +2441,7 @@ int main(int argc, char *argv[])
// Remove dummy mesh created by loadOrCreateMesh
const bool oldParRun = Pstream::parRun(false);
mesh.removeFiles();
rmDir(mesh.objectRegistry::objectPath());
Foam::rmDir(mesh.objectRegistry::objectPath());
Pstream::parRun(oldParRun); // Restore parallel state
}
}