|
Packit |
67cb25 |
/* specfunc/legendre_P.c
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* Copyright (C) 2009-2013 Patrick Alken
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
67cb25 |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
67cb25 |
* the Free Software Foundation; either version 3 of the License, or (at
|
|
Packit |
67cb25 |
* your option) any later version.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* This program is distributed in the hope that it will be useful, but
|
|
Packit |
67cb25 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
67cb25 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
67cb25 |
* General Public License for more details.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
67cb25 |
* along with this program; if not, write to the Free Software
|
|
Packit |
67cb25 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#include <config.h>
|
|
Packit |
67cb25 |
#include <stdlib.h>
|
|
Packit |
67cb25 |
#include <gsl/gsl_math.h>
|
|
Packit |
67cb25 |
#include <gsl/gsl_errno.h>
|
|
Packit |
67cb25 |
#include <gsl/gsl_sf_legendre.h>
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/*
|
|
Packit |
67cb25 |
* The routines in this module compute associated Legendre functions
|
|
Packit |
67cb25 |
* (ALFs) up to order and degree 2700, using the method described
|
|
Packit |
67cb25 |
* in
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* [1] S. A. Holmes and W. E. Featherstone, A unified approach
|
|
Packit |
67cb25 |
* to the Clenshaw summation and the recursive computation of very
|
|
Packit |
67cb25 |
* high degree and order normalised associated Legendre functions,
|
|
Packit |
67cb25 |
* Journal of Geodesy, 76, pg. 279-299, 2002.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* Further information on ALFs can be found in
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* [2] Abramowitz and Stegun, Handbook of Mathematical Functions,
|
|
Packit |
67cb25 |
* Chapter 8, 1972.
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
static void legendre_sqrts(const size_t lmax, double *array);
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#define LEGENDRE
|
|
Packit |
67cb25 |
#include "legendre_source.c"
|
|
Packit |
67cb25 |
#undef LEGENDRE
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#define LEGENDRE_DERIV
|
|
Packit |
67cb25 |
#include "legendre_source.c"
|
|
Packit |
67cb25 |
#undef LEGENDRE_DERIV
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#define LEGENDRE_DERIV_ALT
|
|
Packit |
67cb25 |
#include "legendre_source.c"
|
|
Packit |
67cb25 |
#undef LEGENDRE_DERIV_ALT
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#define LEGENDRE_DERIV2
|
|
Packit |
67cb25 |
#include "legendre_source.c"
|
|
Packit |
67cb25 |
#undef LEGENDRE_DERIV2
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
#define LEGENDRE_DERIV2_ALT
|
|
Packit |
67cb25 |
#include "legendre_source.c"
|
|
Packit |
67cb25 |
#undef LEGENDRE_DERIV2_ALT
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* number of P_{lm} functions for a given lmax */
|
|
Packit |
67cb25 |
size_t
|
|
Packit |
67cb25 |
gsl_sf_legendre_nlm(const size_t lmax)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
return ((lmax + 1) * (lmax + 2) / 2);
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/*
|
|
Packit |
67cb25 |
gsl_sf_legendre_array_n()
|
|
Packit |
67cb25 |
This routine returns the minimum result_array[] size needed
|
|
Packit |
67cb25 |
for a given lmax
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
size_t
|
|
Packit |
67cb25 |
gsl_sf_legendre_array_n(const size_t lmax)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
size_t nlm = gsl_sf_legendre_nlm(lmax);
|
|
Packit |
67cb25 |
size_t nsqrt = 2 * lmax + 2; /* extra room to precompute sqrt factors */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
return (nlm + nsqrt);
|
|
Packit |
67cb25 |
} /* gsl_sf_legendre_array_n() */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/*
|
|
Packit |
67cb25 |
gsl_sf_legendre_array_index()
|
|
Packit |
67cb25 |
This routine computes the index into a result_array[] corresponding
|
|
Packit |
67cb25 |
to a given (l,m)
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
size_t
|
|
Packit |
67cb25 |
gsl_sf_legendre_array_index(const size_t l, const size_t m)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
return (l * (l + 1) / 2 + m);
|
|
Packit |
67cb25 |
} /* gsl_sf_legendre_array_index() */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/*********************************************************
|
|
Packit |
67cb25 |
* INTERNAL ROUTINES *
|
|
Packit |
67cb25 |
*********************************************************/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/*
|
|
Packit |
67cb25 |
legendre_sqrts()
|
|
Packit |
67cb25 |
Precompute square root factors needed for Legendre recurrence.
|
|
Packit |
67cb25 |
On output, array[i] = sqrt(i)
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
static void
|
|
Packit |
67cb25 |
legendre_sqrts(const size_t lmax, double *array)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
size_t l;
|
|
Packit |
67cb25 |
for (l = 0; l <= 2 * lmax + 1; ++l)
|
|
Packit |
67cb25 |
array[l] = sqrt((double) l);
|
|
Packit |
67cb25 |
}
|