From 3bf2984e352ad7448b2bf8b1f6f4f3ccdecb260e Mon Sep 17 00:00:00 2001
From: andy <andy>
Date: Wed, 2 Feb 2011 10:26:53 +0000
Subject: [PATCH] ENH: Deactivate face/cell sources if no faces/cells present

---
 .../field/fieldValues/cellSource/cellSource.C | 19 +++++++++++++++++--
 .../field/fieldValues/faceSource/faceSource.C | 16 +++++++++++++++-
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C
index 896026c3567..31b96f7e98f 100644
--- a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C
+++ b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2009-2010 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2009-2011 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -122,7 +122,22 @@ void Foam::fieldValues::cellSource::initialise(const dictionary& dict)
 {
     setCellZoneCells();
 
-    Info<< type() << " " << name_ << ":" << nl
+    if (nCells_ == 0)
+    {
+        WarningIn
+        (
+            "Foam::fieldValues::cellSource::initialise(const dictionary&)"
+        )
+            << type() << " " << name_ << ": "
+            << sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
+            << "    Source has no cells - deactivating" << endl;
+
+        active_ = false;
+        return;
+    }
+
+    Info<< type() << " " << name_ << ":"
+        << sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
         << "    total cells  = " << nCells_ << nl
         << "    total volume = " << gSum(filterField(mesh().V()))
         << nl << endl;
diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C
index 838658d1a26..259692c5f99 100644
--- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C
+++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2009-2010 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2009-2011 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -249,6 +249,20 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict)
         }
     }
 
+    if (nFaces_ == 0)
+    {
+        WarningIn
+        (
+            "Foam::fieldValues::faceSource::initialise(const dictionary&)"
+        )
+            << type() << " " << name_ << ": "
+            << sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
+            << "    Source has no faces - deactivating" << endl;
+
+        active_ = false;
+        return;
+    }
+
     scalar totalArea;
 
     if (surfacePtr_.valid())
-- 
GitLab