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-2021 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 
70 void Foam::coordinateSystem::assign(const dictionary& dict)
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 if (finder.good() && (finder->stream().peek().isWord("none")))
92  {
94  }
95  else
96  {
97  // Fall through to expecting e1/e2/e3 specification in the dictionary
98  spec_.reset(new coordinateRotations::axes(dict));
99  }
100 
101  rot_ = spec_->R();
102 }
103 
104 
105 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
106 
108 :
109  spec_(),
110  origin_(Zero),
111  rot_(sphericalTensor::I),
112  name_(),
113  note_()
114 {}
115 
116 
118 :
119  spec_(new coordinateRotations::identity()),
120  origin_(Zero),
121  rot_(sphericalTensor::I),
122  name_(),
123  note_()
124 {}
125 
126 
128 :
129  coordinateSystem(word::null, point::zero, crot)
130 {}
131 
132 
134 :
135  coordinateSystem(word::null, point::zero, std::move(crot))
136 {}
137 
138 
140 :
141  spec_(csys.spec_.clone()),
142  origin_(csys.origin_),
143  rot_(csys.rot_),
144  name_(csys.name_),
145  note_(csys.note_)
146 {}
147 
148 
150 :
151  spec_(std::move(csys.spec_)),
152  origin_(std::move(csys.origin_)),
153  rot_(std::move(csys.rot_)),
154  name_(std::move(csys.name_)),
155  note_(std::move(csys.note_))
156 {}
157 
158 
160 :
161  coordinateSystem(nullptr)
162 {
163  if (csys)
164  {
165  // Has valid autoPtr - move.
166  coordinateSystem::operator=(std::move(*csys));
167  csys.clear();
168  }
169  else
170  {
171  // No valid autoPtr - treat like identity
173  }
174 }
175 
176 
178 (
179  const word& name,
180  const coordinateSystem& csys
181 )
182 :
183  spec_(csys.spec_.clone()),
184  origin_(csys.origin_),
185  rot_(csys.rot_),
186  name_(name),
187  note_(csys.note_)
188 {}
189 
190 
192 (
193  const point& origin,
194  const coordinateRotation& crot
195 )
196 :
197  coordinateSystem(word::null, origin, crot)
198 {}
199 
200 
202 (
203  const word& name,
204  const point& origin,
205  const coordinateRotation& crot
206 )
207 :
208  spec_(crot.clone()),
209  origin_(origin),
210  rot_(spec_->R()),
211  name_(name),
212  note_()
213 {}
214 
215 
217 (
218  const point& origin,
219  const vector& axis,
220  const vector& dirn
221 )
222 :
223  coordinateSystem(word::null, origin, axis, dirn)
224 {}
225 
226 
228 (
229  const word& name,
230  const point& origin,
231  const vector& axis,
232  const vector& dirn
233 )
234 :
235  spec_(new coordinateRotations::axes(axis, dirn)),
236  origin_(origin),
237  rot_(spec_->R()),
238  name_(name),
239  note_()
240 {}
241 
242 
244 (
245  const word& name,
246  const dictionary& dict
247 )
248 :
249  spec_(nullptr),
250  origin_(Zero),
251  rot_(sphericalTensor::I),
252  name_(name),
253  note_()
254 {
255  assign(dict);
256 }
257 
258 
260 :
261  coordinateSystem(word::null, dict)
262 {}
263 
264 
266 (
267  const dictionary& dict,
268  const word& dictName
269 )
270 :
271  coordinateSystem(nullptr)
272 {
273  if (dictName.size())
274  {
275  assign(dict.subDict(dictName));
276  }
277  else
278  {
280  }
281 }
282 
283 
284 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
285 
287 {
288  spec_->clear();
289  origin_ = Zero;
290  rot_ = sphericalTensor::I;
291  note_.clear();
292 }
293 
294 
296 {
297  return rot_;
298 }
299 
300 
302 (
303  const UList<point>& global
304 ) const
305 {
306  return rotationsImpl(global);
307 }
308 
309 
311 (
312  const pointUIndList& global
313 ) const
314 {
315  return rotationsImpl(global);
316 }
317 
318 
320 (
321  const point& localCart
322 ) const
323 {
324  return Foam::transform(rot_, localCart) + origin_;
325 }
326 
327 
329 (
330  const point& global
331 ) const
332 {
333  return Foam::invTransform(rot_, global - origin_);
334 }
335 
336 
338 (
339  const vector& local,
340  bool translate
341 ) const
342 {
343  if (translate)
344  {
345  return this->transform(local) + origin_;
346  }
347 
348  return this->transform(local);
349 }
350 
351 
353 (
354  const vectorField& local,
355  bool translate
356 ) const
357 {
358  if (translate)
359  {
360  return this->transform(local) + origin_;
361  }
362 
363  return this->transform(local);
364 }
365 
366 
368 (
369  const vector& global,
370  bool translate
371 ) const
372 {
373  if (translate)
374  {
375  return this->invTransform(global - origin_);
376  }
377 
378  return this->invTransform(global);
379 }
380 
381 
383 (
384  const vectorField& global,
385  bool translate
386 ) const
387 {
388  if (translate)
389  {
390  return this->invTransform(global - origin_);
391  }
392 
393  return this->invTransform(global);
394 }
395 
396 
397 void Foam::coordinateSystem::rotation(autoPtr<coordinateRotation>&& crot)
398 {
399  spec_.reset(std::move(crot));
400  if (spec_)
401  {
402  rot_ = spec_->R();
403  }
404  else
405  {
406  rot_ = sphericalTensor::I;
407  }
408 }
409 
410 
411 void Foam::coordinateSystem::write(Ostream& os) const
412 {
413  if (!valid())
414  {
415  return;
416  }
417 
418  // Suppress output of type for Cartesian
419  if (!isCartesian(type()))
420  {
421  os << type() << ' ';
422  }
423 
424  os << "origin: " << origin_ << ' ';
425  spec_->write(os);
426 }
427 
428 
429 void Foam::coordinateSystem::writeEntry(const word& keyword, Ostream& os) const
430 {
431  if (!valid())
432  {
433  return;
434  }
435 
436  const bool subDict = !keyword.empty();
437 
438  if (subDict)
439  {
440  os.beginBlock(keyword);
441 
442  // Suppress output of type for Cartesian
443  if (!isCartesian(type()))
444  {
445  os.writeEntry<word>("type", type());
446  }
447 
448  if (note_.size())
449  {
450  // The 'note' is optional
451  os.writeEntry("note", note_);
452  }
453  }
454 
455  os.writeEntry("origin", origin_);
456 
457  spec_->writeEntry("rotation", os);
458 
459  if (subDict)
460  {
462  }
463 }
464 
465 
466 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
467 
468 void Foam::coordinateSystem::operator=(const coordinateSystem& csys)
469 {
470  name_ = csys.name_;
471  note_ = csys.note_;
472  origin_ = csys.origin_;
473 
474  // Some extra safety
475  if (csys.spec_)
476  {
477  rotation(csys.spec_.clone());
478  }
479  else
480  {
481  spec_.reset(new coordinateRotations::identity());
482  rot_ = sphericalTensor::I;
483  }
484 }
485 
486 
487 void Foam::coordinateSystem::operator=(coordinateSystem&& csys)
488 {
489  name_ = std::move(csys.name_);
490  note_ = std::move(csys.note_);
491  spec_ = std::move(csys.spec_);
492  origin_ = csys.origin_;
493  rot_ = csys.rot_;
494 }
495 
496 
498 {
500 }
501 
502 
504 {
505  coordinateSystem::operator=(std::move(*csys));
506  csys.clear();
507 }
508 
509 
510 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
511 
512 bool Foam::operator!=(const coordinateSystem& a, const coordinateSystem& b)
513 {
514  return
515  (
516  a.type() != b.type()
517  || a.origin() != b.origin()
518  || a.R() != b.R()
519  );
520 }
521 
522 
523 Foam::Ostream& Foam::operator<<(Ostream& os, const coordinateSystem& csys)
524 {
525  csys.write(os);
527  return os;
528 }
529 
530 
531 // ************************************************************************* //
Foam::coordinateRotation::New
static autoPtr< coordinateRotation > New(const dictionary &dict)
Definition: coordinateRotation.C:64
Foam::Tensor
A templated (3 x 3) tensor of objects of <T> derived from MatrixSpace.
Definition: complexI.H:268
Foam::coordinateSystem::note_
string note_
Definition: coordinateSystem.H:159
Foam::isCartesian
static bool isCartesian(const word &modelType)
Definition: coordinateSystem.C:49
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::coordinateSystem::clear
virtual void clear()
Definition: coordinateSystem.C:279
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:57
Foam::Zero
static constexpr const zero Zero
Definition: zero.H:131
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
dictName
const word dictName("faMeshDefinition")
Foam::coordinateSystem::operator=
void operator=(const coordinateSystem &csys)
Definition: coordinateSystem.C:461
Foam::coordinateSystem::dummy_
static coordinateSystem dummy_
Definition: coordinateSystem.H:162
Foam::Ostream::beginBlock
virtual Ostream & beginBlock(const keyType &kw)
Definition: Ostream.C:84
Foam::coordinateRotations::axes
A coordinateRotation specified using global axes.
Definition: axesRotation.H:100
Foam::transform
dimensionSet transform(const dimensionSet &ds)
Definition: dimensionSet.C:514
cartesianCS.H
Foam::OBJstream::write
virtual Ostream & write(const char c)
Definition: OBJstream.C:71
coordinateSystem.H
Foam::coordinateSystem::rotation
virtual const coordinateRotation & rotation() const
Definition: coordinateSystem.H:448
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:48
Foam::operator!=
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:235
Foam::coordinateSystem::origin
virtual const point & origin() const
Definition: coordinateSystem.H:466
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Definition: boundaryPatch.C:76
R
#define R(A, B, C, D, E, F, K, M)
Foam::constant::physicoChemical::b
const dimensionedScalar b
Definition: createFields.H:27
Foam::Field
Generic templated field type.
Definition: Field.H:59
Foam::coordinateRotation
User specification of a coordinate rotation.
Definition: coordinateRotation.H:75
IOstream.H
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.C:453
Foam::coordinateSystem::name_
word name_
Definition: coordinateSystem.H:156
Foam::coordinateRotation::R
virtual tensor R() const =0
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::Ostream::endBlock
virtual Ostream & endBlock()
Definition: Ostream.C:102
Foam::IOstream::check
virtual bool check(const char *operation) const
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:119
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::Ostream::write
virtual bool write(const token &tok)=0
Foam::coordinateSystem::spec_
autoPtr< coordinateRotation > spec_
Definition: coordinateSystem.H:147
Foam
Definition: atmBoundaryLayer.C:26
Foam::coordinateSystem::globalToLocal
virtual vector globalToLocal(const vector &global, bool translate) const
Definition: coordinateSystem.C:361
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:47
Foam::SphericalTensor< scalar >
Foam::coordinateRotations::identity
An identity coordinateRotation.
Definition: identityRotation.H:71
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:49
Foam::coordinateSystem::rot_
tensor rot_
Definition: coordinateSystem.H:153
Foam::Vector< scalar >
Foam::coordinateSystem::origin_
point origin_
Definition: coordinateSystem.H:150
Foam::coordinateSystem::coordinateSystem
coordinateSystem()
Definition: coordinateSystem.C:110
identityRotation.H
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Definition: POSIX.C:717
Foam::coordinateSystem::assign
void assign(const dictionary &dict)
Definition: coordinateSystem.C:63
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:99
Foam::identity
labelList identity(const label len, label start=0)
Definition: labelList.C:31
Foam::invTransform
dimensionSet invTransform(const dimensionSet &ds)
Definition: dimensionSet.C:520
Foam::word::null
static const word null
Definition: word.H:78
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:302
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Definition: Ostream.H:232
Foam::coordinateSystem::write
virtual void write(Ostream &os) const
Definition: coordinateSystem.C:404
Foam::name
word name(const expressions::valueTypeCode typeCode)
Definition: exprTraits.C:52
Foam::coordinateSystem::localToGlobal
virtual vector localToGlobal(const vector &local, bool translate) const
Definition: coordinateSystem.C:331
Foam::UIndirectList
A List with indirect addressing.
Definition: faMatrix.H:56
Foam::FieldOps::assign
void assign(Field< Tout > &result, const Field< T1 > &a, const UnaryOp &op)
Definition: FieldOps.C:28
Foam::coordinateSystem::invTransformPoint
point invTransformPoint(const point &global) const
Definition: coordinateSystem.C:322
Foam::coordinateRotation::clone
virtual autoPtr< coordinateRotation > clone() const =0
Foam::keyType::LITERAL
@ LITERAL
String literal.
Definition: keyType.H:79
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:52
transform.H
3D tensor transformation operations.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
axesRotation.H
Foam::coordinateSystem::transformPoint
point transformPoint(const point &localCart) const
Definition: coordinateSystem.C:313
Foam::coordinateSystem::writeEntry
virtual void writeEntry(const word &keyword, Ostream &os) const
Definition: coordinateSystem.C:422
Foam::I
static const Identity< scalar > I
Definition: Identity.H:89
Foam::SphericalTensor< scalar >::I
static const SphericalTensor I
Definition: SphericalTensor.H:73
Foam::coordinateSystem
Base class for coordinate system specification, the default coordinate system type is cartesian .
Definition: coordinateSystem.H:129
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:58
Foam::coordinateSystem::R
virtual const tensor & R() const
Definition: coordinateSystem.H:472