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-2016 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_(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 {
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_(Zero),
169  e3_(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  << "vectorField st has different size to tensorField "
215  << abort(FatalError);
216  }
217 
218  return (Rptr_() & vf);
219 }
220 
221 
223 {
225  return Zero;
226 }
227 
228 
230 (
231  const vector& v,
232  const label cmptI
233 ) const
234 {
235  return (Rptr_()[cmptI] & v);
236 }
237 
238 
240 (
241  const vectorField& vf
242 ) const
243 {
244  return (Rptr_().T() & vf);
245 }
246 
247 
249 {
251  return Zero;
252 }
253 
254 
256 (
257  const vector& v,
258  const label cmptI
259 ) const
260 {
261  return (Rptr_()[cmptI].T() & v);
262 }
263 
264 
266 (
267  const tensorField& tf
268 ) const
269 {
270  if (Rptr_->size() != tf.size())
271  {
273  << "tensorField st has different size to tensorField Tr"
274  << abort(FatalError);
275  }
276  return (Rptr_() & tf & Rptr_().T());
277 }
278 
279 
281 (
282  const tensor& t
283 ) const
284 {
286 
287  return Zero;
288 }
289 
290 
292 (
293  const tensorField& tf,
294  const labelList& cellMap
295 ) const
296 {
297  if (cellMap.size() != tf.size())
298  {
300  << "tensorField tf has different size to tensorField Tr"
301  << abort(FatalError);
302  }
303 
304  const tensorField& R = Rptr_();
305  const tensorField Rtr(R.T());
306  tmp<tensorField> tt(new tensorField(cellMap.size()));
307  tensorField& t = tt.ref();
308  forAll(cellMap, i)
309  {
310  const label celli = cellMap[i];
311  t[i] = R[celli] & tf[i] & Rtr[celli];
312  }
313 
314  return tt;
315 }
316 
317 
319 (
320  const vectorField& vf
321 ) const
322 {
323  if (Rptr_->size() != vf.size())
324  {
326  << "tensorField vf has different size to tensorField Tr"
327  << abort(FatalError);
328  }
329 
330  tmp<symmTensorField> tfld(new symmTensorField(Rptr_->size()));
331  symmTensorField& fld = tfld.ref();
332 
333  const tensorField& R = Rptr_();
334  forAll(fld, i)
335  {
336  fld[i] = transformPrincipal(R[i], vf[i]);
337  }
338  return tfld;
339 }
340 
341 
343 (
344  const vector& v
345 ) const
346 {
348  return Zero;
349 }
350 
351 
353 {
354  os.writeKeyword("e3") << e3() << token::END_STATEMENT << nl;
355 }
356 
357 
358 // ************************************************************************* //
virtual const tensor & R() const
Return local-to-global transformation tensor.
Definition: cylindrical.H:145
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
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:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
virtual const vector e3() const
Return local Cartesian z-axis in global coordinates.
Definition: cylindrical.H:173
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
virtual void write(Ostream &) const
Write.
Definition: cylindrical.C:352
Macros for easy insertion into run-time selection tables.
virtual tmp< vectorField > transform(const vectorField &tf) const
Transform vectorField using transformation tensor field.
Definition: cylindrical.C:207
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 tensor & Rtr() const
Return global-to-local transformation tensor.
Definition: cylindrical.H:152
cylindrical(const dictionary &, const objectRegistry &)
Construct from dictionary and objectRegistry.
Definition: cylindrical.C:96
virtual tmp< vectorField > invTransform(const vectorField &vf) const
Inverse transform vectorField using transformation tensor field.
Definition: cylindrical.C:240
virtual tmp< tensorField > transformTensor(const tensorField &tf) const
Transform tensor field using transformation tensorField.
Definition: cylindrical.C:266
const vectorField & cellCentres() const
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
static const zero Zero
Definition: zero.H:91
errorManip< error > abort(error &err)
Definition: errorManip.H:131
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: Field.C:710
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
static const char nl
Definition: Ostream.H:262
defineTypeNameAndDebug(combustionModel, 0)
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:54
virtual const tensor & R() const
Return local-to-global transformation tensor.
Definition: axesRotation.H:145
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
symmTensor transformPrincipal(const tensor &, const vector &) const
Transform principal.
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
virtual void updateCells(const polyMesh &mesh, const labelList &cells)
Update the rotation for a list of cells.
Definition: cylindrical.C:187
virtual void clear()
Reset rotation to an identity rotation.
Definition: cylindrical.C:177
dimensioned< scalar > mag(const dimensioned< Type > &)
const dictionary & parent() const
Return the parent dictionary.
Definition: dictionary.H:251
Field< vector > vectorField
Specialisation of Field<T> for vector.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A coordinate rotation specified using global axis.
Definition: axesRotation.H:64
A class for managing temporary objects.
Definition: PtrList.H:54
Registry of regIOobjects.
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:366
Namespace for OpenFOAM.
virtual tmp< symmTensorField > transformVector(const vectorField &vf) const
Transform vectorField using transformation tensorField and return.
Definition: cylindrical.C:319
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451
IOerror FatalIOError