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-2021 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 {
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 
93 :
94  name_(cs.name_),
95  origin_(cs.origin_),
96  R_(cs.R_, false)
97 {}
98 
99 
100 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
101 
103 {}
104 
105 
106 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
107 
109 (
110  const vector& local,
111  bool translate
112 ) const
113 {
114  if (translate)
115  {
116  return (R_->transform(local)) + origin_;
117  }
118  else
119  {
120  return R_->transform(local);
121  }
122 }
123 
124 
126 (
127  const vectorField& local,
128  bool translate
129 ) const
130 {
131  if (translate)
132  {
133  return (R_->transform(local)) + origin_;
134  }
135  else
136  {
137  return R_->transform(local);
138  }
139 }
140 
141 
143 (
144  const vector& global,
145  bool translate
146 ) const
147 {
148  if (translate)
149  {
150  return R_->invTransform(global - origin_);
151  }
152  else
153  {
154  return R_->invTransform(global);
155  }
156 }
157 
158 
160 (
161  const vectorField& global,
162  bool translate
163 ) const
164 {
165  if (translate)
166  {
167  return R_->invTransform(global - origin_);
168  }
169  else
170  {
171  return R_->invTransform(global);
172  }
173 }
174 
175 
177 {
178  os << type() << " origin: " << origin() << nl;
179  R_->write(os);
180 }
181 
182 
183 void Foam::coordinateSystem::writeDict(Ostream& os, bool subDict) const
184 {
185  if (subDict)
186  {
187  os << indent << name_ << nl
189  }
190 
191  writeEntry(os, "type", type());
192  writeEntry(os, "origin", origin_);
193 
194  os << indent << "coordinateRotation" << nl
196  writeEntry(os, "type", R_->type());
197  R_->write(os);
198  os << decrIndent << indent << token::END_BLOCK << endl;
199 
200  if (subDict)
201  {
202  os << decrIndent << indent << token::END_BLOCK << endl;
203  }
204 }
205 
206 
207 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
208 
210 {
211  name_ = cs.name_;
212  origin_ = cs.origin_;
213  R_ = cs.R_->clone();
214 }
215 
216 
217 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
218 
220 {
221  cs.writeDict(os);
222  os.check("Ostream& operator<<(Ostream&, const coordinateSystem&");
223  return os;
224 }
225 
226 
227 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Templated 3D SphericalTensor derived from VectorSpace adding construction from 1 component,...
A coordinate rotation specified using global axis.
Definition: axesRotation.H:67
Abstract base class for coordinate rotation.
Base class for other coordinate system specifications.
coordinateSystem(const word &name, const point &origin)
Construct from origin.
virtual void write(Ostream &) const
Write.
void operator=(const coordinateSystem &)
Assignment operator.
virtual vector globalToLocal(const vector &, bool translate) const
Convert from global Cartesian system to the local coordinate system.
virtual ~coordinateSystem()
Destructor.
virtual vector localToGlobal(const vector &, bool translate) const
Convert from local coordinate system to the global Cartesian system.
void writeDict(Ostream &, bool subDict=true) const
Write dictionary.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
A class for managing temporary objects.
Definition: tmp.H:55
@ BEGIN_BLOCK
Definition: token.H:113
@ END_BLOCK
Definition: token.H:114
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:241
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
static const Identity< scalar > I
Definition: Identity.H:93
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:234
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
defineTypeNameAndDebug(combustionModel, 0)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
T clone(const T &t)
Definition: List.H:55
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:227
static const char nl
Definition: Ostream.H:266
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict