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-2024 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"
28 #include "polyMesh.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
38 }
39 
40 
41 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
42 
44 {
45  vector dir = p - origin_;
46  dir /= mag(dir) + vSmall;
47 
48  const vector axis = axis_/mag(axis_);
49  const vector r = dir - (dir & axis)*axis;
50 
51  if (mag(r) < small)
52  {
53  // If the point is on the axis choose any radial direction
54  return axesRotation(axis, perpendicular(axis)).R();
55  }
56 
57  return axesRotation(axis, dir).R();
58 }
59 
60 
61 void Foam::cylindrical::init(const UList<vector>& points)
62 {
63  Rptr_.reset(new tensorField(points.size()));
64  tensorField& R = Rptr_();
65 
66  forAll(points, i)
67  {
68  R[i] = this->R(points[i]);
69  }
70 }
71 
72 
73 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
74 
76 (
77  const vector& axis,
78  const point& origin,
79  const UList<vector>& points
80 )
81 :
82  Rptr_(),
83  origin_(origin),
84  axis_(axis)
85 {
86  init(points);
87 }
88 
89 
91 :
92  Rptr_(),
93  origin_
94  (
95  dict.parent().found("origin")
96  ? dict.parent().lookup("origin")
97  : dict.lookup("origin")
98  ),
99  axis_(dict.lookupBackwardsCompatible<vector>({"axis", "e3"}))
100 {}
101 
102 
104 (
105  const dictionary& dict,
106  const UList<vector>& points
107 )
108 :
110 {
111  init(points);
112 }
113 
114 
115 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
116 
118 {
119  if (Rptr_.valid())
120  {
121  Rptr_().setSize(points.size());
122  }
123  else
124  {
125  Rptr_.reset(new tensorField(points.size()));
126  }
127 
128  tensorField& R = Rptr_();
129 
130  forAll(points, i)
131  {
132  R[i] = this->R(points[i]);
133  }
134 }
135 
136 
138 (
139  const vectorField& vf
140 ) const
141 {
142  if (Rptr_->size() != vf.size())
143  {
145  << "vectorField st has different size to tensorField "
146  << abort(FatalError);
147  }
148 
149  return (Rptr_() & vf);
150 }
151 
152 
154 {
156  return Zero;
157 }
158 
159 
161 (
162  const vector& v,
163  const label cmptI
164 ) const
165 {
166  return (Rptr_()[cmptI] & v);
167 }
168 
169 
171 (
172  const vectorField& vf
173 ) const
174 {
175  if (Rptr_->size() != vf.size())
176  {
178  << "vectorField st has different size to tensorField "
179  << abort(FatalError);
180  }
181 
182  return (Rptr_().T() & vf);
183 }
184 
185 
187 {
189  return Zero;
190 }
191 
192 
194 (
195  const vector& v,
196  const label cmptI
197 ) const
198 {
199  return (Rptr_()[cmptI].T() & v);
200 }
201 
202 
204 (
205  const tensorField& tf
206 ) const
207 {
208  if (Rptr_->size() != tf.size())
209  {
211  << "tensorField st has different size to tensorField Tr"
212  << abort(FatalError);
213  }
214  return (Rptr_() & tf & Rptr_().T());
215 }
216 
217 
219 (
220  const vector& p,
221  const tensor& t
222 ) const
223 {
224  const tensor R(this->R(p));
225  return (R & t & R.T());
226 }
227 
228 
230 (
231  const vectorField& vf
232 ) const
233 {
234  if (Rptr_->size() != vf.size())
235  {
237  << "tensorField vf has different size to tensorField Tr"
238  << abort(FatalError);
239  }
240 
241  tmp<symmTensorField> tfld(new symmTensorField(Rptr_->size()));
242  symmTensorField& fld = tfld.ref();
243 
244  const tensorField& R = Rptr_();
245  forAll(fld, i)
246  {
247  fld[i] = transformVectorDiagTensor(R[i], vf[i]);
248  }
249  return tfld;
250 }
251 
252 
254 (
255  const vector& p,
256  const vector& v
257 ) const
258 {
259  return transformVectorDiagTensor(R(p), v);
260 }
261 
262 
264 {
265  writeEntry(os, "axis", axis());
266 }
267 
268 
269 // ************************************************************************* //
bool found
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
Abstract base class for coordinate rotation.
A local coordinate rotation.
Definition: cylindrical.H:68
virtual void write(Ostream &) const
Write.
Definition: cylindrical.C:263
virtual void updatePoints(const UList< vector > &points)
Update the rotation for a list of points.
Definition: cylindrical.C:117
virtual const tensor & R() const
Return local-to-global transformation tensor.
Definition: cylindrical.H:130
virtual vector transform(const vector &v) const
Transform vector using transformation tensor.
Definition: cylindrical.C:153
virtual const vector axis() const
Return local Cartesian z-axis in global coordinates.
Definition: cylindrical.H:157
virtual symmTensor transformDiagTensor(const vector &p, const vector &v) const
Transform diagTensor masquerading as a vector using transformation.
Definition: cylindrical.C:254
cylindrical(const vector &axis, const point &origin, const UList< vector > &points)
Construct from components for list of points.
Definition: cylindrical.C:76
virtual vector invTransform(const vector &v) const
Inverse transform vector using transformation tensor.
Definition: cylindrical.C:186
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const tensorField & tf
const pointField & points
gmvFile<< "tracers "<< particles.size()<< nl;{ pointField positions(particles.size());label particlei=0;forAllConstIter(Cloud< passiveParticle >, particles, iter) { positions[particlei++]=iter().position(mesh);} for(i=0;i< pTraits< point >::nComponents;i++) { forAll(positions, particlei) { gmvFile<< component(positions[particlei], i)<< ' ';} gmvFile<< nl;}}forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
static const zero Zero
Definition: zero.H:97
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
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
dimensioned< scalar > mag(const dimensioned< Type > &)
defineTypeNameAndDebug(combustionModel, 0)
static scalar R(const scalar a, const scalar x)
Definition: invIncGamma.C:102
Field< symmTensor > symmTensorField
Specialisation of Field<T> for symmTensor.
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
error FatalError
dimensionSet perpendicular(const dimensionSet &)
Definition: dimensionSet.C:516
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
dictionary dict
volScalarField & p