coordinateSystem.H
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
27Namespace
28 Foam::coordSystem
29
30Description
31 Namespace for coordinate systems.
32
33Class
34 Foam::coordinateSystem
35
36Description
37 Base class for coordinate system specification,
38 the default coordinate system type is
39 \link coordSystem::cartesian cartesian \endlink.
40
41 All systems are defined by an origin point and a coordinate rotation
42 By default, the \link coordinateRotations::axes axes \endlink
43 specification can be used directly as part of the
44 coordinate system specification. For example,
45
46 \verbatim
47 coordinateSystem
48 {
49 origin (0 0 0);
50 e1 (0 1 0);
51 e3 (1 0 0);
52 }
53 \endverbatim
54
55 However, a more verbose format with rotation provided as a dictionary entry
56 is possible:
57 \verbatim
58 coordinateSystem
59 {
60 type cartesian;
61 origin (0 0 0);
62 rotation
63 {
64 type axes;
65 e1 (0 1 0);
66 e3 (1 0 0);
67 }
68 }
69 \endverbatim
70
71 It also also possible to use the compact (single-dictionary) form
72 and specific a different type of rotation:
73 \verbatim
74 coordinateSystem
75 {
76 type cartesian;
77 origin (0 0 0);
78 rotation euler;
79 angles (90 0 0);
80 }
81 \endverbatim
82
83 This last form can be particularly readable for an identity rotation:
84 coordinateSystem
85 {
86 type cartesian;
87 origin (0 0 0);
88 rotation none;
89 }
90 \endverbatim
91
92 Types of coordinateRotation:
93 -# \link coordinateRotations::identity none \endlink
94 -# \link coordinateRotations::axes axes \endlink
95 -# \link coordinateRotations::axisAngle axisAngle \endlink
96 -# \link coordinateRotations::euler euler \endlink
97 -# \link coordinateRotations::starcd starcd \endlink
98
99 Type of coordinateSystem:
100 -# \link coordSystem::cartesian cartesian \endlink
101 -# \link coordSystem::cylindrical cylindrical \endlink
102 -# \link coordSystem::indirect indirect \endlink (references
103 an entry in coordinateSystems).
104
105SourceFiles
106 coordinateSystem.C
107 coordinateSystemNew.C
108 coordinateSystemTransform.C
109
110\*---------------------------------------------------------------------------*/
111
112#ifndef Foam_coordinateSystem_H
113#define Foam_coordinateSystem_H
114
115#include "vector.H"
116#include "point.H"
117#include "tensor.H"
118#include "vectorField.H"
119#include "pointField.H"
120#include "tensorField.H"
121#include "pointIndList.H"
122#include "coordinateRotation.H"
123#include "autoPtr.H"
124#include "tmp.H"
125
126// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127
128namespace Foam
129{
130
131// Forward Declarations
132class coordinateSystem;
133class objectRegistry;
134
135namespace coordSystem
136{
137class indirect;
138}
139
140
141/*---------------------------------------------------------------------------*\
142 Class coordinateSystem Declaration
143\*---------------------------------------------------------------------------*/
146{
147protected:
148
149 //- Friendship with indirect for dispatching to its underlying system
151
152
153 // Protected Data
154
155 //- User specification of the coordinate rotation
156 // May be invalid after a move assignment or transfer
158
159 //- The coordinate system origin
161
162 //- The rotation tensor
163 tensor rot_;
164
165 //- The name of the coordinate system (optional)
166 word name_;
167
168 //- An optional note describing the coordinate system
169 string note_;
170
171 //- Dummy coordinate system for suppressed manipulation
173
174
175 // Protected Member Functions
176
177 //- Implementation for R() methods
178 template<class PointField>
179 tmp<tensorField> rotationsImpl(const PointField& global) const;
180
181 //- Implementation for transformPoint() methods
182 template<class PointField>
183 tmp<pointField> transformPointImpl(const PointField& localCart) const;
184
185 //- Implementation for transformPosition() methods
186 template<class PointField>
188
189 //- Apply single transform tensor for multiple inputs
190 template<class RetType, class Type, class BinaryOp>
192 (
193 const tensor& tt,
194 const UList<Type>& input,
195 const BinaryOp& bop
196 );
197
198 //- Use position-dependent transform tensors for multiple inputs
199 template<class RetType, class PointField, class Type, class BinaryOp>
201 (
202 const PointField& global,
203 const UList<Type>& input,
204 const BinaryOp& bop
205 ) const;
206
207 //- Use position-dependent transform tensors for single input
208 template<class RetType, class PointField, class Type, class BinaryOp>
210 (
211 const PointField& global,
212 const Type& input,
213 const BinaryOp& bop
214 ) const;
215
216
217 //- From local coordinate system to the global Cartesian system
218 //- with optional translation for the origin
219 virtual vector localToGlobal
220 (
221 const vector& local,
222 bool translate
223 ) const;
224
225 //- From local coordinate system to the global Cartesian system
226 //- with optional translation for the origin
228 (
229 const vectorField& local,
230 bool translate
231 ) const;
232
233 //- From global Cartesian system to the local coordinate system
234 //- with optional translation for the origin
235 virtual vector globalToLocal
236 (
237 const vector& global,
238 bool translate
239 ) const;
240
241 //- From global Cartesian system to the local coordinate system
242 //- with optional translation for the origin
244 (
245 const vectorField& global,
246 bool translate
247 ) const;
248
249
250 //- Assign from dictionary content
251 void assign(const dictionary& dict);
252
253
254 // Constructors
255
256 //- Construct null, without allocating a coordinateRotation
257 //- specification.
258 coordinateSystem(std::nullptr_t);
259
260
261public:
262
263 //- Runtime type information
264 TypeName("coordinateSystem");
265
266 //- Helper for construction of coordinateSystem PtrList
267 // The Istream contains a word followed by a dictionary
268 struct iNew
271 {
272 return coordinateSystem::New(is);
273 }
274 };
275
276
277 // Constructors
278
279 //- Default construct. This is an identity coordinate system
281
282 //- Copy construct from rotation with origin=0
283 explicit coordinateSystem(const coordinateRotation& crot);
284
285 //- Move construct from rotation with origin=0
286 explicit coordinateSystem(coordinateRotation&& crot);
287
288 //- Copy construct
290
291 //- Move construct
293
294 //- Move construct from autoPtr
296
297 //- Copy construct with a different name
299 (
300 const word& name,
301 const coordinateSystem& csys
302 );
303
304 //- Construct from origin and rotation
306 (
307 const point& origin,
308 const coordinateRotation& crot
309 );
310
311 //- Construct from origin and 2 axes
313 (
314 const point& origin,
315 const vector& axis,
316 const vector& dirn
317 );
318
319 //- Construct from origin and rotation
321 (
322 const word& name,
323 const point& origin,
324 const coordinateRotation& crot
325 );
326
327 //- Construct from origin and 2 axes
329 (
330 const word& name,
331 const point& origin,
332 const vector& axis,
333 const vector& dirn
334 );
335
336 //- Construct from dictionary with a given name
337 coordinateSystem(const word& name, const dictionary& dict);
338
339 //- Construct from dictionary without a name
340 explicit coordinateSystem(const dictionary& dict);
341
342 //- Construct from dictionary with optional subDict lookup.
343 //
344 // \param dictName If non-empty, the sub-dictionary to use.
346
347
348 //- Return clone
349 virtual autoPtr<coordinateSystem> clone() const
350 {
351 return autoPtr<coordinateSystem>::New(*this);
352 }
353
354
355 // Declare run-time constructor selection table
357 (
358 autoPtr,
361 (
362 const dictionary& dict
363 ),
364 (dict)
365 );
366
367 // Declare run-time constructor selection table
369 (
370 autoPtr,
372 registry,
373 (
374 const objectRegistry& obr,
375 const dictionary& dict
376 ),
377 (obr, dict)
378 );
379
380
381 // Selectors
382
383 //- Select construct the specified coordinate system type
384 //- with reference to objectRegistry for indirect entries.
385 //
386 // An empty modelType will be treated as "cartesian"
388 (
389 word modelType,
390 const objectRegistry& obr,
391 const dictionary& dict
392 );
393
394 //- Select construct the specified coordinate system type
395 //
396 // An empty modelType will be treated as "cartesian"
398 (
399 word modelType,
400 const dictionary& dict
401 );
402
403 //- Select construct from dictionary with reference to objectRegistry
404 //- for indirect entries.
405 //
406 // \param dictName If non-empty, the sub-dictionary name to use
407 // for the coordinate system description.
408 //
409 // \note When the dictName is empty, it includes an implicit search
410 // for a "coordinateSystem" sub-dictionary for convenience and
411 // compatibility with previous versions (1806 and earlier).
413 (
414 const objectRegistry& obr,
415 const dictionary& dict,
416 const word& dictName = ""
417 );
418
419 //- Select constructed from dictionary
420 // \param dictName If non-empty, the sub-dictionary name to use
421 // for the coordinate system description.
422 //
423 // \note When the dictName is empty, it includes an implicit search
424 // for a "coordinateSystem" sub-dictionary for convenience and
425 // compatibility with previous versions (1806 and earlier).
427 (
428 const dictionary& dict,
429 const word& dictName = ""
430 );
431
432 //- Select constructed from Istream
433 // Expects a name/dictionary as input
435
436
437 //- Destructor
438 virtual ~coordinateSystem() = default;
439
440
441 // Member Functions
442
443 // Characteristics
444
445 //- Consider valid if it has a specification
446 virtual bool valid() const
447 {
448 return bool(spec_);
449 }
450
451 //- True if the rotation tensor is uniform for all locations
452 virtual bool uniform() const
453 {
454 return true;
455 }
456
457
458 // Access
459
460 //- Return origin
461 virtual const point& origin() const
462 {
463 return origin_;
464 }
465
466 //- The rotation specification
467 virtual const coordinateRotation& rotation() const
468 {
469 return *spec_;
470 }
471
472 //- Return the name
473 virtual const word& name() const
474 {
475 return name_;
476 }
477
478 //- Return the optional note
479 virtual const string& note() const
480 {
481 return note_;
482 }
483
484 //- Return const reference to the rotation tensor
485 virtual const tensor& R() const
486 {
487 return rot_;
488 }
489
490 //- The local Cartesian x-axis in global coordinates
491 virtual const vector e1() const
492 {
493 return rot_.cx();
494 }
495
496 //- The local Cartesian y-axis in global coordinates
497 virtual const vector e2() const
498 {
499 return rot_.cy();
500 }
501
502 //- The local Cartesian z-axis in global coordinates
503 virtual const vector e3() const
504 {
505 return rot_.cz();
506 }
507
508
509 // Edit
510
511 //- Rename
512 virtual void rename(const word& newName)
513 {
514 name_ = newName;
515 }
516
517 //- Edit access to optional note
518 virtual string& note()
519 {
520 return note_;
521 }
522
523 //- Edit access to origin
524 virtual point& origin()
525 {
526 return origin_;
527 }
528
529 //- Reset origin and rotation to an identity coordinateSystem
530 // Also resets the note
531 virtual void clear();
532
533 //- Change the rotation
534 virtual void rotation(autoPtr<coordinateRotation>&& crot);
535
536
537 // Write
538
539 //- Write
540 virtual void write(Ostream& os) const;
541
542 //- Write 'coordinateSystem' dictionary entry
543 virtual void writeEntry(Ostream& os) const;
544
545 //- Write dictionary entry
546 virtual void writeEntry(const word& keyword, Ostream& os) const;
547
548
549 // Member Operators
550
551 //- Copy assignment
552 void operator=(const coordinateSystem& csys);
553
554 //- Move assignment
555 void operator=(coordinateSystem&& csys);
556
557 //- Copy assignment from autoPtr
558 void operator=(const autoPtr<coordinateSystem>& csys);
559
560 //- Move assignment from autoPtr
562
563
564 // Rotation
565
566 //- Position-dependent rotation tensor (when uniform = false)
567 //- \return tensor
568 virtual tensor R(const point& global) const;
569
570 //- Position-dependent rotation tensors (when uniform = false)
571 //- \return tensorField
572 virtual tmp<tensorField> R(const UList<point>& global) const;
573
574 //- Position-dependent rotation tensors (when uniform = false)
575 //- \return tensorField
576 virtual tmp<tensorField> R(const pointUIndList& global) const;
577
578
579 // Position
580
581 //- Transform point and add origin offset.
582 // Corresponds to a local-to-global transformation using Cartesian
583 // coordinates for both local and global.
584 point transformPoint(const point& localCart) const;
585
586 //- Transform points and add origin offset.
587 tmp<pointField> transformPoint(const UList<point>& localCart) const;
588
589 //- Transform points and add origin offset.
590 tmp<pointField> transformPoint(const pointUIndList& localCart) const;
591
592
593 //- Remove origin offset and inverse transform point.
594 // Corresponds to a global-to-local transformation using Cartesian
595 // coordinates for both local and global.
596 point invTransformPoint(const point& global) const;
597
598 //- Remove origin offset and inverse transform points.
600
601 //- Remove origin offset and inverse transform points.
603
604
605 // Transformations with change of coordinate types
606
607 //- From local coordinate position to global (cartesian) position
608 point globalPosition(const point& local) const
609 {
610 return localToGlobal(local, true);
611 }
612
613 //- From local coordinate position to global (cartesian) position
614 tmp<pointField> globalPosition(const pointField& local) const
615 {
616 return localToGlobal(local, true);
617 }
618
619 //- From global (cartesian) position to local coordinate position
620 point localPosition(const point& global) const
621 {
622 return globalToLocal(global, true);
623 }
624
625 //- From global (cartesian) position to local coordinate position
626 tmp<pointField> localPosition(const pointField& global) const
627 {
628 return globalToLocal(global, true);
629 }
630
631
632
633 //- From local to global (cartesian) vector components
634 vector globalVector(const vector& local) const
635 {
636 return localToGlobal(local, false);
637 }
638
639 //- From local to global (cartesian) vector components
640 tmp<vectorField> globalVector(const vectorField& local) const
641 {
642 return localToGlobal(local, false);
643 }
644
645 //- From global (cartesian) to local vector components
646 vector localVector(const vector& global) const
647 {
648 return globalToLocal(global, false);
649 }
650
651 //- From global (cartesian) to local vector components
652 tmp<vectorField> localVector(const vectorField& global) const
653 {
654 return globalToLocal(global, false);
655 }
656
657
658 // Transformations (input and output are Cartesian)
659
660#undef defineCoordinateSystemTransform
661#define defineCoordinateSystemTransform(Op, RetType, Type) \
662 \
663 \
664 virtual RetType Op(const Type& input) const; \
665 \
666 \
667 virtual tmp<Field<RetType>> Op(const UList<Type>& input) const; \
668 \
669 \
670 virtual RetType Op(const point& global, const Type& input) const; \
671 \
672 \
673 virtual tmp<Field<RetType>> Op \
674 ( \
675 const UList<point>& global, \
676 const Type& input \
677 ) const; \
678 \
679 \
680 virtual tmp<Field<RetType>> Op \
681 ( \
682 const pointUIndList& global, \
683 const Type& input \
684 ) const; \
685 \
686 \
687 virtual tmp<Field<RetType>> Op \
688 ( \
689 const UList<point>& global, \
690 const UList<Type>& input \
691 ) const; \
692 \
693 \
694 virtual tmp<Field<RetType>> Op \
695 ( \
696 const pointUIndList& global, \
697 const UList<Type>& input \
698 ) const;
699
700
702
706 (
707 transform,
710 );
713
717 (
721 );
724
725 #undef defineCoordinateSystemTransform
726};
727
728
729// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
730
731// Global Operators
732
733//- Compare inequality
734bool operator!=(const coordinateSystem& a, const coordinateSystem& b);
735
736//- Output operator
737Ostream& operator<<(Ostream& os, const coordinateSystem& csys);
738
739
740// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
741
742} // End namespace Foam
743
744
745// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
746
747#ifdef NoRepository
749#endif
750
751// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
752
753#endif
754
755// ************************************************************************* //
#define R(A, B, C, D, E, F, K, M)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
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
A coordinate system forward to a global coordinate system that is normally provided by the constant/c...
Definition: indirectCS.H:78
User specification of a coordinate rotation.
Base class for coordinate system specification, the default coordinate system type is cartesian .
virtual const word & name() const
Return the name.
vector globalVector(const vector &local) const
From local to global (cartesian) vector components.
virtual bool uniform() const
True if the rotation tensor is uniform for all locations.
static autoPtr< coordinateSystem > New(word modelType, const objectRegistry &obr, const dictionary &dict)
virtual const coordinateRotation & rotation() const
The rotation specification.
tmp< pointField > globalPosition(const pointField &local) const
From local coordinate position to global (cartesian) position.
virtual const vector e2() const
The local Cartesian y-axis in global coordinates.
tmp< tensorField > rotationsImpl(const PointField &global) const
Implementation for R() methods.
string note_
An optional note describing the coordinate system.
void operator=(const coordinateSystem &csys)
Copy assignment.
virtual string & note()
Edit access to optional note.
virtual bool valid() const
Consider valid if it has a specification.
tmp< pointField > invTransformPointImpl(const PointField &global) const
Implementation for transformPosition() methods.
virtual vector globalToLocal(const vector &global, bool translate) const
point globalPosition(const point &local) const
From local coordinate position to global (cartesian) position.
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)
point localPosition(const point &global) const
From global (cartesian) position to local coordinate position.
declareRunTimeSelectionTable(autoPtr, coordinateSystem, dictionary,(const dictionary &dict),(dict))
virtual scalar invTransform(const scalar &input) const
With constant rotation tensor.
tmp< Field< RetType > > oneToOneImpl(const PointField &global, const UList< Type > &input, const BinaryOp &bop) const
Use position-dependent transform tensors for multiple inputs.
static coordinateSystem dummy_
Dummy coordinate system for suppressed manipulation.
tensor rot_
The rotation tensor.
virtual scalar transform(const scalar &input) const
With constant rotation tensor.
virtual const point & origin() const
Return origin.
virtual ~coordinateSystem()=default
Destructor.
declareRunTimeSelectionTable(autoPtr, coordinateSystem, registry,(const objectRegistry &obr, const dictionary &dict),(obr, dict))
void assign(const dictionary &dict)
Assign from dictionary content.
static tmp< Field< RetType > > manyTimesImpl(const tensor &tt, const UList< Type > &input, const BinaryOp &bop)
Apply single transform tensor for multiple inputs.
TypeName("coordinateSystem")
Runtime type information.
autoPtr< coordinateRotation > spec_
User specification of the coordinate rotation.
virtual const string & note() const
Return the optional note.
tmp< vectorField > globalVector(const vectorField &local) const
From local to global (cartesian) vector components.
vector localVector(const vector &global) const
From global (cartesian) to local vector components.
tmp< Field< RetType > > oneToManyImpl(const PointField &global, const Type &input, const BinaryOp &bop) const
Use position-dependent transform tensors for single input.
virtual const tensor & R() const
Return const reference to the rotation tensor.
virtual point & origin()
Edit access to origin.
coordinateSystem()
Default construct. This is an identity coordinate system.
virtual void writeEntry(Ostream &os) const
Write 'coordinateSystem' dictionary entry.
virtual symmTensor transformPrincipal(const vector &input) const
With constant rotation tensor.
virtual void rename(const word &newName)
Rename.
virtual const vector e1() const
The local Cartesian x-axis in global coordinates.
tmp< vectorField > localVector(const vectorField &global) const
From global (cartesian) to local vector components.
virtual const vector e3() const
The local Cartesian z-axis in global coordinates.
tmp< pointField > localPosition(const pointField &global) const
From global (cartesian) position to local coordinate position.
virtual void clear()
Reset origin and rotation to an identity coordinateSystem.
virtual autoPtr< coordinateSystem > clone() const
Return clone.
point transformPoint(const point &localCart) const
Transform point and add origin offset.
point origin_
The coordinate system origin.
tmp< pointField > transformPointImpl(const PointField &localCart) const
Implementation for transformPoint() methods.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Registry of regIOobjects.
Tensor of scalars, i.e. Tensor<scalar>.
A class for managing temporary objects.
Definition: tmp.H:65
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
A class for handling words, derived from Foam::string.
Definition: word.H:68
bool
Definition: EEqn.H:20
#define defineCoordinateSystemTransform(Op, RetType, Type)
OBJstream os(runTime.globalPath()/outputName)
const word dictName("faMeshDefinition")
Namespace for OpenFOAM.
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:239
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition: symmTensor.H:59
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
runTime write()
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes)
dictionary dict
volScalarField & b
Definition: createFields.H:27
Helper for construction of coordinateSystem PtrList.
autoPtr< coordinateSystem > operator()(Istream &is) const
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73