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