fixedMeanOutletInletFvPatchField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2018-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
27 #include "volFields.H"
28 #include "surfaceFields.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  const fvPatch& p,
37 )
38 :
40  meanValue_()
41 {}
42 
43 
44 template<class Type>
46 (
47  const fvPatch& p,
49  const dictionary& dict
50 )
51 :
53  meanValue_(Function1<Type>::New("meanValue", dict))
54 {
55  this->phiName_ = dict.lookupOrDefault<word>("phi", "phi");
56 
58  (
59  Field<Type>("value", dict, p.size())
60  );
61 
62  this->refValue() = *this;
63  this->refGrad() = Zero;
64  this->valueFraction() = 0.0;
65 }
66 
67 
68 template<class Type>
70 (
72  const fvPatch& p,
74  const fvPatchFieldMapper& mapper
75 )
76 :
77  outletInletFvPatchField<Type>(ptf, p, iF, mapper),
78  meanValue_(ptf.meanValue_, false)
79 {}
80 
81 
82 template<class Type>
84 (
87 )
88 :
90  meanValue_(ptf.meanValue_, false)
91 {}
92 
93 
94 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
95 
96 template<class Type>
98 {
99  if (this->updated())
100  {
101  return;
102  }
103 
104  const scalar t = this->db().time().userTimeValue();
105  Type meanValue = meanValue_->value(t);
106 
107  Field<Type> newValues(this->patchInternalField());
108 
109  Type meanValuePsi =
110  gSum(this->patch().magSf()*newValues)
111  /gSum(this->patch().magSf());
112 
113  if (mag(meanValue) > small && mag(meanValuePsi)/mag(meanValue) > 0.5)
114  {
115  newValues *= mag(meanValue)/mag(meanValuePsi);
116  }
117  else
118  {
119  newValues += (meanValue - meanValuePsi);
120  }
121 
122  this->refValue() = newValues;
123 
125 }
126 
127 
128 template<class Type>
130 {
132  writeEntry(os, meanValue_());
133  writeEntry(os, "value", *this);
134 }
135 
136 
137 // ************************************************************************* //
Foam::surfaceFields.
Run-time selectable general function of one variable.
Definition: Function1.H:52
dictionary dict
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:63
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
Type gSum(const FieldField< Field, Type > &f)
Pre-declare SubField and related Field type.
Definition: Field.H:56
A class for handling words, derived from string.
Definition: word.H:59
Foam::fvPatchFieldMapper.
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
static const zero Zero
Definition: zero.H:97
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
fixedMeanOutletInletFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
dimensioned< scalar > mag(const dimensioned< Type > &)
volScalarField & p
This boundary condition provides a generic inflow condition, with specified outflow for the case of r...
This boundary condition extrapolates field to the patch using the near-cell values and adjusts the di...