From 225c6777b28e81eb87b23dfbcc2c49fd128f7033 Mon Sep 17 00:00:00 2001
From: Henry Weller <http://cfd.direct>
Date: Wed, 10 Aug 2016 19:48:43 +0100
Subject: [PATCH] functionObjects::specieReactionRates: New functionObject to
 write the domain averaged reaction rates for each specie for each reaction

---
 .../chemistryModel/Make/files                 |   2 +
 .../basicChemistryModel/basicChemistryModel.H |   6 +
 .../chemistryModel/chemistryModel.H           |   4 +-
 .../specieReactionRates/specieReactionRates.C | 202 ++++++++++++++++++
 .../specieReactionRates/specieReactionRates.H | 126 +++++++++++
 5 files changed, 338 insertions(+), 2 deletions(-)
 create mode 100644 src/thermophysicalModels/chemistryModel/functionObjects/specieReactionRates/specieReactionRates.C
 create mode 100644 src/thermophysicalModels/chemistryModel/functionObjects/specieReactionRates/specieReactionRates.H

diff --git a/src/thermophysicalModels/chemistryModel/Make/files b/src/thermophysicalModels/chemistryModel/Make/files
index d0782c33b90..19e704dcfc5 100644
--- a/src/thermophysicalModels/chemistryModel/Make/files
+++ b/src/thermophysicalModels/chemistryModel/Make/files
@@ -11,4 +11,6 @@ chemistryModel/TDACChemistryModel/tabulation/makeChemistryTabulationMethods.C
 
 chemistrySolver/chemistrySolver/makeChemistrySolvers.C
 
+functionObjects/specieReactionRates/specieReactionRates.C
+
 LIB = $(FOAM_LIBBIN)/libchemistryModel
diff --git a/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModel.H b/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModel.H
index c91c2975fde..17b64f542b6 100644
--- a/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModel.H
+++ b/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModel.H
@@ -124,6 +124,12 @@ public:
         //- Chemistry activation switch
         inline Switch chemistry() const;
 
+        //- The number of species
+        virtual label nSpecie() const = 0;
+
+        //- The number of reactions
+        virtual label nReaction() const = 0;
+
         //- Return the latest estimation of integration step
         inline const volScalarField::Internal& deltaTChem() const;
 
diff --git a/src/thermophysicalModels/chemistryModel/chemistryModel/chemistryModel/chemistryModel.H b/src/thermophysicalModels/chemistryModel/chemistryModel/chemistryModel/chemistryModel.H
index f5ee5f6f3d7..98b2ec2a915 100644
--- a/src/thermophysicalModels/chemistryModel/chemistryModel/chemistryModel/chemistryModel.H
+++ b/src/thermophysicalModels/chemistryModel/chemistryModel/chemistryModel/chemistryModel.H
@@ -141,10 +141,10 @@ public:
         inline const PtrList<ThermoType>& specieThermo() const;
 
         //- The number of species
-        inline label nSpecie() const;
+        virtual inline label nSpecie() const;
 
         //- The number of reactions
-        inline label nReaction() const;
+        virtual inline label nReaction() const;
 
         //- Temperature below which the reaction rates are assumed 0
         inline scalar Treact() const;
