initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / thermophysicalModels / radiation / derivedFvPatchFields / greyDiffusiveRadiation / greyDiffusiveRadiationMixedFvPatchScalarField.C
blob80c3c2dc694839322ceaf2cfa40b1df6929fe6be
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2008-2009 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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "greyDiffusiveRadiationMixedFvPatchScalarField.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
32 #include "fvDOM.H"
33 #include "radiationConstants.H"
34 #include "mathematicalConstants.H"
37 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
39 Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::
40 greyDiffusiveRadiationMixedFvPatchScalarField
42     const fvPatch& p,
43     const DimensionedField<scalar, volMesh>& iF
46     mixedFvPatchScalarField(p, iF),
47     TName_("undefinedT"),
48     emissivity_(0.0)
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     TName_(ptf.TName_),
67     emissivity_(ptf.emissivity_)
71 Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::
72 greyDiffusiveRadiationMixedFvPatchScalarField
74     const fvPatch& p,
75     const DimensionedField<scalar, volMesh>& iF,
76     const dictionary& dict
79     mixedFvPatchScalarField(p, iF),
80     TName_(dict.lookup("T")),
81     emissivity_(readScalar(dict.lookup("emissivity")))
83     const scalarField& Tp =
84         patch().lookupPatchField<volScalarField, scalar>(TName_);
86     refValue() =
87         emissivity_*4.0*radiation::sigmaSB.value()*pow4(Tp)
88        /Foam::mathematicalConstant::pi;
90     refGrad() = 0.0;
92     if (dict.found("value"))
93     {
94         fvPatchScalarField::operator=
95         (
96             scalarField("value", dict, p.size())
97         );
98     }
99     else
100     {
101         fvPatchScalarField::operator=(refValue());
102     }
106 Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::
107 greyDiffusiveRadiationMixedFvPatchScalarField
109     const greyDiffusiveRadiationMixedFvPatchScalarField& ptf
112     mixedFvPatchScalarField(ptf),
113     TName_(ptf.TName_),
114     emissivity_(ptf.emissivity_)
118 Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::
119 greyDiffusiveRadiationMixedFvPatchScalarField
121     const greyDiffusiveRadiationMixedFvPatchScalarField& ptf,
122     const DimensionedField<scalar, volMesh>& iF
125     mixedFvPatchScalarField(ptf, iF),
126     TName_(ptf.TName_),
127     emissivity_(ptf.emissivity_)
131 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
133 void Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::
134 updateCoeffs()
136     if (this->updated())
137     {
138         return;
139     }
141     const scalarField& Tp =
142         patch().lookupPatchField<volScalarField, scalar>(TName_);
144     const radiationModel& radiation =
145         db().lookupObject<radiationModel>("radiationProperties");
147     const fvDOM& dom(refCast<const fvDOM>(radiation));
149     label rayId = -1;
150     label lambdaId = -1;
151     dom.setRayIdLambdaId(dimensionedInternalField().name(), rayId, lambdaId);
153     const label patchI = patch().index();
155     if (dom.nLambda() != 1)
156     {
157         FatalErrorIn
158         (
159             "Foam::radiation::"
160             "greyDiffusiveRadiationMixedFvPatchScalarField::updateCoeffs"
161         )   << " a grey boundary condition is used with a non-grey "
162             << "absorption model" << nl << exit(FatalError);
163     }
165     scalarField& Iw = *this;
166     vectorField n = patch().Sf()/patch().magSf();
168     radiativeIntensityRay& ray =
169         const_cast<radiativeIntensityRay&>(dom.IRay(rayId));
171     ray.Qr().boundaryField()[patchI] += Iw*(-n & ray.dAve());
173     forAll(Iw, faceI)
174     {
175         scalar Ir = 0.0;
177         for (label rayI=0; rayI < dom.nRay(); rayI++)
178         {
179             const vector& d = dom.IRay(rayI).d();
181             const scalarField& IFace =
182                 dom.IRay(rayI).ILambda(lambdaId).boundaryField()[patchI];
184             if ((-n[faceI] & d) < 0.0)
185             {
186                 // q into the wall
187                 const vector& dAve = dom.IRay(rayI).dAve();
188                 Ir += IFace[faceI]*mag(n[faceI] & dAve);
189             }
190         }
192         const vector& d = dom.IRay(rayId).d();
194         if ((-n[faceI] & d) > 0.0)
195         {
196             // direction out of the wall
197             refGrad()[faceI] = 0.0;
198             valueFraction()[faceI] = 1.0;
199             refValue()[faceI] =
200                 (
201                     Ir*(1.0 - emissivity_)
202                   + emissivity_*radiation::sigmaSB.value()*pow4(Tp[faceI])
203                 )
204                /mathematicalConstant::pi;
206         }
207         else
208         {
209             // direction into the wall
210             valueFraction()[faceI] = 0.0;
211             refGrad()[faceI] = 0.0;
212             refValue()[faceI] = 0.0; //not used
213         }
214     }
216     mixedFvPatchScalarField::updateCoeffs();
220 void Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::write
222     Ostream& os
223 ) const
225     fvPatchScalarField::write(os);
226     os.writeKeyword("T") << TName_ << token::END_STATEMENT << nl;
227     os.writeKeyword("emissivity") << emissivity_ << token::END_STATEMENT << nl;
228     writeEntry("value", os);
232 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 namespace Foam
236 namespace radiation
238     makePatchTypeField
239     (
240         fvPatchScalarField,
241         greyDiffusiveRadiationMixedFvPatchScalarField
242     );
247 // ************************************************************************* //