coordinateSystem.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "coordinateSystem.H"
30 #include "cartesianCS.H"
31 #include "IOstream.H"
32 #include "axesRotation.H"
33 #include "identityRotation.H"
34 #include "transform.H"
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41  defineTypeNameAndDebug(coordinateSystem, 0);
42  defineRunTimeSelectionTable(coordinateSystem, dictionary);
43  defineRunTimeSelectionTable(coordinateSystem, registry);
44 }
45 
47 
48 
49 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53  //- Is it cartesian?
54  // For output, can treat the base class as Cartesian too,
55  // since it defaults to cartesian on input.
56  static inline bool isCartesian(const word& modelType)
57  {
58  return
59  (
60  modelType == coordinateSystem::typeName_()
61  || modelType == coordSystem::cartesian::typeName_()
62  );
63  }
64 
65 } // End namespace Foam
66 
67 
68 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
69 
71 {
72  dict.readEntry("origin", origin_);
73 
74  note_.clear();
75  dict.readIfPresent("note", note_);
76 
77  // Non-recursive, no pattern search for "rotation"
78  // or "coordinateRotation" (older) sub-dictionary.
79  // Don't warn about older naming for now (OCT-2018)
80 
81  const auto finder = dict.csearchCompat
82  (
83  "rotation", {{"coordinateRotation", -1806}},
85  );
86 
87  if (finder.isDict())
88  {
89  spec_ = coordinateRotation::New(finder.dict());
90  }
91  else
92  {
93  // Fall through to expecting e1/e2/e3 specification in the dictionary
95  }
96 
97  rot_ = spec_->R();
98 }
99 
100 
101 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
102 
104 :
105  spec_(),
106  origin_(Zero),
107  rot_(sphericalTensor::I),
108  name_(),
109  note_()
110 {}
111 
112 
114 :
115  spec_(new coordinateRotations::identity()),
116  origin_(Zero),
117  rot_(sphericalTensor::I),
118  name_(),
119  note_()
120 {}
121 
122 
124 :
125  coordinateSystem(word::null, point::zero, crot)
126 {}
127 
128 
130 :
131  coordinateSystem(word::null, point::zero, std::move(crot))
132 {}
133 
134 
136 :
137  spec_(csys.spec_.clone()),
138  origin_(csys.origin_),
139  rot_(csys.rot_),
140  name_(csys.name_),
141  note_(csys.note_)
142 {}
143 
144 
146 :
147  spec_(std::move(csys.spec_)),
148  origin_(std::move(csys.origin_)),
149  rot_(std::move(csys.rot_)),
150  name_(std::move(csys.name_)),
151  note_(std::move(csys.note_))
152 {}
153 
154 
156 :
157  coordinateSystem(nullptr)
158 {
159  if (csys)
160  {
161  // Has valid autoPtr - move.
162  coordinateSystem::operator=(std::move(*csys));
163  csys.clear();
164  }
165  else
166  {
167  // No valid autoPtr - treat like identity
169  }
170 }
171 
172 
174 (
175  const word& name,
176  const coordinateSystem& csys
177 )
178 :
179  spec_(csys.spec_.clone()),
180  origin_(csys.origin_),
181  rot_(csys.rot_),
182  name_(name),
183  note_(csys.note_)
184 {}
185 
186 
188 (
189  const point& origin,
190  const coordinateRotation& crot
191 )
192 :
193  coordinateSystem(word::null, origin, crot)
194 {}
195 
196 
198 (
199  const word& name,
200  const point& origin,
201  const coordinateRotation& crot
202 )
203 :
204  spec_(crot.clone()),
205  origin_(origin),
206  rot_(spec_->R()),
207  name_(name),
208  note_()
209 {}
210 
211 
213 (
214  const point& origin,
215  const vector& axis,
216  const vector& dirn
217 )
218 :
219  coordinateSystem(word::null, origin, axis, dirn)
220 {}
221 
222 
224 (
225  const word& name,
226  const point& origin,
227  const vector& axis,
228  const vector& dirn
229 )
230 :
231  spec_(new coordinateRotations::axes(axis, dirn)),
232  origin_(origin),
233  rot_(spec_->R()),
234  name_(name),
235  note_()
236 {}
237 
238 
240 (
241  const word& name,
242  const dictionary& dict
243 )
244 :
245  spec_(nullptr),
246  origin_(Zero),
247  rot_(sphericalTensor::I),
248  name_(name),
249  note_()
250 {
251  assign(dict);
252 }
253 
254 
256 :
257  coordinateSystem(word::null, dict)
258 {}
259 
260 
262 (
263  const dictionary& dict,
264  const word& dictName
265 )
266 :
267  coordinateSystem(nullptr)
268 {
269  if (dictName.size())
270  {
272  }
273  else
274  {
275  assign(dict);
276  }
277 }
278 
279 
280 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
281 
283 {
284  spec_->clear();
285  origin_ = Zero;
286  rot_ = sphericalTensor::I;
287  note_.clear();
288 }
289 
290 
292 {
293  return rot_;
294 }
295 
296 
298 (
299  const UList<point>& global
300 ) const
301 {
302  return rotationsImpl(global);
303 }
304 
305 
307 (
308  const pointUIndList& global
309 ) const
310 {
311  return rotationsImpl(global);
312 }
313 
314 
316 (
317  const point& localCart
318 ) const
319 {
320  return Foam::transform(rot_, localCart) + origin_;
321 }
322 
323 
325 (
326  const point& global
327 ) const
328 {
329  return Foam::invTransform(rot_, global - origin_);
330 }
331 
332 
334 (
335  const vector& local,
336  bool translate
337 ) const
338 {
339  if (translate)
340  {
341  return this->transform(local) + origin_;
342  }
343 
344  return this->transform(local);
345 }
346 
347 
349 (
350  const vectorField& local,
351  bool translate
352 ) const
353 {
354  if (translate)
355  {
356  return this->transform(local) + origin_;
357  }
358 
359  return this->transform(local);
360 }
361 
362 
364 (
365  const vector& global,
366  bool translate
367 ) const
368 {
369  if (translate)
370  {
371  return this->invTransform(global - origin_);
372  }
373 
374  return this->invTransform(global);
375 }
376 
377 
379 (
380  const vectorField& global,
381  bool translate
382 ) const
383 {
384  if (translate)
385  {
386  return this->invTransform(global - origin_);
387  }
388 
389  return this->invTransform(global);
390 }
391 
392 
394 {
395  spec_.reset(std::move(crot));
396  if (spec_)
397  {
398  rot_ = spec_->R();
399  }
400  else
401  {
402  rot_ = sphericalTensor::I;
403  }
404 }
405 
406 
408 {
409  if (!valid())
410  {
411  return;
412  }
413 
414  // Suppress output of type for Cartesian
415  if (!isCartesian(type()))
416  {
417  os << type() << ' ';
418  }
419 
420  os << "origin: " << origin_ << ' ';
421  spec_->write(os);
422 }
423 
424 
425 void Foam::coordinateSystem::writeEntry(const word& keyword, Ostream& os) const
426 {
427  if (!valid())
428  {
429  return;
430  }
431 
432  const bool subDict = !keyword.empty();
433 
434  if (subDict)
435  {
436  os.beginBlock(keyword);
437 
438  // Suppress output of type for Cartesian
439  if (!isCartesian(type()))
440  {
441  os.writeEntry<word>("type", type());
442  }
443 
444  if (note_.size())
445  {
446  // The 'note' is optional
447  os.writeEntry("note", note_);
448  }
449  }
450 
451  os.writeEntry("origin", origin_);
452 
453  spec_->writeEntry("rotation", os);
454 
455  if (subDict)
456  {
457  os.endBlock();
458  }
459 }
460 
461 
462 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
463 
465 {
466  name_ = csys.name_;
467  note_ = csys.note_;
468  origin_ = csys.origin_;
469 
470  // Some extra safety
471  if (csys.spec_)
472  {
473  rotation(csys.spec_.clone());
474  }
475  else
476  {
477  spec_.reset(new coordinateRotations::identity());
478  rot_ = sphericalTensor::I;
479  }
480 }
481 
482 
484 {
485  name_ = std::move(csys.name_);
486  note_ = std::move(csys.note_);
487  spec_ = std::move(csys.spec_);
488  origin_ = csys.origin_;
489  rot_ = csys.rot_;
490 }
491 
492 
494 {
496 }
497 
498 
500 {
501  coordinateSystem::operator=(std::move(*csys));
502  csys.clear();
503 }
504 
505 
506 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
507 
509 {
510  return
511  (
512  a.type() != b.type()
513  || a.origin() != b.origin()
514  || a.R() != b.R()
515  );
516 }
517 
518 
520 {
521  csys.write(os);
522  os.check(FUNCTION_NAME);
523  return os;
524 }
525 
526 
527 // ************************************************************************* //
Foam::coordinateRotation::New
static autoPtr< coordinateRotation > New(const dictionary &dict)
Select constructed from dictionary.
Definition: coordinateRotation.C:72
Foam::Tensor< scalar >
Foam::coordinateSystem::note_
string note_
An optional note describing the coordinate system.
Definition: coordinateSystem.H:152
Foam::isCartesian
static bool isCartesian(const word &modelType)
Is it cartesian?
Definition: coordinateSystem.C:56
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::coordinateSystem::clear
virtual void clear()
Reset origin and rotation to an identity coordinateSystem.
Definition: coordinateSystem.C:282
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Foam::coordinateSystem::operator=
void operator=(const coordinateSystem &csys)
Copy assignment.
Definition: coordinateSystem.C:464
Foam::coordinateSystem::dummy_
static coordinateSystem dummy_
Dummy coordinate system for suppressed manipulation.
Definition: coordinateSystem.H:155
dictName
const word dictName("blockMeshDict")
Foam::Ostream::beginBlock
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:91
Foam::coordinateRotations::axes
A coordinateRotation specified using global axes.
Definition: axesRotation.H:104
Foam::transform
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:519
cartesianCS.H
coordinateSystem.H
Foam::coordinateSystem::rotation
virtual const coordinateRotation & rotation() const
The rotation specification.
Definition: coordinateSystem.H:441
Foam::operator!=
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:235
Foam::coordinateSystem::origin
virtual const point & origin() const
Return origin.
Definition: coordinateSystem.H:459
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::Field< vector >
Foam::coordinateRotation
User specification of a coordinate rotation.
Definition: coordinateRotation.H:77
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
IOstream.H
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:528
Foam::coordinateSystem::name_
word name_
The name of the coordinate system (optional)
Definition: coordinateSystem.H:149
Foam::coordinateRotation::R
virtual tensor R() const =0
Calculate and return the rotation tensor.
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::Ostream::endBlock
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:109
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::Ostream::write
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Foam::coordinateSystem::spec_
autoPtr< coordinateRotation > spec_
User specification of the coordinate rotation.
Definition: coordinateSystem.H:140
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::coordinateSystem::globalToLocal
virtual vector globalToLocal(const vector &global, bool translate) const
Definition: coordinateSystem.C:364
Foam::SphericalTensor< scalar >
Foam::coordinateRotations::identity
An identity coordinateRotation.
Definition: identityRotation.H:75
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::coordinateSystem::rot_
tensor rot_
The rotation tensor.
Definition: coordinateSystem.H:146
Foam::Vector< scalar >
Foam::coordinateSystem::origin_
point origin_
The coordinate system origin.
Definition: coordinateSystem.H:143
Foam::coordinateSystem::coordinateSystem
coordinateSystem()
Construct null. This is an identity coordinateSystem.
Definition: coordinateSystem.C:113
identityRotation.H
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::coordinateSystem::assign
void assign(const dictionary &dict)
Assign from dictionary content.
Definition: coordinateSystem.C:70
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
Foam::invTransform
dimensionSet invTransform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:525
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:270
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:232
Foam::coordinateSystem::write
virtual void write(Ostream &os) const
Write.
Definition: coordinateSystem.C:407
Foam::coordinateSystem::localToGlobal
virtual vector localToGlobal(const vector &local, bool translate) const
Definition: coordinateSystem.C:334
Foam::UIndirectList
A List with indirect addressing.
Definition: faMatrix.H:60
Foam::FieldOps::assign
void assign(Field< Tout > &result, const Field< T1 > &a, const UnaryOp &op)
Populate a field as the result of a unary operation on an input.
Definition: FieldOps.C:35
Foam::coordinateSystem::invTransformPoint
point invTransformPoint(const point &global) const
Remove origin offset and inverse transform point.
Definition: coordinateSystem.C:325
Foam::coordinateRotation::clone
virtual autoPtr< coordinateRotation > clone() const =0
Construct and return a clone.
Foam::keyType::LITERAL
String literal.
Definition: keyType.H:73
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
transform.H
3D tensor transformation operations.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
axesRotation.H
Foam::coordinateSystem::transformPoint
point transformPoint(const point &localCart) const
Transform point and add origin offset.
Definition: coordinateSystem.C:316
Foam::coordinateSystem::writeEntry
virtual void writeEntry(const word &keyword, Ostream &os) const
Write dictionary entry.
Definition: coordinateSystem.C:425
Foam::I
static const Identity< scalar > I
Definition: Identity.H:95
Foam::SphericalTensor< scalar >::I
static const SphericalTensor I
Definition: SphericalTensor.H:77
Foam::coordinateSystem
Base class for coordinate system specification, the default coordinate system type is cartesian .
Definition: coordinateSystem.H:122
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62
Foam::coordinateSystem::R
virtual const tensor & R() const
Return const reference to the rotation tensor.
Definition: coordinateSystem.H:465