wideBandAbsorptionEmission.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  namespace radiation
34  {
35  defineTypeNameAndDebug(wideBandAbsorptionEmission, 0);
36 
38  (
39  absorptionEmissionModel,
40  wideBandAbsorptionEmission,
41  dictionary
42  );
43  }
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 (
51  const dictionary& dict,
52  const fvMesh& mesh
53 )
54 :
55  absorptionEmissionModel(dict, mesh),
56  coeffsDict_((dict.subDict(typeName + "Coeffs"))),
57  speciesNames_(0),
58  specieIndex_(label(0)),
59  lookUpTable_
60  (
61  fileName(coeffsDict_.lookup("lookUpTableFileName")),
62  mesh.time().constant(),
63  mesh
64  ),
66  Yj_(nSpecies_),
67  totalWaveLength_(0)
68 {
69  label nBand = 0;
70  const dictionary& functionDicts = dict.subDict(typeName +"Coeffs");
71  forAllConstIter(dictionary, functionDicts, iter)
72  {
73  // safety:
74  if (!iter().isDict())
75  {
76  continue;
77  }
78 
79  const dictionary& dict = iter().dict();
80  dict.lookup("bandLimits") >> iBands_[nBand];
81  dict.lookup("EhrrCoeff") >> iEhrrCoeffs_[nBand];
82  totalWaveLength_ += iBands_[nBand][1] - iBands_[nBand][0];
83 
84  label nSpec = 0;
85  const dictionary& specDicts = dict.subDict("species");
86  forAllConstIter(dictionary, specDicts, iter)
87  {
88  const word& key = iter().keyword();
89  if (nBand == 0)
90  {
91  speciesNames_.insert(key, nSpec);
92  }
93  else
94  {
95  if (!speciesNames_.found(key))
96  {
98  << "specie: " << key << "is not in all the bands"
99  << nl << exit(FatalError);
100  }
101  }
102  coeffs_[nBand][nSpec].initialise(specDicts.subDict(key));
103  nSpec++;
104  }
105  nBand++;
106  }
107  nBands_ = nBand;
108 
109  // Check that all the species on the dictionary are present in the
110  // look-up table and save the corresponding indices of the look-up table
111 
112  label j = 0;
113  forAllConstIter(HashTable<label>, speciesNames_, iter)
114  {
115  if (lookUpTable_.found(iter.key()))
116  {
117  label index = lookUpTable_.findFieldIndex(iter.key());
118  Info<< "specie: " << iter.key() << " found in look-up table "
119  << " with index: " << index << endl;
120  specieIndex_[iter()] = index;
121  }
122  else if (mesh.foundObject<volScalarField>(iter.key()))
123  {
124  volScalarField& Y = const_cast<volScalarField&>
125  (mesh.lookupObject<volScalarField>(iter.key()));
126 
127  Yj_.set(j, &Y);
128 
129  specieIndex_[iter()] = 0.0;
130  j++;
131  Info<< "species: " << iter.key() << " is being solved" << endl;
132  }
133  else
134  {
136  << "specie: " << iter.key()
137  << " is neither in look-up table : "
138  << lookUpTable_.tableName() << " nor is being solved"
139  << exit(FatalError);
140  }
141  }
142 }
143 
144 
145 
146 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
147 
149 {}
150 
151 
152 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
153 
156 {
157  const volScalarField& T = thermo_.T();
158  const volScalarField& p = thermo_.p();
159  const volScalarField& ft = mesh_.lookupObject<volScalarField>("ft");
160 
161  label nSpecies = speciesNames_.size();
162 
164  (
165  new volScalarField
166  (
167  IOobject
168  (
169  "a",
170  mesh().time().timeName(),
171  mesh(),
174  ),
175  mesh(),
177  )
178  );
179 
180  scalarField& a = ta.ref().primitiveFieldRef();
181 
182  forAll(a, i)
183  {
184  const List<scalar>& species = lookUpTable_.lookUp(ft[i]);
185 
186  for (label n=0; n<nSpecies; n++)
187  {
188  label l = 0;
189  scalar Yipi = 0.0;
190  if (specieIndex_[n] != 0)
191  {
192  // moles x pressure [atm]
193  Yipi = species[specieIndex_[n]]*p[i]*9.869231e-6;
194  }
195  else
196  {
197  // mass fraction from species being solved
198  Yipi = Yj_[l][i];
199  l++;
200  }
201 
202  scalar Ti = T[i];
203 
205  coeffs_[n][bandI].coeffs(T[i]);
206 
207  if (coeffs_[n][bandI].invTemp())
208  {
209  Ti = 1.0/T[i];
210  }
211 
212  a[i]+=
213  Yipi
214  *(
215  ((((b[5]*Ti + b[4])*Ti + b[3])*Ti + b[2])*Ti + b[1])*Ti
216  + b[0]
217  );
218  }
219  }
220 
221  return ta;
222 }
223 
224 
227 {
228  return aCont(bandI);
229 }
230 
231 
234 {
236  (
237  new volScalarField
238  (
239  IOobject
240  (
241  "E",
242  mesh().time().timeName(),
243  mesh(),
246  ),
247  mesh(),
249  )
250  );
251 
252  if (mesh().foundObject<volScalarField>("dQ"))
253  {
254  const volScalarField& dQ = mesh().lookupObject<volScalarField>("dQ");
255 
256  if (dQ.dimensions() == dimEnergy/dimTime)
257  {
258  E.ref().primitiveFieldRef() =
259  iEhrrCoeffs_[bandI]
260  *dQ.primitiveField()
261  *(iBands_[bandI][1] - iBands_[bandI][0])
262  /totalWaveLength_
263  /mesh_.V();
264  }
265  else if (dQ.dimensions() == dimEnergy/dimTime/dimVolume)
266  {
267  E.ref().primitiveFieldRef() =
268  iEhrrCoeffs_[bandI]
269  *dQ.primitiveField()
270  *(iBands_[bandI][1] - iBands_[bandI][0])
271  /totalWaveLength_;
272  }
273  else
274  {
276  << "Incompatible dimensions for dQ field" << endl;
277  }
278  }
279 
280  return E;
281 }
282 
283 
285 (
286  volScalarField& a,
287  PtrList<volScalarField>& aLambda
288 ) const
289 {
290  a = dimensionedScalar("zero", dimless/dimLength, 0.0);
291 
292  for (label j=0; j<nBands_; j++)
293  {
294  aLambda[j].primitiveFieldRef() = this->a(j);
295 
296  a.primitiveFieldRef() +=
297  aLambda[j].primitiveField()
298  *(iBands_[j][1] - iBands_[j][0])
299  /totalWaveLength_;
300  }
301 
302 }
303 
304 
305 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A class for handling file names.
Definition: fileName.H:69
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
bool foundObject(const word &name) const
Is the named Type found?
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
const word dictName() const
Return the local dictionary name (final part of scoped name)
Definition: dictionary.H:115
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:633
defineTypeNameAndDebug(cloudAbsorptionEmission, 0)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
const Internal::FieldType & primitiveField() const
Return a const-reference to the internal field.
tmp< volScalarField > eCont(const label bandI=0) const
Emission coefficient for continuous phase.
Model to supply absorption and emission coefficients for radiation modelling.
Macros for easy insertion into run-time selection tables.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
const dimensionSet dimVolume(pow3(dimLength))
Definition: dimensionSets.H:58
dynamicFvMesh & mesh
dQ
Definition: YEEqn.H:14
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
tmp< volScalarField > ECont(const label bandI=0) const
Emission contribution for continuous phase.
A class for handling words, derived from string.
Definition: word.H:59
Fundamental fluid thermodynamic properties.
Definition: fluidThermo.H:49
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
word timeName
Definition: getTimeIndex.H:3
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
const dimensionSet & dimensions() const
Return dimensions.
Internal::FieldType & primitiveFieldRef()
Return a reference to the internal field.
static const char nl
Definition: Ostream.H:262
void correct(volScalarField &a_, PtrList< volScalarField > &aLambda) const
Correct rays.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
const dimensionSet dimEnergy
dimensionedScalar pow3(const dimensionedScalar &ds)
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
#define WarningInFunction
Report a warning using Foam::Warning.
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:62
PtrList< volScalarField > & Y
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
addToRunTimeSelectionTable(absorptionEmissionModel, cloudAbsorptionEmission, dictionary)
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:51
messageStream Info
label n
wideBandAbsorptionEmission(const dictionary &dict, const fvMesh &mesh)
Construct from components.
tmp< volScalarField > aCont(const label bandI=0) const
Absorption coefficient for continuous phase.
const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:49
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:54
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
autoPtr< radiation::radiationModel > radiation(radiation::radiationModel::New(T))
Namespace for OpenFOAM.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451