From a6948a1c1231cdfea4b23373134cc16ac68e5a56 Mon Sep 17 00:00:00 2001 From: sergio Date: Thu, 21 Feb 2013 15:05:11 +0000 Subject: [PATCH 01/23] ENH: Changing name from ODESolidChemistryModel to solidChemistryModel, adding a base class basicSolidChemistryModel and deriving pyrolysisSolidChemistry model for solid --- .../pyrolysisModels/noPyrolysis/noPyrolysis.C | 4 +- .../pyrolysisModels/noPyrolysis/noPyrolysis.H | 6 +- .../reactingOneDim/reactingOneDim.C | 6 +- .../reactingOneDim/reactingOneDim.H | 6 +- .../solidChemistryModel/Make/files | 6 +- .../basicSolidChemistryModel.C | 56 ++++ .../basicSolidChemistryModel.H | 167 +++++++++++ .../basicSolidChemistryModelI.H | 41 +++ .../basicSolidChemistryModelNew.C} | 9 +- .../basicSolidChemistryModels.C} | 11 +- .../makeSolidChemistryModel.H | 14 +- .../pyrolysisChemistryModel.C} | 276 +++++------------- .../pyrolysisChemistryModel.H} | 101 ++----- .../pyrolysisChemistryModelI.H} | 102 +------ .../solidChemistryModel/solidChemistryModel.C | 192 +++++++++++- .../solidChemistryModel/solidChemistryModel.H | 195 +++++++++---- .../solidChemistryModelI.H | 81 ++++- .../makeSolidChemistrySolverType.H | 14 +- .../makeSolidChemistrySolvers.C | 10 +- .../Reactions/solidReaction/solidReaction.C | 20 +- .../constant/panelRegion/chemistryProperties | 2 +- 21 files changed, 812 insertions(+), 507 deletions(-) create mode 100644 src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModel.C create mode 100644 src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModel.H create mode 100644 src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModelI.H rename src/thermophysicalModels/solidChemistryModel/{solidChemistryModel/solidChemistryModelNew.C => basicSolidChemistryModel/basicSolidChemistryModelNew.C} (95%) rename src/thermophysicalModels/solidChemistryModel/{solidChemistryModel/solidChemistryModels.C => basicSolidChemistryModel/basicSolidChemistryModels.C} (88%) rename src/thermophysicalModels/solidChemistryModel/{ODESolidChemistryModel/ODESolidChemistryModel.C => pyrolysisChemistryModel/pyrolysisChemistryModel.C} (68%) rename src/thermophysicalModels/solidChemistryModel/{ODESolidChemistryModel/ODESolidChemistryModel.H => pyrolysisChemistryModel/pyrolysisChemistryModel.H} (67%) rename src/thermophysicalModels/solidChemistryModel/{ODESolidChemistryModel/ODESolidChemistryModelI.H => pyrolysisChemistryModel/pyrolysisChemistryModelI.H} (52%) diff --git a/src/regionModels/pyrolysisModels/noPyrolysis/noPyrolysis.C b/src/regionModels/pyrolysisModels/noPyrolysis/noPyrolysis.C index 794b38514b..3cd4874317 100644 --- a/src/regionModels/pyrolysisModels/noPyrolysis/noPyrolysis.C +++ b/src/regionModels/pyrolysisModels/noPyrolysis/noPyrolysis.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -49,7 +49,7 @@ void noPyrolysis::constructThermoChemistry() { solidChemistry_.reset ( - solidChemistryModel::New(regionMesh()).ptr() + basicSolidChemistryModel::New(regionMesh()).ptr() ); solidThermo_.reset(&solidChemistry_->solidThermo()); diff --git a/src/regionModels/pyrolysisModels/noPyrolysis/noPyrolysis.H b/src/regionModels/pyrolysisModels/noPyrolysis/noPyrolysis.H index 87fbd604c7..055965d359 100644 --- a/src/regionModels/pyrolysisModels/noPyrolysis/noPyrolysis.H +++ b/src/regionModels/pyrolysisModels/noPyrolysis/noPyrolysis.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -37,7 +37,7 @@ SourceFiles #include "pyrolysisModel.H" #include "volFieldsFwd.H" -#include "solidChemistryModel.H" +#include "basicSolidChemistryModel.H" #include "radiationModel.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -82,7 +82,7 @@ protected: void constructThermoChemistry(); //- Reference to the solid chemistry model - autoPtr solidChemistry_; + autoPtr solidChemistry_; //- Reference to solid thermo autoPtr solidThermo_; diff --git a/src/regionModels/pyrolysisModels/reactingOneDim/reactingOneDim.C b/src/regionModels/pyrolysisModels/reactingOneDim/reactingOneDim.C index 84fb91407f..813b16c4a6 100644 --- a/src/regionModels/pyrolysisModels/reactingOneDim/reactingOneDim.C +++ b/src/regionModels/pyrolysisModels/reactingOneDim/reactingOneDim.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -303,7 +303,7 @@ void reactingOneDim::calculateMassTransfer() reactingOneDim::reactingOneDim(const word& modelType, const fvMesh& mesh) : pyrolysisModel(modelType, mesh), - solidChemistry_(solidChemistryModel::New(regionMesh())), + solidChemistry_(basicSolidChemistryModel::New(regionMesh())), solidThermo_(solidChemistry_->solidThermo()), radiation_(radiation::radiationModel::New(solidThermo_.T())), rho_ @@ -386,7 +386,7 @@ reactingOneDim::reactingOneDim ) : pyrolysisModel(modelType, mesh, dict), - solidChemistry_(solidChemistryModel::New(regionMesh())), + solidChemistry_(basicSolidChemistryModel::New(regionMesh())), solidThermo_(solidChemistry_->solidThermo()), radiation_(radiation::radiationModel::New(solidThermo_.T())), rho_ diff --git a/src/regionModels/pyrolysisModels/reactingOneDim/reactingOneDim.H b/src/regionModels/pyrolysisModels/reactingOneDim/reactingOneDim.H index 104e56c34e..c663941b44 100644 --- a/src/regionModels/pyrolysisModels/reactingOneDim/reactingOneDim.H +++ b/src/regionModels/pyrolysisModels/reactingOneDim/reactingOneDim.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -36,7 +36,7 @@ SourceFiles #define reactingOneDim_H #include "pyrolysisModel.H" -#include "solidChemistryModel.H" +#include "basicSolidChemistryModel.H" #include "radiationModel.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -76,7 +76,7 @@ protected: // Protected data //- Reference to the solid chemistry model - autoPtr solidChemistry_; + autoPtr solidChemistry_; //- Reference to solid thermo solidReactionThermo& solidThermo_; diff --git a/src/thermophysicalModels/solidChemistryModel/Make/files b/src/thermophysicalModels/solidChemistryModel/Make/files index 9f2b681e80..fcef028611 100644 --- a/src/thermophysicalModels/solidChemistryModel/Make/files +++ b/src/thermophysicalModels/solidChemistryModel/Make/files @@ -1,7 +1,7 @@ -solidChemistryModel/solidChemistryModel.C -solidChemistryModel/solidChemistryModelNew.C -solidChemistryModel/solidChemistryModels.C +basicSolidChemistryModel/basicSolidChemistryModel.C +basicSolidChemistryModel/basicSolidChemistryModelNew.C +basicSolidChemistryModel/basicSolidChemistryModels.C solidChemistrySolver/makeSolidChemistrySolvers.C diff --git a/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModel.C b/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModel.C new file mode 100644 index 0000000000..cfff71b9ed --- /dev/null +++ b/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModel.C @@ -0,0 +1,56 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 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 . + +\*---------------------------------------------------------------------------*/ + +#include "basicSolidChemistryModel.H" +#include "fvMesh.H" +#include "Time.H" + +/* * * * * * * * * * * * * * * private static data * * * * * * * * * * * * * */ + +namespace Foam +{ + defineTypeNameAndDebug(basicSolidChemistryModel, 0); + defineRunTimeSelectionTable(basicSolidChemistryModel, fvMesh); +} + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::basicSolidChemistryModel::basicSolidChemistryModel +( + const fvMesh& mesh +) +: + basicChemistryModel(mesh), + solidThermo_(solidReactionThermo::New(mesh)) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::basicSolidChemistryModel::~basicSolidChemistryModel() +{} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModel.H b/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModel.H new file mode 100644 index 0000000000..2134bffca1 --- /dev/null +++ b/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModel.H @@ -0,0 +1,167 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013-2013 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 . + +Class + Foam::basicSolidChemistryModel + +Description + Chemistry model for solid thermodynamics + +SourceFiles + basicSolidChemistryModelI.H + basicSolidChemistryModel.C + newChemistrySolidModel.C + +\*---------------------------------------------------------------------------*/ + +#ifndef basicSolidChemistryModel_H +#define basicSolidChemistryModel_H + +#include "basicChemistryModel.H" +#include "autoPtr.H" +#include "runTimeSelectionTables.H" +#include "solidReactionThermo.H" + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of classes +class fvMesh; + +/*---------------------------------------------------------------------------*\ + class basicSolidChemistryModel Declaration +\*---------------------------------------------------------------------------*/ + +class basicSolidChemistryModel +: + public basicChemistryModel +{ + // Private Member Functions + + //- Construct as copy (not implemented) + basicSolidChemistryModel(const basicSolidChemistryModel&); + + //- Disallow default bitwise assignment + void operator=(const basicSolidChemistryModel&); + + +protected: + + // Protected data + + //- Solid thermo package + autoPtr solidThermo_; + + +public: + + //- Runtime type information + TypeName("basicSolidChemistryModel"); + + + //- Declare run-time constructor selection tables + declareRunTimeSelectionTable + ( + autoPtr, + basicSolidChemistryModel, + fvMesh, + (const fvMesh& mesh), + (mesh) + ); + + + // Constructors + + //- Construct from mesh + basicSolidChemistryModel(const fvMesh& mesh); + + + //- Selector + static autoPtr New(const fvMesh& mesh); + + + //- Destructor + virtual ~basicSolidChemistryModel(); + + + // Member Functions + + //- Return access to the solid thermo package + inline solidReactionThermo& solidThermo(); + + //- Return const access to the solid thermo package + inline const solidReactionThermo& solidThermo() const; + + //- Return total gases mass source term [kg/m3/s] + virtual tmp > RRg() const = 0; + + //- Return total solids mass source term [kg/m3/s] + virtual tmp > RRs() const = 0; + + //- Return chemical source terms for solids [kg/m3/s] + virtual const DimensionedField& RRs + ( + const label i + ) const = 0; + + //- Return chemical source terms for gases [kg/m3/s] + virtual const DimensionedField& RRg + ( + const label i + ) const = 0; + + //- Return sensible enthalpy for gas i [J/Kg] + virtual tmp gasHs + ( + const volScalarField& p, + const volScalarField& T, + const label i + ) const = 0; + + //- Return specie Table for gases + virtual const speciesTable& gasTable() const = 0; + + //- Set reacting status of cell, cellI + virtual void setCellReacting(const label cellI, const bool active) = 0; + + //- Calculates the reaction rates + virtual void calculate() = 0; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "basicSolidChemistryModelI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModelI.H b/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModelI.H new file mode 100644 index 0000000000..48aa40841f --- /dev/null +++ b/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModelI.H @@ -0,0 +1,41 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013-2013 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 . + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +inline Foam::solidReactionThermo& Foam::basicSolidChemistryModel::solidThermo() +{ + return solidThermo_(); +} + + +inline const Foam::solidReactionThermo& +Foam::basicSolidChemistryModel::solidThermo() const +{ + return solidThermo_(); +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModelNew.C b/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModelNew.C similarity index 95% rename from src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModelNew.C rename to src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModelNew.C index ca97c91ace..adf318299f 100644 --- a/src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModelNew.C +++ b/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModelNew.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,11 +23,12 @@ License \*---------------------------------------------------------------------------*/ -#include "solidChemistryModel.H" +#include "basicSolidChemistryModel.H" // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // -Foam::autoPtr Foam::solidChemistryModel::New +Foam::autoPtr Foam::basicSolidChemistryModel:: +New ( const fvMesh& mesh ) @@ -160,7 +161,7 @@ Foam::autoPtr Foam::solidChemistryModel::New FatalError<< exit(FatalError); } - return autoPtr(cstrIter()(mesh)); + return autoPtr(cstrIter()(mesh)); } diff --git a/src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModels.C b/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModels.C similarity index 88% rename from src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModels.C rename to src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModels.C index d51976f196..905f6b17a2 100644 --- a/src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModels.C +++ b/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModels.C @@ -22,7 +22,7 @@ License along with OpenFOAM. If not, see . InClass - Foam::solidChemistryModel + Foam::basicSolidChemistryModel Description Creates solid chemistry model instances templated on the type of @@ -32,7 +32,8 @@ Description #include "makeSolidChemistryModel.H" -#include "ODESolidChemistryModel.H" +#include "pyrolysisChemistryModel.H" +#include "basicSolidChemistryModel.H" #include "solidChemistryModel.H" #include "solidThermoPhysicsTypes.H" #include "thermoPhysicsTypes.H" @@ -43,16 +44,18 @@ namespace Foam { makeSolidChemistryModel ( - ODESolidChemistryModel, solidChemistryModel, + pyrolysisChemistryModel, + basicSolidChemistryModel, hConstSolidThermoPhysics, gasHThermoPhysics ); makeSolidChemistryModel ( - ODESolidChemistryModel, solidChemistryModel, + pyrolysisChemistryModel, + basicSolidChemistryModel, hExponentialSolidThermoPhysics, gasHThermoPhysics ); diff --git a/src/thermophysicalModels/solidChemistryModel/makeSolidChemistryModel.H b/src/thermophysicalModels/solidChemistryModel/makeSolidChemistryModel.H index 779418d87b..747858d9ea 100644 --- a/src/thermophysicalModels/solidChemistryModel/makeSolidChemistryModel.H +++ b/src/thermophysicalModels/solidChemistryModel/makeSolidChemistryModel.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -30,6 +30,7 @@ Description #define makeSolidChemistryModel_H #include "addToRunTimeSelectionTable.H" +#include "solidChemistryModel.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -38,10 +39,19 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define makeSolidChemistryModel(SS, Comp, SThermo, GThermo) \ +#define makeSolidChemistryModel(sChemistry, SS, Comp, SThermo, GThermo) \ \ typedef SS SS##Comp##SThermo##GThermo; \ \ + typedef sChemistry sChemistryl##Comp##SThermo; \ + \ + defineTemplateTypeNameAndDebugWithName \ + ( \ + sChemistryl##Comp##SThermo, \ + (#sChemistry"<"#Comp"," + SThermo::typeName() + ">").c_str(), \ + 0 \ + ); \ + \ defineTemplateTypeNameAndDebugWithName \ ( \ SS##Comp##SThermo##GThermo, \ diff --git a/src/thermophysicalModels/solidChemistryModel/ODESolidChemistryModel/ODESolidChemistryModel.C b/src/thermophysicalModels/solidChemistryModel/pyrolysisChemistryModel/pyrolysisChemistryModel.C similarity index 68% rename from src/thermophysicalModels/solidChemistryModel/ODESolidChemistryModel/ODESolidChemistryModel.C rename to src/thermophysicalModels/solidChemistryModel/pyrolysisChemistryModel/pyrolysisChemistryModel.C index f61de4026b..e036fc7a1b 100644 --- a/src/thermophysicalModels/solidChemistryModel/ODESolidChemistryModel/ODESolidChemistryModel.C +++ b/src/thermophysicalModels/solidChemistryModel/pyrolysisChemistryModel/pyrolysisChemistryModel.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,73 +23,33 @@ License \*---------------------------------------------------------------------------*/ -#include "ODESolidChemistryModel.H" -#include "reactingMixture.H" +#include "pyrolysisChemistryModel.H" #include "solidReaction.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -Foam::ODESolidChemistryModel:: -ODESolidChemistryModel +Foam::pyrolysisChemistryModel:: +pyrolysisChemistryModel ( const fvMesh& mesh ) : - CompType(mesh), - ODE(), - Ys_(this->solidThermo().composition().Y()), - reactions_ - ( - dynamic_cast& > - ( - this->solidThermo() - ) - ), - pyrolisisGases_(reactions_[0].gasSpecies()), - solidThermo_ - ( - dynamic_cast& > - ( - this->solidThermo() - ).speciesData() - ), + solidChemistryModel(mesh), + pyrolisisGases_(this->reactions_[0].gasSpecies()), gasThermo_(pyrolisisGases_.size()), nGases_(pyrolisisGases_.size()), - nSpecie_(Ys_.size() + nGases_), - nSolids_(Ys_.size()), - nReaction_(reactions_.size()), - RRs_(nSolids_), + nSpecie_(this->Ys_.size() + nGases_), RRg_(nGases_), - Ys0_(nSolids_), - cellCounter_(0), - reactingCells_(mesh.nCells(), true) + Ys0_(this->nSolids_), + cellCounter_(0) { // create the fields for the chemistry sources - forAll(RRs_, fieldI) + forAll(this->RRs_, fieldI) { - RRs_.set - ( - fieldI, - new DimensionedField - ( - IOobject - ( - "RRs." + Ys_[fieldI].name(), - mesh.time().timeName(), - mesh, - IOobject::NO_READ, - IOobject::NO_WRITE - ), - mesh, - dimensionedScalar("zero", dimMass/dimVolume/dimTime, 0.0) - ) - ); - - IOobject header ( - Ys_[fieldI].name() + "0", + this->Ys_[fieldI].name() + "0", mesh.time().timeName(), mesh, IOobject::NO_READ @@ -105,7 +65,7 @@ ODESolidChemistryModel ( IOobject ( - Ys_[fieldI].name() + "0", + this->Ys_[fieldI].name() + "0", mesh.time().timeName(), mesh, IOobject::MUST_READ, @@ -137,7 +97,7 @@ ODESolidChemistryModel ( IOobject ( - Ys_[fieldI].name() + "0", + this->Ys_[fieldI].name() + "0", mesh.time().timeName(), mesh, IOobject::NO_READ, @@ -150,9 +110,9 @@ ODESolidChemistryModel // Calculate inital values of Ysi0 = rho*delta*Yi Ys0_[fieldI].internalField() = this->solidThermo().rho() - *max(Ys_[fieldI], scalar(0.001))*mesh.V(); + *max(this->Ys_[fieldI], scalar(0.001))*mesh.V(); } - } + } forAll(RRg_, fieldI) { @@ -190,23 +150,24 @@ ODESolidChemistryModel ); } - Info<< "solidChemistryModel: Number of solids = " << nSolids_ << endl; - - Info<< "solidChemistryModel: Number of gases = " << nGases_ << endl; - - forAll(reactions_, i) + Info<< "pyrolysisChemistryModel: " << nl; + Info<< indent << "Number of solids = " << this->nSolids_ << nl; + Info<< indent << "Number of gases = " << nGases_ << nl; + forAll(this->reactions_, i) { - Info<< indent << reactions_[i] << nl; + Info<< dynamic_cast& > + ( + this->reactions_[i] + ) << nl; } - } // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // template -Foam::ODESolidChemistryModel:: -~ODESolidChemistryModel() +Foam::pyrolysisChemistryModel:: +~pyrolysisChemistryModel() {} @@ -214,7 +175,7 @@ Foam::ODESolidChemistryModel:: template Foam::scalarField Foam:: -ODESolidChemistryModel::omega +pyrolysisChemistryModel::omega ( const scalarField& c, const scalar T, @@ -229,9 +190,9 @@ ODESolidChemistryModel::omega scalarField om(nEqns(), 0.0); - forAll(reactions_, i) + forAll(this->reactions_, i) { - const Reaction& R = reactions_[i]; + const Reaction& R = this->reactions_[i]; scalar omegai = omega ( @@ -242,13 +203,13 @@ ODESolidChemistryModel::omega { label si = R.lhs()[s].index; om[si] -= omegai; - rhoL = solidThermo_[si].rho(p, T); + rhoL = this->solidThermo_[si].rho(p, T); } scalar sr = 0.0; forAll(R.rhs(), s) { label si = R.rhs()[s].index; - scalar rhoR = solidThermo_[si].rho(p, T); + scalar rhoR = this->solidThermo_[si].rho(p, T); sr = rhoR/rhoL; om[si] += sr*omegai; @@ -260,7 +221,7 @@ ODESolidChemistryModel::omega forAll(R.grhs(), g) { label gi = R.grhs()[g].index; - om[gi + nSolids_] += (1.0 - sr)*omegai; + om[gi + this->nSolids_] += (1.0 - sr)*omegai; } } @@ -270,7 +231,7 @@ ODESolidChemistryModel::omega template Foam::scalar -Foam::ODESolidChemistryModel::omega +Foam::pyrolysisChemistryModel::omega ( const Reaction& R, const scalarField& c, @@ -314,7 +275,7 @@ Foam::ODESolidChemistryModel::omega template -void Foam::ODESolidChemistryModel:: +void Foam::pyrolysisChemistryModel:: derivatives ( const scalar time, @@ -331,19 +292,19 @@ derivatives //Total mass concentration scalar cTot = 0.0; - for (label i=0; inSolids_; i++) { cTot += c[i]; } scalar newCp = 0.0; scalar newhi = 0.0; - for (label i=0; inSolids_; i++) { scalar dYidt = dcdt[i]/cTot; scalar Yi = c[i]/cTot; - newCp += Yi*solidThermo_[i].Cp(p, T); - newhi -= dYidt*solidThermo_[i].Hc(); + newCp += Yi*this->solidThermo_[i].Cp(p, T); + newhi -= dYidt*this->solidThermo_[i].Hc(); } scalar dTdt = newhi/newCp; @@ -356,7 +317,8 @@ derivatives template -void Foam::ODESolidChemistryModel::jacobian +void Foam::pyrolysisChemistryModel:: +jacobian ( const scalar t, const scalarField& c, @@ -369,7 +331,7 @@ void Foam::ODESolidChemistryModel::jacobian scalarField c2(nSpecie_, 0.0); - for (label i=0; inSolids_; i++) { c2[i] = max(c[i], 0.0); } @@ -385,9 +347,9 @@ void Foam::ODESolidChemistryModel::jacobian // length of the first argument must be nSolids dcdt = omega(c2, T, p); - for (label ri=0; rireactions_.size(); ri++) { - const Reaction& R = reactions_[ri]; + const Reaction& R = this->reactions_[ri]; scalar kf0 = R.kf(p, T, c2); @@ -451,96 +413,9 @@ void Foam::ODESolidChemistryModel::jacobian } -template -Foam::tmp -Foam::ODESolidChemistryModel::tc() const -{ - notImplemented - ( - "ODESolidChemistryModel::tc()" - ); - - return volScalarField::null(); -} - - -template -Foam::tmp -Foam::ODESolidChemistryModel::Sh() const -{ - tmp tSh - ( - new volScalarField - ( - IOobject - ( - "Sh", - this->mesh_.time().timeName(), - this->mesh_, - IOobject::NO_READ, - IOobject::AUTO_WRITE, - false - ), - this->mesh_, - dimensionedScalar("zero", dimEnergy/dimTime/dimVolume, 0.0), - zeroGradientFvPatchScalarField::typeName - ) - ); - - if (this->chemistry_) - { - scalarField& Sh = tSh(); - - forAll(Ys_, i) - { - forAll(Sh, cellI) - { - scalar hf = solidThermo_[i].Hc(); - Sh[cellI] -= hf*RRs_[i][cellI]; - } - } - } - - return tSh; -} - - -template -Foam::tmp -Foam::ODESolidChemistryModel::dQ() const -{ - tmp tdQ - ( - new volScalarField - ( - IOobject - ( - "dQ", - this->mesh_.time().timeName(), - this->mesh_, - IOobject::NO_READ, - IOobject::NO_WRITE, - false - ), - this->mesh_, - dimensionedScalar("dQ", dimEnergy/dimTime, 0.0), - zeroGradientFvPatchScalarField::typeName - ) - ); - - if (this->chemistry_) - { - volScalarField& dQ = tdQ(); - dQ.dimensionedInternalField() = this->mesh_.V()*Sh()(); - } - - return tdQ; -} - - template Foam::label Foam:: -ODESolidChemistryModel::nEqns() const +pyrolysisChemistryModel::nEqns() const { // nEqns = number of solids + gases + temperature + pressure return (nSpecie_ + 2); @@ -548,7 +423,7 @@ ODESolidChemistryModel::nEqns() const template -void Foam::ODESolidChemistryModel:: +void Foam::pyrolysisChemistryModel:: calculate() { if (!this->chemistry_) @@ -570,10 +445,11 @@ calculate() this->solidThermo().rho() ); - forAll(RRs_, i) + forAll(this->RRs_, i) { - RRs_[i].field() = 0.0; + this->RRs_[i].field() = 0.0; } + forAll(RRg_, i) { RRg_[i].field() = 0.0; @@ -585,28 +461,28 @@ calculate() const scalar delta = this->mesh().V()[celli]; - if (reactingCells_[celli]) + if (this->reactingCells_[celli]) { scalar rhoi = rho[celli]; scalar Ti = this->solidThermo().T()[celli]; scalar pi = this->solidThermo().p()[celli]; scalarField c(nSpecie_, 0.0); - for (label i=0; inSolids_; i++) { - c[i] = rhoi*Ys_[i][celli]*delta; + c[i] = rhoi*this->Ys_[i][celli]*delta; } const scalarField dcdt = omega(c, Ti, pi, true); - forAll(RRs_, i) + forAll(this->RRs_, i) { - RRs_[i][celli] = dcdt[i]/delta; + this->RRs_[i][celli] = dcdt[i]/delta; } forAll(RRg_, i) { - RRg_[i][celli] = dcdt[nSolids_ + i]/delta; + RRg_[i][celli] = dcdt[this->nSolids_ + i]/delta; } } } @@ -615,7 +491,7 @@ calculate() template Foam::scalar -Foam::ODESolidChemistryModel::solve +Foam::pyrolysisChemistryModel::solve ( const scalar t0, const scalar deltaT @@ -642,9 +518,9 @@ Foam::ODESolidChemistryModel::solve this->solidThermo().rho() ); - forAll(RRs_, i) + forAll(this->RRs_, i) { - RRs_[i].field() = 0.0; + this->RRs_[i].field() = 0.0; } forAll(RRg_, i) { @@ -654,7 +530,7 @@ Foam::ODESolidChemistryModel::solve forAll(rho, celli) { - if (reactingCells_[celli]) + if (this->reactingCells_[celli]) { cellCounter_ = celli; @@ -668,9 +544,9 @@ Foam::ODESolidChemistryModel::solve scalar delta = this->mesh().V()[celli]; - for (label i=0; inSolids_; i++) { - c[i] = rhoi*Ys_[i][celli]*delta; + c[i] = rhoi*this->Ys_[i][celli]*delta; } c0 = c; @@ -690,7 +566,7 @@ Foam::ODESolidChemistryModel::solve scalar cTot = 0.0; //Total mass concentration - for (label i=0; inSolids_; i++) { cTot += c[i]; } @@ -700,13 +576,13 @@ Foam::ODESolidChemistryModel::solve scalar invRho = 0.0; scalarList dcdt = (c - c0)/dt; - for (label i=0; inSolids_; i++) { scalar dYi = dcdt[i]/cTot; scalar Yi = c[i]/cTot; - newCp += Yi*solidThermo_[i].Cp(pi, Ti); - newhi -= dYi*solidThermo_[i].Hc(); - invRho += Yi/solidThermo_[i].rho(pi, Ti); + newCp += Yi*this->solidThermo_[i].Cp(pi, Ti); + newhi -= dYi*this->solidThermo_[i].Hc(); + invRho += Yi/this->solidThermo_[i].rho(pi, Ti); } scalar dTi = (newhi/newCp)*dt; @@ -722,14 +598,14 @@ Foam::ODESolidChemistryModel::solve deltaTMin = min(tauC, deltaTMin); dc = c - c0; - forAll(RRs_, i) + forAll(this->RRs_, i) { - RRs_[i][celli] = dc[i]/(deltaT*delta); + this->RRs_[i][celli] = dc[i]/(deltaT*delta); } forAll(RRg_, i) { - RRg_[i][celli] = dc[nSolids_ + i]/(deltaT*delta); + RRg_[i][celli] = dc[this->nSolids_ + i]/(deltaT*delta); } // Update Ys0_ @@ -746,7 +622,7 @@ Foam::ODESolidChemistryModel::solve template Foam::tmp -Foam::ODESolidChemistryModel::gasHs +Foam::pyrolysisChemistryModel::gasHs ( const volScalarField& p, const volScalarField& T, @@ -785,9 +661,9 @@ Foam::ODESolidChemistryModel::gasHs } -template +template Foam::scalar -Foam::ODESolidChemistryModel::solve +Foam::pyrolysisChemistryModel::solve ( scalarField &c, const scalar T, @@ -798,7 +674,7 @@ Foam::ODESolidChemistryModel::solve { notImplemented ( - "ODESolidChemistryModel::solve" + "pyrolysisChemistryModel::solve" "(" "scalarField&, " "const scalar, " @@ -809,14 +685,4 @@ Foam::ODESolidChemistryModel::solve ); return (0); } - - -template -void Foam::ODESolidChemistryModel:: -setCellReacting(const label cellI, const bool active) -{ - reactingCells_[cellI] = active; -} - - // ************************************************************************* // diff --git a/src/thermophysicalModels/solidChemistryModel/ODESolidChemistryModel/ODESolidChemistryModel.H b/src/thermophysicalModels/solidChemistryModel/pyrolysisChemistryModel/pyrolysisChemistryModel.H similarity index 67% rename from src/thermophysicalModels/solidChemistryModel/ODESolidChemistryModel/ODESolidChemistryModel.H rename to src/thermophysicalModels/solidChemistryModel/pyrolysisChemistryModel/pyrolysisChemistryModel.H index 21dc5a5eec..6527089c36 100644 --- a/src/thermophysicalModels/solidChemistryModel/ODESolidChemistryModel/ODESolidChemistryModel.H +++ b/src/thermophysicalModels/solidChemistryModel/pyrolysisChemistryModel/pyrolysisChemistryModel.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -22,26 +22,24 @@ License along with OpenFOAM. If not, see . Class - Foam::ODESolidChemistryModel + Foam::pyrolysisChemistryModel Description - Extends base chemistry model by adding a thermo package, and ODE functions. - Introduces chemistry equation system and evaluation of chemical source - terms. + Pyrolysis chemistry model. It includes gas phase in the solid + reaction. SourceFiles - ODESolidChemistryModelI.H - ODESolidChemistryModel.C + pyrolysisChemistryModelI.H + pyrolysisChemistryModel.C \*---------------------------------------------------------------------------*/ -#ifndef ODESolidChemistryModel_H -#define ODESolidChemistryModel_H +#ifndef pyrolysisChemistryModel_H +#define pyrolysisChemistryModel_H -#include "Reaction.H" -#include "ODE.H" #include "volFieldsFwd.H" #include "DimensionedField.H" +#include "solidChemistryModel.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -52,35 +50,25 @@ namespace Foam class fvMesh; /*---------------------------------------------------------------------------*\ - Class ODESolidChemistryModel Declaration + Class pyrolysisChemistryModel Declaration \*---------------------------------------------------------------------------*/ template -class ODESolidChemistryModel +class pyrolysisChemistryModel : - public CompType, - public ODE + public solidChemistryModel { // Private Member Functions //- Disallow default bitwise assignment - void operator=(const ODESolidChemistryModel&); + void operator=(const pyrolysisChemistryModel&); protected: - //- Reference to solid mass fractions - PtrList& Ys_; - - //- Reactions - const PtrList >& reactions_; - //- List of gas species present in reaction system speciesTable pyrolisisGases_; - //- Thermodynamic data of solids - const PtrList& solidThermo_; - //- Thermodynamic data of gases PtrList gasThermo_; @@ -90,24 +78,12 @@ protected: //- Number of components being solved by ODE label nSpecie_; - //- Number of solid components - label nSolids_; - - //- Number of solid reactions - label nReaction_; - - //- List of reaction rate per solid [kg/m3/s] - PtrList > RRs_; - //- List of reaction rate per gas [kg/m3/s] PtrList > RRg_; // Protected Member Functions - //- Write access to source terms for solids - inline PtrList >& RRs(); - //- Write access to source terms for gases inline PtrList >& RRg(); @@ -120,37 +96,25 @@ private: //- Cell counter label cellCounter_; - //- List of active reacting cells - List reactingCells_; - - - // Private members - - //- Set reacting status of cell, cellI - void setCellReacting(const label cellI, const bool active); - public: //- Runtime type information - TypeName("ODESolidChemistryModel"); + TypeName("pyrolysis"); // Constructors //- Construct from mesh - ODESolidChemistryModel(const fvMesh& mesh); + pyrolysisChemistryModel(const fvMesh& mesh); //- Destructor - virtual ~ODESolidChemistryModel(); + virtual ~pyrolysisChemistryModel(); // Member Functions - //- The reactions - inline const PtrList >& reactions() const; - //- Thermodynamic data of gases inline const PtrList& gasThermo() const; @@ -163,9 +127,6 @@ public: //- The number of solids inline label nGases() const; - //- The number of reactions - inline label nReaction() const; - //- dc/dt = omega, rate of change in concentration, for each species virtual scalarField omega @@ -198,12 +159,6 @@ public: // Chemistry model functions - //- Return const access to the chemical source terms for solids - inline const DimensionedField& RRs - ( - const label i - ) const; - //- Return const access to the chemical source terms for gases inline const DimensionedField& RRg ( @@ -213,15 +168,6 @@ public: //- Return total gas source term inline tmp > RRg() const; - //- Return total solid source term - inline tmp > RRs() const; - - //- Return const access to the total source terms - inline const DimensionedField& RR - ( - const label i - ) const; - //- Return sensible enthalpy for gas i [J/Kg] virtual tmp gasHs ( @@ -232,16 +178,7 @@ public: //- Solve the reaction system for the given start time and time // step and return the characteristic time - virtual scalar solve(const scalar t0, const scalar deltaT); - - //- Return the chemical time scale - virtual tmp tc() const; - - //- Return source for enthalpy equation [kg/m/s3] - virtual tmp Sh() const; - - //- Return the heat release, i.e. enthalpy/sec [m2/s3] - virtual tmp dQ() const; + virtual scalar solve(const scalar t0, const scalar deltaT) ; // ODE functions (overriding abstract functions in ODE.H) @@ -281,12 +218,12 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -# include "ODESolidChemistryModelI.H" +# include "pyrolysisChemistryModelI.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository -# include "ODESolidChemistryModel.C" +# include "pyrolysisChemistryModel.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/thermophysicalModels/solidChemistryModel/ODESolidChemistryModel/ODESolidChemistryModelI.H b/src/thermophysicalModels/solidChemistryModel/pyrolysisChemistryModel/pyrolysisChemistryModelI.H similarity index 52% rename from src/thermophysicalModels/solidChemistryModel/ODESolidChemistryModel/ODESolidChemistryModelI.H rename to src/thermophysicalModels/solidChemistryModel/pyrolysisChemistryModel/pyrolysisChemistryModelI.H index 73a5b03d7d..b2d8b16e86 100644 --- a/src/thermophysicalModels/solidChemistryModel/ODESolidChemistryModel/ODESolidChemistryModelI.H +++ b/src/thermophysicalModels/solidChemistryModel/pyrolysisChemistryModel/pyrolysisChemistryModelI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,37 +24,21 @@ License \*---------------------------------------------------------------------------*/ #include "volFields.H" -#include "zeroGradientFvPatchFields.H" + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template inline Foam::PtrList >& -Foam::ODESolidChemistryModel::RRs() -{ - return RRs_; -} - - -template -inline Foam::PtrList >& -Foam::ODESolidChemistryModel::RRg() +Foam::pyrolysisChemistryModel::RRg() { return RRg_; } -template -inline const Foam::PtrList >& -Foam::ODESolidChemistryModel::reactions() const -{ - return reactions_; -} - - template inline const Foam::PtrList& -Foam::ODESolidChemistryModel:: +Foam::pyrolysisChemistryModel:: gasThermo() const { return gasThermo_; @@ -63,7 +47,8 @@ gasThermo() const template inline const Foam::speciesTable& -Foam::ODESolidChemistryModel::gasTable() const +Foam::pyrolysisChemistryModel:: +gasTable() const { return pyrolisisGases_; } @@ -71,35 +56,16 @@ Foam::ODESolidChemistryModel::gasTable() const template inline Foam::label -Foam::ODESolidChemistryModel::nSpecie() const +Foam::pyrolysisChemistryModel:: +nSpecie() const { return nSpecie_; } -template -inline Foam::label -Foam::ODESolidChemistryModel:: -nReaction() const -{ - return nReaction_; -} - - template inline const Foam::DimensionedField& -Foam::ODESolidChemistryModel::RRs -( - const label i -) const -{ - return RRs_[i]; -} - - -template -inline const Foam::DimensionedField& -Foam::ODESolidChemistryModel::RRg +Foam::pyrolysisChemistryModel::RRg ( const label i ) const @@ -110,7 +76,8 @@ Foam::ODESolidChemistryModel::RRg template inline Foam::tmp > -Foam::ODESolidChemistryModel::RRg() const +Foam::pyrolysisChemistryModel:: +RRg() const { tmp > tRRg ( @@ -139,51 +106,4 @@ Foam::ODESolidChemistryModel::RRg() const } return tRRg; } - - -template -inline Foam::tmp > -Foam::ODESolidChemistryModel::RRs() const -{ - tmp > tRRs - ( - new DimensionedField - ( - IOobject - ( - "RRs", - this->time().timeName(), - this->mesh(), - IOobject::NO_READ, - IOobject::NO_WRITE - ), - this->mesh(), - dimensionedScalar("zero", dimMass/dimVolume/dimTime, 0.0) - ) - ); - - if (this->chemistry_) - { - DimensionedField& RRs = tRRs(); - for (label i=0; i < nSolids_; i++) - { - RRs += RRs_[i]; - } - } - return tRRs; -} - - -template -inline const Foam::DimensionedField& -Foam::ODESolidChemistryModel::RR -( - const label i -) const -{ - notImplemented("ODESolidChemistryModel::RR(const label)"); - return (DimensionedField::null()); -} - - // ************************************************************************* // diff --git a/src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModel.C b/src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModel.C index fc5a7ced8c..017283de52 100644 --- a/src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModel.C +++ b/src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModel.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,33 +24,193 @@ License \*---------------------------------------------------------------------------*/ #include "solidChemistryModel.H" -#include "fvMesh.H" -#include "Time.H" - -/* * * * * * * * * * * * * * * private static data * * * * * * * * * * * * * */ - -namespace Foam -{ - defineTypeNameAndDebug(solidChemistryModel, 0); - defineRunTimeSelectionTable(solidChemistryModel, fvMesh); -} +#include "reactingMixture.H" +#include "zeroGradientFvPatchFields.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::solidChemistryModel::solidChemistryModel +template +Foam::solidChemistryModel:: +solidChemistryModel ( const fvMesh& mesh ) : - basicChemistryModel(mesh), - solidThermo_(solidReactionThermo::New(mesh)) -{} + CompType(mesh), + ODE(), + Ys_(this->solidThermo().composition().Y()), + reactions_ + ( + dynamic_cast& > + ( + this->solidThermo() + ) + ), + solidThermo_ + ( + dynamic_cast& > + ( + this->solidThermo() + ).speciesData() + ), + nSolids_(Ys_.size()), + nReaction_(reactions_.size()), + RRs_(nSolids_), + reactingCells_(mesh.nCells(), true) +{ + // create the fields for the chemistry sources + forAll(RRs_, fieldI) + { + RRs_.set + ( + fieldI, + new DimensionedField + ( + IOobject + ( + "RRs." + Ys_[fieldI].name(), + mesh.time().timeName(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensionedScalar("zero", dimMass/dimVolume/dimTime, 0.0) + ) + ); + } +} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // -Foam::solidChemistryModel::~solidChemistryModel() +template +Foam::solidChemistryModel:: +~solidChemistryModel() {} +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +Foam::tmp +Foam::solidChemistryModel::tc() const +{ + notImplemented + ( + "solidChemistryModel::tc()" + ); + return volScalarField::null(); +} + + +template +Foam::tmp +Foam::solidChemistryModel::Sh() const +{ + tmp tSh + ( + new volScalarField + ( + IOobject + ( + "Sh", + this->mesh_.time().timeName(), + this->mesh_, + IOobject::NO_READ, + IOobject::AUTO_WRITE, + false + ), + this->mesh_, + dimensionedScalar("zero", dimEnergy/dimTime/dimVolume, 0.0), + zeroGradientFvPatchScalarField::typeName + ) + ); + + if (this->chemistry_) + { + scalarField& Sh = tSh(); + + forAll(Ys_, i) + { + forAll(Sh, cellI) + { + scalar hf = solidThermo_[i].Hc(); + Sh[cellI] -= hf*RRs_[i][cellI]; + } + } + } + + return tSh; +} + + +template +Foam::tmp +Foam::solidChemistryModel::dQ() const +{ + tmp tdQ + ( + new volScalarField + ( + IOobject + ( + "dQ", + this->mesh_.time().timeName(), + this->mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + this->mesh_, + dimensionedScalar("dQ", dimEnergy/dimTime, 0.0), + zeroGradientFvPatchScalarField::typeName + ) + ); + + if (this->chemistry_) + { + volScalarField& dQ = tdQ(); + dQ.dimensionedInternalField() = this->mesh_.V()*Sh()(); + } + + return tdQ; +} + + +template +Foam::scalar Foam::solidChemistryModel::solve +( + scalarField &c, + const scalar T, + const scalar p, + const scalar t0, + const scalar dt +) const +{ + notImplemented + ( + "solidChemistryModel::solve" + "(" + "scalarField&, " + "const scalar, " + "const scalar, " + "const scalar, " + "const scalar" + ") const" + ); + return (0); +} + + +template +void Foam::solidChemistryModel::setCellReacting +( + const label cellI, + const bool active +) +{ + reactingCells_[cellI] = active; +} + // ************************************************************************* // diff --git a/src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModel.H b/src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModel.H index 1cc883c298..f663892a51 100644 --- a/src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModel.H +++ b/src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModel.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,23 +25,24 @@ Class Foam::solidChemistryModel Description - Chemistry model for solid thermodynamics + Extends base solid chemistry model by adding a thermo package, and ODE + functions. + Introduces chemistry equation system and evaluation of chemical source + terms. SourceFiles solidChemistryModelI.H solidChemistryModel.C - newChemistrySolidModel.C \*---------------------------------------------------------------------------*/ #ifndef solidChemistryModel_H #define solidChemistryModel_H -#include "basicChemistryModel.H" -#include "autoPtr.H" -#include "runTimeSelectionTables.H" -#include "solidReactionThermo.H" - +#include "Reaction.H" +#include "ODE.H" +#include "volFieldsFwd.H" +#include "DimensionedField.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -52,45 +53,57 @@ namespace Foam class fvMesh; /*---------------------------------------------------------------------------*\ - class solidChemistryModel Declaration + Class solidChemistryModel Declaration \*---------------------------------------------------------------------------*/ +template class solidChemistryModel : - public basicChemistryModel + public CompType, + public ODE { // Private Member Functions - //- Construct as copy (not implemented) - solidChemistryModel(const solidChemistryModel&); - //- Disallow default bitwise assignment void operator=(const solidChemistryModel&); protected: - // Protected data + //- Reference to solid mass fractions + PtrList& Ys_; - //- Solid thermo package - autoPtr solidThermo_; + //- Reactions + const PtrList >& reactions_; + + //- Thermodynamic data of solids + const PtrList& solidThermo_; + + //- Number of solid components + label nSolids_; + + //- Number of solid reactions + label nReaction_; + + //- List of reaction rate per solid [kg/m3/s] + PtrList > RRs_; + + //- List of active reacting cells + List reactingCells_; + + // Protected Member Functions + + //- Write access to source terms for solids + inline PtrList >& RRs(); + + //- Set reacting status of cell, cellI + void setCellReacting(const label cellI, const bool active); public: //- Runtime type information - TypeName("solid"); - - - //- Declare run-time constructor selection tables - declareRunTimeSelectionTable - ( - autoPtr, - solidChemistryModel, - fvMesh, - (const fvMesh& mesh), - (mesh) - ); + TypeName("solidChemistryModel"); // Constructors @@ -99,56 +112,108 @@ public: solidChemistryModel(const fvMesh& mesh); - //- Selector - static autoPtr New(const fvMesh& mesh); - - //- Destructor virtual ~solidChemistryModel(); // Member Functions - //- Return access to the solid thermo package - inline solidReactionThermo& solidThermo(); + //- The reactions + inline const PtrList >& reactions() const; - //- Return const access to the solid thermo package - inline const solidReactionThermo& solidThermo() const; + //- The number of reactions + inline label nReaction() const; - //- Return total gases mass source term [kg/m3/s] - virtual tmp > RRg() const = 0; - //- Return total solids mass source term [kg/m3/s] - virtual tmp > RRs() const = 0; - - //- Return chemical source terms for solids [kg/m3/s] - virtual const DimensionedField& RRs + //- dc/dt = omega, rate of change in concentration, for each species + virtual scalarField omega ( - const label i + const scalarField& c, + const scalar T, + const scalar p, + const bool updateC0 = false ) const = 0; - //- Return chemical source terms for gases [kg/m3/s] - virtual const DimensionedField& RRg + //- Return the reaction rate for reaction r and the reference + // species and charateristic times + virtual scalar omega ( - const label i + const Reaction& r, + const scalarField& c, + const scalar T, + const scalar p, + scalar& pf, + scalar& cf, + label& lRef, + scalar& pr, + scalar& cr, + label& rRef ) const = 0; - //- Return sensible enthalpy for gas i [J/Kg] - virtual tmp gasHs - ( - const volScalarField& p, - const volScalarField& T, - const label i - ) const = 0; - - //- Return specie Table for gases - virtual const speciesTable& gasTable() const = 0; - - //- Set reacting status of cell, cellI - virtual void setCellReacting(const label cellI, const bool active) = 0; - //- Calculates the reaction rates virtual void calculate() = 0; + + + // Chemistry model functions + + //- Return const access to the chemical source terms for solids + inline const DimensionedField& RRs + ( + const label i + ) const; + + //- Return total solid source term + inline tmp > RRs() const; + + //- Return const access to the total source terms + inline const DimensionedField& RR + ( + const label i + ) const; + + + //- Solve the reaction system for the given start time and time + // step and return the characteristic time + virtual scalar solve(const scalar t0, const scalar deltaT) = 0; + + //- Return the chemical time scale + virtual tmp tc() const; + + //- Return source for enthalpy equation [kg/m/s3] + virtual tmp Sh() const; + + //- Return the heat release, i.e. enthalpy/sec [m2/s3] + virtual tmp dQ() const; + + + // ODE functions (overriding abstract functions in ODE.H) + + //- Number of ODE's to solve + virtual label nEqns() const = 0; + + virtual void derivatives + ( + const scalar t, + const scalarField& c, + scalarField& dcdt + ) const = 0; + + virtual void jacobian + ( + const scalar t, + const scalarField& c, + scalarField& dcdt, + scalarSquareMatrix& dfdc + ) const = 0; + + virtual scalar solve + ( + scalarField &c, + const scalar T, + const scalar p, + const scalar t0, + const scalar dt + ) const = 0; }; @@ -158,7 +223,13 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#include "solidChemistryModelI.H" +# include "solidChemistryModelI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "solidChemistryModel.C" +#endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModelI.H b/src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModelI.H index 240f9c7118..8392d0b2ff 100644 --- a/src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModelI.H +++ b/src/thermophysicalModels/solidChemistryModel/solidChemistryModel/solidChemistryModelI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,18 +23,87 @@ License \*---------------------------------------------------------------------------*/ +#include "volFields.H" + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -inline Foam::solidReactionThermo& Foam::solidChemistryModel::solidThermo() +template +inline Foam::PtrList >& +Foam::solidChemistryModel::RRs() { - return solidThermo_(); + return RRs_; +} + +template +inline const Foam::PtrList >& +Foam::solidChemistryModel::reactions() const +{ + return reactions_; } -inline const Foam::solidReactionThermo& -Foam::solidChemistryModel::solidThermo() const +template +inline Foam::label +Foam::solidChemistryModel:: +nReaction() const { - return solidThermo_(); + return nReaction_; +} + + +template +inline const Foam::DimensionedField& +Foam::solidChemistryModel::RRs +( + const label i +) const +{ + return RRs_[i]; +} + + +template +inline Foam::tmp > +Foam::solidChemistryModel::RRs() const +{ + tmp > tRRs + ( + new DimensionedField + ( + IOobject + ( + "RRs", + this->time().timeName(), + this->mesh(), + IOobject::NO_READ, + IOobject::NO_WRITE + ), + this->mesh(), + dimensionedScalar("zero", dimMass/dimVolume/dimTime, 0.0) + ) + ); + + if (this->chemistry_) + { + DimensionedField& RRs = tRRs(); + for (label i=0; i < nSolids_; i++) + { + RRs += RRs_[i]; + } + } + return tRRs; +} + + +template +inline const Foam::DimensionedField& +Foam::solidChemistryModel::RR +( + const label i +) const +{ + notImplemented("solidChemistryModel::RR(const label)"); + return (DimensionedField::null()); } diff --git a/src/thermophysicalModels/solidChemistryModel/solidChemistrySolver/makeSolidChemistrySolverType.H b/src/thermophysicalModels/solidChemistryModel/solidChemistrySolver/makeSolidChemistrySolverType.H index e891cba45b..f5bfc13942 100644 --- a/src/thermophysicalModels/solidChemistryModel/solidChemistrySolver/makeSolidChemistrySolverType.H +++ b/src/thermophysicalModels/solidChemistryModel/solidChemistrySolver/makeSolidChemistrySolverType.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -39,15 +39,15 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define makeSolidChemistrySolverType(SS, Comp, SThermo, GThermo) \ +#define makeSolidChemistrySolverType(SS, Schem, Comp, SThermo, GThermo) \ \ - typedef SS > \ - SS##Comp##SThermo##GThermo; \ + typedef SS > \ + SS##Schem##Comp##SThermo##GThermo; \ \ defineTemplateTypeNameAndDebugWithName \ ( \ - SS##Comp##SThermo##GThermo, \ - (#SS"<" + word(Comp::typeName_()) \ + SS##Schem##Comp##SThermo##GThermo, \ + (#SS"<" + word(Schem::typeName_()) \ + "," + SThermo::typeName() + "," + GThermo::typeName() + ">").c_str(), \ 0 \ ); \ @@ -55,7 +55,7 @@ namespace Foam addToRunTimeSelectionTable \ ( \ Comp, \ - SS##Comp##SThermo##GThermo, \ + SS##Schem##Comp##SThermo##GThermo, \ fvMesh \ ); diff --git a/src/thermophysicalModels/solidChemistryModel/solidChemistrySolver/makeSolidChemistrySolvers.C b/src/thermophysicalModels/solidChemistryModel/solidChemistrySolver/makeSolidChemistrySolvers.C index 3b6f13f486..7f65643337 100644 --- a/src/thermophysicalModels/solidChemistryModel/solidChemistrySolver/makeSolidChemistrySolvers.C +++ b/src/thermophysicalModels/solidChemistryModel/solidChemistrySolver/makeSolidChemistrySolvers.C @@ -27,8 +27,8 @@ License #include "solidThermoPhysicsTypes.H" #include "thermoPhysicsTypes.H" -#include "ODESolidChemistryModel.H" -#include "solidChemistryModel.H" +#include "pyrolysisChemistryModel.H" +#include "basicSolidChemistryModel.H" #include "ode.H" @@ -39,7 +39,8 @@ namespace Foam makeSolidChemistrySolverType ( ode, - solidChemistryModel, + pyrolysisChemistryModel, + basicSolidChemistryModel, hConstSolidThermoPhysics, gasHThermoPhysics ) @@ -47,7 +48,8 @@ namespace Foam makeSolidChemistrySolverType ( ode, - solidChemistryModel, + pyrolysisChemistryModel, + basicSolidChemistryModel, hExponentialSolidThermoPhysics, gasHThermoPhysics ) diff --git a/src/thermophysicalModels/solidSpecie/reaction/Reactions/solidReaction/solidReaction.C b/src/thermophysicalModels/solidSpecie/reaction/Reactions/solidReaction/solidReaction.C index 99bb98acb4..474b5cd609 100644 --- a/src/thermophysicalModels/solidSpecie/reaction/Reactions/solidReaction/solidReaction.C +++ b/src/thermophysicalModels/solidSpecie/reaction/Reactions/solidReaction/solidReaction.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -150,12 +150,18 @@ Foam::string Foam::solidReaction::solidReactionStr ) const { this->reactionStrLeft(reaction); - reaction << " + "; - solidReactionStrLeft(reaction); + if (glhs().size() > 0) + { + reaction << " + "; + solidReactionStrLeft(reaction); + } reaction << " = "; this->reactionStrRight(reaction); - reaction << " + "; - solidReactionStrRight(reaction); + if (grhs().size() > 0) + { + reaction << " + "; + solidReactionStrRight(reaction); + } return reaction.str(); } @@ -169,8 +175,6 @@ void Foam::solidReaction::solidReactionStrLeft { for (label i = 0; i < glhs().size(); ++i) { - reaction << " + "; - if (i > 0) { reaction << " + "; @@ -197,8 +201,6 @@ void Foam::solidReaction::solidReactionStrRight for (label i = 0; i < grhs().size(); ++i) { - reaction << " + "; - if (i > 0) { reaction << " + "; diff --git a/tutorials/combustion/fireFoam/les/oppositeBurningPanels/constant/panelRegion/chemistryProperties b/tutorials/combustion/fireFoam/les/oppositeBurningPanels/constant/panelRegion/chemistryProperties index 929ed127f8..9f8ecdd196 100644 --- a/tutorials/combustion/fireFoam/les/oppositeBurningPanels/constant/panelRegion/chemistryProperties +++ b/tutorials/combustion/fireFoam/les/oppositeBurningPanels/constant/panelRegion/chemistryProperties @@ -18,7 +18,7 @@ FoamFile chemistryType { chemistrySolver ode; - chemistryThermo solid; + chemistryThermo pyrolysis; } chemistry on; From 371c5aed111c1169d93585c2e9223efef02e4f84 Mon Sep 17 00:00:00 2001 From: Henry Date: Sat, 23 Feb 2013 14:44:39 +0000 Subject: [PATCH 02/23] multiphase: Update U BCs for MRF --- .../multiphase/compressibleTwoPhaseEulerFoam/UEqns.H | 4 ++++ applications/solvers/multiphase/multiphaseEulerFoam/UEqns.H | 2 ++ .../multiphase/multiphaseEulerFoam/mrfZonesCorrectBCs.H | 6 ++++++ 3 files changed, 12 insertions(+) create mode 100644 applications/solvers/multiphase/multiphaseEulerFoam/mrfZonesCorrectBCs.H diff --git a/applications/solvers/multiphase/compressibleTwoPhaseEulerFoam/UEqns.H b/applications/solvers/multiphase/compressibleTwoPhaseEulerFoam/UEqns.H index ce5c622f9a..ae22926c4e 100644 --- a/applications/solvers/multiphase/compressibleTwoPhaseEulerFoam/UEqns.H +++ b/applications/solvers/multiphase/compressibleTwoPhaseEulerFoam/UEqns.H @@ -1,3 +1,7 @@ +mrfZones.correctBoundaryVelocity(U1); +mrfZones.correctBoundaryVelocity(U2); +mrfZones.correctBoundaryVelocity(U); + fvVectorMatrix U1Eqn(U1, U1.dimensions()*dimVol/dimTime); fvVectorMatrix U2Eqn(U2, U2.dimensions()*dimVol/dimTime); diff --git a/applications/solvers/multiphase/multiphaseEulerFoam/UEqns.H b/applications/solvers/multiphase/multiphaseEulerFoam/UEqns.H index a63ff3c85a..7584d84f27 100644 --- a/applications/solvers/multiphase/multiphaseEulerFoam/UEqns.H +++ b/applications/solvers/multiphase/multiphaseEulerFoam/UEqns.H @@ -1,3 +1,5 @@ +#include "mrfZonesCorrectBCs.H" + PtrList UEqns(fluid.phases().size()); autoPtr dragCoeffs(fluid.dragCoeffs()); diff --git a/applications/solvers/multiphase/multiphaseEulerFoam/mrfZonesCorrectBCs.H b/applications/solvers/multiphase/multiphaseEulerFoam/mrfZonesCorrectBCs.H new file mode 100644 index 0000000000..d670aa4a41 --- /dev/null +++ b/applications/solvers/multiphase/multiphaseEulerFoam/mrfZonesCorrectBCs.H @@ -0,0 +1,6 @@ + forAllIter(PtrDictionary, fluid.phases(), iter) + { + mrfZones.correctBoundaryVelocity(iter().U()); + } + + mrfZones.correctBoundaryVelocity(U); From fe10f6d6c19247819380569ae4ca6c5ff3b2d4c8 Mon Sep 17 00:00:00 2001 From: Henry Date: Sat, 23 Feb 2013 14:45:55 +0000 Subject: [PATCH 03/23] LeastSquaresGrad: New stencil-based least-squares gradient --- src/finiteVolume/Make/files | 3 +- .../LeastSquaresGrad/LeastSquaresGrad.C | 119 +++++ .../LeastSquaresGrad/LeastSquaresGrad.H | 174 +++++++ .../LeastSquaresGrads.C} | 19 +- .../LeastSquaresGrad/LeastSquaresVectors.C | 118 +++++ .../LeastSquaresVectors.H} | 85 ++-- .../extendedLeastSquaresGrad.C | 159 ------ .../extendedLeastSquaresGrad.H | 136 ------ .../extendedLeastSquaresVectors.C | 453 ------------------ .../extendedCellToCellStencilTemplates.C | 9 +- src/finiteVolume/fvMesh/fvMesh.C | 5 - 11 files changed, 477 insertions(+), 803 deletions(-) create mode 100644 src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrad.C create mode 100644 src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrad.H rename src/finiteVolume/finiteVolume/gradSchemes/{extendedLeastSquaresGrad/extendedLeastSquaresGrads.C => LeastSquaresGrad/LeastSquaresGrads.C} (75%) create mode 100644 src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresVectors.C rename src/finiteVolume/finiteVolume/gradSchemes/{extendedLeastSquaresGrad/extendedLeastSquaresVectors.H => LeastSquaresGrad/LeastSquaresVectors.H} (58%) delete mode 100644 src/finiteVolume/finiteVolume/gradSchemes/extendedLeastSquaresGrad/extendedLeastSquaresGrad.C delete mode 100644 src/finiteVolume/finiteVolume/gradSchemes/extendedLeastSquaresGrad/extendedLeastSquaresGrad.H delete mode 100644 src/finiteVolume/finiteVolume/gradSchemes/extendedLeastSquaresGrad/extendedLeastSquaresVectors.C diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index 66729d197c..1ce1f78949 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -340,8 +340,7 @@ $(gradSchemes)/gaussGrad/gaussGrads.C $(gradSchemes)/leastSquaresGrad/leastSquaresVectors.C $(gradSchemes)/leastSquaresGrad/leastSquaresGrads.C -$(gradSchemes)/extendedLeastSquaresGrad/extendedLeastSquaresVectors.C -$(gradSchemes)/extendedLeastSquaresGrad/extendedLeastSquaresGrads.C +$(gradSchemes)/LeastSquaresGrad/LeastSquaresGrads.C $(gradSchemes)/fourthGrad/fourthGrads.C limitedGradSchemes = $(gradSchemes)/limitedGradSchemes diff --git a/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrad.C b/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrad.C new file mode 100644 index 0000000000..92a6eeadd4 --- /dev/null +++ b/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrad.C @@ -0,0 +1,119 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 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 . + +\*---------------------------------------------------------------------------*/ + +#include "LeastSquaresGrad.H" +#include "LeastSquaresVectors.H" +#include "gaussGrad.H" +#include "fvMesh.H" +#include "volMesh.H" +#include "zeroGradientFvPatchField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +Foam::tmp +< + Foam::GeometricField + < + typename Foam::outerProduct::type, + Foam::fvPatchField, + Foam::volMesh + > +> +Foam::fv::LeastSquaresGrad::calcGrad +( + const GeometricField& vtf, + const word& name +) const +{ + typedef typename outerProduct::type GradType; + + const fvMesh& mesh = vtf.mesh(); + + // Get reference to least square vectors + const LeastSquaresVectors& lsv = LeastSquaresVectors::New + ( + mesh + ); + + tmp > tlsGrad + ( + new GeometricField + ( + IOobject + ( + name, + vtf.instance(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensioned + ( + "zero", + vtf.dimensions()/dimLength, + pTraits::zero + ), + zeroGradientFvPatchField::typeName + ) + ); + GeometricField& lsGrad = tlsGrad(); + Field& lsGradIf = lsGrad; + + const extendedCentredCellToCellStencil& stencil = lsv.stencil(); + const List >& lsvs = lsv.vectors(); + + // lsGrad = stencil.weightedSum(vtf, lsv.vectors()); + + List > stencilVtf; + extendedCellToFaceStencil::collectData + ( + stencil.map(), + stencil.stencil(), + vtf, + stencilVtf + ); + + forAll(lsGradIf, celli) + { + const List& stfc = stencilVtf[celli]; + const List& lsvc = lsvs[celli]; + + forAll(stfc, i) + { + lsGradIf[celli] += lsvc[i]*stfc[i]; + } + } + + lsGrad.correctBoundaryConditions(); + + gaussGrad::correctBoundaryConditions(vtf, lsGrad); + + return tlsGrad; +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrad.H b/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrad.H new file mode 100644 index 0000000000..edc9418465 --- /dev/null +++ b/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrad.H @@ -0,0 +1,174 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 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 . + +Class + Foam::fv::LeastSquaresGrad + +Description + Gradient calculated using weighted least-squares on an arbitrary stencil. + The stencil type is provided via a template argument and any cell-based + stencil is supported: + + \table + Stencil | Connections | Scheme name + centredCFCCellToCellStencil | cell-face-cell | Not Instantiated + centredCPCCellToCellStencil | cell-point-cell | pointCellsLeastSquares + centredCECCellToCellStencil | cell-edge-cell | edgeCellsLeastSquares + \endtable + + The first of these is not instantiated by default as the standard + leastSquaresGrad is equivalent and more efficient. + + \heading Usage + + Example of the gradient specification: + \verbatim + gradSchemes + { + default pointCellsLeastSquares; + } + \endverbatim + +See Also + Foam::fv::LeastSquaresVectors + Foam::fv::leastSquaresGrad + +SourceFiles + LeastSquaresGrad.C + LeastSquaresVectors.H + LeastSquaresVectors.C + +\*---------------------------------------------------------------------------*/ + +#ifndef LeastSquaresGrad_H +#define LeastSquaresGrad_H + +#include "gradScheme.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace fv +{ + +/*---------------------------------------------------------------------------*\ + Class LeastSquaresGrad Declaration +\*---------------------------------------------------------------------------*/ + +template +class LeastSquaresGrad +: + public fv::gradScheme +{ + // Private Data + + //- Minimum determinant criterion to choose extra cells + scalar minDet_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + LeastSquaresGrad(const LeastSquaresGrad&); + + //- Disallow default bitwise assignment + void operator=(const LeastSquaresGrad&); + + +public: + + //- Runtime type information + TypeName("LeastSquares"); + + + // Constructors + + //- Construct from Istream + LeastSquaresGrad(const fvMesh& mesh, Istream& schemeData) + : + gradScheme(mesh) + {} + + + // Member Functions + + //- Return the gradient of the given field to the gradScheme::grad + // for optional caching + virtual tmp + < + GeometricField + ::type, fvPatchField, volMesh> + > calcGrad + ( + const GeometricField& vsf, + const word& name + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fv + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// Add the patch constructor functions to the hash tables + +#define makeLeastSquaresGradTypeScheme(SS, STENCIL, TYPE) \ + \ +typedef LeastSquaresGrad LeastSquaresGrad##TYPE##STENCIL##_; \ +defineTemplateTypeNameAndDebugWithName \ + (LeastSquaresGrad##TYPE##STENCIL##_, #SS, 0); \ + \ +gradScheme::addIstreamConstructorToTable \ + > \ + add##SS##STENCIL##TYPE##IstreamConstructorToTable_; + +#define makeLeastSquaresGradScheme(SS, STENCIL) \ + \ +typedef LeastSquaresVectors LeastSquaresVectors##STENCIL##_; \ +defineTemplateTypeNameAndDebugWithName \ + (LeastSquaresVectors##STENCIL##_, #SS, 0); \ + \ +makeLeastSquaresGradTypeScheme(SS,STENCIL,scalar) \ +makeLeastSquaresGradTypeScheme(SS,STENCIL,vector) + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "LeastSquaresGrad.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/finiteVolume/gradSchemes/extendedLeastSquaresGrad/extendedLeastSquaresGrads.C b/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrads.C similarity index 75% rename from src/finiteVolume/finiteVolume/gradSchemes/extendedLeastSquaresGrad/extendedLeastSquaresGrads.C rename to src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrads.C index a9364b5a0c..3a7f49a976 100644 --- a/src/finiteVolume/finiteVolume/gradSchemes/extendedLeastSquaresGrad/extendedLeastSquaresGrads.C +++ b/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresGrads.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,8 +23,9 @@ License \*---------------------------------------------------------------------------*/ -#include "fvMesh.H" -#include "extendedLeastSquaresGrad.H" +#include "LeastSquaresGrad.H" +#include "centredCPCCellToCellStencilObject.H" +#include "centredCECCellToCellStencilObject.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -32,7 +33,17 @@ namespace Foam { namespace fv { - makeFvGradScheme(extendedLeastSquaresGrad) + makeLeastSquaresGradScheme + ( + pointCellsLeastSquares, + centredCPCCellToCellStencilObject + ) + + makeLeastSquaresGradScheme + ( + edgeCellsLeastSquares, + centredCECCellToCellStencilObject + ) } } diff --git a/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresVectors.C b/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresVectors.C new file mode 100644 index 0000000000..c575b23c28 --- /dev/null +++ b/src/finiteVolume/finiteVolume/gradSchemes/LeastSquaresGrad/LeastSquaresVectors.C @@ -0,0 +1,118 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 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 . + +\*---------------------------------------------------------------------------*/ + +#include "LeastSquaresVectors.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::fv::LeastSquaresVectors::LeastSquaresVectors +( + const fvMesh& mesh +) +: + MeshObject(mesh), + vectors_(mesh.nCells()) +{ + calcLeastSquaresVectors(); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::fv::LeastSquaresVectors::~LeastSquaresVectors() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::fv::LeastSquaresVectors::calcLeastSquaresVectors() +{ + if (debug) + { + Info<< "LeastSquaresVectors::calcLeastSquaresVectors() :" + << "Calculating least square gradient vectors" + << endl; + } + + const fvMesh& mesh = this->mesh_; + const extendedCentredCellToCellStencil& stencil = this->stencil(); + + stencil.collectData(mesh.C(), vectors_); + + // Create the base form of the dd-tensor + // including components for the "empty" directions + symmTensor dd0(sqr((Vector