BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / thermophysicalModels / radiationModels / derivedFvPatchFields / wideBandDiffusiveRadiation / wideBandDiffusiveRadiationMixedFvPatchScalarField.C
blobff0bb83b4603963d32238e43dfeceb145c6e3367
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "wideBandDiffusiveRadiationMixedFvPatchScalarField.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "fvPatchFieldMapper.H"
29 #include "volFields.H"
31 #include "fvDOM.H"
32 #include "wideBandAbsorptionEmission.H"
33 #include "constants.H"
35 using namespace Foam::constant;
36 using namespace Foam::constant::mathematical;
38 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
40 Foam::radiation::wideBandDiffusiveRadiationMixedFvPatchScalarField::
41 wideBandDiffusiveRadiationMixedFvPatchScalarField
43     const fvPatch& p,
44     const DimensionedField<scalar, volMesh>& iF
47     mixedFvPatchScalarField(p, iF),
48     radiationCoupledBase(p, "undefined", scalarField::null()),
49     TName_("undefinedT")
51     refValue() = 0.0;
52     refGrad() = 0.0;
53     valueFraction() = 1.0;
57 Foam::radiation::wideBandDiffusiveRadiationMixedFvPatchScalarField::
58 wideBandDiffusiveRadiationMixedFvPatchScalarField
60     const wideBandDiffusiveRadiationMixedFvPatchScalarField& ptf,
61     const fvPatch& p,
62     const DimensionedField<scalar, volMesh>& iF,
63     const fvPatchFieldMapper& mapper
66     mixedFvPatchScalarField(ptf, p, iF, mapper),
67     radiationCoupledBase
68     (
69         p,
70         ptf.emissivityMethod(),
71         ptf.emissivity_
72     ),
73     TName_(ptf.TName_)
77 Foam::radiation::wideBandDiffusiveRadiationMixedFvPatchScalarField::
78 wideBandDiffusiveRadiationMixedFvPatchScalarField
80     const fvPatch& p,
81     const DimensionedField<scalar, volMesh>& iF,
82     const dictionary& dict
85     mixedFvPatchScalarField(p, iF),
86     radiationCoupledBase(p, dict),
87     TName_(dict.lookup("T"))
89     if (dict.found("value"))
90     {
91         fvPatchScalarField::operator=
92         (
93             scalarField("value", dict, p.size())
94         );
95         refValue() = scalarField("refValue", dict, p.size());
96         refGrad() = scalarField("refGradient", dict, p.size());
97         valueFraction() = scalarField("valueFraction", dict, p.size());
98     }
99     else
100     {
101         const scalarField& Tp =
102             patch().lookupPatchField<volScalarField, scalar>(TName_);
104         refValue() =
105             4.0*physicoChemical::sigma.value()*pow4(Tp)*emissivity()/pi;
106         refGrad() = 0.0;
108         fvPatchScalarField::operator=(refValue());
109     }
113 Foam::radiation::wideBandDiffusiveRadiationMixedFvPatchScalarField::
114 wideBandDiffusiveRadiationMixedFvPatchScalarField
116     const wideBandDiffusiveRadiationMixedFvPatchScalarField& ptf
119     mixedFvPatchScalarField(ptf),
120     radiationCoupledBase
121     (
122         ptf.patch(),
123         ptf.emissivityMethod(),
124         ptf.emissivity_
125     ),
126     TName_(ptf.TName_)
130 Foam::radiation::wideBandDiffusiveRadiationMixedFvPatchScalarField::
131 wideBandDiffusiveRadiationMixedFvPatchScalarField
133     const wideBandDiffusiveRadiationMixedFvPatchScalarField& ptf,
134     const DimensionedField<scalar, volMesh>& iF
137     mixedFvPatchScalarField(ptf, iF),
138     radiationCoupledBase
139     (
140         ptf.patch(),
141         ptf.emissivityMethod(),
142         ptf.emissivity_
143     ),
144     TName_(ptf.TName_)
148 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
150 void Foam::radiation::wideBandDiffusiveRadiationMixedFvPatchScalarField::
151 updateCoeffs()
153     if (this->updated())
154     {
155         return;
156     }
158     // Since we're inside initEvaluate/evaluate there might be processor
159     // comms underway. Change the tag we use.
160     int oldTag = UPstream::msgType();
161     UPstream::msgType() = oldTag+1;
163     const radiationModel& radiation =
164         db().lookupObject<radiationModel>("radiationProperties");
166     const fvDOM& dom(refCast<const fvDOM>(radiation));
168     label rayId = -1;
169     label lambdaId = -1;
170     dom.setRayIdLambdaId(dimensionedInternalField().name(), rayId, lambdaId);
172     const label patchI = patch().index();
174     if (dom.nLambda() == 0)
175     {
176         FatalErrorIn
177         (
178             "Foam::radiation::"
179             "wideBandDiffusiveRadiationMixedFvPatchScalarField::updateCoeffs"
180         )   << " a non-grey boundary condition is used with a grey "
181             << "absorption model" << nl << exit(FatalError);
182     }
184     scalarField& Iw = *this;
185     const vectorField n(patch().Sf()/patch().magSf());
187     radiativeIntensityRay& ray =
188         const_cast<radiativeIntensityRay&>(dom.IRay(rayId));
190     ray.Qr().boundaryField()[patchI] += Iw*(n & ray.dAve());
192     const scalarField Eb
193     (
194         dom.blackBody().bLambda(lambdaId).boundaryField()[patchI]
195     );
197     scalarField temissivity = emissivity();
199     forAll(Iw, faceI)
200     {
201         scalar Ir = 0.0;
202         for (label rayI=0; rayI < dom.nRay(); rayI++)
203         {
204             const vector& d = dom.IRay(rayI).d();
206             const scalarField& IFace =
207                 dom.IRay(rayI).ILambda(lambdaId).boundaryField()[patchI];
209             if ((-n[faceI] & d) < 0.0) // qin into the wall
210             {
211                 const vector& dAve = dom.IRay(rayI).dAve();
212                 Ir = Ir + IFace[faceI]*mag(n[faceI] & dAve);
213             }
214         }
216         const vector& d = dom.IRay(rayId).d();
218         if ((-n[faceI] & d) > 0.0)
219         {
220             // direction out of the wall
221             refGrad()[faceI] = 0.0;
222             valueFraction()[faceI] = 1.0;
223             refValue()[faceI] =
224                 (
225                     Ir*(1.0 - temissivity[faceI])
226                   + temissivity[faceI]*Eb[faceI]
227                 )/pi;
228         }
229         else
230         {
231             // direction into the wall
232             valueFraction()[faceI] = 0.0;
233             refGrad()[faceI] = 0.0;
234             refValue()[faceI] = 0.0; //not used
235         }
236     }
238     // Restore tag
239     UPstream::msgType() = oldTag;
241     mixedFvPatchScalarField::updateCoeffs();
245 void Foam::radiation::wideBandDiffusiveRadiationMixedFvPatchScalarField::write
247     Ostream& os
248 ) const
250     mixedFvPatchScalarField::write(os);
251     radiationCoupledBase::write(os);
252     os.writeKeyword("T") << TName_ << token::END_STATEMENT << nl;
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 namespace Foam
261 namespace radiation
263     makePatchTypeField
264     (
265         fvPatchScalarField,
266         wideBandDiffusiveRadiationMixedFvPatchScalarField
267     );
272 // ************************************************************************* //