mappedFlowRateFvPatchVectorField.C 5.93 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 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
-------------------------------------------------------------------------------
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/>.

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

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

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

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


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


65
Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField
66 67 68 69 70 71 72 73 74 75 76 77 78
(
    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"))
{}


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


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


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

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

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

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

134 135 136 137

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

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

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

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

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

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


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


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

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


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