From 2e3f0811a039c1438bd2429ba24154abc2e4799d Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 30 Aug 2023 16:08:30 +0200 Subject: [PATCH] ENH: error handling for empty surfaces in surfaceFieldValue (#2966) - for workflows with appearing/disappearing patches (for example) can specify that empty surfaces should be ignored or warned about instead of raising a FatalError. Note that this handling is additional to the regular top-level "errors" specification. So specifying 'strict' will only actually result in a FatalError if the "errors" does not trap errors. - "ignore" : any empty surfaces are simply ignored and no file output (besides the header). - "warn" : empty surfaces are warned about a few times (10) and the file output contains a NaN entry - "strict" : corresponds to the default behaviour. Throws a FatalError if the surface is empty. This error may still be caught by the top-level "errors" handling. --- .../surfaceFieldValue/surfaceFieldValue.C | 326 ++++++++++++++---- .../surfaceFieldValue/surfaceFieldValue.H | 10 +- 2 files changed, 267 insertions(+), 69 deletions(-) diff --git a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C index 0b8517c8a7..98bf75f3ef 100644 --- a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C +++ b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C @@ -37,6 +37,9 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // +// Max number of warnings +static constexpr const unsigned maxWarnings = 10u; + namespace Foam { namespace functionObjects @@ -135,39 +138,13 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::setFaceZoneFaces() mesh_.faceZones().indices(selectionNames_) ); - // Total number of faces selected + // Total number of faces that could be selected (before patch filtering) label numFaces = 0; for (const label zoneId : zoneIds) { numFaces += mesh_.faceZones()[zoneId].size(); } - if (zoneIds.empty()) - { - FatalErrorInFunction - << type() << ' ' << name() << ": " - << regionTypeNames_[regionType_] << '(' << regionName_ << "):" << nl - << " No matching face zone(s): " - << flatOutput(selectionNames_) << nl - << " Known face zones: " - << flatOutput(mesh_.faceZones().names()) << nl - << exit(FatalError); - } - - // Could also check this - #if 0 - if (!returnReduceOr(numFaces)) - { - WarningInFunction - << type() << ' ' << name() << ": " - << regionTypeNames_[regionType_] << '(' << regionName_ << "):" << nl - << " The faceZone specification: " - << flatOutput(selectionNames_) << nl - << " resulted in 0 faces" << nl - << exit(FatalError); - } - #endif - faceId_.resize_nocopy(numFaces); facePatchId_.resize_nocopy(numFaces); faceFlip_.resize_nocopy(numFaces); @@ -223,7 +200,75 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::setFaceZoneFaces() faceId_.resize(numFaces); facePatchId_.resize(numFaces); faceFlip_.resize(numFaces); - nFaces_ = returnReduce(faceId_.size(), sumOp