mappedFlowRateFvPatchVectorField.C 5.96 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
6
     \\/     M anipulation  |
OpenFOAM bot's avatar
OpenFOAM bot committed
7
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
    Copyright (C) 2011-2016 OpenFOAM Foundation
9
    Copyright (C) 2020 OpenCFD Ltd.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
-------------------------------------------------------------------------------
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/>.

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

29
#include "mappedFlowRateFvPatchVectorField.H"
30 31 32
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H"
33
#include "mappedPatchBase.H"
34 35 36 37
#include "surfaceFields.H"

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

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


51
Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField
52
(
53
    const mappedFlowRateFvPatchVectorField& ptf,
54 55 56 57 58 59 60 61 62 63 64 65
    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_)
{}


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


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


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


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

107
void Foam::mappedFlowRateFvPatchVectorField::updateCoeffs()
108 109 110 111 112 113
{
    if (updated())
    {
        return;
    }

114 115 116 117 118
    // 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;

119 120
    // Get the coupling information from the mappedPatchBase
    const mappedPatchBase& mpp = refCast<const mappedPatchBase>
121 122 123 124 125 126 127 128 129 130 131 132
    (
        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
133
    mpp.distribute(phi);
134

135 136 137 138

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

139
    scalarField U(-phi/patch().magSf());
140

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

    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() << ':'
161
                << this->internalField().name() << " <- "
162 163
                << nbrMesh.name() << ':'
                << nbrPatch.name() << ':'
164
                << this->internalField().name() << " :"
165 166 167 168 169 170
                << " mass flux[Kg/s]:" << -phi
                << endl;
        }
    }
    else
    {
171 172
        FatalErrorInFunction
            << "dimensions of " << phiName_ << " are incorrect" << nl
173
            << "    on patch " << this->patch().name()
174 175
            << " of field " << this->internalField().name()
            << " in file " << this->internalField().objectPath()
176 177 178
            << nl << exit(FatalError);
    }

179 180 181
    // Restore tag
    UPstream::msgType() = oldTag;

182 183 184 185
    fixedValueFvPatchField<vector>::updateCoeffs();
}


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


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

namespace Foam
{
   makePatchTypeField
   (
       fvPatchVectorField,
206
       mappedFlowRateFvPatchVectorField
207 208 209 210 211
   );
}


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