From 0b6d0300c94631cf56d45953c2caf136368939c9 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Tue, 1 Jun 2010 17:23:47 +0100
Subject: [PATCH] ENH: cellSource postprocessing : allow all to select all
 cells

---
 .../field/fieldValues/cellSource/cellSource.C | 78 +++++++++----------
 .../field/fieldValues/cellSource/cellSource.H |  3 +-
 2 files changed, 37 insertions(+), 44 deletions(-)

diff --git a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C
index 97cd9393bd6..7f20d750473 100644
--- a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C
+++ b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C
@@ -32,14 +32,11 @@ License
 defineTypeNameAndDebug(Foam::fieldValues::cellSource, 0);
 
 template<>
-const char* Foam::NamedEnum<Foam::fieldValues::cellSource::sourceType, 1>::
-names[] =
-{
-    "cellZone"
-};
+const char* NamedEnum<fieldValues::cellSource::sourceType, 2>::
+names[] = {"cellZone", "all"};
 
-const Foam::NamedEnum<Foam::fieldValues::cellSource::sourceType, 1>
-    Foam::fieldValues::cellSource::sourceTypeNames_;
+const NamedEnum<fieldValues::cellSource::sourceType, 2>
+    fieldValues::cellSource::sourceTypeNames_;
 
 template<>
 const char* Foam::NamedEnum<Foam::fieldValues::cellSource::operationType, 7>::
@@ -57,35 +54,43 @@ const Foam::NamedEnum<Foam::fieldValues::cellSource::operationType, 7>
 
 void Foam::fieldValues::cellSource::setCellZoneCells()
 {
-    label zoneId = mesh().cellZones().findZoneID(sourceName_);
-
-    if (zoneId < 0)
+    switch (source_)
     {
-        FatalErrorIn("cellSource::cellSource::setCellZoneCells()")
-            << "Unknown cell zone name: " << sourceName_
-            << ". Valid cell zones are: " << mesh().cellZones().names()
-            << nl << exit(FatalError);
-    }
-
-    const cellZone& cZone = mesh().cellZones()[zoneId];
+        case stCellZone:
+        {
+            label zoneId = mesh().cellZones().findZoneID(sourceName_);
+
+            if (zoneId < 0)
+            {
+                FatalErrorIn("cellSource::cellSource::setCellZoneCells()")
+                    << "Unknown cell zone name: " << sourceName_
+                    << ". Valid cell zones are: " << mesh().cellZones().names()
+                    << nl << exit(FatalError);
+            }
+
+            cellId_ = mesh().cellZones()[zoneId];
+            nCells_ = returnReduce(cellId_.size(), sumOp<label>());
+            break;
+        }
 
-    cellId_.setSize(cZone.size());
+        case stAll:
+        {
+            cellId_ = identity(mesh().nCells());
+            nCells_ = returnReduce(cellId_.size(), sumOp<label>());
+            break;
+        }
 
-    label count = 0;
-    forAll(cZone, i)
-    {
-        label cellI = cZone[i];
-        cellId_[count] = cellI;
-        count++;
+        default:
+        {
+            FatalErrorIn("cellSource::setCellZoneCells()")
+               << "Unknown source type. Valid source types are:"
+                << sourceTypeNames_ << nl << exit(FatalError);
+        }
     }
 
-    cellId_.setSize(count);
-    nCells_ = returnReduce(cellId_.size(), sumOp<label>());
-
     if (debug)
     {
-        Pout<< "Original cell zone size = " << cZone.size()
-            << ", new size = " << count << endl;
+        Pout<< "Selected source size = " << cellId_.size() << endl;
     }
 }
 
@@ -94,20 +99,7 @@ void Foam::fieldValues::cellSource::setCellZoneCells()
 
 void Foam::fieldValues::cellSource::initialise(const dictionary& dict)
 {
-    switch (source_)
-    {
-        case stCellZone:
-        {
-            setCellZoneCells();
-            break;
-        }
-        default:
-        {
-            FatalErrorIn("cellSource::initialise()")
-                << "Unknown source type. Valid source types are:"
-                << sourceTypeNames_ << nl << exit(FatalError);
-        }
-    }
+    setCellZoneCells();
 
     Info<< type() << " " << name_ << ":" << nl
         << "    total cells  = " << nCells_ << nl
diff --git a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H
index c271a1c997a..44f836428a9 100644
--- a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H
+++ b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.H
@@ -89,7 +89,8 @@ public:
         //- Source type enumeration
         enum sourceType
         {
-            stCellZone
+            stCellZone,
+            stAll
         };
 
         //- Source type names
-- 
GitLab