Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / thermophysicalModels / radiationModels / derivedFvPatchFields / greyDiffusiveRadiation / greyDiffusiveRadiationMixedFvPatchScalarField.C
blob90727e381bd1e118b279af75a8ad46cab3e01957
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2008-2011 OpenCFD Ltd.
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 "greyDiffusiveRadiationMixedFvPatchScalarField.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "fvPatchFieldMapper.H"
29 #include "volFields.H"
31 #include "fvDOM.H"
32 #include "constants.H"
34 using namespace Foam::constant;
35 using namespace Foam::constant::mathematical;
37 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
39 Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::
40 greyDiffusiveRadiationMixedFvPatchScalarField
42     const fvPatch& p,
43     const DimensionedField<scalar, volMesh>& iF
46     mixedFvPatchScalarField(p, iF),
47     radiationCoupledBase(p, "undefined", scalarField::null()),
48     TName_("undefinedT")
50     refValue() = 0.0;
51     refGrad() = 0.0;
52     valueFraction() = 1.0;
56 Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::
57 greyDiffusiveRadiationMixedFvPatchScalarField
59     const greyDiffusiveRadiationMixedFvPatchScalarField& ptf,
60     const fvPatch& p,
61     const DimensionedField<scalar, volMesh>& iF,
62     const fvPatchFieldMapper& mapper
65     mixedFvPatchScalarField(ptf, p, iF, mapper),
66     radiationCoupledBase
67     (
68         p,
69         ptf.emissivityMethod(),
70         ptf.emissivity_
71     ),
72     TName_(ptf.TName_)
76 Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::
77 greyDiffusiveRadiationMixedFvPatchScalarField
79     const fvPatch& p,
80     const DimensionedField<scalar, volMesh>& iF,
81     const dictionary& dict
84     mixedFvPatchScalarField(p, iF),
85     radiationCoupledBase(p, dict),
86     TName_(dict.lookup("T"))
88     if (dict.found("refValue"))
89     {
90         fvPatchScalarField::operator=
91         (
92             scalarField("value", dict, p.size())
93         );
94         refValue() = scalarField("refValue", dict, p.size());
95         refGrad() = scalarField("refGradient", dict, p.size());
96         valueFraction() = scalarField("valueFraction", dict, p.size());
97     }
98     else
99     {
100         // No value given. Restart as fixedValue b.c.
102         const scalarField& Tp =
103             patch().lookupPatchField<volScalarField, scalar>(TName_);
105         refValue() =
106             4.0*physicoChemical::sigma.value()*pow4(Tp)*emissivity()/pi;
107         refGrad() = 0.0;
108         valueFraction() = 1.0;
110         fvPatchScalarField::operator=(refValue());
111     }
115 Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::
116 greyDiffusiveRadiationMixedFvPatchScalarField
118     const greyDiffusiveRadiationMixedFvPatchScalarField& ptf
121     mixedFvPatchScalarField(ptf),
122     radiationCoupledBase
123     (
124         ptf.patch(),
125         ptf.emissivityMethod(),
126         ptf.emissivity_
127     ),
128     TName_(ptf.TName_)
132 Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::
133 greyDiffusiveRadiationMixedFvPatchScalarField
135     const greyDiffusiveRadiationMixedFvPatchScalarField& ptf,
136     const DimensionedField<scalar, volMesh>& iF
139     mixedFvPatchScalarField(ptf, iF),
140     radiationCoupledBase
141     (
142         ptf.patch(),
143         ptf.emissivityMethod(),
144         ptf.emissivity_
145     ),
146     TName_(ptf.TName_)
150 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
152 void Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::
153 updateCoeffs()
155     if (this->updated())
156     {
157         return;
158     }
160     const scalarField& Tp =
161         patch().lookupPatchField<volScalarField, scalar>(TName_);
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() != 1)
175     {
176         FatalErrorIn
177         (
178             "Foam::radiation::"
179             "greyDiffusiveRadiationMixedFvPatchScalarField::updateCoeffs"
180         )   << " a grey boundary condition is used with a non-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     scalarList temissivity = emissivity();
194     forAll(Iw, faceI)
195     {
196         scalar Ir = 0.0;
198         for (label rayI=0; rayI < dom.nRay(); rayI++)
199         {
200             const vector& d = dom.IRay(rayI).d();
202             const scalarField& IFace =
203                 dom.IRay(rayI).ILambda(lambdaId).boundaryField()[patchI];
205             if ((-n[faceI] & d) < 0.0)
206             {
207                 // q into the wall
208                 const vector& dAve = dom.IRay(rayI).dAve();
209                 Ir += IFace[faceI]*mag(n[faceI] & dAve);
210             }
211         }
213         const vector& d = dom.IRay(rayId).d();
215         if ((-n[faceI] & d) > 0.0)
216         {
217             // direction out of the wall
218             refGrad()[faceI] = 0.0;
219             valueFraction()[faceI] = 1.0;
220             refValue()[faceI] =
221                 (
222                     Ir*(scalar(1.0) - temissivity[faceI])
223                   + temissivity[faceI]*physicoChemical::sigma.value()
224                   * pow4(Tp[faceI])
225                 )/pi;
227              // Emmited heat flux from this ray direction
228             ray.Qem().boundaryField()[patchI][faceI] =
229                 refValue()[faceI]*(n[faceI] & ray.dAve());
230         }
231         else
232         {
233             // direction into the wall
234             valueFraction()[faceI] = 0.0;
235             refGrad()[faceI] = 0.0;
236             refValue()[faceI] = 0.0; //not used
238              // Incident heat flux on this ray direction
239             ray.Qin().boundaryField()[patchI][faceI] =
240                 Iw[faceI]*(n[faceI] & ray.dAve());
241         }
242     }
243     mixedFvPatchScalarField::updateCoeffs();
247 void Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::write
249     Ostream& os
250 ) const
252     mixedFvPatchScalarField::write(os);
253     radiationCoupledBase::write(os);
254     os.writeKeyword("T") << TName_ << token::END_STATEMENT << nl;
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 namespace Foam
262 namespace radiation
264     makePatchTypeField
265     (
266         fvPatchScalarField,
267         greyDiffusiveRadiationMixedFvPatchScalarField
268     );
273 // ************************************************************************* //