flowRateInletVelocityFvPatchVectorField.C 7.08 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
6
7
8
9
10
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

11
12
13
14
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
15
16
17
18
19
20
21

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
22
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
23
24
25

\*---------------------------------------------------------------------------*/

26
#include "flowRateInletVelocityFvPatchVectorField.H"
27
#include "addToRunTimeSelectionTable.H"
28
#include "volFields.H"
29
#include "one.H"
30
31
32

// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

33
Foam::flowRateInletVelocityFvPatchVectorField::
34
flowRateInletVelocityFvPatchVectorField
35
36
37
38
39
40
(
    const fvPatch& p,
    const DimensionedField<vector, volMesh>& iF
)
:
    fixedValueFvPatchField<vector>(p, iF),
41
    flowRate_(),
42
43
    volumetric_(false),
    rhoName_("rho"),
44
45
    rhoInlet_(0.0),
    extrapolateProfile_(false)
46
47
{}

48

49
Foam::flowRateInletVelocityFvPatchVectorField::
50
flowRateInletVelocityFvPatchVectorField
51
52
53
54
55
56
(
    const fvPatch& p,
    const DimensionedField<vector, volMesh>& iF,
    const dictionary& dict
)
:
57
    fixedValueFvPatchField<vector>(p, iF, dict, false),
58
59
60
61
62
    rhoInlet_(dict.lookupOrDefault<scalar>("rhoInlet", -VGREAT)),
    extrapolateProfile_
    (
        dict.lookupOrDefault<Switch>("extrapolateProfile", false)
    )
63
64
65
66
{
    if (dict.found("volumetricFlowRate"))
    {
        volumetric_ = true;
Henry Weller's avatar
Henry Weller committed
67
        flowRate_ = Function1<scalar>::New("volumetricFlowRate", dict);
68
69
70
71
72
        rhoName_ = "rho";
    }
    else if (dict.found("massFlowRate"))
    {
        volumetric_ = false;
Henry Weller's avatar
Henry Weller committed
73
        flowRate_ = Function1<scalar>::New("massFlowRate", dict);
74
        rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
75
76
77
    }
    else
    {
78
        FatalIOErrorInFunction
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
        (
            dict
        )   << "Please supply either 'volumetricFlowRate' or"
            << " 'massFlowRate' and 'rho'" << exit(FatalIOError);
    }

    // Value field require if mass based
    if (dict.found("value"))
    {
        fvPatchField<vector>::operator=
        (
            vectorField("value", dict, p.size())
        );
    }
    else
    {
95
        evaluate(Pstream::commsTypes::blocking);
96
97
    }
}
98

99

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
Foam::flowRateInletVelocityFvPatchVectorField::
flowRateInletVelocityFvPatchVectorField
(
    const flowRateInletVelocityFvPatchVectorField& ptf,
    const fvPatch& p,
    const DimensionedField<vector, volMesh>& iF,
    const fvPatchFieldMapper& mapper
)
:
    fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
    flowRate_(ptf.flowRate_, false),
    volumetric_(ptf.volumetric_),
    rhoName_(ptf.rhoName_),
    rhoInlet_(ptf.rhoInlet_),
    extrapolateProfile_(ptf.extrapolateProfile_)
{}


118
Foam::flowRateInletVelocityFvPatchVectorField::
119
flowRateInletVelocityFvPatchVectorField
120
(
121
    const flowRateInletVelocityFvPatchVectorField& ptf
122
123
124
)
:
    fixedValueFvPatchField<vector>(ptf),
125
    flowRate_(ptf.flowRate_, false),
126
127
    volumetric_(ptf.volumetric_),
    rhoName_(ptf.rhoName_),
128
129
    rhoInlet_(ptf.rhoInlet_),
    extrapolateProfile_(ptf.extrapolateProfile_)
130
131
{}

132

