cylindrical.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 "cylindrical.H"
27 #include "axesRotation.H"
29 #include "polyMesh.H"
30 #include "tensorIOField.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(cylindrical, 0);
38  (
39  coordinateRotation,
40  cylindrical,
41  dictionary
42  );
44  (
45  coordinateRotation,
46  cylindrical,
47  objectRegistry
48  );
49 }
50 
51 
52 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
53 
54 void Foam::cylindrical::init
55 (
56  const objectRegistry& obr,
57  const List<label>& cells
58 )
59 {
60  const polyMesh& mesh = refCast<const polyMesh>(obr);
61  const vectorField& cc = mesh.cellCentres();
62 
63  if (cells.size())
64  {
65  Rptr_.reset(new tensorField(cells.size()));
66 
67  tensorField& R = Rptr_();
68  forAll(cells, i)
69  {
70  label cellI = cells[i];
71  vector dir = cc[cellI] - origin_;
72  dir /= mag(dir) + VSMALL;
73 
74  R[i] = axesRotation(e3_, dir).R();
75  }
76  }
77  else
78  {
79  Rptr_.reset(new tensorField(mesh.nCells()));
80 
81  tensorField& R = Rptr_();
82  forAll(cc, cellI)
83  {
84  vector dir = cc[cellI] - origin_;
85  dir /= mag(dir) + VSMALL;
86 
87  R[cellI] = axesRotation(e3_, dir).R();
88  }
89  }
90 }
91 
92 
93 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
94 
96 (
97  const dictionary& dict,
98  const objectRegistry& obr
99 )
100 :
101  Rptr_(),
102  origin_(point::zero),
103  e3_(vector::zero)
104 {
105  // If origin is specified in the coordinateSystem
106  if (dict.parent().found("origin"))
107  {
108  dict.parent().lookup("origin") >> origin_;
109  }
110 
111  // rotation axis
112  dict.lookup("e3") >> e3_;
113 
114  init(obr);
115 }
116 
117 
119 (
120  const objectRegistry& obr,
121  const vector& axis,
122  const point& origin
123 )
124 :
125  Rptr_(),
126  origin_(origin),
127  e3_(axis)
128 {
129  init(obr);
130 }
131 
132 
134 (
135  const objectRegistry& obr,
136  const vector& axis,
137  const point& origin,
138  const List<label>& cells
139 )
140 :
141  Rptr_(),
142  origin_(origin),
143  e3_(axis)
144 {
145  init(obr, cells);
146 }
147 
148 
150 :
151  Rptr_(),
152  origin_(),
153  e3_()
154 {
155  FatalErrorIn("cylindrical(const dictionary&)")
156  << " cylindrical can not be constructed from dictionary "
157  << " use the construtctor : "
158  "("
159  " const dictionary&, const objectRegistry&"
160  ")"
161  << exit(FatalIOError);
162 }
163 
164 
166 :
167  Rptr_(),
168  origin_(vector::zero),
169  e3_(vector::zero)
170 {
171  Rptr_() = R;
172 }
173 
174 
175 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
176 
178 {
179  if (!Rptr_.empty())
180  {
181  Rptr_.clear();
182  }
183 }
184 
185 
187 (
188  const polyMesh& mesh,
189  const labelList& cells
190 )
191 {
192  const vectorField& cc = mesh.cellCentres();
193  tensorField& R = Rptr_();
194 
195  forAll(cells, i)
196  {
197  label cellI = cells[i];
198  vector dir = cc[cellI] - origin_;
199  dir /= mag(dir) + VSMALL;
200 
201  R[cellI] = axesRotation(e3_, dir).R();
202  }
203 }
204 
205 
207 (
208  const vectorField& vf
209 ) const
210 {
211  if (Rptr_->size() != vf.size())
212  {
214  (
215  "tmp<vectorField> cylindrical::transform(const vectorField&)"
216  )
217  << "vectorField st has different size to tensorField "
218  << abort(FatalError);
219  }
220 
221  return (Rptr_() & vf);
222 }
223 
224 
226 {
228  (
229  "vector cylindrical::transform(const vector&) const"
230  );
231  return vector::zero;
232 }
233 
234 
236 (
237  const vector& v,
238  const label cmptI
239 ) const
240 {
241  return (Rptr_()[cmptI] & v);
242 }
243 
244 
246 (
247  const vectorField& vf
248 ) const
249 {
250  return (Rptr_().T() & vf);
251 }
252 
253 
255 {
257  (
258  "vector cylindrical::invTransform(const vector&) const"
259  );
260  return vector::zero;
261 }
262 
263 
265 (
266  const vector& v,
267  const label cmptI
268 ) const
269 {
270  return (Rptr_()[cmptI].T() & v);
271 }
272 
273 
275 (
276  const tensorField& tf
277 ) const
278 {
279  if (Rptr_->size() != tf.size())
280  {
282  (
283  "tmp<tensorField> cylindrical::transformTensor"
284  "("
285  "const tensorField&"
286  ")"
287  )
288  << "tensorField st has different size to tensorField Tr"
289  << abort(FatalError);
290  }
291  return (Rptr_() & tf & Rptr_().T());
292 }
293 
294 
296 (
297  const tensor& t
298 ) const
299 {
301  (
302  "tensor cylindrical::transformTensor(const tensor&) const"
303  );
304 
305  return tensor::zero;
306 }
307 
308 
310 (
311  const tensorField& tf,
312  const labelList& cellMap
313 ) const
314 {
315  if (cellMap.size() != tf.size())
316  {
318  (
319  "tmp<tensorField> cylindrical::transformTensor"
320  "("
321  "const tensorField&, "
322  "const labelList&"
323  ")"
324  )
325  << "tensorField tf has different size to tensorField Tr"
326  << abort(FatalError);
327  }
328 
329  const tensorField& R = Rptr_();
330  const tensorField Rtr(R.T());
331  tmp<tensorField> tt(new tensorField(cellMap.size()));
332  tensorField& t = tt();
333  forAll(cellMap, i)
334  {
335  const label cellI = cellMap[i];
336  t[i] = R[cellI] & tf[i] & Rtr[cellI];
337  }
338 
339  return tt;
340 }
341 
342 
344 (
345  const vectorField& vf
346 ) const
347 {
348  if (Rptr_->size() != vf.size())
349  {
350  FatalErrorIn("cylindrical::transformVector(const vectorField&)")
351  << "tensorField vf has different size to tensorField Tr"
352  << abort(FatalError);
353  }
354 
355  tmp<symmTensorField> tfld(new symmTensorField(Rptr_->size()));
356  symmTensorField& fld = tfld();
357 
358  const tensorField& R = Rptr_();
359  forAll(fld, i)
360  {
361  fld[i] = transformPrincipal(R[i], vf[i]);
362  }
363  return tfld;
364 }
365 
366 
368 (
369  const vector& v
370 ) const
371 {
373  (
374  "tensor cylindrical::transformVector(const vector&) const"
375  );
376  return symmTensor::zero;
377 }
378 
379 
381 {
382  os.writeKeyword("e3") << e3() << token::END_STATEMENT << nl;
383 }
384 
385 
386 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
virtual tmp< symmTensorField > transformVector(const vectorField &vf) const
Transform vectorField using transformation tensorField and return.
Definition: cylindrical.C:344
dimensioned< scalar > mag(const dimensioned< Type > &)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
virtual const vector e3() const
Return local Cartesian z-axis.
Definition: cylindrical.H:171
Templated 3D symmetric tensor derived from VectorSpace adding construction from 6 components...
Definition: SymmTensor.H:53
static const Tensor zero
Definition: Tensor.H:80
Field< symmTensor > symmTensorField
Specialisation of Field<T> for symmTensor.
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: Field.C:625
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
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
virtual const tensor & Rtr() const
Return global-to-local transformation tensor.
Definition: cylindrical.H:150
const vectorField & cellCentres() const
virtual tmp< vectorField > invTransform(const vectorField &vf) const
Inverse transform vectorField using transformation tensor field.
Definition: cylindrical.C:246
static const SymmTensor zero
Definition: SymmTensor.H:77
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
virtual void clear()
Reset rotation to an identity rotation.
Definition: cylindrical.C:177
A coordinate rotation specified using global axis.
Definition: axesRotation.H:60
static const char nl
Definition: Ostream.H:260
IOerror FatalIOError
Field< vector > vectorField
Specialisation of Field<T> for vector.
#define forAll(list, i)
Definition: UList.H:421
cylindrical(const dictionary &, const objectRegistry &)
Construct from dictionary and objectRegistry.
Definition: cylindrical.C:96
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:47
virtual tmp< vectorField > transform(const vectorField &tf) const
Transform vectorField using transformation tensor field.
Definition: cylindrical.C:207
Macros for easy insertion into run-time selection tables.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
virtual tmp< tensorField > transformTensor(const tensorField &tf) const
Transform tensor field using transformation tensorField.
Definition: cylindrical.C:275
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
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
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.
virtual const tensor & R() const
Return local-to-global transformation tensor.
Definition: cylindrical.H:143
virtual void write(Ostream &) const
Write.
Definition: cylindrical.C:380
static const Vector zero
Definition: Vector.H:80
virtual void updateCells(const polyMesh &mesh, const labelList &cells)
Update the rotation for a list of cells.
Definition: cylindrical.C:187
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
const dictionary & parent() const
Return the parent dictionary.
Definition: dictionary.H:251
#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
defineTypeNameAndDebug(combustionModel, 0)