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 
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
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  {
276  }
277  else
278  {
279  assign(dict);
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 
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 
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  {
461  os.endBlock();
462  }
463 }
464 
465 
466 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
467 
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 
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 
513 {
514  return
515  (
516  a.type() != b.type()
517  || a.origin() != b.origin()
518  || a.R() != b.R()
519  );
520 }
521 
522 
524 {
525  csys.write(os);
527  return os;
528 }
529 
530 
531 // ************************************************************************* //
Foam::coordinateRotation::New
static autoPtr< coordinateRotation > New(const dictionary &dict)
Select constructed from dictionary.
Definition: coordinateRotation.C:71
Foam::Tensor< scalar >
Foam::coordinateSystem::note_
string note_
An optional note describing the coordinate system.
Definition: coordinateSystem.H:162
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:65
Foam::coordinateSystem::clear
virtual void clear()
Reset origin and rotation to an identity coordinateSystem.
Definition: coordinateSystem.C:286
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)
dictName
const word dictName("faMeshDefinition")
Foam::coordinateSystem::operator=
void operator=(const coordinateSystem &csys)
Copy assignment.
Definition: coordinateSystem.C:468
Foam::coordinateSystem::dummy_
static coordinateSystem dummy_
Dummy coordinate system for suppressed manipulation.
Definition: coordinateSystem.H:165
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:521
cartesianCS.H
Foam::OBJstream::write
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
coordinateSystem.H
Foam::coordinateSystem::rotation
virtual const coordinateRotation & rotation() const
The rotation specification.
Definition: coordinateSystem.H:451
Foam::operator!=
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:239
Foam::coordinateSystem::origin
virtual const point & origin() const
Return origin.
Definition: coordinateSystem.H:469
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:78
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:460
Foam::coordinateSystem::name_
word name_
The name of the coordinate system (optional)
Definition: coordinateSystem.H:159
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:58
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::coordinateSystem::spec_
autoPtr< coordinateRotation > spec_
User specification of the coordinate rotation.
Definition: coordinateSystem.H:150
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::coordinateSystem::globalToLocal
virtual vector globalToLocal(const vector &global, bool translate) const
Definition: coordinateSystem.C:368
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:156
Foam::Vector< scalar >
Foam::coordinateSystem::origin_
point origin_
The coordinate system origin.
Definition: coordinateSystem.H:153
Foam::coordinateSystem::coordinateSystem
coordinateSystem()
Default construct. This is an identity coordinate system.
Definition: coordinateSystem.C:117
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:527
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:236
Foam::coordinateSystem::write
virtual void write(Ostream &os) const
Write.
Definition: coordinateSystem.C:411
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::coordinateSystem::localToGlobal
virtual vector localToGlobal(const vector &local, bool translate) const
Definition: coordinateSystem.C:338
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:329
Foam::coordinateRotation::clone
virtual autoPtr< coordinateRotation > clone() const =0
Construct and return a clone.
Foam::keyType::LITERAL
String literal.
Definition: keyType.H:81
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:320
Foam::coordinateSystem::writeEntry
virtual void writeEntry(const word &keyword, Ostream &os) const
Write dictionary entry.
Definition: coordinateSystem.C:429
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:132
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:475