137 #if defined(_MSC_VER)
140 # pragma warning (disable: 4127 4701)
143 namespace GeographicLib {
148 pow(
real(numeric_limits<real>::radix),
149 -3 * numeric_limits<real>::max_exponent / 5);
151 numeric_limits<real>::epsilon() * sqrt(numeric_limits<real>::epsilon());
153 const vector<Math::real> SphericalEngine::Z_(0);
154 vector<Math::real> SphericalEngine::root_(0);
156 template<
bool gradp, SphericalEngine::normalization norm,
int L>
158 real x, real y, real z, real a,
159 real& gradx, real& grady, real& gradz)
162 STATIC_ASSERT(norm == FULL || norm == SCHMIDT,
"Unknown normalization");
163 int N = c[0].nmx(), M = c[0].mmx();
171 u = r ? max(p / r, eps_) : 1,
179 real vc = 0, vc2 = 0, vs = 0, vs2 = 0;
182 real vrc = 0, vrc2 = 0, vrs = 0, vrs2 = 0;
183 real vtc = 0, vtc2 = 0, vts = 0, vts2 = 0;
184 real vlc = 0, vlc2 = 0, vls = 0, vls2 = 0;
186 for (
int m = M; m >= 0; --m) {
188 real wc = 0, wc2 = 0, ws = 0, ws2 = 0;
189 real wrc = 0, wrc2 = 0, wrs = 0, wrs2 = 0;
190 real wtc = 0, wtc2 = 0, wts = 0, wts2 = 0;
191 for (
int l = 0; l < L; ++l)
192 k[l] = c[l].index(N, m) + 1;
193 for (
int n = N; n >= m; --n) {
197 w = root_[2 * n + 1] / (root_[n - m + 1] * root_[n + m + 1]);
198 Ax = q * w * root_[2 * n + 3];
200 B = - q2 * root_[2 * n + 5] /
201 (w * root_[n - m + 2] * root_[n + m + 2]);
204 w = root_[n - m + 1] * root_[n + m + 1];
205 Ax = q * (2 * n + 1) / w;
207 B = - q2 * w / (root_[n - m + 2] * root_[n + m + 2]);
212 for (
int l = 1; l < L; ++l)
213 R += c[l].Cv(--k[l], n, m, f[l]);
215 w = A * wc + B * wc2 + R; wc2 = wc; wc = w;
217 w = A * wrc + B * wrc2 + (n + 1) * R; wrc2 = wrc; wrc = w;
218 w = A * wtc + B * wtc2 - u*Ax * wc2; wtc2 = wtc; wtc = w;
222 for (
int l = 1; l < L; ++l)
223 R += c[l].Sv(k[l], n, m, f[l]);
225 w = A * ws + B * ws2 + R; ws2 = ws; ws = w;
227 w = A * wrs + B * wrs2 + (n + 1) * R; wrs2 = wrs; wrs = w;
228 w = A * wts + B * wts2 - u*Ax * ws2; wts2 = wts; wts = w;
238 v = root_[2] * root_[2 * m + 3] / root_[m + 1];
240 B = - v * root_[2 * m + 5] / (root_[8] * root_[m + 2]) * uq2;
243 v = root_[2] * root_[2 * m + 1] / root_[m + 1];
245 B = - v * root_[2 * m + 3] / (root_[8] * root_[m + 2]) * uq2;
249 v = A * vc + B * vc2 + wc ; vc2 = vc ; vc = v;
250 v = A * vs + B * vs2 + ws ; vs2 = vs ; vs = v;
253 wtc += m * tu * wc; wts += m * tu * ws;
254 v = A * vrc + B * vrc2 + wrc; vrc2 = vrc; vrc = v;
255 v = A * vrs + B * vrs2 + wrs; vrs2 = vrs; vrs = v;
256 v = A * vtc + B * vtc2 + wtc; vtc2 = vtc; vtc = v;
257 v = A * vts + B * vts2 + wts; vts2 = vts; vts = v;
258 v = A * vlc + B * vlc2 + m*ws; vlc2 = vlc; vlc = v;
259 v = A * vls + B * vls2 - m*wc; vls2 = vls; vls = v;
266 B = - root_[15]/2 * uq2;
270 B = - root_[3]/2 * uq2;
275 vc = qs * (wc + A * (cl * vc + sl * vs ) + B * vc2);
282 vrc = - qs * (wrc + A * (cl * vrc + sl * vrs) + B * vrc2);
283 vtc = qs * (wtc + A * (cl * vtc + sl * vts) + B * vtc2);
284 vlc = qs / u * ( A * (cl * vlc + sl * vls) + B * vlc2);
291 gradx = cl * (u * vrc + t * vtc) - sl * vlc;
292 grady = sl * (u * vrc + t * vtc) + cl * vlc;
293 gradz = t * vrc - u * vtc ;
298 template<
bool gradp, SphericalEngine::normalization norm,
int L>
300 real p, real z, real a) {
303 STATIC_ASSERT(norm == FULL || norm == SCHMIDT,
"Unknown normalization");
304 int N = c[0].
nmx(), M = c[0].
mmx();
309 u = r ? max(p / r, eps_) : 1,
316 for (
int m = M; m >= 0; --m) {
318 real wc = 0, wc2 = 0, ws = 0, ws2 = 0;
319 real wrc = 0, wrc2 = 0, wrs = 0, wrs2 = 0;
320 real wtc = 0, wtc2 = 0, wts = 0, wts2 = 0;
321 for (
int l = 0; l < L; ++l)
322 k[l] = c[l].index(N, m) + 1;
323 for (
int n = N; n >= m; --n) {
327 w = root_[2 * n + 1] / (root_[n - m + 1] * root_[n + m + 1]);
328 Ax = q * w * root_[2 * n + 3];
330 B = - q2 * root_[2 * n + 5] /
331 (w * root_[n - m + 2] * root_[n + m + 2]);
334 w = root_[n - m + 1] * root_[n + m + 1];
335 Ax = q * (2 * n + 1) / w;
337 B = - q2 * w / (root_[n - m + 2] * root_[n + m + 2]);
342 for (
int l = 1; l < L; ++l)
343 R += c[l].Cv(--k[l], n, m, f[l]);
345 w = A * wc + B * wc2 + R; wc2 = wc; wc = w;
347 w = A * wrc + B * wrc2 + (n + 1) * R; wrc2 = wrc; wrc = w;
348 w = A * wtc + B * wtc2 - u*Ax * wc2; wtc2 = wtc; wtc = w;
352 for (
int l = 1; l < L; ++l)
353 R += c[l].Sv(k[l], n, m, f[l]);
355 w = A * ws + B * ws2 + R; ws2 = ws; ws = w;
357 w = A * wrs + B * wrs2 + (n + 1) * R; wrs2 = wrs; wrs = w;
358 w = A * wts + B * wts2 - u*Ax * ws2; wts2 = wts; wts = w;
363 circ.SetCoeff(m, wc, ws);
366 wtc += m * tu * wc; wts += m * tu * ws;
367 circ.SetCoeff(m, wc, ws, wrc, wrs, wtc, wts);
376 int L = max(2 * N + 5, 15) + 1, oldL = int(root_.size());
380 for (
int l = oldL; l < L; ++l)
381 root_[l] = sqrt(
real(l));
385 std::vector<real>& C,
386 std::vector<real>& S) {
388 Utility::readarray<int, int, false>(stream, nm, 2);
389 N = nm[0]; M = nm[1];
390 if (!(N >= M && M >= -1 && N * M >= 0))
395 Utility::readarray<double, real, false>(stream, C);
397 Utility::readarray<double, real, false>(stream, S);
403 SphericalEngine::Value<true, SphericalEngine::FULL, 1>
406 SphericalEngine::Value<false, SphericalEngine::FULL, 1>
409 SphericalEngine::Value<true, SphericalEngine::SCHMIDT, 1>
412 SphericalEngine::Value<false, SphericalEngine::SCHMIDT, 1>
416 SphericalEngine::Value<true, SphericalEngine::FULL, 2>
419 SphericalEngine::Value<false, SphericalEngine::FULL, 2>
422 SphericalEngine::Value<true, SphericalEngine::SCHMIDT, 2>
425 SphericalEngine::Value<false, SphericalEngine::SCHMIDT, 2>
429 SphericalEngine::Value<true, SphericalEngine::FULL, 3>
432 SphericalEngine::Value<false, SphericalEngine::FULL, 3>
435 SphericalEngine::Value<true, SphericalEngine::SCHMIDT, 3>
438 SphericalEngine::Value<false, SphericalEngine::SCHMIDT, 3>
442 SphericalEngine::Circle<true, SphericalEngine::FULL, 1>
445 SphericalEngine::Circle<false, SphericalEngine::FULL, 1>
448 SphericalEngine::Circle<true, SphericalEngine::SCHMIDT, 1>
451 SphericalEngine::Circle<false, SphericalEngine::SCHMIDT, 1>
455 SphericalEngine::Circle<true, SphericalEngine::FULL, 2>
458 SphericalEngine::Circle<false, SphericalEngine::FULL, 2>
461 SphericalEngine::Circle<true, SphericalEngine::SCHMIDT, 2>
464 SphericalEngine::Circle<false, SphericalEngine::SCHMIDT, 2>
468 SphericalEngine::Circle<true, SphericalEngine::FULL, 3>
471 SphericalEngine::Circle<false, SphericalEngine::FULL, 3>
474 SphericalEngine::Circle<true, SphericalEngine::SCHMIDT, 3>
477 SphericalEngine::Circle<false, SphericalEngine::SCHMIDT, 3>
#define GEOGRAPHICLIB_EXPORT
GeographicLib::Math::real real
Math::real Cv(int k) const
static int Ssize(int N, int M)
Header for GeographicLib::Utility class.
static CircularEngine Circle(const coeff c[], const real f[], real p, real z, real a)
static void RootTable(int N)
static void readcoeffs(std::istream &stream, int &N, int &M, std::vector< real > &C, std::vector< real > &S)
Package up coefficients for SphericalEngine.
Math::real Sv(int k) const
static std::string str(T x, int p=-1)
#define STATIC_ASSERT(cond, reason)
Header for GeographicLib::CircularEngine class.
Spherical harmonic sums for a circle.
Exception handling for GeographicLib.
static int Csize(int N, int M)
static Math::real Value(const coeff c[], const real f[], real x, real y, real z, real a, real &gradx, real &grady, real &gradz)
Header for GeographicLib::SphericalEngine class.