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 | Copyright (C) 2011-2014 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  {
142  Info<< "coordinateSystem::coordinateSystem"
143  "(const objectRegistry&, const dictionary&):"
144  << nl << "using global coordinate system: "
145  << key << "=" << index << endl;
146  }
147 
148  if (index < 0)
149  {
151  (
152  "coordinateSystem::coordinateSystem"
153  "(const objectRegistry&, const dictionary&):"
154  ) << "could not find coordinate system: " << key << nl
155  << "available coordinate systems: " << lst.toc() << nl << nl
156  << exit(FatalError);
157  }
158 
159  // copy coordinateSystem, but assign the name as the typeName
160  // to avoid strange things in writeDict()
161  operator=(lst[index]);
162  name_ = typeName_();
163  }
164  else
165  {
166  init(dict, obr);
167  }
168 }
169 
170 
172 :
173  name_(is),
174  note_(),
175  origin_(point::zero),
176  R_()
177 {
178  dictionary dict(is);
179  init(dict);
180 }
181 
182 
183 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
184 
186 {}
187 
188 
189 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
190 
192 {
194 
195  dict.add("name", name_);
196 
197  // only write type for derived types
198  if (!ignoreType && type() != typeName_())
199  {
200  dict.add("type", type());
201  }
202 
203  // The note entry is optional
204  if (note_.size())
205  {
206  dict.add("note", note_);
207  }
208 
209  dict.add("origin", origin_);
210  dict.add("e1", R_->e1());
211  dict.add("e3", R_->e3());
212 
213  return dict;
214 }
215 
216 
218 (
219  const vector& local,
220  bool translate
221 ) const
222 {
223  if (translate)
224  {
225  return (R_->transform(local)) + origin_;
226  }
227  else
228  {
229  return R_->transform(local);
230  }
231 }
232 
233 
235 (
236  const vectorField& local,
237  bool translate
238 ) const
239 {
240  if (translate)
241  {
242  return (R_->transform(local)) + origin_;
243  }
244  else
245  {
246  return R_->transform(local);
247  }
248 }
249 
250 
252 (
253  const vector& global,
254  bool translate
255 ) const
256 {
257  if (translate)
258  {
259  return R_->invTransform(global - origin_);
260  }
261  else
262  {
263  return R_->invTransform(global);
264  }
265 }
266 
267 
269 (
270  const vectorField& global,
271  bool translate
272 ) const
273 {
274  if (translate)
275  {
276  return R_->invTransform(global - origin_);
277  }
278  else
279  {
280  return R_->invTransform(global);
281  }
282 }
283 
284 
286 {
287  note_.clear();
288  origin_ = point::zero;
289  R_->clear();
290 }
291 
292 
294 {
295  os << type() << " origin: " << origin() << nl;
296  R_->write(os);
297 }
298 
299 
300 void Foam::coordinateSystem::writeDict(Ostream& os, bool subDict) const
301 {
302  if (subDict)
303  {
304  os << indent << name_ << nl
306  }
307 
308  os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
309 
310 
311  // The note entry is optional
312  if (note_.size())
313  {
314  os.writeKeyword("note") << note_ << token::END_STATEMENT << nl;
315  }
316 
317  os.writeKeyword("origin") << origin_ << token::END_STATEMENT << nl;
318  R_->write(os);
319 
320  if (subDict)
321  {
322  os << decrIndent << indent << token::END_BLOCK << endl;
323  }
324 }
325 
326 
327 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
328 
330 {
331  rhs.lookup("origin") >> origin_;
332  note_.clear();
333  rhs.readIfPresent("note", note_);
334  R_.reset(coordinateRotation::New(rhs.subDict("coordinateRotation")).ptr());
335 }
336 
337 
339 (
340  const dictionary& rhs,
341  const objectRegistry& obr
342 )
343 {
344  if (debug)
345  {
346  Pout<< "coordinateSystem::operator="
347  "("
348  "const dictionary&, "
349  "const objectRegistry&"
350  ") : "
351  << "assign from " << rhs << endl;
352  }
353 
354  rhs.lookup("origin") >> origin_;
355 
356  // The note entry is optional
357  note_.clear();
358  rhs.readIfPresent("note", note_);
359 
360  R_.reset
361  (
362  coordinateRotation::New(rhs.subDict("coordinateRotation"), obr).ptr()
363  );
364 }
365 
366 
367 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
368 
369 bool Foam::operator!=(const coordinateSystem& a, const coordinateSystem& b)
370 {
371  return
372  (
373  a.origin() != b.origin()
374  || a.R().R() != b.R().R()
375  || a.type() != b.type()
376  );
377 }
378 
379 
380 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
381 
383 {
384  cs.write(os);
385  os.check("Ostream& operator<<(Ostream&, const coordinateSystem&");
386  return os;
387 }
388 
389 
390 // ************************************************************************* //
const coordinateRotation & R() const
Return const reference to co-ordinate rotation.
virtual const tensor & R() const =0
Return local-to-global transformation tensor.
virtual bool isDict() const
Return true if this entry is a dictionary.
Definition: entry.H:153
virtual vector globalToLocal(const vector &, bool translate) const
Convert from global Cartesian system to the local coordinate system.
const point & origin() const
Return origin.
Base class for other coordinate system specifications.
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
static const sphericalTensor I(1)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual void clear()
Reset origin and rotation to an identity coordinateSystem.
A class for handling words, derived from string.
Definition: word.H:59
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
void writeDict(Ostream &, bool subDict=true) const
Write dictionary.
messageStream Info
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.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:638
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:133
Namespace for OpenFOAM.
A class for handling keywords in dictionaries.
Definition: keyType.H:56
virtual void write(Ostream &) const
Write.
const entry * lookupEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
Definition: dictionary.C:345
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
A coordinate rotation specified using global axis.
Definition: axesRotation.H:60
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
virtual ITstream & stream() const =0
Return token stream if this entry is a primitive entry.
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:235
Abstract base class for coordinate rotation.
bool operator!=(const particle &, const particle &)
Definition: particle.C:147
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:47
virtual dictionary dict(bool ignoreType=false) const
Return as dictionary of entries.
Macros for easy insertion into run-time selection tables.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:739
void init(const dictionary &)
Init from dict and obr.
coordinateSystem()
Construct null. This is equivalent to an identity coordinateSystem.
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:65
virtual ~coordinateSystem()
Destructor.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
Registry of regIOobjects.
static const Vector zero
Definition: Vector.H:80
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
virtual vector localToGlobal(const vector &, bool translate) const
Convert from local coordinate system to the global Cartesian system.
static const coordinateSystems & New(const objectRegistry &)
Return previously registered or read construct from "constant".
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static autoPtr< coordinateRotation > New(const dictionary &dict, const objectRegistry &obr)
Select constructed from dictionary and objectRegistry.
Provides a centralized coordinateSystem collection.
A class for managing temporary objects.
Definition: PtrList.H:118
defineTypeNameAndDebug(combustionModel, 0)
prefixOSstream Pout(cout,"Pout")
Definition: IOstreams.H:53