fvPatchField.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-2016 OpenFOAM Foundation
9  Copyright (C) 2015-2023 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 "IOobject.H"
30 #include "dictionary.H"
31 #include "fvMesh.H"
33 #include "volMesh.H"
34 
35 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
36 
37 template<class Type>
39 (
40  const dictionary& dict,
42 )
43 {
44  if (!IOobjectOption::isAnyRead(readOpt)) return false;
45  const auto& p = fvPatchFieldBase::patch();
46 
47 
48  const auto* eptr = dict.findEntry("value", keyType::LITERAL);
49 
50  if (eptr)
51  {
52  Field<Type>::assign(*eptr, p.size());
53  return true;
54  }
55 
56  if (IOobjectOption::isReadRequired(readOpt))
57  {
59  << "Required entry 'value' : missing for patch " << p.name()
60  << " in dictionary " << dict.relativeName() << nl
61  << exit(FatalIOError);
62  }
63 
64  return false;
65 }
66 
67 
68 template<class Type>
70 {
71  fvPatchFieldBase::patch().patchInternalField(internalField_, *this);
72 }
73 
74 
75 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
76 
77 template<class Type>
79 (
80  const fvPatch& p,
82 )
83 :
85  Field<Type>(p.size()),
86  internalField_(iF)
87 {}
88 
89 
90 template<class Type>
92 (
93  const fvPatch& p,
95  const word& patchType
96 )
97 :
98  fvPatchFieldBase(p, patchType),
99  Field<Type>(p.size()),
100  internalField_(iF)
101 {}
102 
103 
104 template<class Type>
106 (
107  const fvPatch& p,
109  const Type& value
110 )
111 :
113  Field<Type>(p.size(), value),
114  internalField_(iF)
115 {}
116 
117 
118 template<class Type>
120 (
121  const fvPatch& p,
123  const Field<Type>& pfld
124 )
125 :
127  Field<Type>(pfld),
128  internalField_(iF)
129 {}
130 
131 
132 template<class Type>
134 (
135  const fvPatch& p,
137  Field<Type>&& pfld
138 )
139 :
141  Field<Type>(std::move(pfld)),
142  internalField_(iF)
143 {}
144 
145 
146 template<class Type>
148 (
149  const fvPatch& p,
151  const dictionary& dict,
152  IOobjectOption::readOption requireValue
153 )
154 :
156  Field<Type>(p.size()),
157  internalField_(iF)
158 {
159  readValueEntry(dict, requireValue);
160 }
161 
162 
163 template<class Type>
165 (
166  const fvPatchField<Type>& ptf,
167  const fvPatch& p,
169  const fvPatchFieldMapper& mapper
170 )
171 :
172  fvPatchFieldBase(ptf, p),
173  Field<Type>(p.size()),
174  internalField_(iF)
175 {
176  // For unmapped faces set to internal field value (zero-gradient)
177  if (notNull(iF) && mapper.hasUnmapped())
178  {
179  this->extrapolateInternal();
180  }
181  this->map(ptf, mapper);
182 }
183 
184 
185 template<class Type>
187 (
188  const fvPatchField<Type>& ptf
189 )
190 :
191  fvPatchFieldBase(ptf),
192  Field<Type>(ptf),
193  internalField_(ptf.internalField_)
194 {}
195 
196 
197 template<class Type>
199 (
200  const fvPatchField<Type>& ptf,
202 )
203 :
204  fvPatchFieldBase(ptf),
205  Field<Type>(ptf),
206  internalField_(iF)
207 {}
208 
209 
210 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
211 
212 template<class Type>
214 {
216 }
217 
218 
219 template<class Type>
221 {
222  return patch().deltaCoeffs()*(*this - patchInternalField());
223 }
224 
225 
226 template<class Type>
229 {
230  return patch().patchInternalField(internalField_);
231 }
232 
233 
234 template<class Type>
236 {
237  patch().patchInternalField(internalField_, pfld);
238 }
239 
240 
241 template<class Type>
243 (
244  const fvPatchFieldMapper& mapper
245 )
246 {
247  Field<Type>& f = *this;
248 
249  if (!this->size() && !mapper.distributed())
250  {
251  f.resize_nocopy(mapper.size());
252  if (f.size())
253  {
254  f = this->patchInternalField();
255  }
256  }
257  else
258  {
259  // Map all faces provided with mapping data
260  Field<Type>::autoMap(mapper);
261 
262 
263  // For unmapped faces set to internal field value (zero-gradient)
264  if (mapper.hasUnmapped())
265  {
266  Field<Type> pif(this->patchInternalField());
267 
268  if
269  (
270  mapper.direct()
271  && notNull(mapper.directAddressing())
272  && mapper.directAddressing().size()
273  )
274  {
275  const labelList& mapAddressing = mapper.directAddressing();
276 
277  forAll(mapAddressing, i)
278  {
279  if (mapAddressing[i] < 0)
280  {
281  f[i] = pif[i];
282  }
283  }
284  }
285  else if (!mapper.direct() && mapper.addressing().size())
286  {
287  const labelListList& mapAddressing = mapper.addressing();
288 
289  forAll(mapAddressing, i)
290  {
291  const labelList& localAddrs = mapAddressing[i];
292 
293  if (!localAddrs.size())
294  {
295  f[i] = pif[i];
296  }
297  }
298  }
299  }
300  }
301 }
302 
303 
304 template<class Type>
306 (
307  const fvPatchField<Type>& ptf,
308  const labelList& addr
309 )
310 {
311  Field<Type>::rmap(ptf, addr);
312 }
313 
314 
315 template<class Type>
317 {
318  fvPatchFieldBase::setUpdated(true);
319 }
320 
321 
322 template<class Type>
324 {
325  // Default behaviour ignores the weights
326  if (!updated())
327  {
328  updateCoeffs();
330  fvPatchFieldBase::setUpdated(true);
331  }
332 }
333 
334 
335 template<class Type>
336 void Foam::fvPatchField<Type>::evaluate(const Pstream::commsTypes)
337 {
338  if (!updated())
339  {
340  updateCoeffs();
341  }
343  fvPatchFieldBase::setUpdated(false);
344  fvPatchFieldBase::setManipulated(false);
345 }
346 
347 
348 template<class Type>
350 {
351  fvPatchFieldBase::setManipulated(true);
352 }
353 
354 
355 template<class Type>
357 (
358  fvMatrix<Type>& matrix,
359  const scalarField& weights
360 )
361 {
362  fvPatchFieldBase::setManipulated(true);
363 }
364 
365 
366 template<class Type>
368 (
369  fvMatrix<Type>& matrix,
370  const label iMatrix,
371  const direction cmp
372 )
373 {
374  fvPatchFieldBase::setManipulated(true);
375 }
376 
377 
378 template<class Type>
380 {
381  os.writeEntry("type", type());
382 
383  if (!patchType().empty())
384  {
385  os.writeEntry("patchType", patchType());
386  }
387  if (useImplicit())
388  {
389  os.writeEntry("useImplicit", "true");
390  }
391 }
392 
393 
394 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
395 
396 template<class Type>
398 (
399  const UList<Type>& ul
400 )
401 {
403 }
404 
405 
406 template<class Type>
408 (
409  const fvPatchField<Type>& ptf
410 )
411 {
414 }
415 
416 
417 template<class Type>
419 (
420  const fvPatchField<Type>& ptf
421 )
422 {
425 }
426 
427 
428 template<class Type>
430 (
431  const fvPatchField<Type>& ptf
432 )
433 {
436 }
437 
438 
439 template<class Type>
441 (
442  const fvPatchField<scalar>& ptf
443 )
444 {
447 }
448 
449 
450 template<class Type>
452 (
453  const fvPatchField<scalar>& ptf
454 )
455 {
458 }
459 
460 
461 template<class Type>
463 (
464  const Field<Type>& tf
465 )
466 {
468 }
469 
470 
471 template<class Type>
473 (
474  const Field<Type>& tf
475 )
476 {
478 }
479 
480 
481 template<class Type>
483 (
484  const scalarField& tf
485 )
486 {
488 }
489 
490 
491 template<class Type>
493 (
494  const scalarField& tf
495 )
496 {
498 }
499 
500 
501 template<class Type>
503 (
504  const Type& t
505 )
506 {
508 }
509 
510 
511 template<class Type>
513 (
514  const Type& t
515 )
516 {
518 }
519 
520 
521 template<class Type>
523 (
524  const Type& t
525 )
526 {
528 }
529 
530 
531 template<class Type>
533 (
534  const scalar s
535 )
536 {
538 }
539 
540 
541 template<class Type>
543 (
544  const scalar s
545 )
546 {
548 }
549 
550 
551 template<class Type>
553 (
554  const fvPatchField<Type>& ptf
555 )
556 {
558 }
559 
560 
561 template<class Type>
563 (
564  const Field<Type>& tf
565 )
566 {
568 }
569 
570 
571 template<class Type>
573 (
574  const Type& t
575 )
576 {
578 }
579 
580 
581 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
582 
583 template<class Type>
584 Foam::Ostream& Foam::operator<<(Ostream& os, const fvPatchField<Type>& ptf)
585 {
586  ptf.write(os);
587 
588  os.check(FUNCTION_NAME);
589 
590  return os;
591 }
592 
593 
594 // ************************************************************************* //
bool readValueEntry(const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::LAZY_READ)
Read the "value" entry into *this.
Definition: fvPatchField.C:32
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
type
Types of root.
Definition: Roots.H:52
uint8_t direction
Definition: direction.H:46
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: fvPatchField.C:236
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Definition: fvPatchField.C:213
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
virtual const labelListList & addressing() const
Return the interpolation addressing.
Definition: FieldMapper.H:115
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
void extrapolateInternal()
Assign the patch field from the internal field.
Definition: fvPatchField.C:62
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
virtual bool direct() const =0
Is it a direct (non-interpolating) mapper?
Template invariant parts for fvPatchField.
Definition: fvPatchField.H:77
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:372
virtual const labelUList & directAddressing() const
Return the direct addressing values.
Definition: FieldMapper.H:91
List< labelList > labelListList
List of labelList.
Definition: labelList.H:38
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
virtual label size() const =0
The size of the mapper.
Generic templated field type.
Definition: Field.H:62
A class for handling words, derived from Foam::string.
Definition: word.H:63
A FieldMapper for finite-volume patch fields.
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
Definition: fvPatchField.C:299
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: fvPatchField.H:64
virtual void manipulateMatrix(fvMatrix< Type > &matrix)
Manipulate matrix.
Definition: fvPatchField.C:342
void check(const fvPatchField< Type > &) const
Check against given patch field.
Definition: fvPatchField.C:206
virtual bool hasUnmapped() const =0
Any unmapped values?
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
virtual bool distributed() const
Does the mapper have remote contributions?
Definition: FieldMapper.H:76
void assign(Field< Tout > &result, const Field< T1 > &a, const UnaryOp &op)
Populate a field as the result of a unary operation on an input.
Definition: FieldOps.C:28
virtual tmp< Field< Type > > patchInternalField() const
Return internal field next to patch.
Definition: fvPatchField.C:221
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
labelList f(nPoints)
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets updated() to false.
Definition: fvPatchField.C:329
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:309
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
const std::string patch
OpenFOAM patch number as a std::string.
virtual void updateWeightedCoeffs(const scalarField &weights)
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:316
List< label > labelList
A List of labels.
Definition: List.H:62
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
fvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Definition: fvPatchField.C:72
bool checkPatch(const bool allGeometry, const std::string &name, const polyMesh &mesh, const PatchType &pp, const labelUList &meshEdges, labelHashSet *pointSetPtr=nullptr, labelHashSet *badEdgesPtr=nullptr)
bool notNull(const T *ptr)
True if ptr is not a pointer (of type T) to the nullObject.
Definition: nullObject.H:246
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...
readOption
Enumeration defining read preferences.