flowRateInletVelocityFvPatchVectorField.C 6.62 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2016 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),
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
75
76
77
        rhoName_ = word(dict.lookupOrDefault<word>("rho", "rho"));
    }
    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::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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
template<class RhoType>
void Foam::flowRateInletVelocityFvPatchVectorField::updateValues
(
    const RhoType& rho
)
{
    const scalar t = db().time().timeOutputValue();

    tmp<vectorField> n = patch().nf();

    if (extrapolateProfile_)
    {
        vectorField newValues(this->patchInternalField());

        scalar flowRate = flowRate_->value(t);
        scalar estimatedFlowRate = -gSum(rho*(this->patch().Sf() & newValues));

        if (estimatedFlowRate/flowRate > 0.5)
        {
            newValues *= (mag(flowRate)/mag(estimatedFlowRate));
        }
        else
        {
            newValues -=
                ((flowRate - estimatedFlowRate)/gSum(rho*patch().magSf()))*n;
        }

        this->operator==(newValues);
    }
    else
    {
        const scalar avgU = -flowRate_->value(t)/gSum(rho*patch().magSf());
        operator==(n*avgU);
    }
}


188
189
190
191
192
193
194
195
196
void Foam::flowRateInletVelocityFvPatchVectorField::updateCoeffs()
{
    if (updated())
    {
        return;
    }

    if (volumetric_ || rhoName_ == "none")
    {
197
        updateValues(one());
198
199
200
    }
    else
    {
201
        // Mass flow-rate
andy's avatar
andy committed
202
        if (db().foundObject<volScalarField>(rhoName_))
203
204
205
206
        {
            const fvPatchField<scalar>& rhop =
                patch().lookupPatchField<volScalarField, scalar>(rhoName_);

207
            updateValues(rhop);
208
209
210
211
212
213
        }
        else
        {
            // Use constant density
            if (rhoInlet_ < 0)
            {
214
215
                FatalErrorInFunction
                    << "Did not find registered density field " << rhoName_
216
217
218
                    << " and no constant density 'rhoInlet' specified"
                    << exit(FatalError);
            }
219
220

            updateValues(rhoInlet_);
221
        }
222
223
    }

224
    fixedValueFvPatchVectorField::updateCoeffs();
225
226
227
}


228
void Foam::flowRateInletVelocityFvPatchVectorField::write(Ostream& os) const
229
230
{
    fvPatchField<vector>::write(os);
231
    flowRate_->writeData(os);
232
233
234
    if (!volumetric_)
    {
        writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
235
        writeEntryIfDifferent<scalar>(os, "rhoInlet", -VGREAT, rhoInlet_);
236
    }
237
238
239
240
241
242
243
244
245
246
247
    writeEntry("value", os);
}


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

namespace Foam
{
   makePatchTypeField
   (
       fvPatchVectorField,
248
       flowRateInletVelocityFvPatchVectorField
249
250
251
252
253
   );
}


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