coordinateSystem.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2018-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "coordinateSystem.H"
30#include "cartesianCS.H"
31#include "IOstream.H"
32#include "axesRotation.H"
33#include "identityRotation.H"
34#include "transform.H"
36
37// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38
39namespace Foam
40{
44}
45
47
48
49// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
50
51namespace Foam
52{
53 //- Is it cartesian?
54 // For output, can treat the base class as Cartesian too,
55 // since it defaults to cartesian on input.
56 static inline bool isCartesian(const word& modelType)
57 {
58 return
59 (
60 modelType == coordinateSystem::typeName_()
61 || modelType == coordSystem::cartesian::typeName_()
62 );
63 }
64
65} // End namespace Foam
66
67
68// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
69
71{
72 dict.readEntry("origin", origin_);
73
74 note_.clear();
75 dict.readIfPresent("note", note_);
76
77 const auto finder = dict.csearchCompat
78 (
79 "rotation", {{"coordinateRotation", 1806}},
81 );
82
83 if (finder.good())
84 {
85 if (finder.isDict())
86 {
87 // Use the sub-dict, which is expected to contain "type"
88 spec_ = coordinateRotation::New(finder.dict());
89 }
90 else
91 {
92 // Use current dict. Type specified by "rotation" entry itself.
93 const word rotationType(finder->get<word>());
94 spec_.reset(coordinateRotation::New(rotationType, dict));
95 }
96 }
97 else
98 {
99 // Fall through to expecting e1/e2/e3 specification in the dictionary
101 }
102
103 rot_ = spec_->R();
104}
105
106
107// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
108
110:
111 spec_(nullptr),
112 origin_(Zero),
113 rot_(sphericalTensor::I),
114 name_(),
115 note_()
116{}
117
118
120:
121 spec_(new coordinateRotations::identity()),
122 origin_(Zero),
123 rot_(sphericalTensor::I),
124 name_(),
125 note_()
126{}
127
128
130:
131 coordinateSystem(word::null, point::zero, crot)
132{}
133
134
136:
137 coordinateSystem(word::null, point::zero, std::move(crot))
138{}
139
140
142:
143 spec_(csys.spec_.clone()),
144 origin_(csys.origin_),
145 rot_(csys.rot_),
146 name_(csys.name_),
147 note_(csys.note_)
148{}
149
150
152:
153 spec_(std::move(csys.spec_)),
154 origin_(std::move(csys.origin_)),
155 rot_(std::move(csys.rot_)),
156 name_(std::move(csys.name_)),
157 note_(std::move(csys.note_))
158{}
159
160
162:
163 coordinateSystem(nullptr)
164{
165 if (csys)
166 {
167 // Has valid autoPtr - move.
168 coordinateSystem::operator=(std::move(*csys));
169 csys.clear();
170 }
171 else
172 {
173 // No valid autoPtr - treat like identity
175 }
176}
177
178
180(
181 const word& name,
182 const coordinateSystem& csys
183)
184:
185 spec_(csys.spec_.clone()),
186 origin_(csys.origin_),
187 rot_(csys.rot_),
188 name_(name),
189 note_(csys.note_)
190{}
191
192
194(
195 const point& origin,
196 const coordinateRotation& crot
197)
198:
199 coordinateSystem(word::null, origin, crot)
200{}
201
202
204(
205 const word& name,
206 const point& origin,
207 const coordinateRotation& crot
208)
209:
210 spec_(crot.clone()),
211 origin_(origin),
212 rot_(spec_->R()),
213 name_(name),
214 note_()
215{}
216
217
219(
220 const point& origin,
221 const vector& axis,
222 const vector& dirn
223)
224:
225 coordinateSystem(word::null, origin, axis, dirn)
226{}
227
228
230(
231 const word& name,
232 const point& origin,
233 const vector& axis,
234 const vector& dirn
235)
236:
237 spec_(new coordinateRotations::axes(axis, dirn)),
238 origin_(origin),
239 rot_(spec_->R()),
240 name_(name),
241 note_()
242{}
243
244
246(
247 const word& name,
248 const dictionary& dict
249)
250:
251 spec_(nullptr),
252 origin_(Zero),
253 rot_(sphericalTensor::I),
254 name_(name),
255 note_()
256{
257 assign(dict);
258}
259
260
262:
263 coordinateSystem(nullptr)
264{
265 assign(dict);
266}
267
268
270(
271 const dictionary& dict,
272 const word& dictName
273)
274:
275 coordinateSystem(nullptr)
276{
277 if (dictName.size())
278 {
280 }
281 else
282 {
283 assign(dict);
284 }
285}
286
287
288// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
289
291{
292 spec_->clear();
293 origin_ = Zero;
294 rot_ = sphericalTensor::I;
295 note_.clear();
296}
297
298
300{
301 return rot_;
302}
303
304
306(
307 const UList<point>& global
308) const
309{
310 return rotationsImpl(global);
311}
312
313
315(
316 const pointUIndList& global
317) const
318{
319 return rotationsImpl(global);
320}
321
322
324(
325 const point& localCart
326) const
327{
328 return Foam::transform(rot_, localCart) + origin_;
329}
330
331
333(
334 const point& global
335) const
336{
337 return Foam::invTransform(rot_, global - origin_);
338}
339
340
342(
343 const vector& local,
344 bool translate
345) const
346{
347 if (translate)
348 {
349 return this->transform(local) + origin_;
350 }
351
352 return this->transform(local);
353}
354
355
357(
358 const vectorField& local,
359 bool translate
360) const
361{
362 if (translate)
363 {
364 return this->transform(local) + origin_;
365 }
366
367 return this->transform(local);
368}
369
370
372(
373 const vector& global,
374 bool translate
375) const
376{
377 if (translate)
378 {
379 return this->invTransform(global - origin_);
380 }
381
382 return this->invTransform(global);
383}
384
385
387(
388 const vectorField& global,
389 bool translate
390) const
391{
392 if (translate)
393 {
394 return this->invTransform(global - origin_);
395 }
396
397 return this->invTransform(global);
398}
399
400
402{
403 spec_.reset(std::move(crot));
404 if (spec_)
405 {
406 rot_ = spec_->R();
407 }
408 else
409 {
410 rot_ = sphericalTensor::I;
411 }
412}
413
414
416{
417 if (!valid())
418 {
419 return;
420 }
421
422 // Suppress output of type for Cartesian
423 if (!isCartesian(type()))
424 {
425 os << type() << ' ';
426 }
427
428 os << "origin: " << origin_ << ' ';
429 spec_->write(os);
430}
431
432
434{
435 writeEntry(coordinateSystem::typeName_(), os);
436}
437
438
440{
441 if (!valid())
442 {
443 return;
444 }
445
446 const bool subDict = !keyword.empty();
447
448 if (subDict)
449 {
450 os.beginBlock(keyword);
451
452 // Suppress output of type for Cartesian
453 if (!isCartesian(type()))
454 {
455 os.writeEntry<word>("type", type());
456 }
457
458 if (note_.size())
459 {
460 // The 'note' is optional
461 os.writeEntry("note", note_);
462 }
463 }
464
465 os.writeEntry("origin", origin_);
466
467 spec_->writeEntry("rotation", os);
468
469 if (subDict)
470 {
471 os.endBlock();
472 }
473}
474
475
476// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
477
479{
480 name_ = csys.name_;
481 note_ = csys.note_;
482 origin_ = csys.origin_;
483
484 // Some extra safety
485 if (csys.spec_)
486 {
487 rotation(csys.spec_.clone());
488 }
489 else
490 {
491 spec_.reset(new coordinateRotations::identity());
492 rot_ = sphericalTensor::I;
493 }
494}
495
496
498{
499 name_ = std::move(csys.name_);
500 note_ = std::move(csys.note_);
501 spec_ = std::move(csys.spec_);
502 origin_ = csys.origin_;
503 rot_ = csys.rot_;
504}
505
506
508{
510}
511
512
514{
515 coordinateSystem::operator=(std::move(*csys));
516 csys.clear();
517}
518
519
520// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
521
523{
524 return
525 (
526 a.type() != b.type()
527 || a.origin() != b.origin()
528 || a.R() != b.R()
529 );
530}
531
532
534{
535 csys.write(os);
537 return os;
538}
539
540
541// ************************************************************************* //
#define R(A, B, C, D, E, F, K, M)
Macros for easy insertion into run-time selection tables.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:105
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:239
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:87
static const SphericalTensor I
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
A List with indirect addressing. Like IndirectList but does not store addressing.
Definition: IndirectList.H:79
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
User specification of a coordinate rotation.
virtual tensor R() const =0
Calculate and return the rotation tensor.
A coordinateRotation specified using global axes.
Definition: axesRotation.H:108
An identity coordinateRotation.
Base class for coordinate system specification, the default coordinate system type is cartesian .
virtual const coordinateRotation & rotation() const
The rotation specification.
string note_
An optional note describing the coordinate system.
void operator=(const coordinateSystem &csys)
Copy assignment.
virtual vector globalToLocal(const vector &global, bool translate) const
point invTransformPoint(const point &global) const
Remove origin offset and inverse transform point.
virtual vector localToGlobal(const vector &local, bool translate) const
word name_
The name of the coordinate system (optional)
static coordinateSystem dummy_
Dummy coordinate system for suppressed manipulation.
tensor rot_
The rotation tensor.
virtual const point & origin() const
Return origin.
void assign(const dictionary &dict)
Assign from dictionary content.
virtual void write(Ostream &os) const
Write.
autoPtr< coordinateRotation > spec_
User specification of the coordinate rotation.
virtual const tensor & R() const
Return const reference to the rotation tensor.
coordinateSystem()
Default construct. This is an identity coordinate system.
virtual void writeEntry(Ostream &os) const
Write 'coordinateSystem' dictionary entry.
virtual void clear()
Reset origin and rotation to an identity coordinateSystem.
point transformPoint(const point &localCart) const
Transform point and add origin offset.
point origin_
The coordinate system origin.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
const_searcher csearchCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword and any compatibility names.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
virtual bool write()
Write the output fields.
@ LITERAL
String literal.
Definition: keyType.H:81
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
OBJstream os(runTime.globalPath()/outputName)
const word dictName("faMeshDefinition")
#define FUNCTION_NAME
Namespace for OpenFOAM.
dimensionSet invTransform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:542
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:239
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
Definition: labelList.C:38
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:536
static const Identity< scalar > I
Definition: Identity.H:94
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
static bool isCartesian(const word &modelType)
Is it cartesian?
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
dictionary dict
volScalarField & b
Definition: createFields.H:27
3D tensor transformation operations.