axesRotation.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 | Copyright (C) 2011-2014 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);
37  (
38  coordinateRotation,
39  axesRotation,
40  objectRegistry
41  );
42 }
43 
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 
46 void Foam::axesRotation::calcTransform
47 (
48  const vector& axis1,
49  const vector& axis2,
50  const axisOrder& order
51 )
52 {
53  vector a = axis1/mag(axis1);
54  vector b = axis2;
55 
56  b = b - (b & a)*a;
57 
58  if (mag(b) < SMALL)
59  {
60  FatalErrorIn("axesRotation::calcTransform()")
61  << "axis1, axis2 appear co-linear: "
62  << axis1 << ", " << axis2 << endl
63  << abort(FatalError);
64  }
65 
66  b = b/mag(b);
67  vector c = a^b;
68 
69  tensor Rtr;
70  switch (order)
71  {
72  case e1e2:
73  {
74  Rtr = tensor(a, b, c);
75  break;
76  }
77  case e2e3:
78  {
79  Rtr = tensor(c, a, b);
80  break;
81  }
82  case e3e1:
83  {
84  Rtr = tensor(b, c, a);
85  break;
86  }
87  default:
88  {
90  (
91  "axesRotation::calcTransform"
92  "("
93  "const vector&,"
94  "const vector&,"
95  "const axisOrder&"
96  ")"
97  )
98  << "Unhandled axes specifictation" << endl
99  << abort(FatalError);
100 
101  Rtr = tensor::zero;
102  break;
103  }
104  }
105 
106  // Global->local transformation
107  Rtr_ = Rtr;
108 
109  // Local->global transformation
110  R_ = Rtr.T();
111 }
112 
113 
114 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
115 
117 :
118  R_(sphericalTensor::I),
119  Rtr_(R_)
120 {}
121 
122 
124 (
125  const vector& axis,
126  const vector& dir
127 )
128 :
129  R_(sphericalTensor::I),
130  Rtr_(R_)
131 {
132  calcTransform(axis, dir, e3e1);
133 }
134 
135 
137 (
138  const dictionary& dict
139 )
140 :
141  R_(sphericalTensor::I),
142  Rtr_(R_)
143 {
144  operator=(dict);
145 }
146 
147 
149 (
150  const dictionary& dict,
151  const objectRegistry& obr
152 )
153 :
154  R_(sphericalTensor::I),
155  Rtr_(R_)
156 {
157  operator=(dict);
158 }
159 
160 
162 :
163  R_(R),
164  Rtr_(R_.T())
165 {}
166 
167 
168 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
169 
171 {
173  (
174  "const Foam::tensorField& axesRotation::Tr() const"
175  );
176  return NullObjectRef<tensorField>();
177 }
178 
179 
181 (
182  const vectorField& st
183 ) const
184 {
185  return (R_ & st);
186 }
187 
188 
190 {
191  return (R_ & st);
192 }
193 
194 
196 (
197  const vectorField& st
198 ) const
199 {
200  return (Rtr_ & st);
201 }
202 
203 
205 {
206  return (Rtr_ & st);
207 }
208 
209 
211 (
212  const tensorField& st
213 ) const
214 {
216  (
217  "const tensorField& axesRotation::transformTensor() const"
218  );
219  return tmp<tensorField>(NULL);
220 }
221 
222 
224 (
225  const tensor& st
226 ) const
227 {
228  return (R_ & st & Rtr_);
229 }
230 
231 
233 (
234  const tensorField& st,
235  const labelList& cellMap
236 ) const
237 {
239  (
240  "tmp<Foam::tensorField> axesRotation::transformTensor "
241  "("
242  "const tensorField&,"
243  "const labelList&"
244  ") const"
245  );
246  return tmp<tensorField>(NULL);
247 }
248 
249 
251 (
252  const vectorField& st
253 ) const
254 {
255  tmp<symmTensorField> tfld(new symmTensorField(st.size()));
256  symmTensorField& fld = tfld();
257 
258  forAll(fld, i)
259  {
260  fld[i] = transformPrincipal(R_, st[i]);
261  }
262  return tfld;
263 }
264 
265 
267 (
268  const vector& st
269 ) const
270 {
271  return transformPrincipal(R_, st);
272 }
273 
274 
275 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
276 
278 {
279  if (debug)
280  {
281  Pout<< "axesRotation::operator=(const dictionary&) : "
282  << "assign from " << dict << endl;
283  }
284 
285  vector axis1, axis2;
286  axisOrder order(e3e1);
287 
288  if (dict.readIfPresent("e1", axis1) && dict.readIfPresent("e2", axis2))
289  {
290  order = e1e2;
291  }
292  else if (dict.readIfPresent("e2", axis1)&& dict.readIfPresent("e3", axis2))
293  {
294  order = e2e3;
295  }
296  else if (dict.readIfPresent("e3", axis1)&& dict.readIfPresent("e1", axis2))
297  {
298  order = e3e1;
299  }
300  else if (dict.found("axis") || dict.found("direction"))
301  {
302  // Both "axis" and "direction" are required
303  // If one is missing the appropriate error message will be generated
304  order = e3e1;
305  dict.lookup("axis") >> axis1;
306  dict.lookup("direction") >> axis2;
307  }
308  else
309  {
311  (
312  "axesRotation::operator=(const dictionary&) "
313  ) << "not entry of the type (e1, e2) or (e2, e3) or (e3, e1) "
314  << "found "
315  << exit(FatalError);
316  }
317 
318  calcTransform(axis1, axis2, order);
319 }
320 
321 
323 {
324  os.writeKeyword("e1") << e1() << token::END_STATEMENT << nl;
325  os.writeKeyword("e2") << e2() << token::END_STATEMENT << nl;
326  os.writeKeyword("e3") << e3() << token::END_STATEMENT << nl;
327 }
328 
329 
330 // ************************************************************************* //
void operator=(const dictionary &)
Assign from dictionary.
Definition: axesRotation.C:277
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
virtual const vector e2() const
Return local Cartesian y-axis.
Definition: axesRotation.H:159
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:28
virtual tmp< tensorField > transformTensor(const tensorField &st) const
Transform tensor field using transformation tensorField.
Definition: axesRotation.C:211
dimensioned< scalar > mag(const dimensioned< Type > &)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
virtual tmp< vectorField > transform(const vectorField &st) const
Transform vectorField using transformation tensor field.
Definition: axesRotation.C:181
Tensor< scalar > tensor
Tensor of scalars.
Definition: tensor.H:51
virtual tmp< vectorField > invTransform(const vectorField &st) const
Inverse transform vectorField using transformation tensor field.
Definition: axesRotation.C:196
Templated 3D symmetric tensor derived from VectorSpace adding construction from 6 components...
Definition: SymmTensor.H:53
static const Tensor zero
Definition: Tensor.H:80
virtual const tensorField & Tr() const
Return transformation tensor field.
Definition: axesRotation.C:170
Field< symmTensor > symmTensorField
Specialisation of Field<T> for symmTensor.
static const sphericalTensor I(1)
virtual void write(Ostream &) const
Write.
Definition: axesRotation.C:322
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
virtual tmp< symmTensorField > transformVector(const vectorField &st) const
Transform vectorField using transformation tensorField and return.
Definition: axesRotation.C:251
virtual const tensor & R() const
Return local-to-global transformation tensor.
Definition: axesRotation.H:141
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Templated 3D SphericalTensor derived from VectorSpace adding construction from 1 component, element access using th ii() member function and the inner-product (dot-product) and outer-product operators.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
virtual const vector e3() const
Return local Cartesian z-axis.
Definition: axesRotation.H:165
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual const vector e1() const
Return local Cartesian x-axis.
Definition: axesRotation.H:153
#define forAll(list, i)
Definition: UList.H:421
Macros for easy insertion into run-time selection tables.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
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 ))
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
symmTensor transformPrincipal(const tensor &, const vector &) const
Transform principal.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
Registry of regIOobjects.
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
static const SphericalTensor I
Tensor< Cmpt > T() const
Transpose.
Definition: TensorI.H:286
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
#define notImplemented(functionName)
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:356
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
A class for managing temporary objects.
Definition: PtrList.H:118
axesRotation()
Construct null.
Definition: axesRotation.C:116
defineTypeNameAndDebug(combustionModel, 0)
prefixOSstream Pout(cout,"Pout")
Definition: IOstreams.H:53