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 :
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_ = Field<Type>("jump", dict, p.size());
88  }
89 
90  if (dict.found("jump0"))
91  {
92  jump0_ = Field<Type>("jump0", dict, p.size());
93  }
94  }
95 
96  if (valueRequired)
97  {
98  if (dict.found("value"))
99  {
101  (
102  Field<Type>("value", dict, p.size())
103  );
104  }
105  else
106  {
107  this->evaluate(Pstream::commsTypes::blocking);
108  }
109  }
110 }
111 
112 
113 template<class Type>
115 (
116  const fixedJumpFvPatchField<Type>& ptf
117 )
118 :
120  jump_(ptf.jump_),
121  jump0_(ptf.jump0_),
122  minJump_(ptf.minJump_),
123  relaxFactor_(ptf.relaxFactor_),
124  timeIndex_(ptf.timeIndex_)
125 {}
126 
127 
128 template<class Type>
130 (
131  const fixedJumpFvPatchField<Type>& ptf,
133 )
134 :
136  jump_(ptf.jump_),
137  jump0_(ptf.jump0_),
138  minJump_(ptf.minJump_),
139  relaxFactor_(ptf.relaxFactor_),
140  timeIndex_(ptf.timeIndex_)
141 {}
142 
143 
144 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
145 
146 template<class Type>
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  jump_ = max(jump, minJump_);
162  }
163 }
164 
165 
166 template<class Type>
168 {
169  if (this->cyclicPatch().owner())
170  {
171  return jump_;
172  }
173  else
174  {
175  return refCast<const fixedJumpFvPatchField<Type>>
176  (
177  this->neighbourPatchField()
178  ).jump();
179  }
180 }
181 
182 
183 template<class Type>
185 {
186  if (this->cyclicPatch().owner())
187  {
188  return jump0_;
189  }
190  else
191  {
192  return refCast<const fixedJumpFvPatchField<Type>>
193  (
194  this->neighbourPatchField()
195  ).jump0();
196  }
197 }
198 
199 
200 template<class Type>
202 {
203  return relaxFactor_;
204 }
205 
206 
207 template<class Type>
209 {
210  if (!this->cyclicPatch().owner() || relaxFactor_ < 0)
211  {
212  return;
213  }
214 
215  jump_ = relaxFactor_*jump_ + (1 - relaxFactor_)*jump0_;
216 
217  if (timeIndex_ != this->db().time().timeIndex())
218  {
219  jump0_ = jump_;
220 
221  timeIndex_ = this->db().time().timeIndex();
222  }
223 }
224 
225 
226 template<class Type>
228 (
229  const fvPatchFieldMapper& m
230 )
231 {
233  jump_.autoMap(m);
234  jump0_.autoMap(m);
235 }
236 
237 
238 template<class Type>
240 (
241  const fvPatchField<Type>& ptf,
242  const labelList& addr
243 )
244 {
246 
247  const auto& fjptf = refCast<const fixedJumpFvPatchField<Type>>(ptf);
248  jump_.rmap(fjptf.jump_, addr);
249  jump0_.rmap(fjptf.jump0_, addr);
250 }
251 
252 
253 template<class Type>
255 {
257 
258  // Write patchType if not done already by fvPatchField
259  if (!this->patchType().size())
260  {
261  os.writeEntry("patchType", this->interfaceFieldType());
262  }
263 
264  if (this->cyclicPatch().owner())
265  {
266  jump_.writeEntry("jump", os);
267 
268  if (relaxFactor_ > 0)
269  {
270  os.writeEntry("relax", relaxFactor_);
271  jump0_.writeEntry("jump0", os);
272  }
273  }
274 
275  if (minJump_ != pTraits<Type>::min)
276  {
277  os.writeEntry("minJump", minJump_);
278  }
279 
280  this->writeEntry("value", os);
281 }
282 
283 
284 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:51
Foam::fixedJumpFvPatchField::relax
virtual void relax()
Return the relaxed "jump" across the patch.
Definition: fixedJumpFvPatchField.C:208
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::fixedJumpFvPatchField::setJump
virtual void setJump(const Field< Type > &jump)
Set the jump field.
Definition: fixedJumpFvPatchField.C:147
Foam::fixedJumpFvPatchField::jump0
virtual tmp< Field< Type > > jump0() const
Return the old time "jump" across the patch.
Definition: fixedJumpFvPatchField.C:184
Foam::fixedJumpFvPatchField::autoMap
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: fixedJumpFvPatchField.C:228
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::fixedJumpFvPatchField::relaxFactor
virtual scalar relaxFactor() const
Return the under-relaxation factor.
Definition: fixedJumpFvPatchField.C:201
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::fixedJumpFvPatchField::fixedJumpFvPatchField
fixedJumpFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Definition: fixedJumpFvPatchField.C:35
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::fixedJumpFvPatchField
This boundary condition provides a jump condition, using the cyclic condition as a base.
Definition: fixedJumpFvPatchField.H:111
Foam::fixedJumpFvPatchField::write
virtual void write(Ostream &) const
Write.
Definition: fixedJumpFvPatchField.C:254
Foam::fixedJumpFvPatchField::rmap
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
Definition: fixedJumpFvPatchField.C:240
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
Foam::jumpCyclicFvPatchField
This boundary condition provides a base class for coupled-cyclic conditions with a specified 'jump' (...
Definition: jumpCyclicFvPatchField.H:59
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::List< label >
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
fixedJumpFvPatchField.H
Foam::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:47
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
Foam::fixedJumpFvPatchField::jump
virtual tmp< Field< Type > > jump() const
Return the "jump" across the patch.
Definition: fixedJumpFvPatchField.C:167
Foam::stringOps::evaluate
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.
Definition: stringOpsEvaluate.C:37