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-2020 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 "coordinateSystem.H"
27 #include "coordinateSystems.H"
28 #include "axesRotation.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(coordinateSystem, 0);
36  defineRunTimeSelectionTable(coordinateSystem, dictionary);
37 }
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 (
43  const word& name,
44  const point& origin
45 )
46 :
47  name_(name),
48  origin_(origin),
50 {}
51 
52 
54 (
55  const word& name,
56  const point& origin,
57  const coordinateRotation& cr
58 )
59 :
60  name_(name),
61  origin_(origin),
62  R_(cr.clone())
63 {}
64 
65 
67 (
68  const word& name,
69  const point& origin,
70  const vector& axis,
71  const vector& dirn
72 )
73 :
74  name_(name),
75  origin_(origin),
76  R_(new axesRotation(axis, dirn))
77 {}
78 
79 
81 (
82  const word& name,
83  const dictionary& dict
84 )
85 :
86  name_(name),
87  origin_(dict.lookup("origin")),
88  R_(coordinateRotation::New(dict.subDict("coordinateRotation")).ptr())
89 {}
90 
91 
92 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
93 
95 {}
96 
97 
98 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
99 
101 (
102  const vector& local,
103  bool translate
104 ) const
105 {
106  if (translate)
107  {
108  return (R_->transform(local)) + origin_;
109  }
110  else
111  {
112  return R_->transform(local);
113  }
114 }
115 
116 
118 (
119  const vectorField& local,
120  bool translate
121 ) const
122 {
123  if (translate)
124  {
125  return (R_->transform(local)) + origin_;
126  }
127  else
128  {
129  return R_->transform(local);
130  }
131 }
132 
133 
135 (
136  const vector& global,
137  bool translate
138 ) const
139 {
140  if (translate)
141  {
142  return R_->invTransform(global - origin_);
143  }
144  else
145  {
146  return R_->invTransform(global);
147  }
148 }
149 
150 
152 (
153  const vectorField& global,
154  bool translate
155 ) const
156 {
157  if (translate)
158  {
159  return R_->invTransform(global - origin_);
160  }
161  else
162  {
163  return R_->invTransform(global);
164  }
165 }
166 
167 
169 {
170  os << type() << " origin: " << origin() << nl;
171  R_->write(os);
172 }
173 
174 
175 void Foam::coordinateSystem::writeDict(Ostream& os, bool subDict) const
176 {
177  if (subDict)
178  {
179  os << indent << name_ << nl
181  }
182 
183  writeEntry(os, "type", type());
184 
185 
186  writeEntry(os, "origin", origin_);
187  R_->write(os);
188 
189  if (subDict)
190  {
191  os << decrIndent << indent << token::END_BLOCK << endl;
192  }
193 }
194 
195 
196 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
197 
199 {
200  cs.write(os);
201  os.check("Ostream& operator<<(Ostream&, const coordinateSystem&");
202  return os;
203 }
204 
205 
206 // ************************************************************************* //
virtual autoPtr< coordinateRotation > clone() const =0
Construct and return a clone.
Base class for other coordinate system specifications.
Abstract base class for coordinate rotation.
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
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.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:982
static autoPtr< coordinateRotation > New(const dictionary &dict, const UList< vector > &points)
Select constructed from dictionary and list of points.
A class for handling words, derived from string.
Definition: word.H:59
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
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:260
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
defineTypeNameAndDebug(combustionModel, 0)
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:235
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
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
coordinateSystem(const word &name, const point &origin)
Construct from origin.
A coordinate rotation specified using global axis.
Definition: axesRotation.H:64
A class for managing temporary objects.
Definition: PtrList.H:53
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
void writeDict(Ostream &, bool subDict=true) const
Write dictionary.
virtual void write(Ostream &) const
Write.
Namespace for OpenFOAM.
static const SphericalTensor I
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844