diff --git a/src/thermophysicalModels/chemistryModel/functionObjects/specieReactionRates/specieReactionRates.C b/src/thermophysicalModels/chemistryModel/functionObjects/specieReactionRates/specieReactionRates.C
new file mode 100644
index 00000000000..5c141767714
--- /dev/null
+++ b/src/thermophysicalModels/chemistryModel/functionObjects/specieReactionRates/specieReactionRates.C
@@ -0,0 +1,202 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2016 OpenFOAM Foundation
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "specieReactionRates.H"
+#include "volFields.H"
+#include "fvcVolumeIntegrate.H"
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+template<class ChemistryModelType>
+void Foam::functionObjects::specieReactionRates<ChemistryModelType>::
+writeFileHeader
+(
+    const label i
+)
+{
+    writeHeader(file(), "Specie reaction rates");
+    writeHeaderValue(file(), "nSpecie", chemistryModel_.nSpecie());
+    writeHeaderValue(file(), "nReaction", chemistryModel_.nReaction());
+
+    writeCommented(file(), "Time");
+    writeTabbed(file(), "Reaction");
+
+    const wordList& speciesNames =
+        chemistryModel_.thermo().composition().species();
+
+    forAll (speciesNames, si)
+    {
+        writeTabbed(file(), speciesNames[si]);
+    }
+
+    file() << endl;
+}
+
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+template<class ChemistryModelType>
+Foam::functionObjects::specieReactionRates<ChemistryModelType>::
+specieReactionRates
+(
+    const word& name,
+    const Time& runTime,
+    const dictionary& dict
+)
+:
+    fvMeshFunctionObject(name, runTime, dict),
+    logFiles(obr_, name),
+    chemistryModel_
+    (
+        mesh_.lookupObject<ChemistryModelType>("chemistryProperties")
+    )
+{
+    resetName("specieReactionRates");
+}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+template<class ChemistryModelType>
+Foam::functionObjects::specieReactionRates<ChemistryModelType>::
+~specieReactionRates()
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+template<class ChemistryModelType>
+bool Foam::functionObjects::specieReactionRates<ChemistryModelType>::read
+(
+    const dictionary& dict
+)
+{
+    regionFunctionObject::read(dict);
+
+    return true;
+}
+
+
+template<class ChemistryModelType>
+bool Foam::functionObjects::specieReactionRates<ChemistryModelType>::execute()
+{
+    return true;
+}
+
+
+template<class ChemistryModelType>
+bool Foam::functionObjects::specieReactionRates<ChemistryModelType>::write()
+{
+    logFiles::write();
+
+    const label nSpecie = chemistryModel_.nSpecie();
+    const label nReaction = chemistryModel_.nReaction();
+
+    // Domain volume
+    const scalar V = gSum(mesh_.V());
+
+    for (label ri=0; ri<nReaction; ri++)
+    {
+        if (Pstream::master())
+        {
+            writeTime(file());
+            file() << token::TAB << ri;
+        }
+
+        for (label si=0; si<nSpecie; si++)
+        {
+            volScalarField::Internal RR
+            (
+                chemistryModel_.calculateRR(ri, si)
+            );
+
+            if (Pstream::master())
+            {
+                file() << token::TAB << fvc::domainIntegrate(RR).value()/V;
+            }
+        }
+
+        if (Pstream::master())
+        {
+            file() << nl;
+        }
+    }
+
+    if (Pstream::master())
+    {
+        file() << nl << endl;
+    }
+
+    return true;
+}
+
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+#include "addToRunTimeSelectionTable.H"
+#include "rhoChemistryModel.H"
+#include "psiChemistryModel.H"
+
+namespace Foam
+{
+namespace functionObjects
+{
+    typedef specieReactionRates<psiChemistryModel> psiSpecieReactionRates;
+
+    defineTemplateTypeNameAndDebugWithName
+    (
+        psiSpecieReactionRates,
+        "psiSpecieReactionRates",
+        0
+    );
+
+    addToRunTimeSelectionTable
+    (
+        functionObject,
+        psiSpecieReactionRates,
+        dictionary
+    );
+
+
+    typedef specieReactionRates<rhoChemistryModel> rhoSpecieReactionRates;
+
+    defineTemplateTypeNameAndDebugWithName
+    (
+        rhoSpecieReactionRates,
+        "rhoSpecieReactionRates",
+        0
+    );
+
+    addToRunTimeSelectionTable
+    (
+        functionObject,
+        rhoSpecieReactionRates,
+        dictionary
+    );
+}
+}
+
+
+// ************************************************************************* //
diff --git a/src/thermophysicalModels/chemistryModel/functionObjects/specieReactionRates/specieReactionRates.H b/src/thermophysicalModels/chemistryModel/functionObjects/specieReactionRates/specieReactionRates.H
new file mode 100644
index 00000000000..65bd9645535
--- /dev/null
+++ b/src/thermophysicalModels/chemistryModel/functionObjects/specieReactionRates/specieReactionRates.H
@@ -0,0 +1,126 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2016 OpenFOAM Foundation
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+Class
+    Foam::functionObjects::specieReactionRates
+
+Group
+    grpFieldFunctionObjects
+
+Description
+    Writes the domain averaged reaction rates for each specie for each reaction
+    into the file \<timeDir\>/specieReactionRates.dat
+
+See also
+    Foam::functionObjects::fvMeshFunctionObject
+    Foam::functionObjects::logFiles
+
+SourceFiles
+    specieReactionRates.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef functionObjects_specieReactionRates_H
+#define functionObjects_specieReactionRates_H
+
+#include "fvMeshFunctionObject.H"
+#include "logFiles.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+namespace functionObjects
+{
+
+/*---------------------------------------------------------------------------*\
+                          Class specieReactionRates Declaration
+\*---------------------------------------------------------------------------*/
+
+template<class ChemistryModelType>
+class specieReactionRates
+:
+    public fvMeshFunctionObject,
+    public logFiles
+{
+    // Private Member Data
+
+        const ChemistryModelType& chemistryModel_;
+
+
+    // Private Member Functions
+
+        //- File header information
+        virtual void writeFileHeader(const label i);
+
+        //- Disallow default bitwise copy construct
+        specieReactionRates(const specieReactionRates&);
+
+        //- Disallow default bitwise assignment
+        void operator=(const specieReactionRates&);
+
+
+public:
+
+    //- Runtime type information
+    TypeName("specieReactionRates");
+
+
+    // Constructors
+
+        //- Construct from Time and dictionary
+        specieReactionRates
+        (
+            const word& name,
+            const Time& runTime,
+            const dictionary& dict
+        );
+
+
+    //- Destructor
+    virtual ~specieReactionRates();
+
+
+    // Member Functions
+
+        //- Read the specieReactionRates data
+        virtual bool read(const dictionary&);
+
+        //- Do nothing
+        virtual bool execute();
+
+        //- Write the specie reaction rates
+        virtual bool write();
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace functionObjects
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
-- 
GitLab