LALSimulation  5.4.0.1-fe68b98
bh_sphwf.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 Jolien Creighton
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 /**
21  * @defgroup lalsim_bh_sphwf lalsim-bh-sphwf
22  * @ingroup lalsimulation_programs
23  *
24  * @brief Evaluates a spin-weighted spheroidal wave function
25  *
26  * ### Synopsis
27  *
28  * lalsim-bh-sphwf [-h] [-i theta] -a a -l l -m m -s s
29  *
30  * ### Description
31  *
32  * The `lalsim-bh-sphwf` utility prints the value of the spin-weighted
33  * spheroidal wave function \f$ {}_{s}S_{\ell,m}(\cos\theta, a) \f$
34  * for the specified dimensionless spin parameter @p a, spin weight @p s
35  * mode numbers @p l and @p m, and polar angle @p theta. If the parameter
36  * @p theta is not given, the utility prints a table of the values of
37  * the spin-weighted spheroidal wave function.
38  *
39  * ### Options
40  *
41  * <DL>
42  * <DT>`-h`, `--help`</DT>
43  * <DD>print a help message and exit</DD>
44  * <DT>`-i` theta</DT>
45  * <DD>(optional) set the polar angle (degrees)</DD>
46  * <DT>`-a` a</DT>
47  * <DD>(required) set value of dimensionless spin parameter a/M, |a/M|<1</DD>
48  * <DT>`-l` l</DT>
49  * <DD>(required) set value of mode number l, l>=0</DD>
50  * <DT>`-m` m</DT>
51  * <DD>(required) set value of mode number m, abs(m)<=l</DD>
52  * <DT>`-s` s</DT>
53  * <DD>(required) set value of spin weight s, s<=0</DD>
54  * </DL>
55  *
56  * ### Environment
57  *
58  * The `LAL_DEBUG_LEVEL` can used to control the error and warning reporting of
59  * `lalsim-bh-sphwf`. Common values are: `LAL_DEBUG_LEVEL=0` which suppresses
60  * error messages, `LAL_DEBUG_LEVEL=1` which prints error messages alone,
61  * `LAL_DEBUG_LEVEL=3` which prints both error messages and warning messages,
62  * and `LAL_DEBUG_LEVEL=7` which additionally prints informational messages.
63  *
64  * ### Exit Status
65  *
66  * The `lalsim-bh-sphwf` utility exits 0 on success, and >0 if an error
67  * occurs.
68  *
69  * ### Example
70  *
71  * The command:
72  *
73  * lalsim-bh-sphwf -a 0.97 -l 2 -m 2 -s -2
74  *
75  * prints a table of the spin-weighted spheroidal harmonic for
76  * spin weight -2 (gravitational perturbations) in the l = m = 2 quasinormal
77  * mode for black hole with Kerr spin parameter a/M = 0.97:
78  *
79 @verbatim
80 # theta(deg) Re(S) Im(S)
81  0 1.872344e+00 -6.463929e-02
82  10 1.827823e+00 -6.206959e-02
83  20 1.694394e+00 -5.225983e-02
84  30 1.504102e+00 -4.281635e-02
85  40 1.273225e+00 -3.208053e-02
86  50 1.027770e+00 -2.170445e-02
87  60 7.909086e-01 -1.294164e-02
88  70 5.808472e-01 -6.804991e-03
89  80 4.043798e-01 -2.360517e-03
90  90 2.668276e-01 -8.673617e-19
91  100 1.656352e-01 9.846400e-04
92  110 9.604459e-02 1.063797e-03
93  120 5.104255e-02 8.091283e-04
94  130 2.420241e-02 4.838700e-04
95  140 9.739511e-03 2.305645e-04
96  150 3.034816e-03 8.061289e-05
97  160 5.924425e-04 1.697014e-05
98  170 3.675324e-05 1.099041e-06
99  180 0.000000e+00 0.000000e+00
100 @endverbatim
101  */
102 
103 #include <limits.h>
104 #include <math.h>
105 #include <stdio.h>
106 #include <stdlib.h>
107 
108 #include <lal/LALStdlib.h>
109 #include <lal/LALgetopt.h>
110 #include <lal/LALConstants.h>
111 #include <lal/LALSimBlackHoleRingdown.h>
112 
113 #define theta_invalid -100.0 /* invalid */
114 #define a_invalid -100.0 /* invalid */
115 #define l_invalid (INT_MIN + 1) /* invalid */
116 #define m_invalid (INT_MAX) /* invalid */
117 #define s_invalid (INT_MAX) /* invalid */
119 double a = a_invalid;
120 int l = l_invalid;
121 int m = m_invalid;
122 int s = s_invalid;
123 int spherical = 0;
124 int plotfmt = 0;
125 
126 int usage( const char *program );
127 int parseargs( int argc, char **argv );
128 
129 int main( int argc, char *argv[] )
130 {
132 
133  parseargs(argc, argv);
134 
135  if (theta == theta_invalid) { /* make a table */
136  fprintf(stdout, "# theta(deg)\t Re(S) \t Im(S)\n");
137  for (theta = 0.0; theta <= 180.0; theta += 10.0) {
139  fprintf(stdout, "%8g\t%e\t%e\n", theta, creal(sphwf), cimag(sphwf));
140  }
141  } else { /* evaluate at specified value */
143  fprintf(stdout, "Spheroidal wave function (s)S(l,m)(cos(theta),a):\n");
144  fprintf(stdout, "(%d)S(%d,%d)(cos(%g deg),%g) = %g + %g i\n", s, l, m, theta, a, creal(sphwf), cimag(sphwf));
145  }
146  return 0;
147 }
148 
149 int parseargs(int argc, char **argv)
150 {
151  struct LALoption long_options[] = {
152  { "help", no_argument, 0, 'h' },
153  { "spin", required_argument, 0, 'a' },
154  { "inclination", required_argument, 0, 'i' },
155  { "l", required_argument, 0, 'l' },
156  { "m", required_argument, 0, 'm' },
157  { "s", required_argument, 0, 's' },
158  { 0, 0, 0, 0 }
159  };
160  char args[] = "ha:i:l:m:s:";
161  while (1) {
162  int option_index = 0;
163  int c;
164 
165  c = LALgetopt_long_only(argc, argv, args, long_options, &option_index);
166  if (c == -1) /* end of options */
167  break;
168 
169  switch (c) {
170  case 0: /* if option set a flag, nothing else to do */
171  if (long_options[option_index].flag)
172  break;
173  else {
174  fprintf(stderr, "error parsing option %s with argument %s\n", long_options[option_index].name, LALoptarg);
175  exit(1);
176  }
177  case 'h': /* help */
178  usage(argv[0]);
179  exit(0);
180  case 'a': /* spin */
181  a = atof(LALoptarg);
182  break;
183  case 'i': /* inclination */
184  theta = atof(LALoptarg);
185  break;
186  case 'l':
187  l = atoi(LALoptarg);
188  break;
189  case 'm':
190  m = atoi(LALoptarg);
191  break;
192  case 's':
193  s = atoi(LALoptarg);
194  break;
195  case '?':
196  default:
197  fprintf(stderr, "unknown error while parsing options\n");
198  exit(1);
199  }
200  }
201 
202  if (LALoptind < argc) {
203  fprintf( stderr, "extraneous command line arguments:\n" );
204  while (LALoptind < argc)
205  fprintf(stderr, "%s\n", argv[LALoptind++]);
206  exit(1);
207  }
208 
209  if (a == a_invalid || l == l_invalid || m == m_invalid || s == s_invalid) {
210  fprintf(stderr, "must specify a, l, m, and s\n");
211  usage(argv[0]);
212  exit(1);
213  }
214 
215  if (fabs(a) >= 1.0) {
216  fprintf(stderr, "must specify |a| < 1\n");
217  exit(1);
218  }
219 
220  if (l < abs(s)) {
221  fprintf(stderr, "must specify l >= |s|\n");
222  exit(1);
223  }
224 
225  if (abs(m) > l) {
226  fprintf(stderr, "must specify |m| <= l\n");
227  exit(1);
228  }
229 
230  return 0;
231 }
232 
233 int usage(const char *program)
234 {
235  fprintf(stderr, "usage: %s [options]\n", program);
236  fprintf(stderr, "options:\n" );
237  fprintf(stderr, "\t-h, --help \tprint this message and exit\n");
238  fprintf(stderr, "\t-i theta \t(optional) inclination (polar) angle theta (deg)\n");
239  fprintf(stderr, "\t-a a \t(required) set value of a, -1<a<1\n");
240  fprintf(stderr, "\t-l l \t(required) set value of l, l>=0\n");
241  fprintf(stderr, "\t-m m \t(required) set value of m, abs(m)<=l\n");
242  fprintf(stderr, "\t-s s \t(required) set value of s, s<=0\n");
243  return 0;
244 }
#define c
const char * name
int LALgetopt_long_only(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
int LALoptind
char * LALoptarg
#define no_argument
#define required_argument
#define fprintf
int main(int argc, char *argv[])
Definition: bh_sphwf.c:129
double a
Definition: bh_sphwf.c:119
int usage(const char *program)
Definition: bh_sphwf.c:233
int s
Definition: bh_sphwf.c:122
#define l_invalid
Definition: bh_sphwf.c:115
int parseargs(int argc, char **argv)
Definition: bh_sphwf.c:149
#define s_invalid
Definition: bh_sphwf.c:117
int m
Definition: bh_sphwf.c:121
int plotfmt
Definition: bh_sphwf.c:124
int l
Definition: bh_sphwf.c:120
#define theta_invalid
Definition: bh_sphwf.c:113
int spherical
Definition: bh_sphwf.c:123
double theta
Definition: bh_sphwf.c:118
#define m_invalid
Definition: bh_sphwf.c:116
#define a_invalid
Definition: bh_sphwf.c:114
#define LAL_PI_180
double complex COMPLEX16
COMPLEX16 XLALSimBlackHoleRingdownSpheroidalWaveFunction(double theta, double dimensionless_spin, int l, int m, int s)
Evaluates the value of spheroidal wave function at a given polar angle theta for a specified mode (l,...
void XLALBacktraceErrorHandler(const char *func, const char *file, int line, int errnum)
XLALErrorHandlerType * XLALSetErrorHandler(XLALErrorHandlerType *newHandler)
char * program
Definition: inject.c:87
int * flag