orientedType.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) 2017-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "orientedType.H"
29#include "dictionary.H"
30#include "Istream.H"
31#include "Ostream.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35const Foam::Enum
36<
38>
40({
41 { orientedOption::UNKNOWN, "unknown" },
42 { orientedOption::ORIENTED, "oriented" },
43 { orientedOption::UNORIENTED, "unoriented" },
44});
45
46
47// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
48
50(
51 const orientedType& ot1,
52 const orientedType& ot2
53)
54{
55 return
56 (
57 (ot1.oriented() == UNKNOWN)
58 || (ot2.oriented() == UNKNOWN)
59 || (ot1.oriented() == ot2.oriented())
60 );
61}
62
63
64// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
65
67:
68 oriented_(UNKNOWN)
69{}
70
71
73:
74 oriented_(ot.oriented_)
75{}
76
77
79:
80 oriented_(isOriented ? ORIENTED : UNORIENTED)
81{}
82
83
85:
86 oriented_(orientedOptionNames.read(is))
87{
89}
90
91
92// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
93
95{
96 return oriented_;
97}
98
99
101{
102 return oriented_;
103}
104
105
106void Foam::orientedType::setOriented(const bool on) noexcept
107{
108 oriented_ = on ? ORIENTED : UNORIENTED;
109}
110
111
113{
114 oriented_ = orientedOptionNames.getOrDefault
115 (
116 "oriented",
117 dict,
118 orientedOption::UNKNOWN,
119 true // Failsafe behaviour
120 );
121}
122
123
125{
126 const bool output = (oriented_ == ORIENTED);
127
128 if (output)
129 {
130 os.writeEntry("oriented", orientedOptionNames[oriented_]);
131 }
132
133 return output;
134}
135
136
137// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
138
140{
141 // Oriented state is inherited on assignment
142 oriented_ = ot.oriented();
143}
144
145
147{
148 // Set the oriented status if it was unknown
149 if (oriented_ == UNKNOWN)
150 {
151 oriented_ = ot.oriented();
152 }
153
154 if (!checkType(*this, ot))
155 {
157 << "Operator += is undefined for "
158 << orientedOptionNames[oriented_] << " and "
159 << orientedOptionNames[ot.oriented()] << " types"
160 << abort(FatalError);
161 }
162}
163
164
166{
167 // Set the oriented status if it was unknown
168 if (oriented_ == UNKNOWN)
169 {
170 oriented_ = ot.oriented();
171 }
172
173 if (!checkType(*this, ot))
174 {
176 << "Operator -= is undefined for "
177 << orientedOptionNames[oriented_] << " and "
178 << orientedOptionNames[ot.oriented()] << " types"
179 << abort(FatalError);
180 }
181}
182
183
185{
186 const orientedType& ot1 = *this;
187 if (ot1() ^ ot())
188 {
189 oriented_ = ORIENTED;
190 }
191 else
192 {
193 oriented_ = UNORIENTED;
194 }
195}
196
197
199{
200 const orientedType& ot1 = *this;
201 if (ot1() ^ ot())
202 {
203 oriented_ = ORIENTED;
204 }
205 else
206 {
207 oriented_ = UNORIENTED;
208 }
209}
210
211
213{
214 // No change to oriented_ flag
215}
216
217
219{
220 // No change to oriented_ flag
221}
222
223
225{
226 return oriented_ == ORIENTED;
227}
228
229
230// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
231
233{
234 if (!orientedType::checkType(ot1, ot2))
235 {
237 << "Operator max is undefined for "
239 << orientedType::orientedOptionNames[ot2.oriented()] << " types"
240 << abort(FatalError);
241 }
242
243 return ot1;
244}
245
246
248{
249 if (!orientedType::checkType(ot1, ot2))
250 {
252 << "Operator min is undefined for "
255 << abort(FatalError);
256 }
257
258 return ot1;
259}
260
261
263(
264 const orientedType& ot1,
265 const orientedType& ot2
266)
267{
268 return ot1 ^ ot2;
269}
270
271
273(
274 const orientedType& ot1,
275 const orientedType& ot2
276)
277{
278 return ot1 ^ ot2;
279}
280
281
283{
284 return ot;
285}
286
287
288Foam::orientedType Foam::pow(const orientedType& ot, const scalar r)
289{
290 // Undefined???
291 // - only defined for integers where:
292 // - odd powers = oriented_ = yes (if ot is oriented)
293 // - even powers = oriented_ = no
294 return ot;
295}
296
297
299{
300 return orientedType(false);
301}
302
303
305{
306 return ot;
307}
308
309
311{
312 return orientedType(false);
313}
314
315
317{
318 return ot;
319}
320
321
323{
324 return orientedType(false);
325}
326
327
329{
330 return ot;
331}
332
333
335{
336 return ot;
337}
338
339
341{
342 return ot;
343}
344
345
347{
348 return orientedType(false);
349}
350
351
353{
354 return orientedType(false);
355}
356
357
359{
360 return ot;
361}
362
363
365{
366 return ot;
367}
368
369
371{
372 return ot;
373}
374
375
377{
378 return ot;
379}
380
381
383{
384 return ot;
385}
386
387
389{
390 return ot;
391}
392
393
395{
396 return ot;
397}
398
399
401{
402 return ot;
403}
404
405
407{
408 return ot;
409}
410
411
413(
414 const orientedType& ot1,
415 const orientedType& ot2
416)
417{
418 if (!orientedType::checkType(ot1, ot2))
419 {
421 << "Operator atan2 is undefined for "
424 << abort(FatalError);
425 }
426
427 return ot1;
428}
429
430
432(
433 const orientedType& ot1,
434 const orientedType& ot2
435)
436{
437 if (!orientedType::checkType(ot1, ot2))
438 {
440 << "Operator hypot is undefined for "
443 << abort(FatalError);
444 }
445
446 return ot1;
447}
448
449
451{
452 return ot;
453}
454
455
456// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
457
459{
460 ot.oriented_ = orientedType::orientedOptionNames.read(is);
461
463
464 return is;
465}
466
467
469{
471
473
474 return os;
475}
476
477
478// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
479
480Foam::orientedType Foam::operator+
481(
482 const orientedType& ot1,
483 const orientedType& ot2
484)
485{
486 if (!orientedType::checkType(ot1, ot2))
487 {
489 << "Operator + is undefined for "
490 << orientedType::orientedOptionNames[ot1.oriented()] << " and "
491 << orientedType::orientedOptionNames[ot2.oriented()] << " types"
492 << abort(FatalError);
493 }
494
495 // Note use of () operators to convert to boolean op
496 return orientedType(ot1() || ot2());
497}
498
499
501{
502 return ot;
503}
504
505
506Foam::orientedType Foam::operator-
507(
508 const orientedType& ot1,
509 const orientedType& ot2
510)
511{
512 if (!orientedType::checkType(ot1, ot2))
513 {
515 << "Operator - is undefined for "
516 << orientedType::orientedOptionNames[ot1.oriented()] << " and "
517 << orientedType::orientedOptionNames[ot2.oriented()] << " types"
518 << abort(FatalError);
519 }
520
521 // Note use of () operators to convert to boolean op
522 return orientedType(ot1() || ot2());
523}
524
525
527{
528 return ot;
529}
530
531
533{
534 return ot;
535}
536
537
538Foam::orientedType Foam::operator/
539(
540 const orientedType& ot1,
541 const orientedType& ot2
542)
543{
544 return ot1 ^ ot2;
545}
546
547
548Foam::orientedType Foam::operator*
549(
550 const orientedType& ot1,
551 const orientedType& ot2
552)
553{
554 return ot1 ^ ot2;
555}
556
557
558Foam::orientedType Foam::operator^
559(
560 const orientedType& ot1,
561 const orientedType& ot2
562)
563{
564 // Note use of () operators to convert to boolean op
565 return orientedType(ot1() ^ ot2());
566}
567
568
569Foam::orientedType Foam::operator&
570(
571 const orientedType& ot1,
572 const orientedType& ot2
573)
574{
575 return ot1 ^ ot2;
576}
577
578
579Foam::orientedType Foam::operator&&
580(
581 const orientedType& ot1,
582 const orientedType& ot2
583)
584{
585 return orientedType(false);
586}
587
588
589// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
EnumType read(Istream &is) const
Read a word from Istream and return the corresponding enumeration.
Definition: Enum.C:109
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:239
virtual bool read()
Re-read model coefficients if they have changed.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Class to determine the 'oriented' status of surface fields.
Definition: orientedType.H:57
void operator/=(const orientedType &ot)
Definition: orientedType.C:198
orientedType() noexcept
Default construct as UNKNOWN.
Definition: orientedType.C:66
void operator*=(const orientedType &ot)
Definition: orientedType.C:184
orientedOption
Enumeration defining oriented flags.
Definition: orientedType.H:64
void operator-=(const orientedType &ot)
Definition: orientedType.C:165
void operator=(const orientedType &ot)
Definition: orientedType.C:139
orientedOption & oriented() noexcept
Return non-const reference to the oriented flag.
Definition: orientedType.C:94
bool operator()() const noexcept
True if type is ORIENTED. Same as bool operator.
Definition: orientedType.C:224
bool writeEntry(Ostream &os) const
Write the "oriented" flag entry (if ORIENTED)
Definition: orientedType.C:124
void setOriented(const bool on=true) noexcept
Set the oriented flag: on/off.
Definition: orientedType.C:106
static const Enum< orientedOption > orientedOptionNames
Named enumerations for oriented flags.
Definition: orientedType.H:71
void operator+=(const orientedType &ot)
Definition: orientedType.C:146
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
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< faMatrix< Type > > operator-(const faMatrix< Type > &)
Unary negation.
dimensionedScalar pow6(const dimensionedScalar &ds)
dimensionedScalar pos(const dimensionedScalar &ds)
dimensionedScalar pow5(const dimensionedScalar &ds)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:536
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
dimensionedScalar pos0(const dimensionedScalar &ds)
dimensionedScalar sign(const dimensionedScalar &ds)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensionedScalar pow3(const dimensionedScalar &ds)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
tmp< faMatrix< Type > > operator*(const areaScalarField::Internal &, const faMatrix< Type > &)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
dimensionedScalar negPart(const dimensionedScalar &ds)
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Istream & operator>>(Istream &, directionInfo &)
dimensionedScalar hypot(const dimensionedScalar &x, const dimensionedScalar &y)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
dimensionedScalar pow4(const dimensionedScalar &ds)
errorManip< error > abort(error &err)
Definition: errorManip.H:144
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
dimensionSet trans(const dimensionSet &ds)
Check the argument is dimensionless (for transcendental functions)
Definition: dimensionSet.C:486
dimensionedScalar neg(const dimensionedScalar &ds)
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
const direction noexcept
Definition: Scalar.H:223
error FatalError
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
dimensionedScalar neg0(const dimensionedScalar &ds)
dimensionedScalar cbrt(const dimensionedScalar &ds)
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh > > cmptAv(const DimensionedField< Type, GeoMesh > &df)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
dimensionedScalar posPart(const dimensionedScalar &ds)
dimensionedScalar pow025(const dimensionedScalar &ds)
dictionary dict