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-2021 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& 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_(oriented ? ORIENTED : UNORIENTED)
81 {}
82 
83 
85 :
86  oriented_(orientedOptionNames.read(is))
87 {
88  is.check(FUNCTION_NAME);
89 }
90 
91 
92 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
93 
95 {
96  return oriented_;
97 }
98 
99 
101 {
102  return oriented_;
103 }
104 
105 
106 void Foam::orientedType::setOriented(const bool oriented) noexcept
107 {
108  oriented_ = oriented ? 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 "
238  << orientedType::orientedOptionNames[ot1.oriented()] << " and "
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 "
253  << orientedType::orientedOptionNames[ot1.oriented()] << " and "
254  << orientedType::orientedOptionNames[ot2.oriented()] << "types"
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 
288 Foam::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 "
422  << orientedType::orientedOptionNames[ot1.oriented()] << " and "
423  << orientedType::orientedOptionNames[ot2.oriented()] << "types"
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 "
441  << orientedType::orientedOptionNames[ot1.oriented()] << " and "
442  << orientedType::orientedOptionNames[ot2.oriented()] << "types"
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 
462  is.check(FUNCTION_NAME);
463 
464  return is;
465 }
466 
467 
469 {
471 
473 
474  return os;
475 }
476 
477 
478 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
479 
480 Foam::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 
506 Foam::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 
538 Foam::orientedType Foam::operator/
539 (
540  const orientedType& ot1,
541  const orientedType& ot2
542 )
543 {
544  return ot1 ^ ot2;
545 }
546 
547 
548 Foam::orientedType Foam::operator*
549 (
550  const orientedType& ot1,
551  const orientedType& ot2
552 )
553 {
554  return ot1 ^ ot2;
555 }
556 
557 
558 Foam::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 
569 Foam::orientedType Foam::operator&
570 (
571  const orientedType& ot1,
572  const orientedType& ot2
573 )
574 {
575  return ot1 ^ ot2;
576 }
577 
578 
579 Foam::orientedType Foam::operator&&
580 (
581  const orientedType& ot1,
582  const orientedType& ot2
583 )
584 {
585  return orientedType(false);
586 }
587 
588 
589 // ************************************************************************* //
Foam::trans
dimensionSet trans(const dimensionSet &ds)
Check the argument is dimensionless (for transcendental functions)
Definition: dimensionSet.C:486
Foam::orientedType::operator*=
void operator*=(const orientedType &ot)
Definition: orientedType.C:184
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::output
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
s
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))
Definition: gmvOutputSpray.H:25
Foam::cmptMultiply
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::posPart
dimensionedScalar posPart(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:221
Foam::atan2
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
Definition: dimensionedScalar.C:312
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::orientedType::checkType
static bool checkType(const orientedType &ot1, const orientedType &ot2)
Return true if can operate on this pair of oriented types.
Definition: orientedType.C:50
Foam::operator-
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Foam::neg0
dimensionedScalar neg0(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:210
Foam::orientedType::orientedType
orientedType()
Default construct as "UNKNOWN".
Definition: orientedType.C:66
Foam::orientedType::orientedOptionNames
static const Enum< orientedOption > orientedOptionNames
Named enumerations for oriented flags.
Definition: orientedType.H:71
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::pos0
dimensionedScalar pos0(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:188
Foam::sign
dimensionedScalar sign(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:166
Foam::transform
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:521
Foam::orientedType::operator=
void operator=(const orientedType &ot)
Definition: orientedType.C:139
Foam::orientedType::writeEntry
bool writeEntry(Ostream &os) const
Write the "oriented" flag entry (if ORIENTED)
Definition: orientedType.C:124
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
orientedType.H
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::pow025
dimensionedScalar pow025(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:133
Foam::hypot
dimensionedScalar hypot(const dimensionedScalar &x, const dimensionedScalar &y)
Definition: dimensionedScalar.C:327
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::pow4
dimensionedScalar pow4(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:100
Foam::pow6
dimensionedScalar pow6(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:122
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::pow3
dimensionedScalar pow3(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:89
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:73
Foam::cmptAv
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh >> cmptAv(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:246
Istream.H
Foam::orientedType::operator+=
void operator+=(const orientedType &ot)
Definition: orientedType.C:146
Foam::pow
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Definition: dimensionedScalar.C:75
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
Foam::orientedType::oriented
orientedOption & oriented() noexcept
Return non-const reference to the oriented flag.
Definition: orientedType.C:94
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::pow5
dimensionedScalar pow5(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:111
os
OBJstream os(runTime.globalPath()/outputName)
Foam::orientedType::operator()
bool operator()() const
Definition: orientedType.C:224
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::operator/
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
Definition: dimensionedScalar.C:68
Ostream.H
Foam::cmptDivide
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::negPart
dimensionedScalar negPart(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:232
Foam::orientedType::read
void read(const dictionary &dict)
Read the "oriented" state from dictionary.
Definition: orientedType.C:112
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::operator*
tmp< faMatrix< Type > > operator*(const areaScalarField &, const faMatrix< Type > &)
dictionary.H
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:236
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::cbrt
dimensionedScalar cbrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:155
Foam::orientedType::operator-=
void operator-=(const orientedType &ot)
Definition: orientedType.C:165
Foam::orientedType::orientedOption
orientedOption
Enumeration defining oriented flags.
Definition: orientedType.H:63
Foam::orientedType
Class to determine the 'oriented' status of surface fields.
Definition: orientedType.H:56
Foam::Enum::read
EnumType read(Istream &is) const
Read a word from Istream and return the corresponding enumeration.
Definition: Enum.C:109
Foam::neg
dimensionedScalar neg(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:199
Foam::orientedType::operator/=
void operator/=(const orientedType &ot)
Definition: orientedType.C:198
Foam::orientedType::setOriented
void setOriented(const bool oriented=true) noexcept
Set the oriented flag.
Definition: orientedType.C:106
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177