vectorTensorTransform.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) 2020-2025 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 Class
28  Foam::vectorTensorTransform
29 
30 Description
31  Vector-tensor class used to perform translations and rotations in
32  3D space.
33 
34 SourceFiles
35  vectorTensorTransformI.H
36  vectorTensorTransform.C
37  vectorTensorTransform.txx
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Foam_vectorTensorTransform_H
42 #define Foam_vectorTensorTransform_H
43 
44 #include "tensor.H"
45 #include "word.H"
46 #include "contiguous.H"
47 #include "pointField.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward Declarations
55 class vectorTensorTransform;
56 Istream& operator>>(Istream& is, vectorTensorTransform&);
57 Ostream& operator<<(Ostream& os, const vectorTensorTransform& C);
58 
59 
60 /*---------------------------------------------------------------------------*\
61  Class vectorTensorTransform Declaration
62 \*---------------------------------------------------------------------------*/
63 
65 {
66  // Private Data
67 
68  //- Translation vector
69  vector t_;
70 
71  //- Rotation tensor
72  tensor R_;
73 
74  //- Recording if the transform has non-identity transform to
75  // allow its calculation to be skipped, which is the majority
76  // of the expected cases
77  bool hasR_;
78 
79 
80 public:
81 
82  // Static Data
83 
84  static const char* const typeName;
85 
87 
88  static const vectorTensorTransform I;
89 
90 
91  // Generated Methods
92 
93  //- Copy construct
95 
96  //- Copy assignment
98  operator=(const vectorTensorTransform&) = default;
99 
100 
101  // Constructors
102 
103  //- Default construct - no translation, identity rotation.
104  inline vectorTensorTransform();
105 
106  //- Construct given a translation vector, rotation tensor and
107  //- hasR bool
108  inline vectorTensorTransform
109  (
110  const vector& t,
111  const tensor& R,
112  bool hasR = true
113  );
114 
115  //- Construct a pure translation vectorTensorTransform given a
116  //- translation vector
117  inline explicit vectorTensorTransform(const vector& t);
118 
119  //- Construct a pure rotation vectorTensorTransform given a
120  //- rotation tensor
121  inline explicit vectorTensorTransform(const tensor& R);
122 
123  //- Construct from Istream
124  explicit vectorTensorTransform(Istream&);
125 
126 
127  // Member Functions
128 
129  // Access
130 
131  //- True if it has a non-identity rotation tensor
132  bool hasR() const noexcept { return hasR_; }
133 
134  //- The translation vector
135  const vector& t() const noexcept { return t_; }
136 
137  //- The (forward) rotation tensor
138  const tensor& R() const noexcept { return R_; }
139 
140 
141  // Edit
142 
143  //- Non-const access to the translation vector
144  vector& t() noexcept { return t_; }
145 
146  //- Non-const access to the rotation tensor. Sets hasR = true
147  inline tensor& R() noexcept;
148 
149  //- Test for identity rotation and set hasR accordingly
150  void checkRotation(const scalar tol = ROOTVSMALL);
151 
152 
153  // Transform
154 
155  //- Transform the given position
156  inline vector transformPosition(const vector& v) const;
157 
158  //- Transform the given field of points
159  inline pointField transformPosition(const pointField& pts) const;
161  //- Inplace transform the given points
162  inline void transformPositionList(UList<point>& pts) const;
163 
164  //- Inverse transform the given position
165  inline vector invTransformPosition(const vector& v) const;
166 
167  //- Inverse transform the given field of points
169 
170  //- Inplace inverse transform the given points
171  inline void invTransformPositionList(UList<point>& pts) const;
172 
173  //- Transform the given field
174  template<class Type>
175  tmp<Field<Type>> transform(const Field<Type>& fld) const;
176 
177  //- Inplace transform the given field
178  template<class Type>
179  void transformList(UList<Type>& fld) const;
180 
181 
182  // Member Operators
183 
184  inline void operator&=(const vectorTensorTransform&);
185 
186  //- Assign translation
187  inline void operator=(const vector&);
188  inline void operator+=(const vector&);
189  inline void operator-=(const vector&);
190 
191  inline void operator=(const tensor&);
192  inline void operator&=(const tensor&);
193 
194 
195  // IOstream Operators
196 
197  friend Istream& operator>>(Istream& is, vectorTensorTransform&);
198 
199  friend Ostream& operator<<(Ostream& os, const vectorTensorTransform&);
200 };
201 
202 
203 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
204 
205 //- Contiguous data for vectorTensorTransform
206 template<> struct is_contiguous<vectorTensorTransform> : std::true_type {};
207 
208 
209 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
210 
211 //- Return the inverse of the given vectorTensorTransform
213 
214 //- Return a string representation of a vectorTensorTransform
216 
217 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
218 
219 inline bool operator==
220 (
221  const vectorTensorTransform& tr1,
222  const vectorTensorTransform& tr2
223 );
224 
225 
226 inline bool operator!=
227 (
228  const vectorTensorTransform& tr1,
229  const vectorTensorTransform& tr2
230 
231 );
232 
233 
234 inline vectorTensorTransform operator+
235 (
236  const vectorTensorTransform& tr,
237  const vector& t
238 );
239 
240 
241 inline vectorTensorTransform operator+
242 (
243  const vector& t,
245 );
246 
247 
248 inline vectorTensorTransform operator-
249 (
250  const vectorTensorTransform& tr,
251  const vector& t
252 );
253 
255 inline vectorTensorTransform operator&
256 (
257  const vectorTensorTransform& tr1,
258  const vectorTensorTransform& tr2
259 );
260 
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 } // End namespace Foam
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 #include "vectorTensorTransformI.H"
269 
270 #ifdef NoRepository
271  #include "vectorTensorTransform.txx"
272 #endif
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
276 #endif
277 
278 // ************************************************************************* //
static const char *const typeName
bool hasR() const noexcept
True if it has a non-identity rotation tensor.
vectorTensorTransform & operator=(const vectorTensorTransform &)=default
Copy assignment.
Vector-tensor class used to perform translations and rotations in 3D space.
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
vector invTransformPosition(const vector &v) const
Inverse transform the given position.
Tensor< scalar > tensor
Definition: symmTensor.H:57
void transformList(UList< Type > &fld) const
Inplace transform the given field.
const vector & t() const noexcept
The translation vector.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
Istream & operator>>(Istream &, directionInfo &)
const tensor & R() const noexcept
The (forward) rotation tensor.
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
Vector< scalar > vector
Definition: vector.H:57
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: scalarImpl.H:255
static const vectorTensorTransform I
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
volScalarField & C
tmp< Field< Type > > transform(const Field< Type > &fld) const
Transform the given field.
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;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
void checkRotation(const scalar tol=ROOTVSMALL)
Test for identity rotation and set hasR accordingly.
A template class to specify that a data type can be considered as being contiguous in memory...
Definition: contiguous.H:70
void transformPositionList(UList< point > &pts) const
Inplace transform the given points.
static const vectorTensorTransform zero
A class for managing temporary objects.
Definition: HashPtrTable.H:50
vector transformPosition(const vector &v) const
Transform the given position.
Tensor of scalars, i.e. Tensor<scalar>.
vectorTensorTransform()
Default construct - no translation, identity rotation.
Namespace for OpenFOAM.
void invTransformPositionList(UList< point > &pts) const
Inplace inverse transform the given points.
const pointField & pts