GeographicLib
1.21
|
The evaluation engine for SphericalHarmonic. More...
#include <GeographicLib/SphericalEngine.hpp>
Classes | |
class | coeff |
Package up coefficients for SphericalEngine. More... | |
Public Types | |
enum | normalization { FULL, SCHMIDT } |
Static Public Member Functions | |
template<bool gradp, normalization norm, int L> | |
static Math::real | Value (const coeff c[], const real f[], real x, real y, real z, real a, real &gradx, real &grady, real &gradz) throw () |
template<bool gradp, normalization norm, int L> | |
static CircularEngine | Circle (const coeff c[], const real f[], real p, real z, real a) |
static void | RootTable (int N) |
static void | ClearRootTable () |
Friends | |
class | CircularEngine |
The evaluation engine for SphericalHarmonic.
This serves as the backend to SphericalHarmonic, SphericalHarmonic1, and SphericalHarmonic2. Typically end-users will not have to access this class directly.
See SphericalEngine.cpp for more information on the implementation.
Example of use:
// Example of using the GeographicLib::SphericalEngine class // $Id: 08fe16ba3619311b15fc58956511a88c37886f91 $ #include <iostream> #include <exception> #include <vector> #include <GeographicLib/SphericalEngine.hpp> using namespace std; using namespace GeographicLib; int main() { // See also example-SphericHarmonic.cpp try { int N = 3; // The maxium degree double ca[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; // cosine coefficients vector<double> C(ca, ca + (N + 1) * (N + 2) / 2); double sa[] = {6, 5, 4, 3, 2, 1}; // sine coefficients vector<double> S(sa, sa + N * (N + 1) / 2); SphericalEngine::coeff c[1]; c[0] = SphericalEngine::coeff(C, S, N); double f[] = {1}; double x = 2, y = 3, z = 1, a = 1; double v, vx, vy, vz; v = SphericalEngine::Value<true, SphericalEngine::FULL, 1> (c, f, x, y, z, a, vx, vy, vz); cout << v << " " << vx << " " << vy << " " << vz << "\n"; } catch (const exception& e) { cerr << "Caught exception: " << e.what() << "\n"; return 1; } return 0; }
Supported normalizations for associated Legendre polynomials.
FULL |
Fully normalized associated Legendre polynomials. See SphericalHarmonic::FULL for documentation. |
SCHMIDT |
Schmidt semi-normalized associated Legendre polynomials. See SphericalHarmonic::SCHMIDT for documentation. |
Definition at line 58 of file SphericalEngine.hpp.
Math::real GeographicLib::SphericalEngine::Value | ( | const coeff | c[], |
const real | f[], | ||
real | x, | ||
real | y, | ||
real | z, | ||
real | a, | ||
real & | gradx, | ||
real & | grady, | ||
real & | gradz | ||
) | throw () [static] |
Evaluate a spherical harmonic sum and its gradient.
gradp | should the gradient be calculated. |
norm | the normalization for the associated Legendre polynomials. |
L | the number of terms in the coefficients. |
[in] | c | an array of coeff objects. |
[in] | f | array of coefficient multipliers. f[0] should be 1. |
[in] | x | the x component of the cartesian position. |
[in] | y | the y component of the cartesian position. |
[in] | z | the z component of the cartesian position. |
[in] | a | the normalizing radius. |
[out] | gradx | the x component of the gradient. |
[out] | grady | the y component of the gradient. |
[out] | gradz | the z component of the gradient. |
See the SphericalHarmonic class for the definition of the sum. The coefficients used by this function are, for example, c[0].Cv + f[1] * c[1].Cv + ... + f[L-1] * c[L-1].Cv. (Note that f[0] is not used.) The upper limits on the sum are determined by c[0].nmx() and c[0].mmx(); these limits apply to all the components of the coefficients. The parameters gradp, norm, and L are template parameters, to allow more optimization to be done at compile time.
Clenshaw summation is used which permits the evaluation of the sum without the need to allocate temporary arrays. Thus this function never throws an exception.
Definition at line 159 of file SphericalEngine.cpp.
References STATIC_ASSERT.
CircularEngine GeographicLib::SphericalEngine::Circle | ( | const coeff | c[], |
const real | f[], | ||
real | p, | ||
real | z, | ||
real | a | ||
) | [static] |
Create a CircularEngine object
gradp | should the gradient be calculated. |
norm | the normalization for the associated Legendre polynomials. |
L | the number of terms in the coefficients. |
[in] | c | an array of coeff objects. |
[in] | f | array of coefficient multipliers. f[0] should be 1. |
[in] | p | the radius of the circle = sqrt(x2 + y2). |
[in] | z | the height of the circle. |
[in] | a | the normalizing radius. |
If you need to evaluate the spherical harmonic sum for several points with constant f, p = sqrt(x2 + y2), z, and a, it is more efficient to construct call SphericalEngine::Circle to give a CircularEngine object and then call CircularEngine::operator()() with arguments x/p and y/p.
Definition at line 298 of file SphericalEngine.cpp.
References STATIC_ASSERT, GeographicLib::SphericalEngine::coeff::nmx(), GeographicLib::SphericalEngine::coeff::mmx(), GeographicLib::SphericalEngine::coeff::Cv(), and GeographicLib::SphericalEngine::coeff::Sv().
void GeographicLib::SphericalEngine::RootTable | ( | int | N | ) | [static] |
Check that the static table of square roots is big enough and enlarge it if necessary.
[in] | N | the maximum degree to be used in SphericalEngine. |
Typically, there's no need for an end-user to call this routine, because the constructors for SphericalEngine::coeff do so. However, since this updates a static table, there's a possible race condition in a multi-threaded environment. Because this routine does nothing if the table is already large enough, one way to avoid race conditions is to call this routine at program start up (when it's still single threaded), supplying the largest degree that your program will use. E.g.,
suffices to accommodate extant magnetic and gravity models.
Definition at line 372 of file SphericalEngine.cpp.
Referenced by GeographicLib::SphericalEngine::coeff::coeff().
static void GeographicLib::SphericalEngine::ClearRootTable | ( | ) | [inline, static] |
Clear the static table of square roots and release the memory. Call this only when you are sure you no longer will be using SphericalEngine. Your program will crash if you call SphericalEngine after calling this routine. It's safest not to call this routine at all. (The space used by the table is modest.)
Definition at line 350 of file SphericalEngine.hpp.
friend class CircularEngine [friend] |
Definition at line 46 of file SphericalEngine.hpp.