1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
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
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 "turbulentIntensityKineticEnergyInletFvPatchScalarField.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "fvPatchFieldMapper.H"
29 #include "surfaceFields.H"
30 #include "volFields.H"
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 Foam::turbulentIntensityKineticEnergyInletFvPatchScalarField::
35 turbulentIntensityKineticEnergyInletFvPatchScalarField
38 const DimensionedField<scalar, volMesh>& iF
41 inletOutletFvPatchScalarField(p, iF),
43 UName_("undefined-U"),
44 phiName_("undefined-phi")
46 this->refValue() = 0.0;
47 this->refGrad() = 0.0;
48 this->valueFraction() = 0.0;
51 Foam::turbulentIntensityKineticEnergyInletFvPatchScalarField::
52 turbulentIntensityKineticEnergyInletFvPatchScalarField
54 const turbulentIntensityKineticEnergyInletFvPatchScalarField& ptf,
56 const DimensionedField<scalar, volMesh>& iF,
57 const fvPatchFieldMapper& mapper
60 inletOutletFvPatchScalarField(ptf, p, iF, mapper),
61 intensity_(ptf.intensity_),
63 phiName_(ptf.phiName_)
66 Foam::turbulentIntensityKineticEnergyInletFvPatchScalarField::
67 turbulentIntensityKineticEnergyInletFvPatchScalarField
70 const DimensionedField<scalar, volMesh>& iF,
71 const dictionary& dict
74 inletOutletFvPatchScalarField(p, iF),
75 intensity_(readScalar(dict.lookup("intensity"))),
76 UName_(dict.lookupOrDefault<word>("U", "U")),
77 phiName_(dict.lookupOrDefault<word>("phi", "phi"))
79 if (intensity_ < 0 || intensity_ > 1)
83 "turbulentIntensityKineticEnergyInletFvPatchScalarField::"
84 "turbulentIntensityKineticEnergyInletFvPatchScalarField"
85 "(const fvPatch& p, const DimensionedField<scalar, volMesh>& iF, "
86 "const dictionary& dict)"
87 ) << "Turbulence intensity should be specified as a fraction 0-1 "
88 "of the mean velocity\n"
89 " value given is " << intensity_
90 << "\n on patch " << this->patch().name()
91 << " of field " << this->dimensionedInternalField().name()
92 << " in file " << this->dimensionedInternalField().objectPath()
96 fvPatchScalarField::operator=(scalarField("value", dict, p.size()));
98 this->refValue() = 0.0;
99 this->refGrad() = 0.0;
100 this->valueFraction() = 0.0;
103 Foam::turbulentIntensityKineticEnergyInletFvPatchScalarField::
104 turbulentIntensityKineticEnergyInletFvPatchScalarField
106 const turbulentIntensityKineticEnergyInletFvPatchScalarField& ptf
109 inletOutletFvPatchScalarField(ptf),
110 intensity_(ptf.intensity_),
112 phiName_(ptf.phiName_)
116 Foam::turbulentIntensityKineticEnergyInletFvPatchScalarField::
117 turbulentIntensityKineticEnergyInletFvPatchScalarField
119 const turbulentIntensityKineticEnergyInletFvPatchScalarField& ptf,
120 const DimensionedField<scalar, volMesh>& iF
123 inletOutletFvPatchScalarField(ptf, iF),
124 intensity_(ptf.intensity_),
126 phiName_(ptf.phiName_)
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 void Foam::turbulentIntensityKineticEnergyInletFvPatchScalarField::
140 const fvPatchVectorField& Up =
141 patch().lookupPatchField<volVectorField, vector>(UName_);
143 const fvsPatchScalarField& phip =
144 patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
146 this->refValue() = 1.5*sqr(intensity_)*magSqr(Up);
147 this->valueFraction() = 1.0 - pos(phip);
149 inletOutletFvPatchScalarField::updateCoeffs();
153 void Foam::turbulentIntensityKineticEnergyInletFvPatchScalarField::write
158 fvPatchScalarField::write(os);
159 os.writeKeyword("intensity") << intensity_ << token::END_STATEMENT << nl;
160 os.writeKeyword("U") << UName_ << token::END_STATEMENT << nl;
161 os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
162 writeEntry("value", os);
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 turbulentIntensityKineticEnergyInletFvPatchScalarField
177 // ************************************************************************* //