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-2020 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 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 const Foam::Enum
33 <
35 >
37 ({
38  { orientedOption::ORIENTED, "oriented" },
39  { orientedOption::UNORIENTED, "unoriented" },
40  { orientedOption::UNKNOWN, "unknown" },
41 });
42 
43 
45 (
46  const orientedType& ot1,
47  const orientedType& ot2
48 )
49 {
50  return
51  (
52  (ot1.oriented() == UNKNOWN)
53  || (ot2.oriented() == UNKNOWN)
54  || (ot1.oriented() == ot2.oriented())
55  );
56 }
57 
58 
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60 
62 :
63  oriented_(UNKNOWN)
64 {}
65 
66 
68 :
69  oriented_(ot.oriented_)
70 {}
71 
72 
74 :
75  oriented_(oriented ? ORIENTED : UNORIENTED)
76 {}
77 
78 
80 :
81  oriented_(orientedOptionNames.read(is))
82 {
83  is.check(FUNCTION_NAME);
84 }
85 
86 
87 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
88 
90 {
91  return oriented_;
92 }
93 
94 
96 {
97  return oriented_;
98 }
99 
100 
101 void Foam::orientedType::setOriented(const bool oriented)
102 {
103  oriented_ = oriented ? ORIENTED : UNORIENTED;
104 }
105 
106 
108 {
109  oriented_ = orientedOptionNames.getOrDefault
110  (
111  "oriented",
112  dict,
113  orientedOption::UNKNOWN,
114  true // Failsafe behaviour
115  );
116 }
117 
118 
120 {
121  if (oriented_ == ORIENTED)
122  {
123  os.writeEntry("oriented", orientedOptionNames[oriented_]);
124  }
125 }
126 
127 
128 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
129 
131 {
132  // Oriented state is inherited on assignment
133  oriented_ = ot.oriented();
134 }
135 
136 
138 {
139  // Set the oriented status if it was unknown
140  if (oriented_ == UNKNOWN)
141  {
142  oriented_ = ot.oriented();
143  }
144 
145  if (!checkType(*this, ot))
146  {
148  << "Operator += is undefined for "
149  << orientedOptionNames[oriented_] << " and "
150  << orientedOptionNames[ot.oriented()] << " types"
151  << abort(FatalError);
152  }
153 }
154 
155 
157 {
158  // Set the oriented status if it was unknown
159  if (oriented_ == UNKNOWN)
160  {
161  oriented_ = ot.oriented();
162  }
163 
164  if (!checkType(*this, ot))
165  {
167  << "Operator -= is undefined for "
168  << orientedOptionNames[oriented_] << " and "
169  << orientedOptionNames[ot.oriented()] << " types"
170  << abort(FatalError);
171  }
172 }
173 
174 
176 {
177  const orientedType& ot1 = *this;
178  if (ot1() ^ ot())
179  {
180  oriented_ = ORIENTED;
181  }
182  else
183  {
184  oriented_ = UNORIENTED;
185  }
186 }
187 
188 
190 {
191  const orientedType& ot1 = *this;
192  if (ot1() ^ ot())
193  {
194  oriented_ = ORIENTED;
195  }
196  else
197  {
198  oriented_ = UNORIENTED;
199  }
200 }
201 
202 
204 {
205  // No change to oriented_ flag
206 }
207 
208 
210 {
211  // No change to oriented_ flag
212 }
213 
214 
216 {
217  return oriented_ == ORIENTED;
218 }
219 
220 
221 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
222 
224 {
225  if (!orientedType::checkType(ot1, ot2))
226  {
228  << "Operator max is undefined for "
229  << orientedType::orientedOptionNames[ot1.oriented()] << " and "
230  << orientedType::orientedOptionNames[ot2.oriented()] << " types"
231  << abort(FatalError);
232  }
233 
234  return ot1;
235 }
236 
237 
239 {
240  if (!orientedType::checkType(ot1, ot2))
241  {
243  << "Operator min is undefined for "
244  << orientedType::orientedOptionNames[ot1.oriented()] << " and "
245  << orientedType::orientedOptionNames[ot2.oriented()] << "types"
246  << abort(FatalError);
247  }
248 
249  return ot1;
250 }
251 
252 
254 (
255  const orientedType& ot1,
256  const orientedType& ot2
257 )
258 {
259  return ot1 ^ ot2;
260 }
261 
262 
264 (
265  const orientedType& ot1,
266  const orientedType& ot2
267 )
268 {
269  return ot1 ^ ot2;
270 }
271 
272 
274 {
275  return ot;
276 }
277 
278 
279 Foam::orientedType Foam::pow(const orientedType& ot, const scalar r)
280 {
281  // Undefined???
282  // - only defined for integers where:
283  // - odd powers = oriented_ = yes (if ot is oriented)
284  // - even powers = oriented_ = no
285  return ot;
286 }
287 
288 
290 {
291  return orientedType(false);
292 }
293 
294 
296 {
297  return ot;
298 }
299 
300 
302 {
303  return orientedType(false);
304 }
305 
306 
308 {
309  return ot;
310 }
311 
312 
314 {
315  return orientedType(false);
316 }
317 
318 
320 {
321  return ot;
322 }
323 
324 
326 {
327  return ot;
328 }
329 
330 
332 {
333  return ot;
334 }
335 
336 
338 {
339  return orientedType(false);
340 }
341 
342 
344 {
345  return orientedType(false);
346 }
347 
348 
350 {
351  return ot;
352 }
353 
354 
356 {
357  return ot;
358 }
359 
360 
362 {
363  return ot;
364 }
365 
366 
368 {
369  return ot;
370 }
371 
372 
374 {
375  return ot;
376 }
377 
378 
380 {
381  return ot;
382 }
383 
384 
386 {
387  return ot;
388 }
389 
390 
392 {
393  return ot;
394 }
395 
396 
398 {
399  return ot;
400 }
401 
402 
404 (
405  const orientedType& ot1,
406  const orientedType& ot2
407 )
408 {
409  if (!orientedType::checkType(ot1, ot2))
410  {
412  << "Operator atan2 is undefined for "
413  << orientedType::orientedOptionNames[ot1.oriented()] << " and "
414  << orientedType::orientedOptionNames[ot2.oriented()] << "types"
415  << abort(FatalError);
416  }
417 
418  return ot1;
419 }
420 
421 
423 (
424  const orientedType& ot1,
425  const orientedType& ot2
426 )
427 {
428  if (!orientedType::checkType(ot1, ot2))
429  {
431  << "Operator hypot is undefined for "
432  << orientedType::orientedOptionNames[ot1.oriented()] << " and "
433  << orientedType::orientedOptionNames[ot2.oriented()] << "types"
434  << abort(FatalError);
435  }
436 
437  return ot1;
438 }
439 
440 
442 {
443  return ot;
444 }
445 
446 
447 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
448 
450 {
451  ot.oriented_ = orientedType::orientedOptionNames.read(is);
452 
453  is.check(FUNCTION_NAME);
454 
455  return is;
456 }
457 
458 
460 {
462 
463  os.check(FUNCTION_NAME);
464 
465  return os;
466 }
467 
468 
469 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
470 
471 Foam::orientedType Foam::operator+
472 (
473  const orientedType& ot1,
474  const orientedType& ot2
475 )
476 {
477  if (!orientedType::checkType(ot1, ot2))
478  {
480  << "Operator + is undefined for "
481  << orientedType::orientedOptionNames[ot1.oriented()] << " and "
482  << orientedType::orientedOptionNames[ot2.oriented()] << " types"
483  << abort(FatalError);
484  }
485 
486  // Note use of () operators to convert to boolean op
487  return orientedType(ot1() || ot2());
488 }
489 
490 
492 {
493  return ot;
494 }
495 
496 
497 Foam::orientedType Foam::operator-
498 (
499  const orientedType& ot1,
500  const orientedType& ot2
501 )
502 {
503  if (!orientedType::checkType(ot1, ot2))
504  {
506  << "Operator - is undefined for "
507  << orientedType::orientedOptionNames[ot1.oriented()] << " and "
508  << orientedType::orientedOptionNames[ot2.oriented()] << " types"
509  << abort(FatalError);
510  }
511 
512  // Note use of () operators to convert to boolean op
513  return orientedType(ot1() || ot2());
514 }
515 
516 
518 {
519  return ot;
520 }
521 
522 
524 {
525  return ot;
526 }
527 
528 
529 Foam::orientedType Foam::operator/
530 (
531  const orientedType& ot1,
532  const orientedType& ot2
533 )
534 {
535  return ot1 ^ ot2;
536 }
537 
538 
539 Foam::orientedType Foam::operator*
540 (
541  const orientedType& ot1,
542  const orientedType& ot2
543 )
544 {
545  return ot1 ^ ot2;
546 }
547 
548 
549 Foam::orientedType Foam::operator^
550 (
551  const orientedType& ot1,
552  const orientedType& ot2
553 )
554 {
555  // Note use of () operators to convert to boolean op
556  return orientedType(ot1() ^ ot2());
557 }
558 
559 
560 Foam::orientedType Foam::operator&
561 (
562  const orientedType& ot1,
563  const orientedType& ot2
564 )
565 {
566  return ot1 ^ ot2;
567 }
568 
569 
570 Foam::orientedType Foam::operator&&
571 (
572  const orientedType& ot1,
573  const orientedType& ot2
574 )
575 {
576  return orientedType(false);
577 }
578 
579 
580 // ************************************************************************* //
Foam::trans
dimensionSet trans(const dimensionSet &ds)
Check the argument is dimensionless (for transcendental functions)
Definition: dimensionSet.C:484
Foam::orientedType::operator*=
void operator*=(const orientedType &ot)
Definition: orientedType.C:175
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
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::orientedType::oriented
orientedOption & oriented()
Return non-const reference to the oriented flag.
Definition: orientedType.C:89
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:45
Foam::operator-
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Foam::neg0
dimensionedScalar neg0(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:210
Foam::orientedType::orientedType
orientedType()
Null constructor - flag initialised to false.
Definition: orientedType.C:61
Foam::orientedType::orientedOptionNames
static const Enum< orientedOption > orientedOptionNames
Definition: orientedType.H:75
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:519
Foam::orientedType::operator=
void operator=(const orientedType &ot)
Definition: orientedType.C:130
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
Foam::orientedType::setOriented
void setOriented(const bool oriented=true)
Set the oriented flag.
Definition: orientedType.C:101
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
Foam::orientedType::operator+=
void operator+=(const orientedType &ot)
Definition: orientedType.C:137
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
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:51
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:121
Foam::pow5
dimensionedScalar pow5(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:111
Foam::orientedType::operator()
bool operator()() const
Definition: orientedType.C:215
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
Foam::cmptDivide
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::negPart
dimensionedScalar negPart(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:232
Foam::orientedType::writeEntry
void writeEntry(Ostream &os) const
Write the oriented flag entry.
Definition: orientedType.C:119
Foam::orientedType::read
void read(const dictionary &dict)
Read the oriented state from dictionary.
Definition: orientedType.C:107
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 > &)
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:270
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:232
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:156
Foam::orientedType::orientedOption
orientedOption
Enumeration defining the valid oriented flags.
Definition: orientedType.H:68
Foam::orientedType
Class to determine the 'oriented' status of surface fields.
Definition: orientedType.H:61
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:189
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177