Skip to content
Snippets Groups Projects
Commit 0abafd98 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

BUG: areaWrite fails with partial fields (#2084)

- depending on how the finiteArea is split up across processors,
  it is possible that some processors have failed to register
  fields in their object registry.

  Now ensure that the field names are synchronized in parallel before
  attempting a write. Replace locally missing fields with a dummy
  zero-sized field.
parent 2990b14d
No related merge requests found
EXE_INC = \ EXE_INC = \
-I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/surfMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude -I$(LIB_SRC)/meshTools/lnInclude
LIB_LIBS = \ LIB_LIBS = \
-lOpenFOAM \ -lOpenFOAM \
-lfileFormats \
-lsurfMesh \
-lmeshTools -lmeshTools
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -144,12 +144,15 @@ class areaWrite ...@@ -144,12 +144,15 @@ class areaWrite
// Private Member Functions // Private Member Functions
//- Write fieldName on surface and on outputDir path //- Write fieldName on surface and on outputDir path.
// Can have a field nullptr for partially missing fields,
// but the caller should generally filter out completely
// missing fields.
template<class Type> template<class Type>
void writeSurface void writeSurface
( (
surfaceWriter& writer, surfaceWriter& writer,
const Field<Type>& values, const Field<Type>* fieldPtr,
const word& fieldName const word& fieldName
); );
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -35,10 +35,12 @@ template<class Type> ...@@ -35,10 +35,12 @@ template<class Type>
void Foam::areaWrite::writeSurface void Foam::areaWrite::writeSurface
( (
surfaceWriter& writer, surfaceWriter& writer,
const Field<Type>& values, const Field<Type>* fieldPtr,
const word& fieldName const word& fieldName
) )
{ {
const Field<Type>& values = (fieldPtr ? *fieldPtr : Field<Type>::null());
fileName outputName = writer.write(fieldName, values); fileName outputName = writer.write(fieldName, values);
// Case-local file name with "<case>" to make relocatable // Case-local file name with "<case>" to make relocatable
...@@ -64,11 +66,23 @@ void Foam::areaWrite::performAction ...@@ -64,11 +66,23 @@ void Foam::areaWrite::performAction
wordList fieldNames; wordList fieldNames;
if (loadFromFiles_) if (loadFromFiles_)
{ {
fieldNames = objects.sortedNames<GeoField>(fieldSelection_); // With syncPar (sorted and parallel-consistent)
fieldNames = objects.names<GeoField>(fieldSelection_, true);
} }
else else
{ {
fieldNames = areaMesh.thisDb().sortedNames<GeoField>(fieldSelection_); fieldNames = areaMesh.thisDb().names<GeoField>(fieldSelection_);
// With syncPar
if (Pstream::parRun())
{
// Synchronize names
Pstream::combineGather(fieldNames, ListOps::uniqueEqOp<word>());
Pstream::combineScatter(fieldNames);
}
// Sort for consistent order on all processors
Foam::sort(fieldNames);
} }
for (const word& fieldName : fieldNames) for (const word& fieldName : fieldNames)
...@@ -92,16 +106,14 @@ void Foam::areaWrite::performAction ...@@ -92,16 +106,14 @@ void Foam::areaWrite::performAction
areaMesh areaMesh
); );
writeSurface(writer, fld, fieldName); writeSurface(writer, &fld, fieldName);
} }
else else
{ {
writeSurface const auto* fieldPtr =
( areaMesh.thisDb().cfindObject<GeoField>(fieldName);
writer,
areaMesh.thisDb().lookupObject<GeoField>(fieldName), writeSurface(writer, fieldPtr, fieldName);
fieldName
);
} }
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment