coordinateSystem.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 "IOstream.H"
27 #include "axesRotation.H"
28 #include "coordinateSystem.H"
29 #include "coordinateSystems.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(coordinateSystem, 0);
37  defineRunTimeSelectionTable(coordinateSystem, dictionary);
38 }
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
43 :
44  name_(),
45  note_(),
46  origin_(point::zero),
48 {}
49 
50 
52 (
53  const word& name,
54  const coordinateSystem& cs
55 )
56 :
57  name_(name),
58  note_(),
59  origin_(cs.origin_),
60  R_(const_cast<coordinateRotation*>(&cs.R()))
61 {}
62 
63 
65 (
66  const word& name,
67  const point& origin,
68  const coordinateRotation& cr
69 )
70 :
71  name_(name),
72  note_(),
73  origin_(origin),
74  R_(const_cast<coordinateRotation*>(&cr))
75 {}
76 
77 
79 (
80  const word& name,
81  const point& origin,
82  const vector& axis,
83  const vector& dirn
84 )
85 :
86  name_(name),
87  note_(),
88  origin_(origin),
89  R_(new axesRotation(axis, dirn))
90 {}
91 
92 
94 (
95  const word& name,
96  const dictionary& dict
97 )
98 :
99  name_(name),
100  note_(),
101  origin_(point::zero),
102  R_()
103 {
104  init(dict);
105 }
106 
107 
109 :
110  name_(),
111  note_(),
112  origin_(point::zero),
113  R_()
114 {
115  init(dict);
116 }
117 
118 
120 (
121  const objectRegistry& obr,
122  const dictionary& dict
123 )
124 :
125  name_(),
126  note_(),
127  origin_(point::zero),
128  R_()
129 {
130  const entry* entryPtr = dict.lookupEntryPtr(typeName_(), false, false);
131 
132  // non-dictionary entry is a lookup into global coordinateSystems
133  if (entryPtr && !entryPtr->isDict())
134  {
135  keyType key(entryPtr->stream());
136 
137  const coordinateSystems& lst = coordinateSystems::New(obr);
138  const label index = lst.findIndex(key);
139 
140  if (debug)
141  {
143  << "Using global coordinate system: "
144  << key << "=" << index << endl;
145  }
146 
147  if (index < 0)
148  {
150  << "could not find coordinate system: " << key << nl
151  << "available coordinate systems: " << lst.toc() << nl << nl
152  << exit(FatalError);
153  }
154 
155  // copy coordinateSystem, but assign the name as the typeName
156  // to avoid strange things in writeDict()
157  operator=(lst[index]);
158  name_ = typeName_();
159  }
160  else
161  {
162  init(dict, obr);
163  }
164 }
165 
166 
168 :
169  name_(is),
170  note_(),
171  origin_(point::zero),
172  R_()
173 {
174  dictionary dict(is);
175  init(dict);
176 }
177 
178 
179 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
180 
182 {}
183 
184 
185 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
186 
188 {
190 
191  dict.add("name", name_);
192 
193  // only write type for derived types
194  if (!ignoreType && type() != typeName_())
195  {
196  dict.add("type", type());
197  }
198 
199  // The note entry is optional
200  if (note_.size())
201  {
202  dict.add("note", note_);
203  }
204 
205  dict.add("origin", origin_);
206  dict.add("e1", R_->e1());
207  dict.add("e3", R_->e3());
208 
209  return dict;
210 }
211 
212 
214 (
215  const vector& local,
216  bool translate
217 ) const
218 {
219  if (translate)
220  {
221  return (R_->transform(local)) + origin_;
222  }
223  else
224  {
225  return R_->transform(local);
226  }
227 }
228 
229 
231 (
232  const vectorField& local,
233  bool translate
234 ) const
235 {
236  if (translate)
237  {
238  return (R_->transform(local)) + origin_;
239  }
240  else
241  {
242  return R_->transform(local);
243  }
244 }
245 
246 
248 (
249  const vector& global,
250  bool translate
251 ) const
252 {
253  if (translate)
254  {
255  return R_->invTransform(global - origin_);
256  }
257  else
258  {
259  return R_->invTransform(global);
260  }
261 }
262 
263 
265 (
266  const vectorField& global,
267  bool translate
268 ) const
269 {
270  if (translate)
271  {
272  return R_->invTransform(global - origin_);
273  }
274  else
275  {
276  return R_->invTransform(global);
277  }
278 }
279 
280 
282 {
283  note_.clear();
284  origin_ = Zero;
285  R_->clear();
286 }
287 
288 
290 {
291  os << type() << " origin: " << origin() << nl;
292  R_->write(os);
293 }
294 
295 
296 void Foam::coordinateSystem::writeDict(Ostream& os, bool subDict) const
297 {
298  if (subDict)
299  {
300  os << indent << name_ << nl
302  }
303 
304  writeEntry(os, "type", type());
305 
306 
307  // The note entry is optional
308  if (note_.size())
309  {
310  writeEntry(os, "note", note_);
311  }
312 
313  writeEntry(os, "origin", origin_);
314  R_->write(os);
315 
316  if (subDict)
317  {
318  os << decrIndent << indent << token::END_BLOCK << endl;
319  }
320 }
321 
322 
323 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
324 
326 {
327  rhs.lookup("origin") >> origin_;
328  note_.clear();
329  rhs.readIfPresent("note", note_);
330  R_.reset(coordinateRotation::New(rhs.subDict("coordinateRotation")).ptr());
331 }
332 
333 
335 (
336  const dictionary& rhs,
337  const objectRegistry& obr
338 )
339 {
340  if (debug)
341  {
342  Pout<< "coordinateSystem::operator="
343  "("
344  "const dictionary&, "
345  "const objectRegistry&"
346  ") : "
347  << "assign from " << rhs << endl;
348  }
349 
350  rhs.lookup("origin") >> origin_;
351 
352  // The note entry is optional
353  note_.clear();
354  rhs.readIfPresent("note", note_);
355 
356  R_.reset
357  (
358  coordinateRotation::New(rhs.subDict("coordinateRotation"), obr).ptr()
359  );
360 }
361 
362 
363 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
364 
366 {
367  return
368  (
369  a.origin() != b.origin()
370  || a.R().R() != b.R().R()
371  || a.type() != b.type()
372  );
373 }
374 
375 
376 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
377 
379 {
380  cs.write(os);
381  os.check("Ostream& operator<<(Ostream&, const coordinateSystem&");
382  return os;
383 }
384 
385 
386 // ************************************************************************* //
Base class for other coordinate system specifications.
A class for handling keywords in dictionaries.
Definition: keyType.H:64
Abstract base class for coordinate rotation.
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
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:226
const entry * lookupEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
Definition: dictionary.C:477
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
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Provides a centralized coordinateSystem collection.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
const point & origin() const
Return origin.
virtual ~coordinateSystem()
Destructor.
virtual vector localToGlobal(const vector &, bool translate) const
Convert from local coordinate system to the global Cartesian system.
Macros for easy insertion into run-time selection tables.
virtual void clear()
Reset origin and rotation to an identity coordinateSystem.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:821
coordinateSystem()
Construct null. This is equivalent to an identity coordinateSystem.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:699
Templated 3D SphericalTensor derived from VectorSpace adding construction from 1 component, element access using th ii() member function and the inner-product (dot-product) and outer-product operators.
static const Identity< scalar > I
Definition: Identity.H:93
const dimensionedScalar b
Wien displacement law constant: default SI units: [m K].
Definition: createFields.H:27
A class for handling words, derived from string.
Definition: word.H:59
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
static const zero Zero
Definition: zero.H:97
virtual bool isDict() const
Return true if this entry is a dictionary.
Definition: entry.H:156
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual vector globalToLocal(const vector &, bool translate) const
Convert from global Cartesian system to the local coordinate system.
static const char nl
Definition: Ostream.H:265
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
defineTypeNameAndDebug(combustionModel, 0)
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:240
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
virtual const tensor & R() const =0
Return local-to-global transformation tensor.
static const coordinateSystems & New(const objectRegistry &)
Return previously registered or read construct from "constant".
static autoPtr< coordinateRotation > New(const dictionary &dict, const objectRegistry &obr)
Select constructed from dictionary and objectRegistry.
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Ostream & operator<<(Ostream &, const ensightPart &)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:49
A coordinate rotation specified using global axis.
Definition: axesRotation.H:64
A class for managing temporary objects.
Definition: PtrList.H:53
Registry of regIOobjects.
virtual ITstream & stream() const =0
Return token stream if this entry is a primitive entry.
bool operator!=(const particle &, const particle &)
Definition: particle.C:1223
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:233
virtual dictionary dict(bool ignoreType=false) const
Return as dictionary of entries.
void init(const dictionary &)
Init from dict and obr.
void writeDict(Ostream &, bool subDict=true) const
Write dictionary.
virtual void write(Ostream &) const
Write.
Namespace for OpenFOAM.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:65
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:583
const coordinateRotation & R() const
Return const reference to co-ordinate rotation.
#define InfoInFunction
Report an information message using Foam::Info.