Merge branch 'feature-reactionSensitivity' into 'develop'

reactionSensitivityAnalysis FO

 This function object creates four data files named:

    "consumption"    :   consumption rate
    "production"     :   destruction rate
    "productionInt"  :   integral between dumps of the production rate
    "consumptionInt" :   integral between dumps of the consumption rate

    The function object indicates reaction rates of creation or destruction of species in each reaction.

code:
        src/postProcessing/functionObjects/utilities/reactionSensitivityAnalysis/
tutorial:
         /tutorials/combustion/chemFoam/gri

The output format file is (consumption.dat):

time :        1e-2
dellat T:   1e-5
Reaction         specie1  specie2 ....
1                          RR11       RR12
2                          RR21       RR22
.
.



See merge request !44
This commit is contained in:
Andrew Heather 2016-06-03 17:21:46 +01:00
commit feab373f69
8 changed files with 701 additions and 1 deletions

View File

@ -50,4 +50,6 @@ yPlus/yPlusFunctionObject.C
setTimeStep/setTimeStepFunctionObject.C
reactionSensitivityAnalysis/reactionsSensitivityAnalysisFunctionObject.C
LIB = $(FOAM_LIBBIN)/libutilityFunctionObjects

View File

@ -8,6 +8,9 @@ EXE_INC = \
-I$(LIB_SRC)/TurbulenceModels/compressible/lnInclude \
-I$(LIB_SRC)/transportModels/compressible/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/chemistryModel/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/reactionThermo/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude \
@ -27,4 +30,6 @@ LIB_LIBS = \
-lfiniteVolume \
-lmeshTools \
-lsampling \
-lsurfMesh
-lsurfMesh \
-lchemistryModel \
-lreactionThermophysicalModels

View File

