LALSimulation  5.4.0.1-fe68b98
LALSimNRSurrogateUtilities.h
Go to the documentation of this file.
1 /* Copyright (C) 2018 Jonathan Blackman
2  * Utility functions that are useful for evaluating NR surrogates.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with with program; see the file COPYING. If not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17  * MA 02110-1301 USA
18  */
19 
20 #include <math.h>
21 #include <lal/XLALError.h>
22 #include <lal/Units.h>
23 #include <gsl/gsl_math.h>
24 #include <gsl/gsl_blas.h>
25 
26 #ifdef __GNUC__
27 #define UNUSED __attribute__ ((unused))
28 #else
29 #define UNUSED
30 #endif
31 
32 /**
33  * Structure for a multi-modal waveform. Can store any set of modes.
34  */
35 typedef struct tagMultiModalWaveform {
36  REAL8 phiRef; /**< orbital phase at reference pt. */
37  int n_modes; /**< Number of modes */
38  int n_times; /**< Number of time samples in each mode */
39  int *lvals; /**< The ell values of each mode (n_modes entries) */
40  int *mvals; /**< The m values of each mode (n_modes entries) */
41  gsl_vector **modes_real_part; /**< The real part of each mode - n_modes vectors of length n_times */
42  gsl_vector **modes_imag_part; /**< The imaginary part of each mode - n_modes vectors of length n_times */
44 
45 /**
46  * Helper structure for computing WignerDMatrices, which require x(t)^n for many values of n.
47  */
48 typedef struct tagRealPowers {
49  int LMax; /**< Maximum L; powers computed depend on LMax. */
50  int n_entries; /**< Number of entries in **powers. */
51  int n_times; /**< Length of each entry. */
52  gsl_vector **powers; /**< The data; x^n. */
53 } RealPowers;
54 
55 /**
56  * Helper structure for computing WignerDMatrices, which require z(t)^n for many values of n.
57  */
58 typedef struct tagComplexPowers {
59  int LMax; /**< Maximum L; powers computed depend on LMax. */
60  int n_entries; /**< Number of entries in **powers. */
61  int n_times; /**< Length of each entry. */
62  gsl_vector **real_part; /**< The real part of z^n. */
63  gsl_vector **imag_part; /**< The imag part of z^n. */
65 
66 typedef struct tagWignerDMatrices {
67  int LMax; /**< Includes (ell, m) modes with 2 <= ell <= LMax. */
68  int n_entries; /**< Number of (ell, m, m') entries. */
69  int n_times; /**< Number of time samples per entry. */
70  gsl_vector **real_part; /**< The real part of each entry. */
71  gsl_vector **imag_part; /**< The imaginary part of each entry. */
73 
74 UNUSED static void MultiModalWaveform_Init(MultiModalWaveform **wave, int LMax, int n_times);
76 UNUSED static void WignerDMatrices_Init(WignerDMatrices **matrices, int n_times, int LMax);
77 UNUSED static void WignerDMatrices_Destroy(WignerDMatrices *matrices);
78 UNUSED static int WignerDMatrix_Index(int ell, int m, int mp);
79 UNUSED static void WignerDMatrices_Compute(WignerDMatrices *matrices, gsl_vector **quat);
80 UNUSED static void RealPowers_Init(RealPowers **rp, int LMax, int n_times);
81 UNUSED static void RealPowers_Destroy(RealPowers *rp);
82 UNUSED static void RealPowers_Compute(RealPowers *rp, gsl_vector *x);
83 UNUSED static void ComplexPowers_Init(ComplexPowers **cp, int LMax, int n_times);
84 UNUSED static void ComplexPowers_Destroy(ComplexPowers *cp);
85 UNUSED static void ComplexPowers_Compute(ComplexPowers *cp, gsl_vector *x, gsl_vector *y);
86 
87 UNUSED static double factorial(int n);
88 UNUSED static double factorial_ratio(int n, int k);
89 UNUSED static double binomial(int n, int k);
90 UNUSED static double wigner_coef(int ell, int mp, int m);
91 
92 UNUSED static void complex_vector_mult(gsl_vector *x1, gsl_vector *y1, gsl_vector *x2, gsl_vector *y2,
93  gsl_vector *tmp1, gsl_vector *tmp2);
94 
95 UNUSED static void NRSur_ab4_dy(
96  double *dy, // Result, length 11
97  double *k1, // dy/dt evaluated at node 1
98  double *k2, // dy/dt evaluated at node 2
99  double *k3, // dy/dt evaluated at node 3
100  double *k4, // dy/dt evaluated at node 4
101  double dt12, // t_2 - t_1
102  double dt23, // t_3 - t_2
103  double dt34, // t_4 - t_3
104  double dt45, // t_5 - t_4
105  int dim // Vector dimension of dy and the k vectors.
106 );
107 
108 /**
109  * Function to transform waveform modes from the coorbital frame
110  * to the inertial frame. First transforms to the coprecessing frame
111  * by rotating about the z-axis by the orbital phase, then rotates
112  * to the inertial frame using the coprecessing frame quaternions.
113  */
115  MultiModalWaveform *h, /**< Output. Dimensionless waveform modes. Should be initialized already. */
116  MultiModalWaveform *h_coorb, /**< Coorbital frame waveform modes. */
117  gsl_vector **quat, /**< Coprecessing frame quaternions. */
118  gsl_vector *orbphase /**< Orbital phase. */
119 );
120 
121 UNUSED static int quatInv(double *qInv, double *q);
122 UNUSED static int multiplyQuats(double *prod, double *q1, double *q2);
123 UNUSED static int quaternionTransformVector(
124  double *new_vec, double *quat, double *vec);
125 UNUSED static int transformTimeDependentVector(gsl_vector **vec, gsl_vector **quat);
126 
127 UNUSED static int get_dimless_omega(
128  REAL8 *omegaMin_dimless,
129  REAL8 *omegaRef_dimless,
130  const REAL8 fMin,
131  const REAL8 fRef,
132  const REAL8 Mtot_sec
133 );
#define LMax
static REAL8 UNUSED q2(REAL8 e0, REAL8 f0, REAL8 inc, REAL8 bet, REAL8 FPlus, REAL8 FCross)
static REAL8 UNUSED q1(REAL8 e0, REAL8 f0, REAL8 inc, REAL8 bet, REAL8 FPlus, REAL8 FCross)
static UNUSED void WignerDMatrices_Destroy(WignerDMatrices *matrices)
static UNUSED double wigner_coef(int ell, int mp, int m)
static UNUSED int quatInv(double *qInv, double *q)
static UNUSED void MultiModalWaveform_Init(MultiModalWaveform **wave, int LMax, int n_times)
static UNUSED void WignerDMatrices_Compute(WignerDMatrices *matrices, gsl_vector **quat)
static UNUSED void ComplexPowers_Destroy(ComplexPowers *cp)
static UNUSED void NRSur_ab4_dy(double *dy, double *k1, double *k2, double *k3, double *k4, double dt12, double dt23, double dt34, double dt45, int dim)
static UNUSED void complex_vector_mult(gsl_vector *x1, gsl_vector *y1, gsl_vector *x2, gsl_vector *y2, gsl_vector *tmp1, gsl_vector *tmp2)
static UNUSED int WignerDMatrix_Index(int ell, int m, int mp)
static UNUSED void WignerDMatrices_Init(WignerDMatrices **matrices, int n_times, int LMax)
static UNUSED void RealPowers_Init(RealPowers **rp, int LMax, int n_times)
static UNUSED int quaternionTransformVector(double *new_vec, double *quat, double *vec)
static UNUSED void MultiModalWaveform_Destroy(MultiModalWaveform *wave)
static UNUSED int get_dimless_omega(REAL8 *omegaMin_dimless, REAL8 *omegaRef_dimless, const REAL8 fMin, const REAL8 fRef, const REAL8 Mtot_sec)
static UNUSED int multiplyQuats(double *prod, double *q1, double *q2)
static UNUSED double factorial(int n)
static UNUSED int transformTimeDependentVector(gsl_vector **vec, gsl_vector **quat)
static UNUSED void RealPowers_Destroy(RealPowers *rp)
static UNUSED double factorial_ratio(int n, int k)
static UNUSED void RealPowers_Compute(RealPowers *rp, gsl_vector *x)
static UNUSED void ComplexPowers_Compute(ComplexPowers *cp, gsl_vector *x, gsl_vector *y)
static UNUSED void ComplexPowers_Init(ComplexPowers **cp, int LMax, int n_times)
static UNUSED double binomial(int n, int k)
static UNUSED void TransformModesCoorbitalToInertial(MultiModalWaveform *h, MultiModalWaveform *h_coorb, gsl_vector **quat, gsl_vector *orbphase)
Function to transform waveform modes from the coorbital frame to the inertial frame.
REAL8 tmp1
double REAL8
static const INT4 m
static const INT4 q
Helper structure for computing WignerDMatrices, which require z(t)^n for many values of n.
int n_entries
Number of entries in **powers.
gsl_vector ** imag_part
The imag part of z^n.
int LMax
Maximum L; powers computed depend on LMax.
gsl_vector ** real_part
The real part of z^n.
int n_times
Length of each entry.
Structure for a multi-modal waveform.
gsl_vector ** modes_real_part
The real part of each mode - n_modes vectors of length n_times.
int * mvals
The m values of each mode (n_modes entries)
int * lvals
The ell values of each mode (n_modes entries)
REAL8 phiRef
orbital phase at reference pt.
gsl_vector ** modes_imag_part
The imaginary part of each mode - n_modes vectors of length n_times.
int n_modes
Number of modes.
int n_times
Number of time samples in each mode.
Helper structure for computing WignerDMatrices, which require x(t)^n for many values of n.
gsl_vector ** powers
The data; x^n.
int n_times
Length of each entry.
int LMax
Maximum L; powers computed depend on LMax.
int n_entries
Number of entries in **powers.
int LMax
Includes (ell, m) modes with 2 <= ell <= LMax.
gsl_vector ** imag_part
The imaginary part of each entry.
int n_entries
Number of (ell, m, m') entries.
gsl_vector ** real_part
The real part of each entry.
int n_times
Number of time samples per entry.