axesRotation.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "axesRotation.H"
27 #include "dictionary.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(axesRotation, 0);
35  addToRunTimeSelectionTable(coordinateRotation, axesRotation, dictionary);
36  addToRunTimeSelectionTable(coordinateRotation, axesRotation, points);
37 }
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 void Foam::axesRotation::calcTransform
42 (
43  const vector& axis1,
44  const vector& axis2,
45  const axisOrder& order
46 )
47 {
48  vector a = axis1/mag(axis1);
49  vector b = axis2;
50 
51  b = b - (b & a)*a;
52 
53  if (mag(b) < small)
54  {
56  << "axis1, axis2 appear co-linear: "
57  << axis1 << ", " << axis2 << endl
58  << abort(FatalError);
59  }
60 
61  b = b/mag(b);
62  vector c = a^b;
63 
64  tensor Rtr;
65  switch (order)
66  {
67  case e1e2:
68  {
69  Rtr = tensor(a, b, c);
70  break;
71  }
72  case e2e3:
73  {
74  Rtr = tensor(c, a, b);
75  break;
76  }
77  case e3e1:
78  {
79  Rtr = tensor(b, c, a);
80  break;
81  }
82  default:
83  {
85  << "Unhandled axes specification" << endl
86  << abort(FatalError);
87 
88  Rtr = Zero;
89  break;
90  }
91  }
92 
93  // Global->local transformation
94  Rtr_ = Rtr;
95 
96  // Local->global transformation
97  R_ = Rtr.T();
98 }
99 
100 
101 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
102 
104 (
105  const vector& axis,
106  const vector& dir
107 )
108 :
109  R_(sphericalTensor::I),
110  Rtr_(R_)
111 {
112  calcTransform(axis, dir, e3e1);
113 }
114 
115 
117 :
118  R_(R),
119  Rtr_(R_.T())
120 {}
121 
122 
124 (
125  const dictionary& dict
126 )
127 :
128  R_(sphericalTensor::I),
129  Rtr_(R_)
130 {
131  operator=(dict);
132 }
133 
134 
136 (
137  const dictionary& dict,
138  const UList<vector>& points
139 )
140 :
141  axesRotation(dict)
142 {}
143 
144 
145 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
146 
148 (
149  const vectorField& st
150 ) const
151 {
152  return (R_ & st);
153 }
154 
155 
157 {
158  return (R_ & st);
159 }
160 
161 
163 (
164  const vectorField& st
165 ) const
166 {
167  return (Rtr_ & st);
168 }
169 
170 
172 {
173  return (Rtr_ & st);
174 }
175 
176 
178 (
179  const tensorField& st
180 ) const
181 {
183  return tmp<tensorField>(nullptr);
184 }
185 
186 
188 (
189  const tensor& st
190 ) const
191 {
192  return (R_ & st & Rtr_);
193 }
194 
195 
197 (
198  const vectorField& st
199 ) const
200 {
201  tmp<symmTensorField> tfld(new symmTensorField(st.size()));
202  symmTensorField& fld = tfld.ref();
203 
204  forAll(fld, i)
205  {
206  fld[i] = transformPrincipal(R_, st[i]);
207  }
208  return tfld;
209 }
210 
211 
213 (
214  const vector& st
215 ) const
216 {
217  return transformPrincipal(R_, st);
218 }
219 
220 
222 {
223  writeEntry(os, "e1", e1());
224  writeEntry(os, "e2", e2());
225  writeEntry(os, "e3", e3());
226 }
227 
228 
229 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
230 
232 {
233  if (debug)
234  {
235  Pout<< "axesRotation::operator=(const dictionary&) : "
236  << "assign from " << dict << endl;
237  }
238 
239  vector axis1, axis2;
240  axisOrder order(e3e1);
241 
242  if (dict.readIfPresent("e1", axis1) && dict.readIfPresent("e2", axis2))
243  {
244  order = e1e2;
245  }
246  else if (dict.readIfPresent("e2", axis1)&& dict.readIfPresent("e3", axis2))
247  {
248  order = e2e3;
249  }
250  else if (dict.readIfPresent("e3", axis1)&& dict.readIfPresent("e1", axis2))
251  {
252  order = e3e1;
253  }
254  else if (dict.found("axis") || dict.found("direction"))
255  {
256  // Both "axis" and "direction" are required
257  // If one is missing the appropriate error message will be generated
258  order = e3e1;
259  dict.lookup("axis") >> axis1;
260  dict.lookup("direction") >> axis2;
261  }
262  else
263  {
265  << "not entry of the type (e1, e2) or (e2, e3) or (e3, e1) "
266  << "found "
267  << exit(FatalError);
268  }
269 
270  calcTransform(axis1, axis2, order);
271 }
272 
273 
274 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:643
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
symmTensor transformPrincipal(const tensor &, const vector &) const
Transform principal.
Field< symmTensor > symmTensorField
Specialisation of Field<T> for symmTensor.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
const dimensionedScalar b
Wien displacement law constant: default SI units: [m K].
Definition: createFields.H:27
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual const vector e2() const
Return local Cartesian y-axis in global coordinates.
Definition: axesRotation.H:145
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
virtual tmp< vectorField > invTransform(const vectorField &st) const
Inverse transform vectorField using transformation tensor field.
Definition: axesRotation.C:163
virtual tmp< symmTensorField > transformVector(const vectorField &st) const
Transform vectorField using transformation tensorField and return.
Definition: axesRotation.C:197
Macros for easy insertion into run-time selection tables.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
virtual const vector e3() const
Return local Cartesian z-axis in global coordinates.
Definition: axesRotation.H:151
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
static const zero Zero
Definition: zero.H:97
errorManip< error > abort(error &err)
Definition: errorManip.H:131
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:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual tmp< vectorField > transform(const vectorField &st) const
Transform vectorField using transformation tensor field.
Definition: axesRotation.C:148
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
virtual const vector e1() const
Return local Cartesian x-axis in global coordinates.
Definition: axesRotation.H:139
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
void operator=(const dictionary &)
Assign from dictionary.
Definition: axesRotation.C:231
#define R(A, B, C, D, E, F, K, M)
virtual void write(Ostream &) const
Write.
Definition: axesRotation.C:221
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
dimensioned< scalar > mag(const dimensioned< Type > &)
axesRotation(const vector &axis, const vector &dir)
Construct from 2 axes.
Definition: axesRotation.C:104
A class for managing temporary objects.
Definition: PtrList.H:53
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:370
virtual tmp< tensorField > transformTensor(const tensorField &st) const
Transform tensor field using transformation tensorField.
Definition: axesRotation.C:178
Tensor< scalar > tensor
Tensor of scalars.
Definition: tensor.H:51
Namespace for OpenFOAM.
static const SphericalTensor I
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844