@ -0,0 +1,321 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd
\\/ 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 "reactionsSensitivityAnalysis.H"
#include "dictionary.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class chemistryType>
void Foam::reactionsSensitivityAnalysis<chemistryType>::createFileNames()
{
if (writeToFile() && !prodFilePtr_.valid())
{
prodFilePtr_ = createFile("production");
writeHeader(prodFilePtr_(), "production");
writeFileHeader(prodFilePtr_());
consFilePtr_ = createFile("consumption");
writeHeader(consFilePtr_(), "consumption");
writeFileHeader(consFilePtr_());
prodIntFilePtr_ = createFile("productionInt");
writeHeader(prodIntFilePtr_(), "productionInt");
writeFileHeader(prodIntFilePtr_());
consIntFilePtr_ = createFile("consumptionInt");
writeHeader(consIntFilePtr_(), "consumptionInt");
writeFileHeader(consIntFilePtr_());
}
}
template<class chemistryType>
void Foam::reactionsSensitivityAnalysis<chemistryType>::writeFileHeader
(
OFstream& os
)
{
writeCommented(os, "Reaction");
forAll(speciesNames_, k)
{
os << tab << speciesNames_[k] << tab;
}
os << nl << endl;
}
template<class chemistryType>
void Foam::reactionsSensitivityAnalysis<chemistryType>::calculateSpeciesRR
(
const basicChemistryModel& basicChemistry
)
{
tmp<DimensionedField<scalar, volMesh> > RRt
(
new DimensionedField<scalar, volMesh>
(
IOobject
(
"RR",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("zero", dimMass/dimVolume/dimTime, 0.0)
)
);
DimensionedField<scalar, volMesh>& RR = RRt.ref();
scalar dt = mesh_.time().deltaT().value();
endTime_ += dt;
forAll(production_, specieI)
{
forAll(production_[specieI], reactionI)
{
RR = basicChemistry.calculateRR(reactionI, specieI);
if (RR[0] > 0.0)
{
production_[specieI][reactionI] = RR[0];
productionInt_[specieI][reactionI] =+ dt*RR[0];
}
else if (RR[0] < 0.0)
{
consumption_[specieI][reactionI] = RR[0];
consumptionInt_[specieI][reactionI] =+ dt*RR[0];
}
else
{
production_[specieI][reactionI] = 0.0;
consumption_[specieI][reactionI] = 0.0;
}
}
}
}
template<class chemistryType>
void Foam::reactionsSensitivityAnalysis<chemistryType>::writeSpeciesRR()
{
consFilePtr_() << "time : " << mesh_.time().value() << tab << nl;
consFilePtr_() << "delta T : "<< mesh_.time().deltaT().value() << nl << nl;
prodFilePtr_() << "time : " << mesh_.time().value() << tab << nl;
prodFilePtr_() << "delta T : "<< mesh_.time().deltaT().value() << nl << nl;
consIntFilePtr_() << "start time : " << startTime_ << tab
<< "end time :" << endTime_ << nl;
prodIntFilePtr_() << "start time : " << startTime_ << tab
<< "end time :" << endTime_ << nl;
for
(
label reactionI = 0; reactionI < nReactions_; reactionI++
)
{
consFilePtr_() << reactionI << tab;
consIntFilePtr_() << reactionI << tab;
prodFilePtr_() << reactionI << tab;
prodIntFilePtr_() << reactionI << tab;
forAll(speciesNames_, i)
{
prodFilePtr_() << production_[i][reactionI] << tab;
consFilePtr_() << consumption_[i][reactionI] << tab;
prodIntFilePtr_() << productionInt_[i][reactionI] << tab;
consIntFilePtr_() << consumptionInt_[i][reactionI] << tab;
consumptionInt_[i][reactionI] = 0.0;
productionInt_[i][reactionI] = 0.0;
}
consFilePtr_() << nl;
consIntFilePtr_() << nl;
prodFilePtr_() << nl;
prodIntFilePtr_() << nl;
}
consFilePtr_() << nl << nl;
consIntFilePtr_() << nl << nl;
prodFilePtr_() << nl << nl;
prodIntFilePtr_() << nl << nl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class chemistryType>
Foam::reactionsSensitivityAnalysis<chemistryType>::reactionsSensitivityAnalysis
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles
)
:
functionObjectFile(obr, name),
name_(name),
mesh_(refCast<const fvMesh>(obr)),
active_(true),
production_(0),
consumption_(0),
productionInt_(0),
consumptionInt_(0),
startTime_(0),
endTime_(0),
speciesNames_(),
nReactions_(0),
prodFilePtr_(),
consFilePtr_(),
prodIntFilePtr_(),
consIntFilePtr_()
{
read(dict);
if (mesh_.nCells() != 1)
{
FatalErrorInFunction
<< "Function object only applicable to single cell cases "
<< abort(FatalError);
}
if (mesh_.foundObject<basicChemistryModel>("chemistryProperties"))
{
const chemistryType& chemistry = refCast<const chemistryType>
(
mesh_.lookupObject<basicChemistryModel>("chemistryProperties")
);
speciesNames_.setSize
(
chemistry.thermo().composition().species().size()
);
forAll(speciesNames_, i)
{
speciesNames_[i] = chemistry.thermo().composition().species()[i];
}
nReactions_ = chemistry.nReaction();
if (production_.size() == 0)
{
production_.setSize(speciesNames_.size());
consumption_.setSize(production_.size());
productionInt_.setSize(production_.size());
consumptionInt_.setSize(production_.size());
forAll(production_, i)
{
production_[i].setSize(nReactions_, 0.0);
consumption_[i].setSize(nReactions_, 0.0);
productionInt_[i].setSize(nReactions_, 0.0);
consumptionInt_[i].setSize(nReactions_, 0.0);
}
}
}
else
{
FatalErrorInFunction
<< " Not chemistry model found. "
<< " Object available are : " << mesh_.names()
<< exit(FatalError);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class chemistryType>
Foam::reactionsSensitivityAnalysis<chemistryType>::
~reactionsSensitivityAnalysis()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class chemistryType>
void Foam::reactionsSensitivityAnalysis<chemistryType>::read
(
const dictionary& dict
)
{}
template<class chemistryType>
void Foam::reactionsSensitivityAnalysis<chemistryType>::execute()
{
createFileNames();
const basicChemistryModel& chemistry =
mesh_.lookupObject<basicChemistryModel>
(
"chemistryProperties"
);
calculateSpeciesRR(chemistry);
}
template<class chemistryType>
void Foam::reactionsSensitivityAnalysis<chemistryType>::end()
{
// Do nothing - only valid on write
}
template<class chemistryType>
void Foam::reactionsSensitivityAnalysis<chemistryType>::timeSet()
{
// Do nothing
}
template<class chemistryType>
void Foam::reactionsSensitivityAnalysis<chemistryType>::write()
{
if (!active_)
{
return;
}
if (Pstream::master())
{
//functionObjectFile::write();
writeSpeciesRR();
startTime_ = endTime_;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,220 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd
\\/ 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::reactionsSensitivityAnalysis
Group
grpUtilitiesFunctionObjects
Description
This function object creates four data files named:
"consumption" : consumption rate
"production" : destruction rate
"productionInt" : integral between dumps of the production rate
"consumptionInt" : integral between dumps of the consumption rate
The function object indicates reaction rates of creation or destruction
of species in each reaction.
SourceFiles
reactionsSensitivityAnalysis.C
IOreactionsSensitivityAnalysis.H
\*---------------------------------------------------------------------------*/
#ifndef reactionsSensitivityAnalysis_H
#define reactionsSensitivityAnalysis_H
#include "functionObjectFile.H"
#include "volFields.H"
#include "basicChemistryModel.H"
#include "autoPtr.H"
#include "basicMultiComponentMixture.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class objectRegistry;
class dictionary;
/*---------------------------------------------------------------------------*\
Class reactionsSensitivityAnalysis Declaration
\*---------------------------------------------------------------------------*/
template<class chemistryType>
class reactionsSensitivityAnalysis
:
public functionObjectFile
{
// Private data
//- Name of this set of reactionsSensitivityAnalysis objects
word name_;
//- Reference to the mesh database
const fvMesh& mesh_;
//- On/off switch
bool active_;
//- List list for species production
scalarListList production_;
//- List list for species consumption
scalarListList consumption_;
//- List list for species production integral
scalarListList productionInt_;
//- List list for species consumption integral
scalarListList consumptionInt_;
//- Start time of integration
scalar startTime_;
//- End time of integration
scalar endTime_;
//- Word list of species
wordList speciesNames_;
//-Number of reactions
label nReactions_;
// File streams
//- Integrated coefficients
autoPtr<OFstream> prodFilePtr_;
//- Moment coefficient
autoPtr<OFstream> consFilePtr_;
//- Drag coefficient
autoPtr<OFstream> prodIntFilePtr_;
//- Lift coefficient
autoPtr<OFstream> consIntFilePtr_;
// Private Member Functions
//- Create file names for forces and bins
void createFileNames();
//- Output file header information
void writeFileHeader(OFstream& os);
//- Calculate production and destruction of each species
void calculateSpeciesRR(const basicChemistryModel&);
//- Write species production/consumption rates
void writeSpeciesRR();
//- Disallow default bitwise copy construct
reactionsSensitivityAnalysis(const reactionsSensitivityAnalysis&);
//- Disallow default bitwise assignment
void operator=(const reactionsSensitivityAnalysis&);
public:
//- Runtime type information
TypeName("reactionsSensitivityAnalysis");
// Constructors
//- Construct for given objectRegistry and dictionary.
// Allow the possibility to load fields from files
reactionsSensitivityAnalysis
(
const word& name,
const objectRegistry&,
const dictionary&,
const bool loadFromFiles = false
);
//- Destructor
virtual ~reactionsSensitivityAnalysis();
// Member Functions
//- Return name of the set of reactionsSensitivityAnalysis
virtual const word& name() const
{
return name_;
}
//- Read the reactionsSensitivityAnalysis data
virtual void read(const dictionary&);
//- Execute, currently does nothing
virtual void execute();
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Called when time was set at the end of the Time::operator++
virtual void timeSet();
//- Calculate the reactionsSensitivityAnalysis and write
virtual void write();
//- Update for changes of mesh
virtual void updateMesh(const mapPolyMesh&)
{}
//- Update for changes of mesh
virtual void movePoints(const polyMesh&)
{}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "reactionsSensitivityAnalysis.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,75 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd
\\/ 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 "reactionsSensitivityAnalysisFunctionObject.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTemplateTypeNameAndDebugWithName
(
reactionsSensitivityAnalysis<rhoChemistryModel>,
"rhoReactionsSensitivityAnalysis",
0
);
defineTemplateTypeNameAndDebugWithName
(
rhoReactionsSensitivityAnalysisFunctionObject,
"rhoReactionsSensitivityAnalysis",
0
);
addToRunTimeSelectionTable
(
functionObject,
rhoReactionsSensitivityAnalysisFunctionObject,
dictionary
);
defineTemplateTypeNameAndDebugWithName
(
reactionsSensitivityAnalysis<psiChemistryModel>,
"psiReactionsSensitivityAnalysis",
0
);
defineTemplateTypeNameAndDebugWithName
(
psiReactionsSensitivityAnalysisFunctionObject,
"psiReactionsSensitivityAnalysis",
0
);
addToRunTimeSelectionTable
(
functionObject,
psiReactionsSensitivityAnalysisFunctionObject,
dictionary
);
}
// ************************************************************************* //

View File

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd
\\/ 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/>.
Typedef
Foam::reactionsSensitivityAnalysisFunctionObject
Description
FunctionObject wrapper around reactionsSensitivityAnalysis to allow
it to be created via the functions entry within controlDict.
SourceFiles
reactionsSensitivityAnalysisFunctionObject.C
\*---------------------------------------------------------------------------*/
#ifndef reactionsSensitivityAnalysisFunctionObject_H
#define reactionsSensitivityAnalysisFunctionObject_H
#include "OutputFilterFunctionObject.H"
#include "reactionsSensitivityAnalysis.H"
#include "rhoChemistryModel.H"
#include "psiChemistryModel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef OutputFilterFunctionObject
<
reactionsSensitivityAnalysis<rhoChemistryModel>
> rhoReactionsSensitivityAnalysisFunctionObject;
typedef OutputFilterFunctionObject
<
reactionsSensitivityAnalysis<psiChemistryModel>
> psiReactionsSensitivityAnalysisFunctionObject;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -175,6 +175,9 @@ public:
//- Return the heat release, i.e. enthalpy/sec [m2/s3]
virtual tmp<volScalarField> dQ() const = 0;
//- Return number of reactions
virtual label nReaction() const = 0;
};

View File

@ -52,4 +52,14 @@ DebugSwitches
SolverPerformance 0;
}
functions
{
sensitivityAnalysis
{
functionObjectLibs ( "libutilityFunctionObjects.so" );
type psiReactionsSensitivityAnalysis;
outputControl outputTime;
enabled true;
}
}
// ************************************************************************* //