140# pragma warning (disable: 4127 4701)
147 vector<Math::real>& SphericalEngine::sqrttable() {
148 static vector<real> sqrttable(0);
152 template<
bool gradp, SphericalEngine::normalization norm,
int L>
154 real x, real y, real z, real a,
155 real& gradx, real& grady, real& gradz)
157 static_assert(L > 0,
"L must be positive");
158 static_assert(norm ==
FULL || norm ==
SCHMIDT,
"Unknown normalization");
159 int N = c[0].
nmx(), M = c[0].
mmx();
163 cl = p != 0 ? x / p : 1,
164 sl = p != 0 ? y / p : 0,
166 t = r != 0 ? z / r : 0,
167 u = r != 0 ? fmax(p / r, eps()) : 1,
175 real vc = 0, vc2 = 0, vs = 0, vs2 = 0;
178 real vrc = 0, vrc2 = 0, vrs = 0, vrs2 = 0;
179 real vtc = 0, vtc2 = 0, vts = 0, vts2 = 0;
180 real vlc = 0, vlc2 = 0, vls = 0, vls2 = 0;
182 const vector<real>& root( sqrttable() );
183 for (
int m = M; m >= 0; --m) {
186 wc = 0, wc2 = 0, ws = 0, ws2 = 0,
187 wrc = 0, wrc2 = 0, wrs = 0, wrs2 = 0,
188 wtc = 0, wtc2 = 0, wts = 0, wts2 = 0;
189 for (
int l = 0; l < L; ++l)
190 k[l] = c[l].index(N, m) + 1;
191 for (
int n = N; n >= m; --n) {
195 w = root[2 * n + 1] / (root[n - m + 1] * root[n + m + 1]);
196 Ax = q * w * root[2 * n + 3];
198 B = - q2 * root[2 * n + 5] /
199 (w * root[n - m + 2] * root[n + m + 2]);
202 w = root[n - m + 1] * root[n + m + 1];
203 Ax = q * (2 * n + 1) / w;
205 B = - q2 * w / (root[n - m + 2] * root[n + m + 2]);
210 for (
int l = 1; l < L; ++l)
211 R += c[l].Cv(--k[l], n, m, f[l]);
213 w = A * wc + B * wc2 + R; wc2 = wc; wc = w;
215 w = A * wrc + B * wrc2 + (n + 1) * R; wrc2 = wrc; wrc = w;
216 w = A * wtc + B * wtc2 - u*Ax * wc2; wtc2 = wtc; wtc = w;
220 for (
int l = 1; l < L; ++l)
221 R += c[l].Sv(k[l], n, m, f[l]);
223 w = A * ws + B * ws2 + R; ws2 = ws; ws = w;
225 w = A * wrs + B * wrs2 + (n + 1) * R; wrs2 = wrs; wrs = w;
226 w = A * wts + B * wts2 - u*Ax * ws2; wts2 = wts; wts = w;
236 v = root[2] * root[2 * m + 3] / root[m + 1];
238 B = - v * root[2 * m + 5] / (root[8] * root[m + 2]) * uq2;
241 v = root[2] * root[2 * m + 1] / root[m + 1];
243 B = - v * root[2 * m + 3] / (root[8] * root[m + 2]) * uq2;
247 v = A * vc + B * vc2 + wc ; vc2 = vc ; vc = v;
248 v = A * vs + B * vs2 + ws ; vs2 = vs ; vs = v;
251 wtc += m * tu * wc; wts += m * tu * ws;
252 v = A * vrc + B * vrc2 + wrc; vrc2 = vrc; vrc = v;
253 v = A * vrs + B * vrs2 + wrs; vrs2 = vrs; vrs = v;
254 v = A * vtc + B * vtc2 + wtc; vtc2 = vtc; vtc = v;
255 v = A * vts + B * vts2 + wts; vts2 = vts; vts = v;
256 v = A * vlc + B * vlc2 + m*ws; vlc2 = vlc; vlc = v;
257 v = A * vls + B * vls2 - m*wc; vls2 = vls; vls = v;
264 B = - root[15]/2 * uq2;
268 B = - root[3]/2 * uq2;
273 vc = qs * (wc + A * (cl * vc + sl * vs ) + B * vc2);
280 vrc = - qs * (wrc + A * (cl * vrc + sl * vrs) + B * vrc2);
281 vtc = qs * (wtc + A * (cl * vtc + sl * vts) + B * vtc2);
282 vlc = qs / u * ( A * (cl * vlc + sl * vls) + B * vlc2);
289 gradx = cl * (u * vrc + t * vtc) - sl * vlc;
290 grady = sl * (u * vrc + t * vtc) + cl * vlc;
291 gradz = t * vrc - u * vtc ;
296 template<
bool gradp, SphericalEngine::normalization norm,
int L>
298 real p, real z, real a) {
300 static_assert(L > 0,
"L must be positive");
301 static_assert(norm ==
FULL || norm ==
SCHMIDT,
"Unknown normalization");
302 int N = c[0].
nmx(), M = c[0].
mmx();
306 t = r != 0 ? z / r : 0,
307 u = r != 0 ? fmax(p / r, eps()) : 1,
314 const vector<real>& root( sqrttable() );
315 for (
int m = M; m >= 0; --m) {
318 wc = 0, wc2 = 0, ws = 0, ws2 = 0,
319 wrc = 0, wrc2 = 0, wrs = 0, wrs2 = 0,
320 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 vector<real>& root( sqrttable() );
377 int L = max(2 * N + 5, 15) + 1, oldL = int(root.size());
381 for (
int l = oldL; l < L; ++l)
382 root[l] = sqrt(real(l));
390 if (!((
N >= M && M >= 0) || (
N == -1 && M == -1)))
396 Utility::readarray<int, int, false>(stream, nm, 2);
397 int N0 = nm[0], M0 = nm[1];
398 if (!((N0 >= M0 && M0 >= 0) || (N0 == -1 && M0 == -1)))
402 N = truncate ? min(
N, N0) : N0;
403 M = truncate ? min(M, M0) : M0;
409 Utility::readarray<double, real, false>(stream, C);
410 if (skip) stream.seekg(streamoff(skip), ios::cur);
411 Utility::readarray<double, real, false>(stream, S);
412 if (skip) stream.seekg(streamoff(skip), ios::cur);
414 for (
int m = 0, k = 0; m <= M; ++m) {
415 Utility::readarray<double, real, false>(stream, &C[k],
N + 1 - m);
416 stream.seekg((N0 -
N) *
sizeof(
double), ios::cur);
419 if (skip) stream.seekg(streamoff(skip), ios::cur);
420 for (
int m = 1, k = 0; m <= M; ++m) {
421 Utility::readarray<double, real, false>(stream, &S[k],
N + 1 - m);
422 stream.seekg((N0 -
N) *
sizeof(
double), ios::cur);
425 if (skip) stream.seekg(streamoff(skip), ios::cur);
432 SphericalEngine::Value<true, SphericalEngine::FULL, 1>
433 (
const coeff[],
const real[], real, real, real, real, real&, real&, real&);
435 SphericalEngine::Value<false, SphericalEngine::FULL, 1>
436 (
const coeff[],
const real[], real, real, real, real, real&, real&, real&);
438 SphericalEngine::Value<true, SphericalEngine::SCHMIDT, 1>
439 (
const coeff[],
const real[], real, real, real, real, real&, real&, real&);
441 SphericalEngine::Value<false, SphericalEngine::SCHMIDT, 1>
442 (
const coeff[],
const real[], real, real, real, real, real&, real&, real&);
445 SphericalEngine::Value<true, SphericalEngine::FULL, 2>
446 (
const coeff[],
const real[], real, real, real, real, real&, real&, real&);
448 SphericalEngine::Value<false, SphericalEngine::FULL, 2>
449 (
const coeff[],
const real[], real, real, real, real, real&, real&, real&);
451 SphericalEngine::Value<true, SphericalEngine::SCHMIDT, 2>
452 (
const coeff[],
const real[], real, real, real, real, real&, real&, real&);
454 SphericalEngine::Value<false, SphericalEngine::SCHMIDT, 2>
455 (
const coeff[],
const real[], real, real, real, real, real&, real&, real&);
458 SphericalEngine::Value<true, SphericalEngine::FULL, 3>
459 (
const coeff[],
const real[], real, real, real, real, real&, real&, real&);
461 SphericalEngine::Value<false, SphericalEngine::FULL, 3>
462 (
const coeff[],
const real[], real, real, real, real, real&, real&, real&);
464 SphericalEngine::Value<true, SphericalEngine::SCHMIDT, 3>
465 (
const coeff[],
const real[], real, real, real, real, real&, real&, real&);
467 SphericalEngine::Value<false, SphericalEngine::SCHMIDT, 3>
468 (
const coeff[],
const real[], real, real, real, real, real&, real&, real&);
471 SphericalEngine::Circle<true, SphericalEngine::FULL, 1>
472 (
const coeff[],
const real[], real, real, real);
474 SphericalEngine::Circle<false, SphericalEngine::FULL, 1>
475 (
const coeff[],
const real[], real, real, real);
477 SphericalEngine::Circle<true, SphericalEngine::SCHMIDT, 1>
478 (
const coeff[],
const real[], real, real, real);
480 SphericalEngine::Circle<false, SphericalEngine::SCHMIDT, 1>
481 (
const coeff[],
const real[], real, real, real);
484 SphericalEngine::Circle<true, SphericalEngine::FULL, 2>
485 (
const coeff[],
const real[], real, real, real);
487 SphericalEngine::Circle<false, SphericalEngine::FULL, 2>
488 (
const coeff[],
const real[], real, real, real);
490 SphericalEngine::Circle<true, SphericalEngine::SCHMIDT, 2>
491 (
const coeff[],
const real[], real, real, real);
493 SphericalEngine::Circle<false, SphericalEngine::SCHMIDT, 2>
494 (
const coeff[],
const real[], real, real, real);
497 SphericalEngine::Circle<true, SphericalEngine::FULL, 3>
498 (
const coeff[],
const real[], real, real, real);
500 SphericalEngine::Circle<false, SphericalEngine::FULL, 3>
501 (
const coeff[],
const real[], real, real, real);
503 SphericalEngine::Circle<true, SphericalEngine::SCHMIDT, 3>
504 (
const coeff[],
const real[], real, real, real);
506 SphericalEngine::Circle<false, SphericalEngine::SCHMIDT, 3>
507 (
const coeff[],
const real[], real, real, real);
Header for GeographicLib::CircularEngine class.
#define GEOGRAPHICLIB_EXPORT
Header for GeographicLib::SphericalEngine class.
Header for GeographicLib::Utility class.
Spherical harmonic sums for a circle.
Exception handling for GeographicLib.
Package up coefficients for SphericalEngine.
Math::real Sv(int k) const
static int Csize(int N, int M)
static int Ssize(int N, int M)
static void readcoeffs(std::istream &stream, int &N, int &M, std::vector< real > &C, std::vector< real > &S, bool truncate=false)
Math::real Cv(int k) const
static Math::real Value(const coeff c[], const real f[], real x, real y, real z, real a, real &gradx, real &grady, real &gradz)
static void RootTable(int N)
static CircularEngine Circle(const coeff c[], const real f[], real p, real z, real a)
static std::string str(T x, int p=-1)
Namespace for GeographicLib.