From c13199d3cef5a17f9e0f3a1bb00b6c50a719d0a0 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Wed, 2 Jan 2019 14:44:21 +0100
Subject: [PATCH] STYLE: make chemistryReader private inheritance (issue #1144)

- The chemistryReader is only used during construction of reactingMixture
  and thus does not require public visibility.
---
 .../chemistryReader/chemistryReader.C         | 11 +++----
 .../chemistryReader/chemistryReader.H         | 12 +------
 .../foamChemistryReader/foamChemistryReader.C | 14 ++++----
 .../foamChemistryReader/foamChemistryReader.H |  3 +-
 .../mixtures/SpecieMixture/SpecieMixture.H    | 10 ++++--
 .../basicCombustionMixture.H                  |  9 +++--
 .../basicMultiComponentMixture.H              |  9 +++--
 .../basicSpecieMixture/basicSpecieMixture.H   |  9 +++--
 .../mixtures/egrMixture/egrMixture.H          | 11 +++++--
 .../homogeneousMixture/homogeneousMixture.H   | 16 +++++----
 .../inhomogeneousMixture.H                    | 14 ++++++--
 .../multiComponentMixture.H                   | 14 +++++---
 .../reactingMixture/reactingMixture.C         | 19 ++++++++---
 .../reactingMixture/reactingMixture.H         | 33 ++++++++-----------
 .../singleComponentMixture.C                  |  7 ----
 .../singleComponentMixture.H                  |  9 +++--
 .../singleStepReactingMixture.C               |  6 ++--
 .../veryInhomogeneousMixture.H                | 13 +++++---
 18 files changed, 117 insertions(+), 102 deletions(-)

diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemistryReader/chemistryReader.C b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemistryReader/chemistryReader.C
index 69032a11694..bc1af21c14c 100644
--- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemistryReader/chemistryReader.C
+++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemistryReader/chemistryReader.C
@@ -35,12 +35,11 @@ Foam::chemistryReader<ThermoType>::New
     speciesTable& species
 )
 {
-    // Let the chemistry reader type default to CHEMKIN
-    // for backward compatibility
-    word readerName("chemkinReader");
-
-    // otherwise use the specified reader
-    thermoDict.readIfPresent("chemistryReader", readerName);
+    // Use specified reader or default to CHEMKIN for backward compatibility
+    const word readerName
+    (
+        thermoDict.lookupOrDefault<word>("chemistryReader", "chemkinReader")
+    );
 
     Info<< "Selecting chemistryReader " << readerName << endl;
 
diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemistryReader/chemistryReader.H b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemistryReader/chemistryReader.H
index c9a2e1fc6a4..859256fca86 100644
--- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemistryReader/chemistryReader.H
+++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemistryReader/chemistryReader.H
@@ -59,15 +59,6 @@ typedef HashTable<List<specieElement>> speciesCompositionTable;
 template<class ThermoType>
 class chemistryReader
 {
-    // Private Member Functions
-
-        //- No copy construct
-        chemistryReader(const chemistryReader&) = delete;
-
-        //- No copy assignment
-        void operator=(const chemistryReader&) = delete;
-
-
 public:
 
     //- Runtime type information
@@ -110,8 +101,7 @@ public:
 
 
     //- Destructor
-    virtual ~chemistryReader()
-    {}
+    virtual ~chemistryReader() = default;
 
 
     // Member Functions
diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/foamChemistryReader/foamChemistryReader.C b/src/thermophysicalModels/reactionThermo/chemistryReaders/foamChemistryReader/foamChemistryReader.C
index 8d4df109569..a2f618052ab 100644
--- a/src/thermophysicalModels/reactionThermo/chemistryReaders/foamChemistryReader/foamChemistryReader.C
+++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/foamChemistryReader/foamChemistryReader.C
@@ -36,7 +36,7 @@ Foam::speciesTable& Foam::foamChemistryReader<ThermoType>::setSpecies
     speciesTable& species
 )
 {
-    wordList s(dict.lookup("species"));
+    wordList s(dict.get<wordList>("species"));
     species.transfer(s);
     return species;
 }
@@ -51,23 +51,23 @@ void Foam::foamChemistryReader<ThermoType>::readSpeciesComposition()
         return;
     }
 
