totalPressureFvPatchScalarField.C 7.18 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-2017 OpenFOAM Foundation
9
    Copyright (C) 2020 OpenCFD Ltd.
10 11 12 13
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

14 15 16 17
    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.
18 19 20 21 22 23 24

    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
25
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
26 27 28 29 30 31 32 33 34 35 36 37

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

#include "totalPressureFvPatchScalarField.H"
#include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H"
#include "volFields.H"
#include "surfaceFields.H"


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

38
Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
39 40 41 42 43 44
(
    const fvPatch& p,
    const DimensionedField<scalar, volMesh>& iF
)
:
    fixedValueFvPatchScalarField(p, iF),
45 46
    UName_("U"),
    phiName_("phi"),
47
    rhoName_("rho"),
48
    psiName_("none"),
49
    gamma_(0.0),
50
    p0_(p.size(), Zero)
51 52 53
{}


54
Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
55 56 57 58 59 60
(
    const fvPatch& p,
    const DimensionedField<scalar, volMesh>& iF,
    const dictionary& dict
)
:
61
    fixedValueFvPatchScalarField(p, iF, dict, false),
62 63 64 65
    UName_(dict.getOrDefault<word>("U", "U")),
    phiName_(dict.getOrDefault<word>("phi", "phi")),
    rhoName_(dict.getOrDefault<word>("rho", "rho")),
    psiName_(dict.getOrDefault<word>("psi", "none")),
66
    gamma_(psiName_ != "none" ? dict.get<scalar>("gamma") : 1),
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    p0_("p0", dict, p.size())
{
    if (dict.found("value"))
    {
        fvPatchField<scalar>::operator=
        (
            scalarField("value", dict, p.size())
        );
    }
    else
    {
        fvPatchField<scalar>::operator=(p0_);
    }
}


83
Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
(
    const totalPressureFvPatchScalarField& ptf,
    const fvPatch& p,
    const DimensionedField<scalar, volMesh>& iF,
    const fvPatchFieldMapper& mapper
)
:
    fixedValueFvPatchScalarField(ptf, p, iF, mapper),
    UName_(ptf.UName_),
    phiName_(ptf.phiName_),
    rhoName_(ptf.rhoName_),
    psiName_(ptf.psiName_),
    gamma_(ptf.gamma_),
    p0_(ptf.p0_, mapper)
{}


101
Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
102 103 104 105 106 107 108 109 110 111 112 113 114 115
(
    const totalPressureFvPatchScalarField& tppsf
)
:
    fixedValueFvPatchScalarField(tppsf),
    UName_(tppsf.UName_),
    phiName_(tppsf.phiName_),
    rhoName_(tppsf.rhoName_),
    psiName_(tppsf.psiName_),
    gamma_(tppsf.gamma_),
    p0_(tppsf.p0_)
{}


116
Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
(
    const totalPressureFvPatchScalarField& tppsf,
    const DimensionedField<scalar, volMesh>& iF
)
:
    fixedValueFvPatchScalarField(tppsf, iF),
    UName_(tppsf.UName_),
    phiName_(tppsf.phiName_),
    rhoName_(tppsf.rhoName_),
    psiName_(tppsf.psiName_),
    gamma_(tppsf.gamma_),
    p0_(tppsf.p0_)
{}


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

134
void Foam::totalPressureFvPatchScalarField::autoMap
135 136 137 138 139 140 141 142 143
(
    const fvPatchFieldMapper& m
)
{
    fixedValueFvPatchScalarField::autoMap(m);
    p0_.autoMap(m);
}


144
void Foam::totalPressureFvPatchScalarField::rmap
145 146 147 148 149 150 151 152 153 154 155 156 157 158
(
    const fvPatchScalarField& ptf,
    const labelList& addr
)
{
    fixedValueFvPatchScalarField::rmap(ptf, addr);

    const totalPressureFvPatchScalarField& tiptf =
        refCast<const totalPressureFvPatchScalarField>(ptf);

    p0_.rmap(tiptf.p0_, addr);
}


159 160 161 162 163
void Foam::totalPressureFvPatchScalarField::updateCoeffs
(
    const scalarField& p0p,
    const vectorField& Up
)
164 165 166 167 168 169 170 171 172
{
    if (updated())
    {
        return;
    }

    const fvsPatchField<scalar>& phip =
        patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);

173
    if (internalField().dimensions() == dimPressure)
174
    {
175
        if (psiName_ == "none")
176
        {
177
            // Variable density and low-speed compressible flow
178

179 180 181
            const fvPatchField<scalar>& rho =
                patch().lookupPatchField<volScalarField, scalar>(rhoName_);

Henry Weller's avatar
Henry Weller committed
182
            operator==(p0p - 0.5*rho*(1.0 - pos0(phip))*magSqr(Up));
183 184 185
        }
        else
        {
186 187 188 189 190 191 192 193 194 195 196 197 198 199
            // High-speed compressible flow

            const fvPatchField<scalar>& psip =
                patch().lookupPatchField<volScalarField, scalar>(psiName_);

            if (gamma_ > 1)
            {
                scalar gM1ByG = (gamma_ - 1)/gamma_;

                operator==
                (
                    p0p
                   /pow
                    (
Henry Weller's avatar
Henry Weller committed
200
                        (1.0 + 0.5*psip*gM1ByG*(1.0 - pos0(phip))*magSqr(Up)),
201 202 203 204 205 206
                        1.0/gM1ByG
                    )
                );
            }
            else
            {
Henry Weller's avatar
Henry Weller committed
207
                operator==(p0p/(1.0 + 0.5*psip*(1.0 - pos0(phip))*magSqr(Up)));
208
            }
209
        }
210

211
    }
212
    else if (internalField().dimensions() == dimPressure/dimDensity)
213
    {
214
        // Incompressible flow
Henry Weller's avatar
Henry Weller committed
215
        operator==(p0p - 0.5*(1.0 - pos0(phip))*magSqr(Up));
216 217 218
    }
    else
    {
219
        FatalErrorInFunction
220 221 222 223 224 225
            << " Incorrect pressure dimensions " << internalField().dimensions()
            << nl
            << "    Should be " << dimPressure
            << " for compressible/variable density flow" << nl
            << "    or " << dimPressure/dimDensity
            << " for incompressible flow," << nl
226
            << "    on patch " << this->patch().name()
227 228
            << " of field " << this->internalField().name()
            << " in file " << this->internalField().objectPath()
229 230 231 232 233 234 235
            << exit(FatalError);
    }

    fixedValueFvPatchScalarField::updateCoeffs();
}


236
void Foam::totalPressureFvPatchScalarField::updateCoeffs()
237
{
238 239 240 241 242
    updateCoeffs
    (
        p0(),
        patch().lookupPatchField<volVectorField, vector>(UName())
    );
243 244 245
}


246
void Foam::totalPressureFvPatchScalarField::write(Ostream& os) const
247 248
{
    fvPatchScalarField::write(os);
249 250 251 252 253
    os.writeEntryIfDifferent<word>("U", "U", UName_);
    os.writeEntryIfDifferent<word>("phi", "phi", phiName_);
    os.writeEntry("rho", rhoName_);
    os.writeEntry("psi", psiName_);
    os.writeEntry("gamma", gamma_);
254 255 256 257 258 259 260
    p0_.writeEntry("p0", os);
    writeEntry("value", os);
}


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

261 262 263 264 265 266 267 268
namespace Foam
{
    makePatchTypeField
    (
        fvPatchScalarField,
        totalPressureFvPatchScalarField
    );
}
269 270

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