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-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 
35 const 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& a,
52  const orientedType& b
53 ) noexcept
54 {
55  return
56  (
57  (a.oriented() == b.oriented())
58  || (a.oriented() == orientedOption::UNKNOWN)
59  || (b.oriented() == orientedOption::UNKNOWN)
60  );
61 }
62 
63 
64 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
65 
66 namespace Foam
67 {
68 
69 static inline bool checkTypes
70 (
71  const char* what,
72  const orientedType& a,
73  const orientedType& b
74 )
75 {
76  // ie, checkType(a,b)
77  const bool ok
78  (
79  (a.oriented() == b.oriented())
80  || (a.oriented() == orientedType::orientedOption::UNKNOWN)
81  || (b.oriented() == orientedType::orientedOption::UNKNOWN)
82  );
83 
84  if (!ok)
85  {
87  << what << " : undefined for "
89  << orientedType::orientedOptionNames[b.oriented()] << " types"
90  << abort(FatalError);
91  }
92 
93  return ok;
94 }
95 
96 } // End namespace Foam
97 
98 
99 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
100 
102 :
103  oriented_(orientedOptionNames.read(is))
104 {
105  is.check(FUNCTION_NAME);
106 }
107 
108 
109 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110 
112 {
114  (
115  "oriented",
117  orientedOption::UNKNOWN,
118  true // Failsafe behaviour
119  );
120 }
121 
122 
124 {
125  const bool output = (oriented_ == ORIENTED);
126 
127  if (output)
128  {
129  os.writeEntry("oriented", orientedOptionNames[oriented_]);
130  }
132  return output;
133 }
134 
135 
136 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
137 
139 {
140  // Set the oriented status if it was unknown
141  if (oriented_ == UNKNOWN)
142  {
143  oriented_ = ot.oriented();
144  }
145 
146  (void) checkTypes("Operator +=", *this, ot);
147 }
148 
149 
150 void Foam::orientedType::operator-=(const orientedType& ot)
151 {
152  // Set the oriented status if it was unknown
153  if (oriented_ == orientedOption::UNKNOWN)
154  {
155  oriented_ = ot.oriented();
156  }
157 
158  (void) checkTypes("Operator -=", *this, ot);
159 }
160 
163 {
164  setOriented(is_oriented() != ot.is_oriented());
165 }
166 
169 {
170  setOriented(is_oriented() != ot.is_oriented());
171 }
172 
174 void Foam::orientedType::operator*=(const scalar s)
175 {
176  // No change to oriented_ flag
177 }
178 
179 
180 void Foam::orientedType::operator/=(const scalar s)
181 {
182  // No change to oriented_ flag
183 }
184 
185 
186 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
187 
189 {
190  (void) checkTypes("Function min", a, b);
191  return a;
192 }
193 
194 
196 {
197  (void) checkTypes("Function max", a, b);
198  return a;
199 }
200 
201 
202 Foam::orientedType Foam::lerp(const orientedType& a, const orientedType& b)
203 {
204  (void) checkTypes("Function lerp", a, b);
206  // Behaves like addition
207  return orientedType(a.is_oriented() || b.is_oriented());
208 }
209 
210 
212 (
213  const orientedType& ot1,
214  const orientedType& ot2
215 )
216 {
217  return ot1 ^ ot2;
218 }
219 
220 
222 (
223  const orientedType& ot1,
224  const orientedType& ot2
225 )
226 {
227  return ot1 ^ ot2;
228 }
229 
232 {
233  return ot;
234 }
235 
236 
237 Foam::orientedType Foam::pow(const orientedType& ot, const scalar p)
238 {
239  // Undefined???
240  // - only defined for integers where:
241  // - odd powers = oriented_ = yes (if ot is oriented)
242  // - even powers = oriented_ = no
243  return ot;
244 }
245 
248 {
249  return orientedType(false);
250 }
251 
254 {
255  return orientedType(false);
256 }
257 
260 {
261  return ot;
262 }
263 
266 {
267  return orientedType(false);
268 }
269 
272 {
273  return ot;
274 }
275 
278 {
279  return orientedType(false);
280 }
281 
284 {
285  return ot;
286 }
287 
290 {
291  return ot;
292 }
293 
296 {
297  return ot;
298 }
299 
302 {
303  return orientedType(false);
304 }
305 
308 {
309  return orientedType(false);
310 }
311 
314 {
315  return ot;
316 }
317 
320 {
321  return ot;
322 }
323 
326 {
327  return ot;
328 }
329 
332 {
333  return ot;
334 }
335 
338 {
339  return ot;
340 }
341 
344 {
345  return ot;
346 }
347 
350 {
351  return ot;
352 }
353 
356 {
357  return ot;
358 }
359 
360 
362 {
363  return ot;
364 }
365 
366 
368 (
369  const orientedType& ot1,
370  const orientedType& ot2
371 )
372 {
373  (void) checkTypes("Function atan2", ot1, ot2);
374 
375  return ot1;
376 }
377 
378 
380 (
381  const orientedType& ot1,
382  const orientedType& ot2
383 )
384 {
385  (void) checkTypes("Function hypot", ot1, ot2);
386 
387  return ot1;
388 }
389 
390 
391 Foam::orientedType Foam::transform(const orientedType& ot)
392 {
393  return ot;
394 }
395 
396 
397 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
398 
399 Foam::Istream& Foam::operator>>(Istream& is, orientedType& ot)
400 {
401  ot.oriented_ = orientedType::orientedOptionNames.read(is);
403  is.check(FUNCTION_NAME);
404 
405  return is;
406 }
407 
408 
409 Foam::Ostream& Foam::operator<<(Ostream& os, const orientedType& ot)
410 {
411  os << orientedType::orientedOptionNames[ot.oriented()];
412 
414 
415  return os;
416 }
417 
418 
419 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
420 
421 Foam::orientedType Foam::operator+
422 (
423  const orientedType& ot1,
424  const orientedType& ot2
425 )
426 {
427  (void) checkTypes("Operator +", ot1, ot2);
428 
429  return orientedType(ot1.is_oriented() || ot2.is_oriented());
430 }
431 
432 
434 {
435  return ot;
436 }
437 
438 
439 Foam::orientedType Foam::operator-
440 (
441  const orientedType& ot1,
442  const orientedType& ot2
443 )
444 {
445  (void) checkTypes("Operator -", ot1, ot2);
446 
447  return orientedType(ot1.is_oriented() || ot2.is_oriented());
448 }
449 
451 Foam::orientedType Foam::operator*(const scalar s, const orientedType& ot)
452 {
453  return ot;
454 }
455 
456 
458 {
459  return ot;
460 }
461 
462 
463 Foam::orientedType Foam::operator/
464 (
465  const orientedType& ot1,
466  const orientedType& ot2
467 )
468 {
469  return ot1 ^ ot2;
470 }
471 
472 
473 Foam::orientedType Foam::operator*
474 (
475  const orientedType& ot1,
476  const orientedType& ot2
477 )
478 {
479  return ot1 ^ ot2;
480 }
481 
482 
483 Foam::orientedType Foam::operator^
484 (
485  const orientedType& ot1,
486  const orientedType& ot2
487 )
488 {
489  return orientedType(ot1.is_oriented() != ot2.is_oriented());
490 }
491 
492 
493 Foam::orientedType Foam::operator&
494 (
495  const orientedType& ot1,
496  const orientedType& ot2
497 )
498 {
499  return ot1 ^ ot2;
500 }
501 
502 
503 Foam::orientedType Foam::operator&&
504 (
505  const orientedType& ot1,
506  const orientedType& ot2
507 )
508 {
509  return orientedType(false);
510 }
511 
512 
513 // ************************************************************************* //
constexpr orientedType() noexcept
Default construct as UNKNOWN.
Definition: orientedType.H:107
dimensionedScalar sign(const dimensionedScalar &ds)
EnumType read(Istream &is) const
Read a word from Istream and return the corresponding enumeration.
Definition: Enum.C:102
dictionary dict
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh >> cmptAv(const DimensionedField< Type, GeoMesh > &f1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
orientedOption
Enumeration defining oriented flags.
Definition: orientedType.H:61
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:45
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Mrf setOriented(true)
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensionedScalar pow025(const dimensionedScalar &ds)
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
static const Enum< orientedOption > orientedOptionNames
Named enumerations for oriented flags.
Definition: orientedType.H:74
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:321
Class to determine the &#39;oriented&#39; status of surface fields.
Definition: orientedType.H:52
bool writeEntry(Ostream &os) const
Write the "oriented" flag entry (if ORIENTED)
Definition: orientedType.C:116
dimensionedScalar posPart(const dimensionedScalar &ds)
dimensionedScalar neg(const dimensionedScalar &ds)
dimensionedScalar pow5(const dimensionedScalar &ds)
EnumType getOrDefault(const word &key, const dictionary &dict, const EnumType deflt, const bool warnOnly=false) const
Find the key in the dictionary and return the corresponding enumeration element based on its name...
Definition: Enum.C:173
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
bool is_oriented() const noexcept
True if ORIENTED.
Definition: orientedType.H:158
dimensionedScalar pos(const dimensionedScalar &ds)
void operator+=(const orientedType &ot)
Definition: orientedType.C:131
tmp< faMatrix< Type > > operator*(const areaScalarField::Internal &, const faMatrix< Type > &)
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Istream & operator>>(Istream &, directionInfo &)
dimensionedScalar cbrt(const dimensionedScalar &ds)
dimensionedScalar neg0(const dimensionedScalar &ds)
static bool checkTypes(const char *what, const orientedType &a, const orientedType &b)
Definition: orientedType.C:63
static bool checkType(const orientedType &a, const orientedType &b) noexcept
True if can operate on this combination of oriented types.
Definition: orientedType.C:43
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
dimensionSet pow2(const dimensionSet &ds)
Definition: dimensionSet.C:352
errorManip< error > abort(error &err)
Definition: errorManip.H:139
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Unary negation.
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
dimensionedScalar pos0(const dimensionedScalar &ds)
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
orientedOption oriented() const noexcept
Return the oriented flag.
Definition: orientedType.H:148
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
dimensioned< Type > lerp(const dimensioned< Type > &a, const dimensioned< Type > &b, const scalar t)
dimensionSet trans(const dimensionSet &ds)
Check the argument is dimensionless (for transcendental functions)
Definition: dimensionSet.C:471
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
void read(const dictionary &dict)
Read the "oriented" state from dictionary.
Definition: orientedType.C:104
dimensionedScalar pow3(const dimensionedScalar &ds)
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: error.H:64
dimensionedScalar pow4(const dimensionedScalar &ds)
dimensionedScalar pow6(const dimensionedScalar &ds)
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:44
void operator/=(const orientedType &ot)
Definition: orientedType.C:161
volScalarField & p
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))
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:521
dimensionedScalar hypot(const dimensionedScalar &x, const dimensionedScalar &y)
void operator*=(const orientedType &ot)
Definition: orientedType.C:155
void operator-=(const orientedType &ot)
Definition: orientedType.C:143
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Namespace for OpenFOAM.
dimensionedScalar negPart(const dimensionedScalar &ds)