133
Foam::flowRateInletVelocityFvPatchVectorField::
134
flowRateInletVelocityFvPatchVectorField
135
(
136
    const flowRateInletVelocityFvPatchVectorField& ptf,
137
138
139
140
    const DimensionedField<vector, volMesh>& iF
)
:
    fixedValueFvPatchField<vector>(ptf, iF),
141
    flowRate_(ptf.flowRate_, false),
142
143
    volumetric_(ptf.volumetric_),
    rhoName_(ptf.rhoName_),
144
145
    rhoInlet_(ptf.rhoInlet_),
    extrapolateProfile_(ptf.extrapolateProfile_)
146
147
148
149
150
{}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

151
152
153
154
155
156
157
158
template<class RhoType>
void Foam::flowRateInletVelocityFvPatchVectorField::updateValues
(
    const RhoType& rho
)
{
    const scalar t = db().time().timeOutputValue();

159
    const vectorField n(patch().nf());
160
161
162

    if (extrapolateProfile_)
    {
163
        vectorField Up(this->patchInternalField());
164

165
166
167
168
169
170
171
172
173
174
175
        // Patch normal extrapolated velocity
        scalarField nUp(n & Up);

        // Remove the normal component of the extrapolate patch velocity
        Up -= nUp*n;

        // Remove any reverse flow
        nUp = min(nUp, 0.0);

        const scalar flowRate = flowRate_->value(t);
        const scalar estimatedFlowRate = -gSum(rho*(this->patch().magSf()*nUp));
176
177
178

        if (estimatedFlowRate/flowRate > 0.5)
        {
179
            nUp *= (mag(flowRate)/mag(estimatedFlowRate));
180
181
182
        }
        else
        {
183
            nUp -= ((flowRate - estimatedFlowRate)/gSum(rho*patch().magSf()));
184
185
        }

186
187
188
189
190
        // Add the corrected normal component of velocity to the patch velocity
        Up += nUp*n;

        // Correct the patch velocity
        this->operator==(Up);
191
192
193
194
    }
    else
    {
        const scalar avgU = -flowRate_->value(t)/gSum(rho*patch().magSf());
195
        operator==(avgU*n);
196
197
198
199
    }
}


200
201
202
203
204
205
206
207
208
void Foam::flowRateInletVelocityFvPatchVectorField::updateCoeffs()
{
    if (updated())
    {
        return;
    }

    if (volumetric_ || rhoName_ == "none")
    {
209
        updateValues(one());
210
211
212
    }
    else
    {
213
        // Mass flow-rate
andy's avatar
andy committed
214
        if (db().foundObject<volScalarField>(rhoName_))
215
216
217
218
        {
            const fvPatchField<scalar>& rhop =
                patch().lookupPatchField<volScalarField, scalar>(rhoName_);

219
            updateValues(rhop);
220
221
222
223
224
225
        }
        else
        {
            // Use constant density
            if (rhoInlet_ < 0)
            {
226
227
                FatalErrorInFunction
                    << "Did not find registered density field " << rhoName_
228
229
230
                    << " and no constant density 'rhoInlet' specified"
                    << exit(FatalError);
            }
231
232

            updateValues(rhoInlet_);
233
        }
234
235
    }

236
    fixedValueFvPatchVectorField::updateCoeffs();
237
238
239
}


240
void Foam::flowRateInletVelocityFvPatchVectorField::write(Ostream& os) const
241
242
{
    fvPatchField<vector>::write(os);
243
    flowRate_->writeData(os);
244
245
246
    if (!volumetric_)
    {
        writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
247
        writeEntryIfDifferent<scalar>(os, "rhoInlet", -VGREAT, rhoInlet_);
248
    }
249
250
    os.writeKeyword("extrapolateProfile")
        << extrapolateProfile_ << token::END_STATEMENT << nl;
251
252
253
254
255
256
257
258
259
260
261
    writeEntry("value", os);
}


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
   makePatchTypeField
   (
       fvPatchVectorField,
262
       flowRateInletVelocityFvPatchVectorField
263
264
265
266
267
   );
}


// ************************************************************************* //