-    wordList e(chemDict_.lookup("elements"));
+    wordList e(chemDict_.get<wordList>("elements"));
     label currentElementIndex(0);
 
     DynamicList<word> elementNames_;
     HashTable<label> elementIndices_;
 
-    forAll(e, ei)
+    for (const word& elemName : e)
     {
-        if (!elementIndices_.found(e[ei]))
+        if (!elementIndices_.found(elemName))
         {
-            elementIndices_.insert(e[ei], currentElementIndex++);
-            elementNames_.append(e[ei]);
+            elementIndices_.insert(elemName, currentElementIndex++);
+            elementNames_.append(elemName);
         }
         else
         {
             IOWarningInFunction(chemDict_)
-                << "element " << e[ei] << " already in table." << endl;
+                << "element " << elemName << " already in table." << endl;
         }
     }
 
diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/foamChemistryReader/foamChemistryReader.H b/src/thermophysicalModels/reactionThermo/chemistryReaders/foamChemistryReader/foamChemistryReader.H
index 4caa30ee3e7..74dbe24f968 100644
--- a/src/thermophysicalModels/reactionThermo/chemistryReaders/foamChemistryReader/foamChemistryReader.H
+++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/foamChemistryReader/foamChemistryReader.H
@@ -126,8 +126,7 @@ public:
 
 
     //- Destructor
-    virtual ~foamChemistryReader()
-    {}
+    virtual ~foamChemistryReader() = default;
 
 
     // Member functions
diff --git a/src/thermophysicalModels/reactionThermo/mixtures/SpecieMixture/SpecieMixture.H b/src/thermophysicalModels/reactionThermo/mixtures/SpecieMixture/SpecieMixture.H
index f4a20ca9e65..a8a7627e3b5 100644
--- a/src/thermophysicalModels/reactionThermo/mixtures/SpecieMixture/SpecieMixture.H
+++ b/src/thermophysicalModels/reactionThermo/mixtures/SpecieMixture/SpecieMixture.H
@@ -66,12 +66,16 @@ public:
     // Constructors
 
         //- Construct from dictionary, mesh and phase name
-        SpecieMixture(const dictionary&, const fvMesh&, const word& phaseName);
+        SpecieMixture
+        (
+            const dictionary& thermoDict,
+            const fvMesh& mesh,
+            const word& phaseName
+        );
 
 
     //- Destructor
-    virtual ~SpecieMixture()
-    {}
+    virtual ~SpecieMixture() = default;
 
 
     // Member functions
diff --git a/src/thermophysicalModels/reactionThermo/mixtures/basicCombustionMixture/basicCombustionMixture.H b/src/thermophysicalModels/reactionThermo/mixtures/basicCombustionMixture/basicCombustionMixture.H
index f192ef1c53c..a1c3b8d45bd 100644
--- a/src/thermophysicalModels/reactionThermo/mixtures/basicCombustionMixture/basicCombustionMixture.H
+++ b/src/thermophysicalModels/reactionThermo/mixtures/basicCombustionMixture/basicCombustionMixture.H
@@ -69,16 +69,15 @@ public:
         //- Construct from dictionary, specie names, mesh and phase name
         basicCombustionMixture
         (
-            const dictionary&,
+            const dictionary& thermoDict,
             const wordList& specieNames,
-            const fvMesh&,
-            const word&
+            const fvMesh& mesh,
+            const word& phaseName
         );
 
 
     //- Destructor
-    virtual ~basicCombustionMixture()
-    {}
+    virtual ~basicCombustionMixture() = default;
 
 
     // Member functions
