Loading...
Searching...
No Matches
faPatchField.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) 2016-2017 Wikki Ltd
9 Copyright (C) 2020-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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 "dictionary.H"
30#include "faPatchField.H"
31#include "faPatchFieldMapper.H"
32
33// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
34
35template<class Type>
37(
38 const dictionary& dict,
40)
41{
42 if (!IOobjectOption::isAnyRead(readOpt)) return false;
43 const auto& p = faPatchFieldBase::patch();
44
45
46 const auto* eptr = dict.findEntry("value", keyType::LITERAL);
47
48 if (eptr)
49 {
50 Field<Type>::assign(*eptr, p.size());
51 return true;
52 }
53
55 {
57 << "Required entry 'value' : missing for patch " << p.name()
58 << " in dictionary " << dict.relativeName() << nl
60 }
61
62 return false;
63}
64
65
66template<class Type>
68{
69 const auto& p = faPatchFieldBase::patch();
70 this->resize_nocopy(p.size()); // In general this is a no-op
71 p.patchInternalField(internalField_, *this);
72}
73
74
75// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
76
77template<class Type>
79(
80 const faPatch& p,
82)
83:
85 Field<Type>(p.size()),
86 internalField_(iF)
87{}
88
89
90template<class Type>
92(
93 const faPatch& p,
95 const Type& value
96)
97:
99 Field<Type>(p.size(), value),
100 internalField_(iF)
101{}
102
103
104template<class Type>
106(
107 const faPatch& p,
109 const Field<Type>& pfld
110)
111:
113 Field<Type>(pfld),
114 internalField_(iF)
115{}
116
117
118template<class Type>
120(
121 const faPatch& p,
123 Field<Type>&& pfld
124)
125:
127 Field<Type>(std::move(pfld)),
128 internalField_(iF)
129{}
130
131
132template<class Type>
134(
135 const faPatch& p,
137 const dictionary& dict,
138 IOobjectOption::readOption requireValue
139)
140:
142 Field<Type>(p.size()),
143 internalField_(iF)
144{
145 if (!readValueEntry(dict, requireValue))
146 {
147 // Not read (eg, optional and missing): define zero
149 }
150}
151
152
153template<class Type>
155(
156 const faPatchField<Type>& ptf,
157 const faPatch& p,
158 const DimensionedField<Type, areaMesh>& iF,
159 const faPatchFieldMapper& mapper
160)
161:
163 Field<Type>(ptf, mapper),
164 internalField_(iF)
165{}
166
167
168template<class Type>
170(
171 const faPatchField<Type>& pfld,
172 const faPatch& p,
174 const Type& value
175)
176:
178 Field<Type>(p.size(), value),
179 internalField_(iF)
180{}
181
182
183template<class Type>
185(
186 const faPatchField<Type>& pfld,
188)
189:
190 faPatchFieldBase(pfld),
191 Field<Type>(pfld),
192 internalField_(iF)
193{}
194
195
196// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
197
198template<class Type>
200{
202}
203
204
205template<class Type>
207{
208 // Get patch internal field, store temporarily in result
209 this->patchInternalField(result);
210 const auto& pif = result;
211
212 const Field<Type>& pfld = *this;
213 const auto& dc = patch().deltaCoeffs();
214
215 const label len = result.size();
216
217 for (label i = 0; i < len; ++i)
219 result[i] = dc[i]*(pfld[i] - pif[i]);
220 }
221}
222
223
224template<class Type>
226{
227 auto tfld = tmp<Field<Type>>::New(this->size());
228 this->snGrad(static_cast<UList<Type>&>(tfld.ref()));
229 return tfld;
230}
231
232
233template<class Type>
236{
237 return patch().patchInternalField(internalField_);
238}
239
240
241template<class Type>
243{
244 patch().patchInternalField(internalField_, pfld);
245}
246
247
248template<class Type>
250{
252}
253
254
255template<class Type>
257(
258 const faPatchField<Type>& ptf,
259 const labelList& addr
261{
262 Field<Type>::rmap(ptf, addr);
263}
264
265
266template<class Type>
268{
270}
271
272
273template<class Type>
275{
276 if (!updated())
277 {
278 updateCoeffs();
279 }
283}
284
285
286template<class Type>
288{
289 os.writeEntry("type", type());
290
291 if (!patchType().empty())
292 {
293 os.writeEntry("patchType", patchType());
295}
296
297
298// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
299
300template<class Type>
302(
303 const UList<Type>& ul
305{
307}
308
309
310template<class Type>
312(
313 const faPatchField<Type>& ptf
314)
318}
319
320
321template<class Type>
323(
324 const faPatchField<Type>& ptf
325)
329}
330
331
332template<class Type>
334(
335 const faPatchField<Type>& ptf
336)
340}
341
342
343template<class Type>
345(
346 const faPatchField<scalar>& ptf
347)
351}
352
353
354template<class Type>
356(
357 const faPatchField<scalar>& ptf
358)
362}
363
364
365template<class Type>
367(
368 const Field<Type>& tf
370{
373
374
375template<class Type>
377(
378 const Field<Type>& tf
379)
380{
382}
383
384
385template<class Type>
387(
388 const scalarField& tf
390{
392}
393
394
395template<class Type>
397(
398 const scalarField& tf
400{
402}
403
404
405template<class Type>
407(
408 const Type& t
410{
412}
413
414
415template<class Type>
417(
418 const Type& t
420{
422}
423
424
425template<class Type>
427(
428 const Type& t
430{
432}
433
434
435template<class Type>
437(
438 const scalar s
440{
442}
443
444
445template<class Type>
447(
448 const scalar s
450{
452}
453
454
455template<class Type>
457(
458 const faPatchField<Type>& ptf
460{
462}
463
464
465template<class Type>
467(
468 const Field<Type>& tf
470{
472}
473
474
475template<class Type>
477(
478 const Type& t
479)
480{
482}
483
484
485// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
486
487template<class Type>
488Foam::Ostream& Foam::operator<<(Ostream& os, const faPatchField<Type>& ptf)
489{
490 ptf.write(os);
491
492 os.check(FUNCTION_NAME);
493
494 return os;
495}
496
497
498// ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
void operator=(const Field< Type > &)
Copy assignment.
Definition Field.C:781
void autoMap(const FieldMapper &map, const bool applyFlip=true)
Map from self.
Definition Field.C:465
void operator+=(const UList< Type > &)
Definition Field.C:833
void operator-=(const UList< Type > &)
Definition Field.C:834
constexpr Field() noexcept
Default construct.
Definition FieldI.H:24
void operator*=(const UList< scalar > &)
Definition Field.C:835
void assign(const entry &e, const label len)
Assign from a primitive dictionary entry with the following behaviour:
Definition Field.C:206
void operator/=(const UList< scalar > &)
Definition Field.C:836
void rmap(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 reverse-map from the given field
Definition Field.C:528
static bool isReadRequired(readOption opt) noexcept
True if (MUST_READ | READ_MODIFIED) bits are set.
readOption
Enumeration defining read preferences.
static bool isAnyRead(readOption opt) noexcept
True if any reading may be required (ie, != NO_READ).
void resize_nocopy(const label len)
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
bool empty() const noexcept
Definition UList.H:701
void size(const label n)
Definition UList.H:118
commsTypes
Communications types.
Definition UPstream.H:81
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Template invariant parts for faPatchField.
faPatchFieldBase(const faPatch &p)
Construct from patch.
void setManipulated(bool state) noexcept
Set matrix manipulated state. Currently a no-op for faPatchField.
void setUpdated(bool state) noexcept
Set updated state.
const word & patchType() const noexcept
The optional patch type.
bool updated() const noexcept
True if the boundary condition has already been updated.
const faPatch & patch() const noexcept
Return the patch.
void checkPatch(const faPatchFieldBase &rhs) const
Check that patches are identical.
A FieldMapper for finite-area patch fields.
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
faPatchField(const faPatch &, const DimensionedField< Type, areaMesh > &)
Construct from patch and internal field.
virtual tmp< Field< Type > > patchInternalField() const
Return internal field next to patch.
virtual void rmap(const faPatchField< Type > &, const labelList &)
Reverse map the given faPatchField onto this faPatchField.
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
virtual void write(Ostream &os) const
Write.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
virtual void autoMap(const faPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
void check(const faPatchField< Type > &) const
Check against given patch field.
bool readValueEntry(const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::LAZY_READ)
Read the "value" entry into *this.
void extrapolateInternal()
Assign the patch field from the internal field.
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Evaluate the patch field, sets updated() to false.
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition faPatch.H:76
@ LITERAL
String literal.
Definition keyType.H:82
A class for managing temporary objects.
Definition tmp.H:75
volScalarField & p
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
OBJstream os(runTime.globalPath()/outputName)
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))
#define FUNCTION_NAME
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
List< label > labelList
A List of labels.
Definition List.H:62
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition POSIX.C:801
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict