00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "sphericalCS.H"
00027
00028 #include <OpenFOAM/one.H>
00029 #include <OpenFOAM/Switch.H>
00030 #include <OpenFOAM/mathematicalConstants.H>
00031 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00032
00033
00034
00035 namespace Foam
00036 {
00037 defineTypeNameAndDebug(sphericalCS, 0);
00038 addToRunTimeSelectionTable(coordinateSystem, sphericalCS, dictionary);
00039 addToRunTimeSelectionTable(coordinateSystem, sphericalCS, origRotation);
00040 }
00041
00042
00043
00044
00045 Foam::sphericalCS::sphericalCS(const bool inDegrees)
00046 :
00047 coordinateSystem(),
00048 inDegrees_(inDegrees)
00049 {}
00050
00051
00052 Foam::sphericalCS::sphericalCS
00053 (
00054 const coordinateSystem& cs,
00055 const bool inDegrees
00056 )
00057 :
00058 coordinateSystem(cs),
00059 inDegrees_(inDegrees)
00060 {}
00061
00062
00063 Foam::sphericalCS::sphericalCS
00064 (
00065 const word& name,
00066 const coordinateSystem& cs,
00067 const bool inDegrees
00068 )
00069 :
00070 coordinateSystem(name, cs),
00071 inDegrees_(inDegrees)
00072 {}
00073
00074
00075 Foam::sphericalCS::sphericalCS
00076 (
00077 const word& name,
00078 const point& origin,
00079 const coordinateRotation& cr,
00080 const bool inDegrees
00081 )
00082 :
00083 coordinateSystem(name, origin, cr),
00084 inDegrees_(inDegrees)
00085 {}
00086
00087
00088 Foam::sphericalCS::sphericalCS
00089 (
00090 const word& name,
00091 const point& origin,
00092 const vector& axis,
00093 const vector& dirn,
00094 const bool inDegrees
00095 )
00096 :
00097 coordinateSystem(name, origin, axis, dirn),
00098 inDegrees_(inDegrees)
00099 {}
00100
00101
00102 Foam::sphericalCS::sphericalCS
00103 (
00104 const word& name,
00105 const dictionary& dict
00106 )
00107 :
00108 coordinateSystem(name, dict),
00109 inDegrees_(dict.lookupOrDefault<Switch>("degrees", true))
00110 {}
00111
00112
00113
00114
00115 bool Foam::sphericalCS::inDegrees() const
00116 {
00117 return inDegrees_;
00118 }
00119
00120
00121 bool& Foam::sphericalCS::inDegrees()
00122 {
00123 return inDegrees_;
00124 }
00125
00126
00127 Foam::vector Foam::sphericalCS::localToGlobal
00128 (
00129 const vector& local,
00130 bool translate
00131 ) const
00132 {
00133 scalar r = local.x();
00134 const scalar theta
00135 (
00136 local.y()
00137 * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
00138 );
00139 const scalar phi
00140 (
00141 local.z()
00142 * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
00143 );
00144
00145 return coordinateSystem::localToGlobal
00146 (
00147 vector(r*cos(theta)*sin(phi), r*sin(theta)*sin(phi), r*cos(phi)),
00148 translate
00149 );
00150 }
00151
00152
00153 Foam::tmp<Foam::vectorField> Foam::sphericalCS::localToGlobal
00154 (
00155 const vectorField& local,
00156 bool translate
00157 ) const
00158 {
00159 const scalarField r = local.component(vector::X);
00160 const scalarField theta
00161 (
00162 local.component(vector::Y)
00163 * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
00164 );
00165 const scalarField phi
00166 (
00167 local.component(vector::Z)
00168 * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 )
00169 );
00170
00171 vectorField lc(local.size());
00172 lc.replace(vector::X, r*cos(theta)*sin(phi));
00173 lc.replace(vector::Y, r*sin(theta)*sin(phi));
00174 lc.replace(vector::Z, r*cos(phi));
00175
00176 return coordinateSystem::localToGlobal(lc, translate);
00177 }
00178
00179
00180 Foam::vector Foam::sphericalCS::globalToLocal
00181 (
00182 const vector& global,
00183 bool translate
00184 ) const
00185 {
00186 const vector lc = coordinateSystem::globalToLocal(global, translate);
00187 const scalar r = mag(lc);
00188
00189 return vector
00190 (
00191 r,
00192 atan2
00193 (
00194 lc.y(), lc.x()
00195 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 ),
00196 acos
00197 (
00198 lc.z()/(r + SMALL)
00199 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
00200 );
00201 }
00202
00203
00204 Foam::tmp<Foam::vectorField> Foam::sphericalCS::globalToLocal
00205 (
00206 const vectorField& global,
00207 bool translate
00208 ) const
00209 {
00210 const vectorField lc = coordinateSystem::globalToLocal(global, translate);
00211 const scalarField r = mag(lc);
00212
00213 tmp<vectorField> tresult(new vectorField(lc.size()));
00214 vectorField& result = tresult();
00215
00216 result.replace
00217 (
00218 vector::X, r
00219
00220 );
00221
00222 result.replace
00223 (
00224 vector::Y,
00225 atan2
00226 (
00227 lc.component(vector::Y),
00228 lc.component(vector::X)
00229 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
00230 );
00231
00232 result.replace
00233 (
00234 vector::Z,
00235 acos
00236 (
00237 lc.component(vector::Z)/(r + SMALL)
00238 ) * ( inDegrees_ ? 180.0/mathematicalConstant::pi : 1.0 )
00239 );
00240
00241 return tresult;
00242 }
00243
00244
00245