diff --git a/src/thermophysicalModels/reactionThermo/mixtures/basicMultiComponentMixture/basicMultiComponentMixture.H b/src/thermophysicalModels/reactionThermo/mixtures/basicMultiComponentMixture/basicMultiComponentMixture.H
index ad2babab73a..1ad9cd123d3 100644
--- a/src/thermophysicalModels/reactionThermo/mixtures/basicMultiComponentMixture/basicMultiComponentMixture.H
+++ b/src/thermophysicalModels/reactionThermo/mixtures/basicMultiComponentMixture/basicMultiComponentMixture.H
@@ -90,16 +90,15 @@ public:
         //- Construct from dictionary, species names, mesh and phase name
         basicMultiComponentMixture
         (
-            const dictionary&,
+            const dictionary& thermoDict,
             const wordList& specieNames,
-            const fvMesh&,
-            const word&
+            const fvMesh& mesh,
+            const word& phaseName
         );
 
 
     //- Destructor
-    virtual ~basicMultiComponentMixture()
-    {}
+    virtual ~basicMultiComponentMixture() = default;
 
 
     // Member functions
diff --git a/src/thermophysicalModels/reactionThermo/mixtures/basicSpecieMixture/basicSpecieMixture.H b/src/thermophysicalModels/reactionThermo/mixtures/basicSpecieMixture/basicSpecieMixture.H
index f1d1856d001..624266aeda1 100644
--- a/src/thermophysicalModels/reactionThermo/mixtures/basicSpecieMixture/basicSpecieMixture.H
+++ b/src/thermophysicalModels/reactionThermo/mixtures/basicSpecieMixture/basicSpecieMixture.H
@@ -69,16 +69,15 @@ public:
         //- Construct from dictionary, species names, mesh and phase name
         basicSpecieMixture
         (
-            const dictionary&,
+            const dictionary& thermoDict,
             const wordList& specieNames,
-            const fvMesh&,
-            const word&
+            const fvMesh& mesh,
+            const word& phaseName
         );
 
 
     //- Destructor
-    virtual ~basicSpecieMixture()
-    {}
+    virtual ~basicSpecieMixture() = default;
 
 
     // Member functions
diff --git a/src/thermophysicalModels/reactionThermo/mixtures/egrMixture/egrMixture.H b/src/thermophysicalModels/reactionThermo/mixtures/egrMixture/egrMixture.H
index d3f64ce2748..ae3c0947d58 100644
--- a/src/thermophysicalModels/reactionThermo/mixtures/egrMixture/egrMixture.H
+++ b/src/thermophysicalModels/reactionThermo/mixtures/egrMixture/egrMixture.H
@@ -76,8 +76,8 @@ class egrMixture
         //- Residual gases
         volScalarField& egr_;
 
-        //- Construct as copy (not implemented)
-        egrMixture(const egrMixture<ThermoType>&);
+        //- No copy construct
+        egrMixture(const egrMixture<ThermoType>&) = delete;
 
 
 public:
@@ -89,7 +89,12 @@ public:
     // Constructors
 
         //- Construct from dictionary, mesh and phaseName
-        egrMixture(const dictionary&, const fvMesh&, const word&);
+        egrMixture
+        (
+            const dictionary& thermoDict,
+            const fvMesh& mesh,
+            const word& phaseName
+        );
 
 
     //- Destructor
diff --git a/src/thermophysicalModels/reactionThermo/mixtures/homogeneousMixture/homogeneousMixture.H b/src/thermophysicalModels/reactionThermo/mixtures/homogeneousMixture/homogeneousMixture.H
index 4e4e2e50e19..3c600668e8d 100644
--- a/src/thermophysicalModels/reactionThermo/mixtures/homogeneousMixture/homogeneousMixture.H
+++ b/src/thermophysicalModels/reactionThermo/mixtures/homogeneousMixture/homogeneousMixture.H
@@ -64,12 +64,12 @@ class homogeneousMixture
 
         mutable ThermoType mixture_;
 
