fixedMeanFvPatchField.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) 2012-2024 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 
26 #include "fixedMeanFvPatchField.H"
27 #include "volFields.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const fvPatch& p,
36  const dictionary& dict
37 )
38 :
40  (
41  p,
42  iF,
43  dict,
44  !Pstream::parRun() && p.boundaryMesh().mesh().time().processorCase()
45  ),
46  meanValue_
47  (
48  Function1<Type>::New
49  (
50  "meanValue",
51  this->db().time().userUnits(),
52  iF.dimensions(),
53  dict
54  )
55  )
56 {
57  if (Pstream::parRun() || !p.boundaryMesh().mesh().time().processorCase())
58  {
59  this->evaluate();
60  }
61 }
62 
63 
64 template<class Type>
66 (
67  const fixedMeanFvPatchField<Type>& ptf,
68  const fvPatch& p,
70  const fieldMapper& mapper
71 )
72 :
73  fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
74  meanValue_(ptf.meanValue_, false)
75 {}
76 
77 
78 template<class Type>
80 (
81  const fixedMeanFvPatchField<Type>& ptf,
83 )
84 :
85  fixedValueFvPatchField<Type>(ptf, iF),
86  meanValue_(ptf.meanValue_, false)
87 {}
88 
89 
90 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
91 
92 template<class Type>
94 {
95  if (this->updated())
96  {
97  return;
98  }
99 
100  Type meanValue = meanValue_->value(this->db().time().value());
101 
102  Field<Type> newValues(this->patchInternalField());
103 
104  Type meanValuePsi =
105  gSum(this->patch().magSf()*newValues)
106  /gSum(this->patch().magSf());
107 
108  if (mag(meanValue) > small && mag(meanValuePsi)/mag(meanValue) > 0.5)
109  {
110  newValues *= mag(meanValue)/mag(meanValuePsi);
111  }
112  else
113  {
114  newValues += (meanValue - meanValuePsi);
115  }
116 
117  this->operator==(newValues);
118 
120 }
121 
122 
123 template<class Type>
125 {
127  writeEntry
128  (
129  os,
130  this->db().time().userUnits(),
131  this->internalField().dimensions(),
132  meanValue_()
133  );
134  writeEntry(os, "value", *this);
135 }
136 
137 
138 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Pre-declare SubField and related Field type.
Definition: Field.H:83
Run-time selectable general function of one variable.
Definition: Function1.H:125
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Inter-processor communications stream.
Definition: Pstream.H:56
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:399
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Abstract base class for field mapping.
Definition: fieldMapper.H:48
This boundary condition extrapolates field to the patch using the near-cell values and adjusts the di...
virtual void write(Ostream &) const
Write.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
fixedMeanFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &, const dictionary &)
Construct from patch, internal field and dictionary.
This boundary condition supplies a fixed value constraint, and is the base class for a number of othe...
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
Definition: fvPatchField.C:209
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:229
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:202
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:64
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
Type gSum(const FieldField< Field, Type > &f)
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
const HashTable< dimensionSet > & dimensions()
Get the table of dimension sets.
Definition: dimensionSets.C:96
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
dimensioned< scalar > mag(const dimensioned< Type > &)
dictionary dict
volScalarField & p