From 127002427325bc8114a91c740487b07fa4a4a00e Mon Sep 17 00:00:00 2001
From: Andrew Heather <>
Date: Fri, 3 Jan 2020 17:06:05 +0000
Subject: [PATCH] ENH: SemiImplicitSource - simplified handling of enums

---
 .../semiImplicitSource/SemiImplicitSource.C   | 57 ++++---------------
 .../semiImplicitSource/SemiImplicitSource.H   | 10 +---
 2 files changed, 14 insertions(+), 53 deletions(-)

diff --git a/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSource.C b/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSource.C
index 62b71fb3361..1f76d81df21 100644
--- a/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSource.C
+++ b/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSource.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
+    Copyright (C) 2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -33,55 +34,19 @@ License
 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
 
 template<class Type>
-const Foam::wordList Foam::fv::SemiImplicitSource<Type>::volumeModeTypeNames_
-{
-    "absolute", "specific"
-};
+const Foam::Enum
+<
+    typename Foam::fv::SemiImplicitSource<Type>::volumeModeType
+>
+Foam::fv::SemiImplicitSource<Type>::volumeModeTypeNames_
+({
+    { volumeModeType::vmAbsolute, "absolute" },
+    { volumeModeType::vmSpecific, "specific" },
+});
 
 
 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
 
-template<class Type>
-typename Foam::fv::SemiImplicitSource<Type>::volumeModeType
-Foam::fv::SemiImplicitSource<Type>::wordToVolumeModeType
-(
-    const word& vmtName
-) const
-{
-    forAll(volumeModeTypeNames_, i)
-    {
-        if (vmtName == volumeModeTypeNames_[i])
-        {
-            return volumeModeType(i);
-        }
-    }
-
-    FatalErrorInFunction
-        << "Unknown volumeMode type " << vmtName
-        << ". Valid volumeMode types are:" << nl << volumeModeTypeNames_
-        << exit(FatalError);
-
-    return volumeModeType(0);
-}
-
-
-template<class Type>
-Foam::word Foam::fv::SemiImplicitSource<Type>::volumeModeTypeToWord
-(
-    const volumeModeType& vmtType
-) const
-{
-    if (vmtType > volumeModeTypeNames_.size())
-    {
-        return "UNKNOWN";
-    }
-    else
-    {
-        return volumeModeTypeNames_[vmtType];
-    }
-}
-
-
 template<class Type>
 void Foam::fv::SemiImplicitSource<Type>::setFieldData(const dictionary& dict)
 {
@@ -207,7 +172,7 @@ bool Foam::fv::SemiImplicitSource<Type>::read(const dictionary& dict)
 {
     if (cellSetOption::read(dict))
     {
-        volumeMode_ = wordToVolumeModeType(coeffs_.get<word>("volumeMode"));
+        volumeMode_ = volumeModeTypeNames_.get("volumeMode", coeffs_);
         setFieldData(coeffs_.subDict("injectionRateSuSp"));
 
         return true;
diff --git a/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSource.H b/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSource.H
index 52af960bcc9..ba9a8bef3ec 100644
--- a/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSource.H
+++ b/src/fvOptions/sources/general/semiImplicitSource/SemiImplicitSource.H
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
+    Copyright (C) 2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -72,6 +73,7 @@ SourceFiles
 
 #include "Tuple2.H"
 #include "cellSetOption.H"
+#include "Enum.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -112,7 +114,7 @@ public:
         };
 
         //- Word list of volume mode type names
-        static const wordList volumeModeTypeNames_;
+        static const Enum<volumeModeType> volumeModeTypeNames_;
 
 
 protected:
@@ -131,12 +133,6 @@ protected:
 
     // Protected functions
 
-        //- Helper function to convert from a word to a volumeModeType
-        volumeModeType wordToVolumeModeType(const word& vtName) const;
-
-        //- Helper function to convert from a volumeModeType to a word
-        word volumeModeTypeToWord(const volumeModeType& vtType) const;
-
         //- Set the local field data
         void setFieldData(const dictionary& dict);
 
-- 
GitLab