fixedJumpFvPatchField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  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 #include "fixedJumpFvPatchField.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const fvPatch& p,
38 )
39 :
40  jumpCyclicFvPatchField<Type>(p, iF),
41  jump_(this->size(), Zero),
42  jump0_(this->size(), Zero),
43  minJump_(pTraits<Type>::min),
44  relaxFactor_(-1),
45  timeIndex_(-1)
46 {}
47 
48 
49 template<class Type>
51 (
52  const fixedJumpFvPatchField<Type>& ptf,
53  const fvPatch& p,
55  const fvPatchFieldMapper& mapper
56 )
57 :
58  jumpCyclicFvPatchField<Type>(ptf, p, iF, mapper),
59  jump_(ptf.jump_, mapper),
60  jump0_(ptf.jump0_, mapper),
61  minJump_(ptf.minJump_),
62  relaxFactor_(ptf.relaxFactor_),
63  timeIndex_(ptf.timeIndex_)
64 {}
65 
66 
67 template<class Type>
69 (
70  const fvPatch& p,
72  const dictionary& dict,
73  const bool valueRequired
74 )
75 :
76  jumpCyclicFvPatchField<Type>(p, iF, dict, false), // Pass no valueRequired
77  jump_(p.size(), Zero),
78  jump0_(p.size(), Zero),
79  minJump_(dict.getOrDefault<Type>("minJump", pTraits<Type>::min)),
80  relaxFactor_(dict.getOrDefault<scalar>("relax", -1)),
81  timeIndex_(this->db().time().timeIndex())
82 {
83  if (this->cyclicPatch().owner())
84  {
85  if (valueRequired)
86  {
87  jump_.assign("jump", dict, p.size(), IOobjectOption::MUST_READ);
88  }
89 
90  jump0_.assign("jump0", dict, p.size(), IOobjectOption::LAZY_READ);
91  }
92 
93  if (valueRequired)
94  {
95  if (!this->readValueEntry(dict))
96  {
97  this->evaluate(Pstream::commsTypes::blocking);
98  }
99  }
100 }
101 
102 
103 template<class Type>
105 (
106  const fixedJumpFvPatchField<Type>& ptf
107 )
108 :
109  jumpCyclicFvPatchField<Type>(ptf),
110  jump_(ptf.jump_),
111  jump0_(ptf.jump0_),
112  minJump_(ptf.minJump_),
113  relaxFactor_(ptf.relaxFactor_),
114  timeIndex_(ptf.timeIndex_)
115 {}
116 
117 
118 template<class Type>
120 (
121  const fixedJumpFvPatchField<Type>& ptf,
123 )
124 :
125  jumpCyclicFvPatchField<Type>(ptf, iF),
126  jump_(ptf.jump_),
127  jump0_(ptf.jump0_),
128  minJump_(ptf.minJump_),
129  relaxFactor_(ptf.relaxFactor_),
130  timeIndex_(ptf.timeIndex_)
131 {}
132 
133 
134 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
135 
136 template<class Type>
138 {
139  if (this->cyclicPatch().owner())
140  {
141  jump_ = max(jump, minJump_);
142  }
143 }
144 
145 
146 template<class Type>
147 void Foam::fixedJumpFvPatchField<Type>::setJump(const Type& jump)
148 {
149  if (this->cyclicPatch().owner())
150  {
151  jump_ = max(jump, minJump_);
152  }
153 }
154 
155 
156 template<class Type>
158 {
159  if (this->cyclicPatch().owner())
160  {
161  return jump_;
162  }
163  else
164  {
165  return refCast<const fixedJumpFvPatchField<Type>>
166  (
167  this->neighbourPatchField()
168  ).jump();
169  }
170 }
171 
172 
173 template<class Type>
175 {
176  if (this->cyclicPatch().owner())
177  {
178  return jump0_;
179  }
180  else
181  {
182  return refCast<const fixedJumpFvPatchField<Type>>
183  (
184  this->neighbourPatchField()
185  ).jump0();
186  }
187 }
188 
189 
190 template<class Type>
192 {
193  return relaxFactor_;
194 }
195 
196 
197 template<class Type>
199 {
200  if (!this->cyclicPatch().owner() || relaxFactor_ < 0)
201  {
202  return;
203  }
204 
205  jump_ = lerp(jump0_, jump_, relaxFactor_);
206 
207  if (timeIndex_ != this->db().time().timeIndex())
208  {
209  jump0_ = jump_;
210 
211  timeIndex_ = this->db().time().timeIndex();
212  }
213 }
214 
215 
216 template<class Type>
218 (
219  const fvPatchFieldMapper& m
220 )
221 {
222  jumpCyclicFvPatchField<Type>::autoMap(m);
223  jump_.autoMap(m);
224  jump0_.autoMap(m);
225 }
226 
227 
228 template<class Type>
230 (
231  const fvPatchField<Type>& ptf,
232  const labelList& addr
233 )
234 {
236 
237  const auto& fjptf = refCast<const fixedJumpFvPatchField<Type>>(ptf);
238  jump_.rmap(fjptf.jump_, addr);
239  jump0_.rmap(fjptf.jump0_, addr);
240 }
241 
242 
243 template<class Type>
245 {
247 
248  // Write patchType if not done already by fvPatchField
249  if (this->patchType().empty())
250  {
251  os.writeEntry("patchType", this->interfaceFieldType());
252  }
253 
254  if (this->cyclicPatch().owner())
255  {
256  jump_.writeEntry("jump", os);
257 
258  if (relaxFactor_ > 0)
259  {
260  os.writeEntry("relax", relaxFactor_);
261  jump0_.writeEntry("jump0", os);
262  }
263  }
264 
265  if (minJump_ != pTraits<Type>::min)
266  {
267  os.writeEntry("minJump", minJump_);
268  }
269 
270  fvPatchField<Type>::writeValueEntry(os);
271 }
272 
273 
274 // ************************************************************************* //
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Generic templated field type.
Definition: Field.H:62
fixedJumpFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
A FieldMapper for finite-volume patch fields.
This boundary condition provides a base class for coupled-cyclic conditions with a specified &#39;jump&#39; (...
string evaluate(label fieldWidth, const std::string &s, size_t pos=0, size_t len=std::string::npos)
String evaluation with specified (positive, non-zero) field width.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
virtual void write(Ostream &) const
Write.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
dimensioned< Type > lerp(const dimensioned< Type > &a, const dimensioned< Type > &b, const scalar t)
void assign(const entry &e, const label len)
Assign from a primitive dictionary entry with the following behaviour:
Definition: Field.C:207
This boundary condition provides a jump condition, using the cyclic condition as a base...
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
virtual void relax()
Return the relaxed "jump" across the patch.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
virtual tmp< Field< Type > > jump() const
Return the "jump" across the patch.
virtual void setJump(const Field< Type > &jump)
Set the jump field.
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
virtual scalar relaxFactor() const
Return the under-relaxation factor.
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
virtual tmp< Field< Type > > jump0() const
Return the old time "jump" across the patch.
label timeIndex
Definition: getTimeIndex.H:24
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127