uniformInletOutletFvPatchField.C 5.8 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
OpenFOAM bot's avatar
OpenFOAM bot committed
6 7
     \\/     M anipulation  |
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
    Copyright (C) 2013-2017 OpenFOAM Foundation
9
    Copyright (C) 2015-2020 OpenCFD Ltd.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
-------------------------------------------------------------------------------
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/>.

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

#include "uniformInletOutletFvPatchField.H"

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

template<class Type>
Foam::uniformInletOutletFvPatchField<Type>::uniformInletOutletFvPatchField
(
    const fvPatch& p,
    const DimensionedField<Type, volMesh>& iF
)
:
    mixedFvPatchField<Type>(p, iF),
    phiName_("phi")
{
43 44
    this->refValue() = Zero;
    this->refGrad() = Zero;
45 46 47 48 49 50 51 52 53
    this->valueFraction() = 0.0;
}


template<class Type>
Foam::uniformInletOutletFvPatchField<Type>::uniformInletOutletFvPatchField
(
    const fvPatch& p,
    const DimensionedField<Type, volMesh>& iF,
54
    const dictionary& dict
55 56 57
)
:
    mixedFvPatchField<Type>(p, iF),
58
    phiName_(dict.getOrDefault<word>("phi", "phi")),
Henry Weller's avatar
Henry Weller committed
59
    uniformInletValue_(Function1<Type>::New("uniformInletValue", dict))
60
{
61
    this->patchType() = dict.getOrDefault<word>("patchType", word::null);
62 63
    this->refValue() =
        uniformInletValue_->value(this->db().time().timeOutputValue());
64

65 66 67 68 69 70 71 72
    if (dict.found("value"))
    {
        fvPatchField<Type>::operator=
        (
            Field<Type>("value", dict, p.size())
        );
    }
    else
73 74 75 76
    {
        fvPatchField<Type>::operator=(this->refValue());
    }

77
    this->refGrad() = Zero;
78
    this->valueFraction() = 0.0;
79 80 81 82 83 84
}


template<class Type>
Foam::uniformInletOutletFvPatchField<Type>::uniformInletOutletFvPatchField
(
85
    const uniformInletOutletFvPatchField<Type>& ptf,
86 87
    const fvPatch& p,
    const DimensionedField<Type, volMesh>& iF,
88
    const fvPatchFieldMapper& mapper
89 90
)
:
91 92
    mixedFvPatchField<Type>(p, iF),  // Don't map
    phiName_(ptf.phiName_),
93
    uniformInletValue_(ptf.uniformInletValue_.clone())
94
{
95 96 97
    this->patchType() = ptf.patchType();

    // Evaluate refValue since not mapped
98 99
    this->refValue() =
        uniformInletValue_->value(this->db().time().timeOutputValue());
100

101
    this->refGrad() = Zero;
102
    this->valueFraction() = 0.0;
103 104 105 106 107

    // Initialize the patch value to the refValue
    fvPatchField<Type>::operator=(this->refValue());

    this->map(ptf, mapper);
108 109 110 111 112 113 114 115 116 117 118
}


template<class Type>
Foam::uniformInletOutletFvPatchField<Type>::uniformInletOutletFvPatchField
(
    const uniformInletOutletFvPatchField<Type>& ptf
)
:
    mixedFvPatchField<Type>(ptf),
    phiName_(ptf.phiName_),
119
    uniformInletValue_(ptf.uniformInletValue_.clone())
120 121 122 123 124 125 126 127 128 129 130 131
{}


template<class Type>
Foam::uniformInletOutletFvPatchField<Type>::uniformInletOutletFvPatchField
(
    const uniformInletOutletFvPatchField<Type>& ptf,
    const DimensionedField<Type, volMesh>& iF
)
:
    mixedFvPatchField<Type>(ptf, iF),
    phiName_(ptf.phiName_),
132
    uniformInletValue_(ptf.uniformInletValue_.clone())
133 134 135 136 137 138 139 140 141 142 143 144 145
{}


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

template<class Type>
void Foam::uniformInletOutletFvPatchField<Type>::updateCoeffs()
{
    if (this->updated())
    {
        return;
    }

146 147 148 149
    // Update the uniform value as a function of time
    const scalar t = this->db().time().timeOutputValue();
    this->refValue() = uniformInletValue_->value(t);

150 151 152 153 154 155
    const Field<scalar>& phip =
        this->patch().template lookupPatchField<surfaceScalarField, scalar>
        (
            phiName_
        );

Henry Weller's avatar
Henry Weller committed
156
    this->valueFraction() = 1.0 - pos0(phip);
157 158 159 160 161 162 163 164 165

    mixedFvPatchField<Type>::updateCoeffs();
}


template<class Type>
void Foam::uniformInletOutletFvPatchField<Type>::write(Ostream& os) const
{
    fvPatchField<Type>::write(os);
166
    os.writeEntryIfDifferent<word>("phi", "phi", phiName_);
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
    this->uniformInletValue_->writeData(os);
    this->writeEntry("value", os);
}


// * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //

template<class Type>
void Foam::uniformInletOutletFvPatchField<Type>::autoMap
(
    const fvPatchFieldMapper& m
)
{
    mixedFvPatchField<Type>::autoMap(m);

    // Override
183 184
    this->refValue() =
        uniformInletValue_->value(this->db().time().timeOutputValue());
185 186 187 188 189 190 191 192 193 194 195 196 197
}


template<class Type>
void Foam::uniformInletOutletFvPatchField<Type>::rmap
(
    const fvPatchField<Type>& ptf,
    const labelList& addr
)
{
    mixedFvPatchField<Type>::rmap(ptf, addr);

    // Override
198 199
    this->refValue() =
        uniformInletValue_->value(this->db().time().timeOutputValue());
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
}


// * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //

template<class Type>
void Foam::uniformInletOutletFvPatchField<Type>::operator=
(
    const fvPatchField<Type>& ptf
)
{
    fvPatchField<Type>::operator=
    (
        this->valueFraction()*this->refValue()
        + (1 - this->valueFraction())*ptf
    );
}


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