mappedFlowRateFvPatchVectorField.C 5.87 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2015 OpenFOAM Foundation
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    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.

    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
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

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

26
#include "mappedFlowRateFvPatchVectorField.H"
27
28
29
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H"
30
#include "mappedPatchBase.H"
31
32
33
34
#include "surfaceFields.H"

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

35
Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField
36
37
38
39
40
41
42
43
44
45
46
47
(
    const fvPatch& p,
    const DimensionedField<vector, volMesh>& iF
)
:
    fixedValueFvPatchField<vector>(p, iF),
    nbrPhiName_("none"),
    phiName_("phi"),
    rhoName_("rho")
{}


48
Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField
49
(
50
    const mappedFlowRateFvPatchVectorField& ptf,
51
52
53
54
55
56
57
58
59
60
61
62
    const fvPatch& p,
    const DimensionedField<vector, volMesh>& iF,
    const fvPatchFieldMapper& mapper
)
:
    fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
    nbrPhiName_(ptf.nbrPhiName_),
    phiName_(ptf.phiName_),
    rhoName_(ptf.rhoName_)
{}


63
Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField
64
65
66
67
68
69
70
71
72
73
74
75
76
(
    const fvPatch& p,
    const DimensionedField<vector, volMesh>& iF,
    const dictionary& dict
)
:
    fixedValueFvPatchField<vector>(p, iF, dict),
    nbrPhiName_(dict.lookupOrDefault<word>("nbrPhi", "phi")),
    phiName_(dict.lookupOrDefault<word>("phi", "phi")),
    rhoName_(dict.lookupOrDefault<word>("rho", "rho"))
{}


77
Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField
78
(
79
    const mappedFlowRateFvPatchVectorField& ptf
80
81
82
83
84
85
86
87
88
)
:
    fixedValueFvPatchField<vector>(ptf),
    nbrPhiName_(ptf.nbrPhiName_),
    phiName_(ptf.phiName_),
    rhoName_(ptf.rhoName_)
{}


89
Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField
90
(
91
    const mappedFlowRateFvPatchVectorField& ptf,
92
93
94
95
96
97
98
99
100
101
102
103
    const DimensionedField<vector, volMesh>& iF
)
:
    fixedValueFvPatchField<vector>(ptf, iF),
    nbrPhiName_(ptf.nbrPhiName_),
    phiName_(ptf.phiName_),
    rhoName_(ptf.rhoName_)
{}


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

104
void Foam::mappedFlowRateFvPatchVectorField::updateCoeffs()
105
106
107
108
109
110
{
    if (updated())
    {
        return;
    }

111
112
113
114
115
    // Since we're inside initEvaluate/evaluate there might be processor
    // comms underway. Change the tag we use.
    int oldTag = UPstream::msgType();
    UPstream::msgType() = oldTag+1;

116
117
    // Get the coupling information from the mappedPatchBase
    const mappedPatchBase& mpp = refCast<const mappedPatchBase>
118
119
120
121
122
123
124
125
126
127
128
129
    (
        patch().patch()
    );
    const polyMesh& nbrMesh = mpp.sampleMesh();
    const fvPatch& nbrPatch = refCast<const fvMesh>
    (
        nbrMesh
    ).boundary()[mpp.samplePolyPatch().index()];

    scalarList phi =
        nbrPatch.lookupPatchField<surfaceScalarField, scalar>(nbrPhiName_);

andy's avatar
andy committed
130
    mpp.distribute(phi);
sergio's avatar
sergio committed
131

132
133
134
135

    const surfaceScalarField& phiName =
        db().lookupObject<surfaceScalarField>(phiName_);

136
    scalarField U(-phi/patch().magSf());
137

138
    vectorField n(patch().nf());
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157

    if (phiName.dimensions() == dimVelocity*dimArea)
    {
        // volumetric flow-rate
        operator==(n*U);
    }
    else if (phiName.dimensions() == dimDensity*dimVelocity*dimArea)
    {
        const fvPatchField<scalar>& rhop =
            patch().lookupPatchField<volScalarField, scalar>(rhoName_);

        // mass flow-rate
        operator==(n*U/rhop);

        if (debug)
        {
            scalar phi = gSum(rhop*(*this) & patch().Sf());
            Info<< patch().boundaryMesh().mesh().name() << ':'
                << patch().name() << ':'
158
                << this->internalField().name() << " <- "
159
160
                << nbrMesh.name() << ':'
                << nbrPatch.name() << ':'
161
                << this->internalField().name() << " :"
162
163
164
165
166
167
                << " mass flux[Kg/s]:" << -phi
                << endl;
        }
    }
    else
    {
168
169
        FatalErrorInFunction
            << "dimensions of " << phiName_ << " are incorrect" << nl
170
            << "    on patch " << this->patch().name()
171
172
            << " of field " << this->internalField().name()
            << " in file " << this->internalField().objectPath()
173
174
175
            << nl << exit(FatalError);
    }

176
177
178
    // Restore tag
    UPstream::msgType() = oldTag;

179
180
181
182
    fixedValueFvPatchField<vector>::updateCoeffs();
}


183
void Foam::mappedFlowRateFvPatchVectorField::write
andy's avatar
andy committed
184
185
186
(
    Ostream& os
) const
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
{
    fvPatchField<vector>::write(os);
    writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
    writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
    os.writeKeyword("nbrPhi") << nbrPhiName_ << token::END_STATEMENT << nl;
    writeEntry("value", os);
}


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

namespace Foam
{
   makePatchTypeField
   (
       fvPatchVectorField,
203
       mappedFlowRateFvPatchVectorField
204
205
206
207
208
   );
}


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