-        //- Construct as copy (not implemented)
-        homogeneousMixture(const homogeneousMixture<ThermoType>&);
-
         //- Regress variable
         volScalarField& b_;
 
+        //- No copy construct
+        homogeneousMixture(const homogeneousMixture<ThermoType>&) = delete;
+
 
 public:
 
@@ -80,12 +80,16 @@ public:
     // Constructors
 
         //- Construct from dictionary, mesh and phase name
-        homogeneousMixture(const dictionary&, const fvMesh&, const word&);
+        homogeneousMixture
+        (
+            const dictionary& thermoDict,
+            const fvMesh& mesh,
+            const word& phaseName
+        );
 
 
     //- Destructor
-    virtual ~homogeneousMixture()
-    {}
+    virtual ~homogeneousMixture() = default;
 
 
     // Member functions
diff --git a/src/thermophysicalModels/reactionThermo/mixtures/inhomogeneousMixture/inhomogeneousMixture.H b/src/thermophysicalModels/reactionThermo/mixtures/inhomogeneousMixture/inhomogeneousMixture.H
index 28078850599..efebb9fa512 100644
--- a/src/thermophysicalModels/reactionThermo/mixtures/inhomogeneousMixture/inhomogeneousMixture.H
+++ b/src/thermophysicalModels/reactionThermo/mixtures/inhomogeneousMixture/inhomogeneousMixture.H
@@ -73,8 +73,11 @@ class inhomogeneousMixture
         //- Regress variable
         volScalarField& b_;
 
-        //- Construct as copy (not implemented)
-        inhomogeneousMixture(const inhomogeneousMixture<ThermoType>&);
+        //- No copy construct
+        inhomogeneousMixture
+        (
+            const inhomogeneousMixture<ThermoType>&
+        ) = delete;
 
 
 public:
@@ -86,7 +89,12 @@ public:
     // Constructors
 
         //- Construct from dictionary, mesh and phase name
-        inhomogeneousMixture(const dictionary&, const fvMesh&, const word&);
+        inhomogeneousMixture
+        (
+            const dictionary& thermoDict,
+            const fvMesh& mesh,
+            const word& phaseName
+        );
 
 
     //- Destructor
diff --git a/src/thermophysicalModels/reactionThermo/mixtures/multiComponentMixture/multiComponentMixture.H b/src/thermophysicalModels/reactionThermo/mixtures/multiComponentMixture/multiComponentMixture.H
index 071eb76ffcd..b467cabbafd 100644
--- a/src/thermophysicalModels/reactionThermo/mixtures/multiComponentMixture/multiComponentMixture.H
+++ b/src/thermophysicalModels/reactionThermo/mixtures/multiComponentMixture/multiComponentMixture.H
@@ -96,17 +96,21 @@ public:
             const dictionary&,
             const wordList& specieNames,
             const HashPtrTable<ThermoType>& thermoData,
-            const fvMesh&,
-            const word&
+            const fvMesh& mesh,
+            const word& phaseName
         );
 
         //- Construct from dictionary, mesh and phase name
-        multiComponentMixture(const dictionary&, const fvMesh&, const word&);
+        multiComponentMixture
+        (
+            const dictionary& thermoDict,
+            const fvMesh& mesh,
+            const word& phaseName
+        );
 
 
     //- Destructor
-    virtual ~multiComponentMixture()
-    {}
+    virtual ~multiComponentMixture() = default;
 
 
     // Member functions
