Debian Codegraph @

src/atlas/trans/local/LegendrePolynomials.h

raw
1 /*
2 * (C) Copyright 2013 ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10
11 #pragma once
12
13 #include <cstddef>
14 #include <vector>
15
16 namespace atlas {
17 namespace trans {
18
19 //-----------------------------------------------------------------------------
20 // Routine to compute the Legendre polynomials in serial according to Belousov
21 // (using correction by Swarztrauber)
22 //
23 // Reference:
24 // S.L. Belousov, Tables of normalized associated Legendre Polynomials, Pergamon
25 // Press (1962)
26 // P.N. Swarztrauber, On computing the points and weights for Gauss-Legendre
27 // quadrature,
28 // SIAM J. Sci. Comput. Vol. 24 (3) pp. 945-954 (2002)
29 //
30 // Author of Fortran version:
31 // Mats Hamrud, Philippe Courtier, Nils Wedi *ECMWF*
32 //
33 // Ported to C++ by:
34 // Andreas Mueller *ECMWF*
35 //
36 void compute_zfn(const int trc, double zfn[]);
37
38
39 // Workspace to avoid repeated allocations
40 struct LegendrePolynomialsWorkspace {
41 LegendrePolynomialsWorkspace(int trc) {
42 vsin.reserve(trc+1);
43 vcos.reserve(trc+1);
44 }
45 std::vector<double> vsin;
46 std::vector<double> vcos;
47 };
48
49 void compute_legendre_polynomials_lat(const int trc, // truncation (in)
50 const double lat, // latitude in radians (in)
51 double legpol[], // legendre polynomials
52 double zfn[],
53 LegendrePolynomialsWorkspace& w); // workspace to avoid allocations
54
55 void compute_legendre_polynomials(
56 const int trc, // truncation (in)
57 const int nlats, // number of latitudes
58 const double lats[], // latitudes in radians (in)
59 double legendre_sym[], // values of associated Legendre functions, symmetric part
60 double legendre_asym[], // values of associated Legendre functions, asymmetric part
61 size_t leg_start_sym[], // start indices for different zonal wave numbers, symmetric part
62 size_t leg_start_asym[]); // start indices for different zonal wave numbers, asymmetric part
63
64 void compute_legendre_polynomials_all(const int trc, // truncation (in)
65 const int nlats, // number of latitudes
66 const double lats[], // latitudes in radians (in)
67 double legendre[]); // legendre polynomials for all latitudes
68
69 // --------------------------------------------------------------------------------------------------------------------
70
71 } // namespace trans
72 } // namespace atlas