cylindrical.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-2019 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 
55 {
56  const vector e3 = e3_/mag(e3_);
57  const vector r = dir - (dir & e3)*e3;
58 
59  if (mag(r) < small)
60  {
61  // If the cell centre is on the axis choose any radial direction
62  return axesRotation(e3, perpendicular(e3)).R();
63  }
64  else
65  {
66  return axesRotation(e3, dir).R();
67  }
68 }
69 
70 
71 void Foam::cylindrical::init
72 (
73  const objectRegistry& obr,
74  const List<label>& cells
75 )
76 {
77  const polyMesh& mesh = refCast<const polyMesh>(obr);
78 
79  Rptr_.reset(new tensorField(cells.size()));
80 
81  updateCells(mesh, cells);
82 }
83 
84 
85 void Foam::cylindrical::init(const objectRegistry& obr)
86 {
87  const polyMesh& mesh = refCast<const polyMesh>(obr);
88 
89  Rptr_.reset(new tensorField(mesh.nCells()));
90 
91  const vectorField& cc = mesh.cellCentres();
92 
93  tensorField& R = Rptr_();
94  forAll(cc, celli)
95  {
96  vector dir = cc[celli] - origin_;
97  dir /= mag(dir) + vSmall;
98 
99  R[celli] = this->R(dir);
100  }
101 }
102 
103 
104 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
105 
107 (
108  const dictionary& dict,
109  const objectRegistry& obr
110 )
111 :
112  Rptr_(),
113  origin_(point::zero),
114  e3_(Zero)
115 {
116  // If origin is specified in the coordinateSystem
117  if (dict.parent().found("origin"))
118  {
119  dict.parent().lookup("origin") >> origin_;
120  }
121 
122  // rotation axis
123  dict.lookup("e3") >> e3_;
124 
125  init(obr);
126 }
127 
128 
130 (
131  const objectRegistry& obr,
132  const vector& axis,
133  const point& origin
134 )
135 :
136  Rptr_(),
137  origin_(origin),
138  e3_(axis)
139 {
140  init(obr);
141 }
142 
143 
145 (
146  const objectRegistry& obr,
147  const vector& axis,
148  const point& origin,
149  const List<label>& cells
150 )
151 :
152  Rptr_(),
153  origin_(origin),
154  e3_(axis)
155 {
156  init(obr, cells);
157 }
158 
159 
161 :
162  Rptr_(),
163  origin_(),
164  e3_()
165 {
167  << " cylindrical can not be constructed from dictionary "
168  << " use the construtctor : "
169  "("
170  " const dictionary&, const objectRegistry&"
171  ")"
172  << exit(FatalIOError);
173 }
174 
175 
177 :
178  Rptr_(),
179  origin_(Zero),
180  e3_(Zero)
181 {
182  Rptr_() = R;
183 }
184 
185 
186 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
187 
189 {
190  if (!Rptr_.empty())
191  {
192  Rptr_.clear();
193  }
194 }
195 
196 
198 (
199  const polyMesh& mesh,
200  const labelList& cells
201 )
202 {
203  const vectorField& cc = mesh.cellCentres();
204  tensorField& R = Rptr_();
205 
206  forAll(cells, i)
207  {
208  label celli = cells[i];
209  vector dir = cc[celli] - origin_;
210  dir /= mag(dir) + vSmall;
211 
212  R[i] = this->R(dir);
213  }
214 }
215 
216 
218 (
219  const vectorField& vf
220 ) const
221 {
222  if (Rptr_->size() != vf.size())
223  {
225  << "vectorField st has different size to tensorField "
226  << abort(FatalError);
227  }
228 
229  return (Rptr_() & vf);
230 }
231 
232 
234 {
236  return Zero;
237 }
238 
239 
241 (
242  const vector& v,
243  const label cmptI
244 ) const
245 {
246  return (Rptr_()[cmptI] & v);
247 }
248 
249 
251 (
252  const vectorField& vf
253 ) const
254 {
255  return (Rptr_().T() & vf);
256 }
257 
258 
260 {
262  return Zero;
263 }
264 
265 
267 (
268  const vector& v,
269  const label cmptI
270 ) const
271 {
272  return (Rptr_()[cmptI].T() & v);
273 }
274 
275 
277 (
278  const tensorField& tf
279 ) const
280 {
281  if (Rptr_->size() != tf.size())
282  {
284  << "tensorField st has different size to tensorField Tr"
285  << abort(FatalError);
286  }
287  return (Rptr_() & tf & Rptr_().T());
288 }
289 
290 
292 (
293  const tensor& t
294 ) const
295 {
297 
298  return Zero;
299 }
300 
301 
303 (
304  const tensorField& tf,
305  const labelList& cellMap
306 ) const
307 {
308  if (cellMap.size() != tf.size())
309  {
311  << "tensorField tf has different size to tensorField Tr"
312  << abort(FatalError);
313  }
314 
315  const tensorField& R = Rptr_();
316  const tensorField Rtr(R.T());
317  tmp<tensorField> tt(new tensorField(cellMap.size()));
318  tensorField& t = tt.ref();
319  forAll(cellMap, i)
320  {
321  t[i] = R[i] & tf[i] & Rtr[i];
322  }
323 
324  return tt;
325 }
326 
327 
329 (
330  const vectorField& vf
331 ) const
332 {
333  if (Rptr_->size() != vf.size())
334  {
336  << "tensorField vf has different size to tensorField Tr"
337  << abort(FatalError);
338  }
339 
340  tmp<symmTensorField> tfld(new symmTensorField(Rptr_->size()));
341  symmTensorField& fld = tfld.ref();
342 
343  const tensorField& R = Rptr_();
344  forAll(fld, i)
345  {
346  fld[i] = transformPrincipal(R[i], vf[i]);
347  }
348  return tfld;
349 }
350 
351 
353 (
354  const vector& v
355 ) const
356 {
358  return Zero;
359 }
360 
361 
363 {
364  writeEntry(os, "e3", e3());
365 }
366 
367 
368 // ************************************************************************* //
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:438
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
symmTensor transformPrincipal(const tensor &, const vector &) const
Transform principal.
virtual tmp< tensorField > transformTensor(const tensorField &tf) const
Transform tensor field using transformation tensorField.
Definition: cylindrical.C:277
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.
virtual const tensor & Rtr() const
Return global-to-local transformation tensor.
Definition: cylindrical.H:159
virtual tmp< vectorField > invTransform(const vectorField &vf) const
Inverse transform vectorField using transformation tensor field.
Definition: cylindrical.C:251
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:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
Macros for easy insertion into run-time selection tables.
virtual const tensor & R() const
Return local-to-global transformation tensor.
Definition: cylindrical.H:152
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))
const dictionary & parent() const
Return the parent dictionary.
Definition: dictionary.H:282
virtual const vector e3() const
Return local Cartesian z-axis in global coordinates.
Definition: cylindrical.H:180
cylindrical(const dictionary &, const objectRegistry &)
Construct from dictionary and objectRegistry.
Definition: cylindrical.C:107
static const zero Zero
Definition: zero.H:97
virtual tmp< vectorField > transform(const vectorField &tf) const
Transform vectorField using transformation tensor field.
Definition: cylindrical.C:218
virtual void write(Ostream &) const
Write.
Definition: cylindrical.C:362
const vectorField & cellCentres() const
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void reset(const label nPoints, const label nInternalFaces, const label nFaces, const label nCells)
Reset this primitiveMesh given the primitive array sizes.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
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
Vector< Cmpt > perpendicular(const Vector< Cmpt > &v)
Definition: VectorI.H:166
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:198
#define R(A, B, C, D, E, F, K, M)
virtual void clear()
Reset rotation to an identity rotation.
Definition: cylindrical.C:188
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: Field.C:520
dimensioned< scalar > mag(const dimensioned< Type > &)
Field< vector > vectorField
Specialisation of Field<T> for vector.
virtual tmp< symmTensorField > transformVector(const vectorField &vf) const
Transform vectorField using transformation tensorField and return.
Definition: cylindrical.C:329
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A class for managing temporary objects.
Definition: PtrList.H:53
Registry of regIOobjects.
Templated 3D tensor derived from MatrixSpace adding construction from 9 components, element access using xx(), xy() etc. member functions and the inner-product (dot-product) and outer-product of two Vectors (tensor-product) operators.
Definition: complexI.H:215
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:366
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:583
IOerror FatalIOError