From 4214a95553c3c50a9747bad790cb02241e63ba7f Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Thu, 20 May 2021 15:16:58 +0200 Subject: [PATCH] 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. --- .../utilities/areaWrite/areaWrite.H | 9 +++-- .../utilities/areaWrite/areaWriteTemplates.C | 34 +++++++++++++------ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/functionObjects/utilities/areaWrite/areaWrite.H b/src/functionObjects/utilities/areaWrite/areaWrite.H index 832bc00f321..fdcec555c3f 100644 --- a/src/functionObjects/utilities/areaWrite/areaWrite.H +++ b/src/functionObjects/utilities/areaWrite/areaWrite.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -144,12 +144,15 @@ class areaWrite // 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> void writeSurface ( surfaceWriter& writer, - const Field<Type>& values, + const Field<Type>* fieldPtr, const word& fieldName ); diff --git a/src/functionObjects/utilities/areaWrite/areaWriteTemplates.C b/src/functionObjects/utilities/areaWrite/areaWriteTemplates.C index 1a6813fcbf3..f100554d6e1 100644 --- a/src/functionObjects/utilities/areaWrite/areaWriteTemplates.C +++ b/src/functionObjects/utilities/areaWrite/areaWriteTemplates.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,10 +35,12 @@ template<class Type> void Foam::areaWrite::writeSurface ( surfaceWriter& writer, - const Field<Type>& values, + const Field<Type>* fieldPtr, const word& fieldName ) { + const Field<Type>& values = (fieldPtr ? *fieldPtr : Field<Type>::null()); + fileName outputName = writer.write(fieldName, values); // Case-local file name with "<case>" to make relocatable @@ -64,11 +66,23 @@ void Foam::areaWrite::performAction wordList fieldNames; if (loadFromFiles_) { - fieldNames = objects.sortedNames<GeoField>(fieldSelection_); + // With syncPar (sorted and parallel-consistent) + fieldNames = objects.names<GeoField>(fieldSelection_, true); } 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) @@ -92,16 +106,14 @@ void Foam::areaWrite::performAction areaMesh ); - writeSurface(writer, fld, fieldName); + writeSurface(writer, &fld, fieldName); } else { - writeSurface - ( - writer, - areaMesh.thisDb().lookupObject<GeoField>(fieldName), - fieldName - ); + const auto* fieldPtr = + areaMesh.thisDb().cfindObject<GeoField>(fieldName); + + writeSurface(writer, fieldPtr, fieldName); } } } -- GitLab