diff --git a/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.C b/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.C
index 124d9a76cc8..0652e4a213b 100644
--- a/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.C
+++ b/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.C
@@ -26,6 +26,16 @@ License
 #include "reactingMixture.H"
 #include "fvMesh.H"
 
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+template<class ThermoType>
+Foam::autoPtr<Foam::chemistryReader<ThermoType>>&
+Foam::reactingMixture<ThermoType>::reader()
+{
+    return static_cast<autoPtr<chemistryReader<ThermoType>>&>(*this);
+}
+
+
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 template<class ThermoType>
@@ -45,20 +55,21 @@ Foam::reactingMixture<ThermoType>::reactingMixture
     (
         thermoDict,
         *this,
-        autoPtr<chemistryReader<ThermoType>>::operator()().speciesThermo(),
+        this->reader()->speciesThermo(),
         mesh,
         phaseName
     ),
     PtrList<Reaction<ThermoType>>
     (
-        autoPtr<chemistryReader<ThermoType>>::operator()().reactions()
+        this->reader()->reactions()
     ),
     speciesComposition_
     (
-        autoPtr<chemistryReader<ThermoType>>::operator()().specieComposition()
+        this->reader()->specieComposition()
     )
 {
-    autoPtr<chemistryReader<ThermoType>>::clear();
+    // Done with reader
+    reader().clear();
 }
 
 
diff --git a/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.H b/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.H
index 774d2b11790..dc0abf3a935 100644
--- a/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.H
+++ b/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.H
@@ -55,11 +55,11 @@ template<class ThermoType>
 class reactingMixture
 :
     public speciesTable,
