Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
meshTools
coordinateSystems
sphericalCS.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) 1991-2010 OpenCFD Ltd.
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 "
sphericalCS.H
"
27
28
#include <
OpenFOAM/one.H
>
29
#include <
OpenFOAM/Switch.H
>
30
#include <
OpenFOAM/mathematicalConstants.H
>
31
#include <
OpenFOAM/addToRunTimeSelectionTable.H
>
32
33
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35
namespace
Foam
36
{
37
defineTypeNameAndDebug
(sphericalCS, 0);
38
addToRunTimeSelectionTable
(coordinateSystem, sphericalCS, dictionary);
39
addToRunTimeSelectionTable
(coordinateSystem, sphericalCS, origRotation);
40
}
41
42
43
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44
45
Foam::sphericalCS::sphericalCS
(
const
bool
inDegrees)
46
:
47
coordinateSystem
(),
48
inDegrees_(inDegrees)
49
{}
50
51
52
Foam::sphericalCS::sphericalCS
53
(
54
const
coordinateSystem
& cs,
55
const
bool
inDegrees
56
)
57
:
58
coordinateSystem
(cs),
59
inDegrees_(inDegrees)
60
{}
61
62
63
Foam::sphericalCS::sphericalCS
64
(
65
const
word
&
name
,
66
const
coordinateSystem
& cs,
67
const
bool
inDegrees
68
)
69
:
70
coordinateSystem
(name, cs),
71
inDegrees_(inDegrees)
72
{}
73
74
75
Foam::sphericalCS::sphericalCS
76
(
77
const
word
& name,
78
const
point
& origin,
79
const
coordinateRotation
& cr,
80
const
bool
inDegrees
81
)
82
:
83
coordinateSystem
(name, origin, cr),
84
inDegrees_(inDegrees)
85
{}
86
87
88
Foam::sphericalCS::sphericalCS
89
(
90
const
word
& name,
91
const
point
& origin,
92
const
vector
& axis,
93
const
vector
& dirn,
94
const
bool
inDegrees
95
)
96
:
97
coordinateSystem
(name, origin, axis, dirn),
98
inDegrees_(inDegrees)
99
{}
100
101
102
Foam::sphericalCS::sphericalCS
103
(
104
const
word
& name,
105
const
dictionary
& dict
106
)
107
:
108
coordinateSystem
(name, dict),
109
inDegrees_(dict.
lookupOrDefault
<
Switch
>(
"degrees"
,
true
))
110
{}
111
112
113
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114
115
bool
Foam::sphericalCS::inDegrees
()
const
116
{
117
return
inDegrees_;
118
}
119
120
121
bool
&
Foam::sphericalCS::inDegrees
()
122
{
123
return
inDegrees_;
124
}
125
126
127
Foam::vector
Foam::sphericalCS::localToGlobal
128
(
129
const
vector
& local,
130
bool
translate
131
)
const
132
{
133
scalar r = local.
x
();
134
const
scalar theta
135
(
136
local.
y
()
137
* ( inDegrees_ ?
mathematicalConstant::pi
/180.0 : 1.0 )
138
);
139
const
scalar
phi
140
(
141
local.
z
()
142
* ( inDegrees_ ?
mathematicalConstant::pi
/180.0 : 1.0 )
143
);
144
145
return
coordinateSystem::localToGlobal
146
(
147
vector
(r*
cos
(theta)*
sin
(phi), r*
sin
(theta)*
sin
(phi), r*
cos
(phi)),
148
translate
149
);
150
}
151
152
153
Foam::tmp<Foam::vectorField>
Foam::sphericalCS::localToGlobal
154
(
155
const
vectorField
& local,
156
bool
translate
157
)
const
158
{
159
const
scalarField
r = local.
component
(
vector::X
);
160
const
scalarField
theta
161
(
162
local.
component
(
vector::Y
)
163
* ( inDegrees_ ?
mathematicalConstant::pi
/180.0 : 1.0 )
164
);
165
const
scalarField
phi
166
(
167
local.
component
(
vector::Z
)
168
* ( inDegrees_ ?
mathematicalConstant::pi
/180.0 : 1.0 )
169
);
170
171
vectorField
lc(local.
size
());
172
lc.
replace
(
vector::X
, r*
cos
(theta)*
sin
(phi));
173
lc.replace(
vector::Y
, r*
sin
(theta)*
sin
(phi));
174
lc.replace(
vector::Z
, r*
cos
(phi));
175
176
return
coordinateSystem::localToGlobal
(lc, translate);
177
}
178
179
180
Foam::vector
Foam::sphericalCS::globalToLocal
181
(
182
const
vector
& global,
183
bool
translate
184
)
const
185
{
186
const
vector
lc =
coordinateSystem::globalToLocal
(global, translate);
187
const
scalar r =
mag
(lc);
188
189
return
vector
190
(
191
r,
192
atan2
193
(
194
lc.
y
(), lc.
x
()
195
) * ( inDegrees_ ? 180.0/
mathematicalConstant::pi
: 1.0 ),
196
acos
197
(
198
lc.
z
()/(r + SMALL)
199
) * ( inDegrees_ ? 180.0/
mathematicalConstant::pi
: 1.0 )
200
);
201
}
202
203
204
Foam::tmp<Foam::vectorField>
Foam::sphericalCS::globalToLocal
205
(
206
const
vectorField
& global,
207
bool
translate
208
)
const
209
{
210
const
vectorField
lc =
coordinateSystem::globalToLocal
(global, translate);
211
const
scalarField
r =
mag
(lc);
212
213
tmp<vectorField>
tresult(
new
vectorField
(lc.
size
()));
214
vectorField
& result = tresult();
215
216
result.
replace
217
(
218
vector::X
, r
219
220
);
221
222
result.
replace
223
(
224
vector::Y
,
225
atan2
226
(
227
lc.
component
(
vector::Y
),
228
lc.
component
(
vector::X
)
229
) * ( inDegrees_ ? 180.0/
mathematicalConstant::pi
: 1.0 )
230
);
231
232
result.
replace
233
(
234
vector::Z
,
235
acos
236
(
237
lc.
component
(
vector::Z
)/(r + SMALL)
238
) * ( inDegrees_ ? 180.0/
mathematicalConstant::pi
: 1.0 )
239
);
240
241
return
tresult;
242
}
243
244
245
// ************************ vim: set sw=4 sts=4 et: ************************ //