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