BUG: PointEdgeWave : n cyclics bool instead of label
[OpenFOAM-1.6.x.git] / src / thermophysicalModels / radiation / derivedFvPatchFields / greyDiffusiveRadiation / greyDiffusiveRadiationMixedFvPatchScalarField.C
blobcdf38518ae8e93f1a8290b1bcce3346c9b376ac0
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     if (dict.found("refValue"))
84     {
85         fvPatchScalarField::operator=
86         (
87             scalarField("value", dict, p.size())
88         );
89         refValue() = scalarField("refValue", dict, p.size());
90         refGrad() = scalarField("refGradient", dict, p.size());
91         valueFraction() = scalarField("valueFraction", dict, p.size());
92     }
93     else
94     {
95         // No value given. Restart as fixedValue b.c.
97         const scalarField& Tp =
98             patch().lookupPatchField<volScalarField, scalar>(TName_);
100         refValue() =
101             emissivity_*4.0*radiation::sigmaSB.value()*pow4(Tp)
102            /Foam::mathematicalConstant::pi;
104         refGrad() = 0.0;
105         valueFraction() = 1.0;
107         fvPatchScalarField::operator=(refValue());
108     }
112 Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::
113 greyDiffusiveRadiationMixedFvPatchScalarField
115     const greyDiffusiveRadiationMixedFvPatchScalarField& ptf
118     mixedFvPatchScalarField(ptf),
119     TName_(ptf.TName_),
120     emissivity_(ptf.emissivity_)
124 Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::
125 greyDiffusiveRadiationMixedFvPatchScalarField
127     const greyDiffusiveRadiationMixedFvPatchScalarField& ptf,
128     const DimensionedField<scalar, volMesh>& iF
131     mixedFvPatchScalarField(ptf, iF),
132     TName_(ptf.TName_),
133     emissivity_(ptf.emissivity_)
137 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
139 void Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::
140 updateCoeffs()
142     if (this->updated())
143     {
144         return;
145     }
147     const scalarField& Tp =
148         patch().lookupPatchField<volScalarField, scalar>(TName_);
150     const radiationModel& radiation =
151         db().lookupObject<radiationModel>("radiationProperties");
153     const fvDOM& dom(refCast<const fvDOM>(radiation));
155     label rayId = -1;
156     label lambdaId = -1;
157     dom.setRayIdLambdaId(dimensionedInternalField().name(), rayId, lambdaId);
159     const label patchI = patch().index();
161     if (dom.nLambda() != 1)
162     {
163         FatalErrorIn
164         (
165             "Foam::radiation::"
166             "greyDiffusiveRadiationMixedFvPatchScalarField::updateCoeffs"
167         )   << " a grey boundary condition is used with a non-grey "
168             << "absorption model" << nl << exit(FatalError);
169     }
171     scalarField& Iw = *this;
172     vectorField n = patch().Sf()/patch().magSf();
174     radiativeIntensityRay& ray =
175         const_cast<radiativeIntensityRay&>(dom.IRay(rayId));
177     ray.Qr().boundaryField()[patchI] += Iw*(n & ray.dAve());
179     forAll(Iw, faceI)
180     {
181         scalar Ir = 0.0;
183         for (label rayI=0; rayI < dom.nRay(); rayI++)
184         {
185             const vector& d = dom.IRay(rayI).d();
187             const scalarField& IFace =
188                 dom.IRay(rayI).ILambda(lambdaId).boundaryField()[patchI];
190             if ((-n[faceI] & d) < 0.0)
191             {
192                 // q into the wall
193                 const vector& dAve = dom.IRay(rayI).dAve();
194                 Ir += IFace[faceI]*mag(n[faceI] & dAve);
195             }
196         }
198         const vector& d = dom.IRay(rayId).d();
200         if ((-n[faceI] & d) > 0.0)
201         {
202             // direction out of the wall
203             refGrad()[faceI] = 0.0;
204             valueFraction()[faceI] = 1.0;
205             refValue()[faceI] =
206                 (
207                     Ir*(1.0 - emissivity_)
208                   + emissivity_*radiation::sigmaSB.value()*pow4(Tp[faceI])
209                 )
210                /mathematicalConstant::pi;
212         }
213         else
214         {
215             // direction into the wall
216             valueFraction()[faceI] = 0.0;
217             refGrad()[faceI] = 0.0;
218             refValue()[faceI] = 0.0; //not used
219         }
220     }
222     mixedFvPatchScalarField::updateCoeffs();
226 void Foam::radiation::greyDiffusiveRadiationMixedFvPatchScalarField::write
228     Ostream& os
229 ) const
231     mixedFvPatchScalarField::write(os);
232     os.writeKeyword("T") << TName_ << token::END_STATEMENT << nl;
233     os.writeKeyword("emissivity") << emissivity_ << token::END_STATEMENT << nl;
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 namespace Foam
241 namespace radiation
243     makePatchTypeField
244     (
245         fvPatchScalarField,
246         greyDiffusiveRadiationMixedFvPatchScalarField
247     );
252 // ************************************************************************* //