-    public autoPtr<chemistryReader<ThermoType>>,
+    private autoPtr<chemistryReader<ThermoType>>,
     public multiComponentMixture<ThermoType>,
     public PtrList<Reaction<ThermoType>>
 {
-    // Private member data
+    // Private Member Data
 
         //- Table of species composition
         speciesCompositionTable speciesComposition_;
@@ -67,6 +67,9 @@ class reactingMixture
 
     // Private Member Functions
 
+        //- The chemistry reader
+        autoPtr<chemistryReader<ThermoType>>& reader();
+
         //- No copy construct
         reactingMixture(const reactingMixture&) = delete;
 
@@ -83,12 +86,16 @@ public:
     // Constructors
 
         //- Construct from dictionary, mesh and phase name
-        reactingMixture(const dictionary&, const fvMesh&, const word&);
+        reactingMixture
+        (
+            const dictionary& thermoDict,
+            const fvMesh& mesh,
+            const word& phaseName
+        );
 
 
     //- Destructor
-    virtual ~reactingMixture()
-    {}
+    virtual ~reactingMixture() = default;
 
 
     // Member functions
@@ -102,20 +109,8 @@ public:
         //- Read dictionary
         void read(const dictionary&);
 
-        label size() const
-        {
-            return PtrList<Reaction<ThermoType>>::size();
-        }
-
-        Reaction<ThermoType>& operator[](const label i)
-        {
-            return PtrList<Reaction<ThermoType>>::operator[](i);
-        }
-
-        const Reaction<ThermoType>& operator[](const label i) const
-        {
-            return PtrList<Reaction<ThermoType>>::operator[](i);
-        }
+        using PtrList<Reaction<ThermoType>>::size;
+        using PtrList<Reaction<ThermoType>>::operator[];
 
         //- Table of species composition
         const speciesCompositionTable& specieComposition() const
diff --git a/src/thermophysicalModels/reactionThermo/mixtures/singleComponentMixture/singleComponentMixture.C b/src/thermophysicalModels/reactionThermo/mixtures/singleComponentMixture/singleComponentMixture.C
index b8374445dc9..637736dd2d6 100644
--- a/src/thermophysicalModels/reactionThermo/mixtures/singleComponentMixture/singleComponentMixture.C
+++ b/src/thermophysicalModels/reactionThermo/mixtures/singleComponentMixture/singleComponentMixture.C
@@ -40,13 +40,6 @@ Foam::singleComponentMixture<ThermoType>::singleComponentMixture
 {}
 
 
-// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
-
-template<class ThermoType>
-Foam::singleComponentMixture<ThermoType>::~singleComponentMixture()
-{}
-
-
 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
 
 template<class ThermoType>
diff --git a/src/thermophysicalModels/reactionThermo/mixtures/singleComponentMixture/singleComponentMixture.H b/src/thermophysicalModels/reactionThermo/mixtures/singleComponentMixture/singleComponentMixture.H
index 7067d07081b..1870877b8cd 100644
--- a/src/thermophysicalModels/reactionThermo/mixtures/singleComponentMixture/singleComponentMixture.H
+++ b/src/thermophysicalModels/reactionThermo/mixtures/singleComponentMixture/singleComponentMixture.H
@@ -66,11 +66,16 @@ public:
     // Constructors
 
         //- Construct from dictionary, mesh and phase name
-        singleComponentMixture(const dictionary&, const fvMesh&, const word&);
+        singleComponentMixture
+        (
+            const dictionary& thermoDict,
+            const fvMesh& mesh,
+            const word& phaseName
+        );
 
 
     //- Destructor
-    virtual ~singleComponentMixture();
+    virtual ~singleComponentMixture() = default;
 
 
     // Member Functions
diff --git a/src/thermophysicalModels/reactionThermo/mixtures/singleStepReactingMixture/singleStepReactingMixture.C b/src/thermophysicalModels/reactionThermo/mixtures/singleStepReactingMixture/singleStepReactingMixture.C
index 01b48e5dbdc..4b915c2ca31 100644
--- a/src/thermophysicalModels/reactionThermo/mixtures/singleStepReactingMixture/singleStepReactingMixture.C
+++ b/src/thermophysicalModels/reactionThermo/mixtures/singleStepReactingMixture/singleStepReactingMixture.C
@@ -32,7 +32,7 @@ template<class ThermoType>
 void Foam::singleStepReactingMixture<ThermoType>::calculateqFuel()
 {
     const Reaction<ThermoType>& reaction = this->operator[](0);
-    const  scalar Wu = this->speciesData()[fuelIndex_].W();
+    const scalar Wu = this->speciesData()[fuelIndex_].W();
 
     forAll(reaction.lhs(), i)
     {
@@ -134,7 +134,7 @@ void Foam::singleStepReactingMixture<ThermoType>::fresCorrect()
 {
     const Reaction<ThermoType>& reaction = this->operator[](0);
 
-    label O2Index = this->species()["O2"];
+    const label O2Index = this->species()["O2"];
     const volScalarField& YFuel = this->Y()[fuelIndex_];
     const volScalarField& YO2 = this->Y()[O2Index];
 
@@ -236,8 +236,6 @@ Foam::singleStepReactingMixture<ThermoType>::singleStepReactingMixture
         massAndAirStoichRatios();
 
         calculateMaxProducts();
-
-        autoPtr<chemistryReader<ThermoType>>::clear();
     }
     else
     {
diff --git a/src/thermophysicalModels/reactionThermo/mixtures/veryInhomogeneousMixture/veryInhomogeneousMixture.H b/src/thermophysicalModels/reactionThermo/mixtures/veryInhomogeneousMixture/veryInhomogeneousMixture.H
index fe662be3529..e6ab583aa01 100644
--- a/src/thermophysicalModels/reactionThermo/mixtures/veryInhomogeneousMixture/veryInhomogeneousMixture.H
+++ b/src/thermophysicalModels/reactionThermo/mixtures/veryInhomogeneousMixture/veryInhomogeneousMixture.H
@@ -76,8 +76,11 @@ class veryInhomogeneousMixture
         //- Regress variable
         volScalarField& b_;
 
-        //- Construct as copy (not implemented)
-        veryInhomogeneousMixture(const veryInhomogeneousMixture<ThermoType>&);
+        //- No copy construct
+        veryInhomogeneousMixture
+        (
+            const veryInhomogeneousMixture<ThermoType>&
+        ) = delete;
 
 
 public:
@@ -91,9 +94,9 @@ public:
         //- Construct from dictionary, mesh and phase name
         veryInhomogeneousMixture
         (
-            const dictionary&,
-            const fvMesh&,
-            const word&
+            const dictionary& thermoDict,
+            const fvMesh& mesh,
+            const word& phaseName
         );
 
 
-- 
GitLab