diff --git a/src/postProcessing/functionObjects/utilities/Make/files b/src/postProcessing/functionObjects/utilities/Make/files index 1cee77173d..e9b8fed150 100644 --- a/src/postProcessing/functionObjects/utilities/Make/files +++ b/src/postProcessing/functionObjects/utilities/Make/files @@ -50,4 +50,6 @@ yPlus/yPlusFunctionObject.C setTimeStep/setTimeStepFunctionObject.C +reactionSensitivityAnalysis/reactionsSensitivityAnalysisFunctionObject.C + LIB = $(FOAM_LIBBIN)/libutilityFunctionObjects diff --git a/src/postProcessing/functionObjects/utilities/Make/options b/src/postProcessing/functionObjects/utilities/Make/options index da63b33ea2..82ceb9db5f 100644 --- a/src/postProcessing/functionObjects/utilities/Make/options +++ b/src/postProcessing/functionObjects/utilities/Make/options @@ -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 \ No newline at end of file diff --git a/src/postProcessing/functionObjects/utilities/reactionSensitivityAnalysis/reactionsSensitivityAnalysis.C b/src/postProcessing/functionObjects/utilities/reactionSensitivityAnalysis/reactionsSensitivityAnalysis.C new file mode 100644 index 0000000000..14616b7225 --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/reactionSensitivityAnalysis/reactionsSensitivityAnalysis.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#include "reactionsSensitivityAnalysis.H" +#include "dictionary.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +void Foam::reactionsSensitivityAnalysis::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 +void Foam::reactionsSensitivityAnalysis::writeFileHeader +( + OFstream& os +) +{ + writeCommented(os, "Reaction"); + + forAll(speciesNames_, k) + { + os << tab << speciesNames_[k] << tab; + } + + os << nl << endl; +} + + +template +void Foam::reactionsSensitivityAnalysis::calculateSpeciesRR +( + const basicChemistryModel& basicChemistry +) +{ + + tmp > RRt + ( + new DimensionedField + ( + IOobject + ( + "RR", + mesh_.time().timeName(), + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh_, + dimensionedScalar("zero", dimMass/dimVolume/dimTime, 0.0) + ) + ); + + DimensionedField& 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 +void Foam::reactionsSensitivityAnalysis::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 +Foam::reactionsSensitivityAnalysis::reactionsSensitivityAnalysis +( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + const bool loadFromFiles +) +: + functionObjectFile(obr, name), + name_(name), + mesh_(refCast(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("chemistryProperties")) + { + const chemistryType& chemistry = refCast + ( + mesh_.lookupObject("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 +Foam::reactionsSensitivityAnalysis:: +~reactionsSensitivityAnalysis() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::reactionsSensitivityAnalysis::read +( + const dictionary& dict +) +{} + + +template +void Foam::reactionsSensitivityAnalysis::execute() +{ + createFileNames(); + + const basicChemistryModel& chemistry = + mesh_.lookupObject + ( + "chemistryProperties" + ); + calculateSpeciesRR(chemistry); +} + + +template +void Foam::reactionsSensitivityAnalysis::end() +{ + // Do nothing - only valid on write +} + + +template +void Foam::reactionsSensitivityAnalysis::timeSet() +{ + // Do nothing +} + + +template +void Foam::reactionsSensitivityAnalysis::write() +{ + if (!active_) + { + return; + } + + if (Pstream::master()) + { + //functionObjectFile::write(); + + writeSpeciesRR(); + + startTime_ = endTime_; + } +} + + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/utilities/reactionSensitivityAnalysis/reactionsSensitivityAnalysis.H b/src/postProcessing/functionObjects/utilities/reactionSensitivityAnalysis/reactionsSensitivityAnalysis.H new file mode 100644 index 0000000000..270d0f4056 --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/reactionSensitivityAnalysis/reactionsSensitivityAnalysis.H @@ -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 . + +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 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 prodFilePtr_; + + //- Moment coefficient + autoPtr consFilePtr_; + + //- Drag coefficient + autoPtr prodIntFilePtr_; + + //- Lift coefficient + autoPtr 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 + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/utilities/reactionSensitivityAnalysis/reactionsSensitivityAnalysisFunctionObject.C b/src/postProcessing/functionObjects/utilities/reactionSensitivityAnalysis/reactionsSensitivityAnalysisFunctionObject.C new file mode 100644 index 0000000000..01110e17c8 --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/reactionSensitivityAnalysis/reactionsSensitivityAnalysisFunctionObject.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#include "reactionsSensitivityAnalysisFunctionObject.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTemplateTypeNameAndDebugWithName + ( + reactionsSensitivityAnalysis, + "rhoReactionsSensitivityAnalysis", + 0 + ); + + defineTemplateTypeNameAndDebugWithName + ( + rhoReactionsSensitivityAnalysisFunctionObject, + "rhoReactionsSensitivityAnalysis", + 0 + ); + + addToRunTimeSelectionTable + ( + functionObject, + rhoReactionsSensitivityAnalysisFunctionObject, + dictionary + ); + + defineTemplateTypeNameAndDebugWithName + ( + reactionsSensitivityAnalysis, + "psiReactionsSensitivityAnalysis", + 0 + ); + + defineTemplateTypeNameAndDebugWithName + ( + psiReactionsSensitivityAnalysisFunctionObject, + "psiReactionsSensitivityAnalysis", + 0 + ); + + addToRunTimeSelectionTable + ( + functionObject, + psiReactionsSensitivityAnalysisFunctionObject, + dictionary + ); +} + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/utilities/reactionSensitivityAnalysis/reactionsSensitivityAnalysisFunctionObject.H b/src/postProcessing/functionObjects/utilities/reactionSensitivityAnalysis/reactionsSensitivityAnalysisFunctionObject.H new file mode 100644 index 0000000000..7abeca2d78 --- /dev/null +++ b/src/postProcessing/functionObjects/utilities/reactionSensitivityAnalysis/reactionsSensitivityAnalysisFunctionObject.H @@ -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 . + +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 + > rhoReactionsSensitivityAnalysisFunctionObject; + + + typedef OutputFilterFunctionObject + < + reactionsSensitivityAnalysis + > psiReactionsSensitivityAnalysisFunctionObject; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModel.H b/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModel.H index eb927e71b2..8f8c39dcab 100644 --- a/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModel.H +++ b/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModel.H @@ -175,6 +175,9 @@ public: //- Return the heat release, i.e. enthalpy/sec [m2/s3] virtual tmp dQ() const = 0; + + //- Return number of reactions + virtual label nReaction() const = 0; }; diff --git a/tutorials/combustion/chemFoam/gri/system/controlDict b/tutorials/combustion/chemFoam/gri/system/controlDict index 9daf656f3c..ff0400dd00 100644 --- a/tutorials/combustion/chemFoam/gri/system/controlDict +++ b/tutorials/combustion/chemFoam/gri/system/controlDict @@ -52,4 +52,14 @@ DebugSwitches SolverPerformance 0; } +functions +{ + sensitivityAnalysis + { + functionObjectLibs ( "libutilityFunctionObjects.so" ); + type psiReactionsSensitivityAnalysis; + outputControl outputTime; + enabled true; + } +} // ************************************************************************* //