Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALSimulation 6.2.0.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ns-params.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2013 J. Creighton, B. Lackey
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 <stdio.h>
22#include <stdlib.h>
23
24#include <lal/LALConstants.h>
25#include <lal/LALgetopt.h>
26#include <lal/LALStdlib.h>
27#include <lal/LALSimNeutronStar.h>
28
29int usage(const char *program);
30int parseargs(int argc, char *argv[]);
31int output(const char *fmt, double c, double m, double r, double k2);
32
33/* global variables */
34
37
38int main(int argc, char *argv[])
39{
42
43 parseargs(argc, argv);
44
46 printf("Equation of State: %s\n", XLALSimNeutronStarEOSName(global_eos));
47 printf("Maximum Mass (solar) = %g\n",
49 if (global_mass != 0.0) {
50 double m = global_mass * LAL_MSUN_SI;
52 double r = XLALSimNeutronStarRadius(m, fam);
53 double k = XLALSimNeutronStarLoveNumberK2(m, fam);
54 double c = global_mass * LAL_MRSUN_SI / r;
55 double l = (2.0 / 3.0) * k / pow(c, 5);
56 printf("Parameters for Neutron Star Mass (solar) = %g\n", global_mass);
57 printf("- Central Pressure (Pa) = %g\n", p);
58 printf("- Radius (km) = %g\n", r / 1000.0);
59 printf("- Compactness (dimensionless) = %g\n", c);
60 printf("- Love Number (dimensionless) = %g\n", k);
61 printf("- Tidal Parameter (dimensionless) = %g\n", l);
62 }
63
67 return 0;
68}
69
70int parseargs(int argc, char **argv)
71{
72 struct LALoption long_options[] = {
73 {"help", no_argument, 0, 'h'},
74 {"mass", required_argument, 0, 'm'},
75 {"eos-file", required_argument, 0, 'f'},
76 {"eos-name", required_argument, 0, 'n'},
77 {"polytrope", no_argument, 0, 'P'},
78 {"gamma", required_argument, 0, 'G'},
79 {"pressure", required_argument, 0, 'p'},
80 {"density", required_argument, 0, 'r'},
81 {"piecewisepolytrope", no_argument, 0, 'Q'},
82 {"logp1", required_argument, 0, 'q'},
83 {"gamma1", required_argument, 0, '1'},
84 {"gamma2", required_argument, 0, '2'},
85 {"gamma3", required_argument, 0, '3'},
86 {"4parameterspectraldecomposition", no_argument, 0, 'S'},
87 {"SDgamma0", required_argument, 0, 'w'},
88 {"SDgamma1", required_argument, 0, 'x'},
89 {"SDgamma2", required_argument, 0, 'y'},
90 {"SDgamma3", required_argument, 0, 'z'},
91 {0, 0, 0, 0}
92 };
93 char args[] = "hm:f:n:PG:p:r:Qq:1:2:3:Sw:x:y:z:";
94
95 /* quantities for 1-piece polytrope: */
96 int polytropeFlag = 0;
97 double Gamma = 0, reference_pressure_si = 0, reference_density_si = 0;
98
99 /* quantities for 4-parameter piecewise polytrope: */
100 int piecewisePolytropeFlag = 0;
101 double logp1_si = 0, gamma1 = 0, gamma2 = 0, gamma3 = 0;
102
103 /* quantities for 4-coeff. spectral decomposition */
104 int spectralFlag = 0;
105 double SDgamma0 = 0, SDgamma1 = 0, SDgamma2 = 0, SDgamma3 = 0;
106
107 while (1) {
108 int option_index = 0;
109 int c;
110
111 c = LALgetopt_long_only(argc, argv, args, long_options, &option_index);
112 if (c == -1) /* end of options */
113 break;
114
115 switch (c) {
116 case 0: /* if option set a flag, nothing else to do */
117 if (long_options[option_index].flag)
118 break;
119 else {
120 fprintf(stderr, "error parsing option %s with argument %s\n",
121 long_options[option_index].name, LALoptarg);
122 exit(1);
123 }
124 case 'h': /* help */
125 usage(argv[0]);
126 exit(0);
127 case 'm': /* mass */
128 global_mass = atof(LALoptarg);
129 break;
130 case 'f': /* eos-file */
132 break;
133 case 'n': /* eos-name */
135 break;
136
137 /* using a 1-piece polytrope */
138 case 'P':
139 polytropeFlag = 1;
140 break;
141 case 'G':
142 Gamma = atof(LALoptarg);
143 break;
144 case 'p':
145 reference_pressure_si = atof(LALoptarg);
146 break;
147 case 'r':
148 reference_density_si = atof(LALoptarg);
149 break;
150
151 /* using a 4-piece polytrope */
152 case 'Q':
153 piecewisePolytropeFlag = 1;
154 break;
155 case 'q':
156 logp1_si = atof(LALoptarg);
157 break;
158 case '1':
159 gamma1 = atof(LALoptarg);
160 break;
161 case '2':
162 gamma2 = atof(LALoptarg);
163 break;
164 case '3':
165 gamma3 = atof(LALoptarg);
166 break;
167
168 /* using 4 coeff. spectral decomposition */
169 case 'S':
170 spectralFlag = 1;
171 break;
172 case 'w':
173 SDgamma0 = atof(LALoptarg);
174 break;
175 case 'x':
176 SDgamma1 = atof(LALoptarg);
177 break;
178 case 'y':
179 SDgamma2 = atof(LALoptarg);
180 break;
181 case 'z':
182 SDgamma3 = atof(LALoptarg);
183 break;
184
185 default:
186 fprintf(stderr, "unknown error while parsing options\n");
187 exit(1);
188 }
189 }
190
191 /* set eos to 1-piece polytrope */
192 if (polytropeFlag == 1)
193 global_eos =
194 XLALSimNeutronStarEOSPolytrope(Gamma, reference_pressure_si,
195 reference_density_si);
196
197 /* set eos to 4-parameter piecewise polytrope */
198 if (piecewisePolytropeFlag == 1)
199 global_eos =
201 gamma1, gamma2, gamma3);
202
203 /* set eos to 4 coeff. spectral decomposition */
204 if (spectralFlag == 1)
205 global_eos =
207 SDgamma1, SDgamma2, SDgamma3);
208
209 if (LALoptind < argc) {
210 fprintf(stderr, "extraneous command line arguments:\n");
211 while (LALoptind < argc)
212 fprintf(stderr, "%s\n", argv[LALoptind++]);
213 exit(1);
214 }
215
216 if (!global_eos) {
217 fprintf(stderr, "error: no equation of state selected\n");
218 usage(argv[0]);
219 exit(1);
220 }
221
222 return 0;
223}
224
225int usage(const char *program)
226{
227 int e, c;
228 fprintf(stderr, "usage: %s [options]\n", program);
229 fprintf(stderr,
230 "\t-h, --help \tprint this message and exit\n");
231 fprintf(stderr,
232 "\t-m MASS, --mass=MASS \tparameters of a neutron star of mass MASS (solar)\n");
233 fprintf(stderr,
234 "\t-f FILE, --eos-file=FILE \tuse EOS with from data filename FILE\n");
235 fprintf(stderr,
236 "\t-n NAME, --eos-name=NAME \tuse EOS with name NAME\n");
237 fprintf(stderr, "\n");
238 fprintf(stderr,
239 "\t-P, --polytrope \tuse single polytrope\n");
240 fprintf(stderr, "\t-G GAMMA, --gamma=GAMMA \tadiabatic index\n");
241 fprintf(stderr,
242 "\t-p PRESSURE, --pressure=PRESSURE \tpressure at reference density\n");
243 fprintf(stderr,
244 "\t-r DENSITY, --density=DENSITY \treference density\n");
245 fprintf(stderr, "\n");
246 fprintf(stderr,
247 "\t-Q, --piecewisepolytrope \tuse 4-parameter piecewise polytrope (PRD 79, 124032 (2009))\n");
248 fprintf(stderr,
249 "\t-q log(p_1), --logp1=log(p_1) \tlog of pressure at rho_1=10^17.7 kg/m^3\n");
250 fprintf(stderr,
251 "\t-1 Gamma_1, --gamma1=Gamma_1 \tadiabatic index <10^17.7 kg/m^3\n");
252 fprintf(stderr,
253 "\t-2 Gamma_2, --gamma2=Gamma_2 \tadiabatic index 10^17.7--10^18 kg/m^3\n");
254 fprintf(stderr,
255 "\t-3 Gamma_3, --gamma3=Gamma_3 \tadiabatic index >10^18.0 kg/m^3\n");
256 fprintf(stderr, "\n");
257 fprintf(stderr,
258 "\t-S --4paramspectraldecomp \tuse 4-parameter spectral decomposition (PRD 82, 103011 (2010))\n");
259 fprintf(stderr,
260 "\t-w SDgamma0, --SDgamma0=SDgamma0 \tadiabatic index spectral decomposition coefficient 1 0.2--2.0\n");
261 fprintf(stderr,
262 "\t-x SDgamma1, --SDgamma1=SDgamma1 \tadiabatic index spectral decomposition coefficient 2 -1.6--1.7\n");
263 fprintf(stderr,
264 "\t-y SDgamma2, --SDgamma2=SDgamma2 \tadiabatic index spectral decomposition coefficient 3 -0.8--0.6\n");
265 fprintf(stderr,
266 "\t-z SDgamma3, --SDgamma3=SDgamma3 \tadiabatic index spectral decomposition coefficient 4 -0.2--0.2\n");
267 fprintf(stderr, "recognized tabulated equations of state:");
268 for (e = 0, c = 0; e < (int)(sizeof(lalSimNeutronStarEOSNames)/sizeof(*lalSimNeutronStarEOSNames)); ++e) {
269 c += fprintf(stderr, "%s%s", c ? ", " : "\n\t", lalSimNeutronStarEOSNames[e]);
270 if (c > 50)
271 c = 0;
272 }
273 fprintf(stderr, "\n");
274
275 return 0;
276}
void LALCheckMemoryLeaks(void)
#define c
const char * name
struct tagLALSimNeutronStarFamily LALSimNeutronStarFamily
Incomplete type for a neutron star family having a particular EOS.
struct tagLALSimNeutronStarEOS LALSimNeutronStarEOS
Incomplete type for the neutron star Equation of State (EOS).
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 l
Definition: bh_qnmode.c:135
double e
Definition: bh_ringdown.c:117
#define LAL_MSUN_SI
#define LAL_MRSUN_SI
LALSimNeutronStarEOS * XLALSimNeutronStarEOSPolytrope(double Gamma, double reference_pressure_si, double reference_density_si)
Creates a polytrope Equation of State defined by p = K rho^Gamma.
LALSimNeutronStarEOS * XLALSimNeutronStarEOSByName(const char *name)
Creates an equation of state structure from tabulated equation of state data of a known name.
const char *const lalSimNeutronStarEOSNames[111]
Recognised names of equations of state.
LALSimNeutronStarEOS * XLALSimNeutronStarEOS4ParameterSpectralDecomposition(double SDgamma0, double SDgamma1, double SDgamma2, double SDgamma3)
Reads 4 spectral decomposition eos parameters to make an eos.
LALSimNeutronStarEOS * XLALSimNeutronStarEOSFromFile(const char *fname)
Reads a data file containing a tabulated equation of state.
LALSimNeutronStarEOS * XLALSimNeutronStarEOS4ParameterPiecewisePolytrope(double logp1_si, double gamma1, double gamma2, double gamma3)
Creates a 4-parameter piecewise-polytrope Equation of State.
char * XLALSimNeutronStarEOSName(LALSimNeutronStarEOS *eos)
The name of the equation of state.
void XLALDestroySimNeutronStarEOS(LALSimNeutronStarEOS *eos)
Frees the memory associated with a pointer to an EOS structure.
LALSimNeutronStarFamily * XLALCreateSimNeutronStarFamily(LALSimNeutronStarEOS *eos)
Creates a neutron star family structure for a given equation of state.
double XLALSimNeutronStarLoveNumberK2(double m, LALSimNeutronStarFamily *fam)
Returns the tidal Love number k2 of a neutron star of mass m.
void XLALDestroySimNeutronStarFamily(LALSimNeutronStarFamily *fam)
Frees the memory associated with a pointer to a neutron star family.
double XLALSimNeutronStarRadius(double m, LALSimNeutronStarFamily *fam)
Returns the radius of a neutron star of mass m.
double XLALSimNeutronStarCentralPressure(double m, LALSimNeutronStarFamily *fam)
Returns the central pressure of a neutron star of mass m.
double XLALSimNeutronStarMaximumMass(LALSimNeutronStarFamily *fam)
Returns the maximum mass of a neutron star family.
static const INT4 r
static const INT4 m
void XLALAbortErrorHandler(const char *func, const char *file, int line, int errnum)
XLALErrorHandlerType * XLALSetErrorHandler(XLALErrorHandlerType *newHandler)
char * program
Definition: inject.c:87
p
double global_mass
Definition: ns-params.c:36
int main(int argc, char *argv[])
Definition: ns-params.c:38
int usage(const char *program)
Definition: ns-params.c:225
int output(const char *fmt, double c, double m, double r, double k2)
int parseargs(int argc, char *argv[])
LALSimNeutronStarEOS * global_eos
Definition: ns-params.c:35
int * flag