radiativeIntensityRay.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-2015 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 
26 #include "radiativeIntensityRay.H"
27 #include "fvm.H"
28 #include "fvDOM.H"
29 #include "constants.H"
30 
31 using namespace Foam::constant;
32 
33 const Foam::word
35 
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
40 (
41  const fvDOM& dom,
42  const fvMesh& mesh,
43  const scalar phi,
44  const scalar theta,
45  const scalar deltaPhi,
46  const scalar deltaTheta,
47  const label nLambda,
48  const absorptionEmissionModel& absorptionEmission,
49  const blackBodyEmission& blackBody,
50  const label rayId
51 )
52 :
53  dom_(dom),
54  mesh_(mesh),
55  absorptionEmission_(absorptionEmission),
56  blackBody_(blackBody),
57  I_
58  (
59  IOobject
60  (
61  "I" + name(rayId),
62  mesh_.time().timeName(),
63  mesh_,
66  ),
67  mesh_,
69  ),
70  Qr_
71  (
72  IOobject
73  (
74  "Qr" + name(rayId),
75  mesh_.time().timeName(),
76  mesh_,
79  ),
80  mesh_,
82  ),
83  Qin_
84  (
85  IOobject
86  (
87  "Qin" + name(rayId),
88  mesh_.time().timeName(),
89  mesh_,
92  ),
93  mesh_,
95  ),
96  Qem_
97  (
98  IOobject
99  (
100  "Qem" + name(rayId),
101  mesh_.time().timeName(),
102  mesh_,
105  ),
106  mesh_,
107  dimensionedScalar("Qem", dimMass/pow3(dimTime), 0.0)
108  ),
109  d_(vector::zero),
110  dAve_(vector::zero),
111  theta_(theta),
112  phi_(phi),
113  omega_(0.0),
114  nLambda_(nLambda),
115  ILambda_(nLambda),
116  myRayId_(rayId)
117 {
118  scalar sinTheta = Foam::sin(theta);
119  scalar cosTheta = Foam::cos(theta);
120  scalar sinPhi = Foam::sin(phi);
121  scalar cosPhi = Foam::cos(phi);
122 
123  omega_ = 2.0*sinTheta*Foam::sin(deltaTheta/2.0)*deltaPhi;
124  d_ = vector(sinTheta*sinPhi, sinTheta*cosPhi, cosTheta);
125  dAve_ = vector
126  (
127  sinPhi
128  *Foam::sin(0.5*deltaPhi)
129  *(deltaTheta - Foam::cos(2.0*theta)
130  *Foam::sin(deltaTheta)),
131  cosPhi
132  *Foam::sin(0.5*deltaPhi)
133  *(deltaTheta - Foam::cos(2.0*theta)
134  *Foam::sin(deltaTheta)),
135  0.5*deltaPhi*Foam::sin(2.0*theta)*Foam::sin(deltaTheta)
136  );
137 
138  if (mesh_.nSolutionD() == 2)
139  {
140  vector meshDir(vector::zero);
141  if (dom_.meshOrientation() != vector::zero)
142  {
143  meshDir = dom_.meshOrientation();
144  }
145  else
146  {
147  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
148  {
149  if (mesh_.geometricD()[cmpt] == -1)
150  {
151  meshDir[cmpt] = 1;
152  }
153  }
154  }
155  const vector normal(vector(0, 0, 1));
156 
157  const tensor coordRot = rotationTensor(normal, meshDir);
158 
159  dAve_ = coordRot & dAve_;
160  d_ = coordRot & d_;
161  }
162  else if (mesh_.nSolutionD() == 1)
163  {
164  vector meshDir(vector::zero);
165  if (dom_.meshOrientation() != vector::zero)
166  {
167  meshDir = dom_.meshOrientation();
168  }
169  else
170  {
171  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
172  {
173  if (mesh_.geometricD()[cmpt] == 1)
174  {
175  meshDir[cmpt] = 1;
176  }
177  }
178  }
179  const vector normal(vector(1, 0, 0));
180 
181  dAve_ = (dAve_ & normal)*meshDir;
182  d_ = (d_ & normal)*meshDir;
183  }
184 
185  autoPtr<volScalarField> IDefaultPtr;
186 
187  forAll(ILambda_, lambdaI)
188  {
189  IOobject IHeader
190  (
191  intensityPrefix + "_" + name(rayId) + "_" + name(lambdaI),
192  mesh_.time().timeName(),
193  mesh_,
196  );
197 
198  // Check if field exists and can be read
199  if (IHeader.headerOk())
200  {
201  ILambda_.set
202  (
203  lambdaI,
204  new volScalarField(IHeader, mesh_)
205  );
206  }
207  else
208  {
209  // Demand driven load the IDefault field
210  if (!IDefaultPtr.valid())
211  {
212  IDefaultPtr.reset
213  (
214  new volScalarField
215  (
216  IOobject
217  (
218  "IDefault",
219  mesh_.time().timeName(),
220  mesh_,
223  ),
224  mesh_
225  )
226  );
227  }
228 
229  // Reset the MUST_READ flag
230  IOobject noReadHeader(IHeader);
231  noReadHeader.readOpt() = IOobject::NO_READ;
232 
233  ILambda_.set
234  (
235  lambdaI,
236  new volScalarField(noReadHeader, IDefaultPtr())
237  );
238  }
239  }
240 }
241 
242 
243 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
244 
246 {}
247 
248 
249 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
250 
252 {
253  // Reset boundary heat flux to zero
254  Qr_.boundaryField() = 0.0;
255 
256  scalar maxResidual = -GREAT;
257 
258  forAll(ILambda_, lambdaI)
259  {
260  const volScalarField& k = dom_.aLambda(lambdaI);
261 
262  tmp<fvScalarMatrix> IiEq;
263 
264  if (!dom_.cacheDiv())
265  {
266  const surfaceScalarField Ji(dAve_ & mesh_.Sf());
267 
268  IiEq =
269  (
270  fvm::div(Ji, ILambda_[lambdaI], "div(Ji,Ii_h)")
271  + fvm::Sp(k*omega_, ILambda_[lambdaI])
272  ==
273  1.0/constant::mathematical::pi*omega_
274  * (
275  (k - absorptionEmission_.aDisp(lambdaI))
276  *blackBody_.bLambda(lambdaI)
277  + absorptionEmission_.ECont(lambdaI)
278  + absorptionEmission_.EDisp(lambdaI)
279  )
280  );
281  }
282  else
283  {
284  IiEq =
285  (
286  dom_.fvRayDiv(myRayId_, lambdaI)
287  + fvm::Sp(k*omega_, ILambda_[lambdaI])
288  ==
289  1.0/constant::mathematical::pi*omega_
290  * (
291  (k - absorptionEmission_.aDisp(lambdaI))
292  *blackBody_.bLambda(lambdaI)
293  + absorptionEmission_.E(lambdaI)/4
294  )
295  );
296  }
297 
298  IiEq().relax();
299 
300  const solverPerformance ILambdaSol = solve
301  (
302  IiEq(),
303  mesh_.solver("Ii")
304  );
305 
306  const scalar initialRes =
307  ILambdaSol.initialResidual()*omega_/dom_.omegaMax();
308 
309  maxResidual = max(initialRes, maxResidual);
310  }
311 
312  return maxResidual;
313 }
314 
315 
317 {
318  I_ = dimensionedScalar("zero", dimMass/pow3(dimTime), 0.0);
319 
320  forAll(ILambda_, lambdaI)
321  {
322  I_ += ILambda_[lambdaI];
323  }
324 }
325 
326 
327 // ************************************************************************* //
Foam::Tensor
Templated 3D tensor derived from VectorSpace adding construction from 9 components,...
Definition: complexI.H:224
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::IOobject::AUTO_WRITE
@ AUTO_WRITE
Definition: IOobject.H:117
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::constant
Collection of constants.
Definition: atomicConstants.C:37
radiativeIntensityRay.H
phi
surfaceScalarField & phi
Definition: setRegionFluidFields.H:8
Foam::sin
dimensionedScalar sin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:255
Foam::radiation::radiativeIntensityRay::~radiativeIntensityRay
~radiativeIntensityRay()
Destructor.
Definition: radiativeIntensityRay.C:245
Foam::radiation::radiativeIntensityRay::intensityPrefix
static const word intensityPrefix
Definition: radiativeIntensityRay.H:59
Foam::radiation::radiativeIntensityRay::addIntensity
void addIntensity()
Add radiative intensities from all the bands.
Definition: radiativeIntensityRay.C:316
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::nComponents
@ nComponents
Number of components in this vector space.
Definition: VectorSpace.H:88
Foam::vectorTools::cosPhi
T cosPhi(const Vector< T > &a, const Vector< T > &b, const T &tolerance=SMALL)
Calculate angle between a and b in radians.
Definition: vectorTools.H:105
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
fvDOM.H
Foam::radiation::radiativeIntensityRay::correct
scalar correct()
Update radiative intensity on i direction.
Definition: radiativeIntensityRay.C:251
Foam::fvm::Sp
tmp< fvMatrix< Type > > Sp(const DimensionedField< scalar, volMesh > &, const GeometricField< Type, fvPatchField, volMesh > &)
Foam::IOobject::headerOk
bool headerOk()
Read and check header info.
Definition: IOobject.C:439
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:51
Foam::label
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
Foam::IOobject::readOpt
readOption readOpt() const
Definition: IOobject.H:317
Foam::pow3
dimensionedScalar pow3(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:87
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:41
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
Foam::SolverPerformance::initialResidual
const Type & initialResidual() const
Return initial residual.
Definition: SolverPerformance.H:164
fvm.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:41
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam::dimMass
const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:49
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
constants.H
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::solve
SolverPerformance< Type > solve(fvMatrix< Type > &, const dictionary &)
Solve returning the solution statistics given convergence tolerance.
Foam::Vector< scalar >
Foam::autoPtr::valid
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set).
Definition: autoPtrI.H:83
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::constant::mathematical::pi
const scalar pi(M_PI)
Foam::autoPtr::reset
void reset(T *=0)
If object pointer already set, delete object and set to given.
Definition: autoPtrI.H:114
Foam::radiation::absorptionEmissionModel
Model to supply absorption and emission coefficients for radiation modelling.
Definition: absorptionEmissionModel.H:52
Foam::radiation::blackBodyEmission
Class black body emission.
Definition: blackBodyEmission.H:56
Foam::rotationTensor
tensor rotationTensor(const vector &n1, const vector &n2)
Definition: transform.H:46
Foam::radiation::radiativeIntensityRay::radiativeIntensityRay
radiativeIntensityRay(const radiativeIntensityRay &)
Disallow default bitwise copy construct.
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::fvm::div
tmp< fvMatrix< Type > > div(const surfaceScalarField &flux, const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvmDiv.C:46
Foam::SolverPerformance
SolverPerformance is the class returned by the LduMatrix solver containing performance statistics.
Definition: SolverPerformance.H:49
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
normal
A normal distribution model.
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:256
Foam::radiation::fvDOM
Finite Volume Discrete Ordinates Method. Solves the RTE equation for n directions in a participating ...
Definition: fvDOM.H:91