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-2015 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 
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  {
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  << "Unhandled axes specifictation" << endl
91  << abort(FatalError);
92 
93  Rtr = tensor::zero;
94  break;
95  }
96  }
97 
98  // Global->local transformation
99  Rtr_ = Rtr;
100 
101  // Local->global transformation
102  R_ = Rtr.T();
103 }
104 
105 
106 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
107 
109 :
110  R_(sphericalTensor::I),
111  Rtr_(R_)
112 {}
113 
114 
116 (
117  const vector& axis,
118  const vector& dir
119 )
120 :
121  R_(sphericalTensor::I),
122  Rtr_(R_)
123 {
124  calcTransform(axis, dir, e3e1);
125 }
126 
127 
129 (
130  const dictionary& dict
131 )
132 :
133  R_(sphericalTensor::I),
134  Rtr_(R_)
135 {
136  operator=(dict);
137 }
138 
139 
141 (
142  const dictionary& dict,
143  const objectRegistry& obr
144 )
145 :
146  R_(sphericalTensor::I),
147  Rtr_(R_)
148 {
149  operator=(dict);
150 }
151 
152 
154 :
155  R_(R),
156  Rtr_(R_.T())
157 {}
158 
159 
161 :
162  R_(r.R_),
163  Rtr_(r.Rtr_)
164 {}
165 
166 
167 
168 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
169 
171 {
173  return NullObjectRef<tensorField>();
174 }
175 
176 
178 (
179  const vectorField& st
180 ) const
181 {
182  return (R_ & st);
183 }
184 
185 
187 {
188  return (R_ & st);
189 }
190 
191 
193 (
194  const vectorField& st
195 ) const
196 {
197  return (Rtr_ & st);
198 }
199 
200 
202 {
203  return (Rtr_ & st);
204 }
205 
206 
208 (
209  const tensorField& st
210 ) const
211 {
213  return tmp<tensorField>(NULL);
214 }
215 
216 
218 (
219  const tensor& st
220 ) const
221 {
222  return (R_ & st & Rtr_);
223 }
224 
225 
227 (
228  const tensorField& st,
229  const labelList& cellMap
230 ) const
231 {
233  return tmp<tensorField>(NULL);
234 }
235 
236 
238 (
239  const vectorField& st
240 ) const
241 {
242  tmp<symmTensorField> tfld(new symmTensorField(st.size()));
243  symmTensorField& fld = tfld();
244 
245  forAll(fld, i)
246  {
247  fld[i] = transformPrincipal(R_, st[i]);
248  }
249  return tfld;
250 }
251 
252 
254 (
255  const vector& st
256 ) const
257 {
258  return transformPrincipal(R_, st);
259 }
260 
261 
262 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
263 
265 {
266  if (debug)
267  {
268  Pout<< "axesRotation::operator=(const dictionary&) : "
269  << "assign from " << dict << endl;
270  }
271 
272  vector axis1, axis2;
273  axisOrder order(e3e1);
274 
275  if (dict.readIfPresent("e1", axis1) && dict.readIfPresent("e2", axis2))
276  {
277  order = e1e2;
278  }
279  else if (dict.readIfPresent("e2", axis1)&& dict.readIfPresent("e3", axis2))
280  {
281  order = e2e3;
282  }
283  else if (dict.readIfPresent("e3", axis1)&& dict.readIfPresent("e1", axis2))
284  {
285  order = e3e1;
286  }
287  else if (dict.found("axis") || dict.found("direction"))
288  {
289  // Both "axis" and "direction" are required
290  // If one is missing the appropriate error message will be generated
291  order = e3e1;
292  dict.lookup("axis") >> axis1;
293  dict.lookup("direction") >> axis2;
294  }
295  else
296  {
298  << "not entry of the type (e1, e2) or (e2, e3) or (e3, e1) "
299  << "found "
300  << exit(FatalError);
301  }
302 
303  calcTransform(axis1, axis2, order);
304 }
305 
306 
308 {
309  os.writeKeyword("e1") << e1() << token::END_STATEMENT << nl;
310  os.writeKeyword("e2") << e2() << token::END_STATEMENT << nl;
311  os.writeKeyword("e3") << e3() << token::END_STATEMENT << nl;
312 }
313 
314 
315 // ************************************************************************* //
Foam::axesRotation::write
virtual void write(Ostream &) const
Write.
Definition: axesRotation.C:307
Foam::Tensor
Templated 3D tensor derived from VectorSpace adding construction from 9 components,...
Definition: complexI.H:224
Foam::token::END_STATEMENT
@ END_STATEMENT
Definition: token.H:99
Foam::SymmTensor< scalar >
Foam::axesRotation::invTransform
virtual tmp< vectorField > invTransform(const vectorField &st) const
Inverse transform vectorField using transformation tensor field.
Definition: axesRotation.C:193
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::dictionary::readIfPresent
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Definition: dictionaryTemplates.C:94
Foam::axesRotation
A coordinate rotation specified using global axis.
Definition: axesRotation.H:60
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::tensor
Tensor< scalar > tensor
Tensor of scalars.
Definition: tensor.H:51
Foam::axesRotation::axesRotation
axesRotation()
Construct null.
Definition: axesRotation.C:108
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::axesRotation::transformVector
virtual tmp< symmTensorField > transformVector(const vectorField &st) const
Transform vectorField using transformation tensorField and return.
Definition: axesRotation.C:238
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::symmTensorField
Field< symmTensor > symmTensorField
Specialisation of Field<T> for symmTensor.
Definition: primitiveFieldsFwd.H:51
Foam::axesRotation::calcTransform
void calcTransform(const vector &axis1, const vector &axis2, const axisOrder &order=e3e1)
Calculate transformation tensor.
Definition: axesRotation.C:47
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:365
R
#define R(A, B, C, D, E, F, K, M)
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:28
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:55
Foam::I
static const sphericalTensor I(1)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::axesRotation::Tr
virtual const tensorField & Tr() const
Return transformation tensor field.
Definition: axesRotation.C:170
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
fld
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))
Foam::axesRotation::operator=
void operator=(const dictionary &)
Assign from dictionary.
Definition: axesRotation.C:264
Foam::axesRotation::axisOrder
axisOrder
The combination of local axes to be used.
Definition: axesRotation.H:73
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::SphericalTensor
Templated 3D SphericalTensor derived from VectorSpace adding construction from 1 component,...
Definition: SphericalTensor.H:51
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::Ostream::writeKeyword
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
dictionary.H
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::axesRotation::transform
virtual tmp< vectorField > transform(const vectorField &st) const
Transform vectorField using transformation tensor field.
Definition: axesRotation.C:178
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
axesRotation.H
Foam::SphericalTensor::I
static const SphericalTensor I
Definition: SphericalTensor.H:78
Foam::axesRotation::transformTensor
virtual tmp< tensorField > transformTensor(const tensorField &st) const
Transform tensor field using transformation tensorField.
Definition: axesRotation.C:208
Foam::Tensor::T
Tensor< Cmpt > T() const
Transpose.
Definition: TensorI.H:286