Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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& 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}
63
64// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
65
66namespace Foam
67{
68
69static 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())
82 );
83
84 if (!ok)
85 {
87 << what << " : undefined for "
89 << orientedType::orientedOptionNames[b.oriented()] << " types"
90 << abort(FatalError);
91 }
92
93 return ok;
95
96} // End namespace Foam
97
98
99// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
100
102:
103 oriented_(orientedOptionNames.read(is))
105 is.check(FUNCTION_NAME);
106}
107
108
109// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110
112{
114 (
115 "oriented",
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
150void 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
165}
166
171}
172
174void Foam::orientedType::operator*=(const scalar s)
175{
176 // No change to oriented_ flag
177}
178
179
180void Foam::orientedType::operator/=(const scalar s)
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
202Foam::orientedType Foam::lerp(const orientedType& a, const orientedType& b)
203{
204 (void) checkTypes("Function lerp", a, b);
205
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
237Foam::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
362{
363 return ot;
364}
365
366
368(
369 const orientedType& ot1,
370 const orientedType& ot2
371)
373 (void) checkTypes("Function atan2", ot1, ot2);
374
375 return ot1;
376}
377
378
380(
381 const orientedType& ot1,
382 const orientedType& ot2
383)
385 (void) checkTypes("Function hypot", ot1, ot2);
386
387 return ot1;
388}
389
390
391Foam::orientedType Foam::transform(const orientedType& ot)
393 return ot;
394}
395
396
397// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
398
399Foam::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
409Foam::Ostream& Foam::operator<<(Ostream& os, const orientedType& ot)
410{
411 os << orientedType::orientedOptionNames[ot.oriented()];
412
413 os.check(FUNCTION_NAME);
415 return os;
416}
417
418
419// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
420
421Foam::orientedType Foam::operator+
422(
423 const orientedType& ot1,
424 const orientedType& ot2
425)
427 (void) checkTypes("Operator +", ot1, ot2);
428
429 return orientedType(ot1.is_oriented() || ot2.is_oriented());
430}
431
434{
435 return ot;
436}
437
438
439Foam::orientedType Foam::operator-
440(
441 const orientedType& ot1,
442 const orientedType& ot2
443)
445 (void) checkTypes("Operator -", ot1, ot2);
446
447 return orientedType(ot1.is_oriented() || ot2.is_oriented());
448}
449
451Foam::orientedType Foam::operator*(const scalar s, const orientedType& ot)
452{
453 return ot;
454}
455
457Foam::orientedType Foam::operator/(const orientedType& ot, const scalar s)
458{
459 return ot;
460}
461
462
463Foam::orientedType Foam::operator/
464(
465 const orientedType& ot1,
466 const orientedType& ot2
467)
468{
469 return ot1 ^ ot2;
470}
471
472
473Foam::orientedType Foam::operator*
474(
475 const orientedType& ot1,
476 const orientedType& ot2
477)
478{
479 return ot1 ^ ot2;
480}
481
482
483Foam::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
493Foam::orientedType Foam::operator&
494(
495 const orientedType& ot1,
496 const orientedType& ot2
497)
498{
499 return ot1 ^ ot2;
500}
501
502
503Foam::orientedType Foam::operator&&
504(
505 const orientedType& ot1,
506 const orientedType& ot2
507)
508{
509 return orientedType(false);
510}
511
512
513// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
EnumType read(Istream &is) const
Read a word from Istream and return the corresponding enumeration.
Definition Enum.C:102
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
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Class to determine the 'oriented' status of surface fields.
void operator/=(const orientedType &ot)
bool is_oriented() const noexcept
True if ORIENTED.
void operator*=(const orientedType &ot)
void read(const dictionary &dict)
Read the "oriented" state from dictionary.
orientedOption
Enumeration defining oriented flags.
@ UNKNOWN
Unknown/undefined orientation.
@ ORIENTED
Is oriented.
static bool checkType(const orientedType &a, const orientedType &b) noexcept
True if can operate on this combination of oriented types.
void operator-=(const orientedType &ot)
bool writeEntry(Ostream &os) const
Write the "oriented" flag entry (if ORIENTED).
static const Enum< orientedOption > orientedOptionNames
Named enumerations for oriented flags.
orientedOption oriented() const noexcept
Return the oriented flag.
void operator+=(const orientedType &ot)
constexpr orientedType() noexcept
Default construct as UNKNOWN.
orientedType(const orientedType &) noexcept=default
Copy construct.
volScalarField & p
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
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
Namespace for OpenFOAM.
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:40
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 > &)
refinementData transform(const tensor &, const refinementData val)
No-op rotational transform for base types.
tmp< faMatrix< Type > > operator*(const areaScalarField::Internal &, const faMatrix< Type > &)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
static bool checkTypes(const char *what, const orientedType &a, const orientedType &b)
dimensionedScalar negPart(const dimensionedScalar &ds)
dimensionedScalar sqrt(const dimensionedScalar &ds)
tmp< DimensionedField< typename DimensionedField< Type, GeoMesh >::cmptType, GeoMesh > > cmptAv(const DimensionedField< Type, GeoMesh > &f1)
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:26
dimensionedScalar pow4(const dimensionedScalar &ds)
errorManip< error > abort(error &err)
Definition errorManip.H:139
dimensionSet trans(const dimensionSet &ds)
Check the argument is dimensionless (for transcendental functions).
dimensionedScalar neg(const dimensionedScalar &ds)
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
dimensionedScalar neg0(const dimensionedScalar &ds)
dimensionedScalar cbrt(const dimensionedScalar &ds)
dimensionSet pow2(const dimensionSet &ds)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
dimensionedScalar posPart(const dimensionedScalar &ds)
dimensioned< Type > lerp(const dimensioned< Type > &a, const dimensioned< Type > &b, const scalar t)
dimensionedScalar pow025(const dimensionedScalar &ds)
dictionary dict
volScalarField & b
Mrf setOriented(true)