Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALSimulation 6.2.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ns-eos-table.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 <stdio.h>
21#include <stdlib.h>
22
23#include <lal/LALConstants.h>
24#include <lal/LALgetopt.h>
25#include <lal/LALStdlib.h>
26#include <lal/LALSimNeutronStar.h>
27
28int usage(const char *program);
29int parseargs(int argc, char *argv[]);
30int output(const char *fmt, double h, double p, double epsilon, double rho,
31 double dedp, double vsound);
32
33/* global variables */
34int global_cgs = 0;
37
38const char *const default_fmt = "%p\\t%r\\n";
39const char *global_fmt;
40
41const long default_npts = 100;
43
44/* unit conversion constants */
45#define CENTIMETER_SI 0.01 /* 1 cm in m */
46#define DYNE_PER_CENTIMETER_SQUARED_SI 0.1 /* 1 dyn/cm^2 in Pa */
47#define GRAM_PER_CENTIMETER_CUBED_SI 1000.0 /* 1 g/cm^3 in kg/m^3 */
48
49int main(int argc, char *argv[])
50{
51 double hmax;
52 long i;
53
55
58 parseargs(argc, argv);
59
61 for (i = 0; i < global_npts; i++) {
62 double h = hmax * (0.5 + i) / global_npts;
63 double p;
64 double epsilon;
65 double rho;
66 double dedp;
67 double vsound;
68 if (global_geom) { /* output in geometric units */
71 epsilon =
73 (h, global_eos);
74 rho =
76 (h, global_eos);
77 dedp =
79 (p, global_eos);
80 vsound =
82 } else { /* output in SI units by default */
84 epsilon =
87 rho =
90 dedp =
94 if (global_cgs) { /* output in cgs units by converting from SI units */
96 epsilon /= DYNE_PER_CENTIMETER_SQUARED_SI; /* same as ERG_PER_CENTIMETER_CUBED_SI */
98 /* dedp is dimensionless */
99 vsound /= CENTIMETER_SI;
100 }
101 }
102 output(global_fmt, h, p, epsilon, rho, dedp, vsound);
103 }
104
107 return 0;
108}
109
110int output(const char *fmt, double h, double p, double epsilon, double rho,
111 double dedp, double vsound)
112{
113 int i;
114 for (i = 0; fmt[i]; ++i) {
115 switch (fmt[i]) {
116 case '%': /* conversion character */
117 switch (fmt[i + 1]) {
118 case '%':
119 fputc('%', stdout);
120 break;
121 case 'h':
122 fprintf(stdout, "%.18e", h);
123 break;
124 case 'p':
125 fprintf(stdout, "%.18e", p);
126 break;
127 case 'e':
128 fprintf(stdout, "%.18e", epsilon);
129 break;
130 case 'r':
131 fprintf(stdout, "%.18e", rho);
132 break;
133 case 'd':
134 fprintf(stdout, "%.18e", dedp);
135 break;
136 case 'v':
137 fprintf(stdout, "%.18e", vsound);
138 break;
139 default:
140 fprintf(stderr,
141 "unrecognized conversion %%%c in output format\n",
142 fmt[i + 1]);
143 exit(1);
144 break;
145 }
146 ++i;
147 break;
148 case '\\': /* escaped character */
149 switch (fmt[i + 1]) {
150 case '\\':
151 fputc('\\', stdout);
152 break;
153 case 'a':
154 fputc('\a', stdout);
155 break;
156 case 'b':
157 fputc('\b', stdout);
158 break;
159 case 'f':
160 fputc('\f', stdout);
161 break;
162 case 'n':
163 fputc('\n', stdout);
164 break;
165 case 'r':
166 fputc('\r', stdout);
167 break;
168 case 't':
169 fputc('\t', stdout);
170 break;
171 case 'v':
172 fputc('\v', stdout);
173 break;
174 case '\0': /* impossible! */
175 fprintf(stderr,
176 "impossible escaped NUL character in format\n");
177 exit(1);
178 default:
179 fputc(fmt[i + 1], stdout);
180 break;
181 }
182 ++i;
183 break;
184 default:
185 fputc(fmt[i], stdout);
186 break;
187 }
188 }
189 return 0;
190}
191
192int parseargs(int argc, char **argv)
193{
194 struct LALoption long_options[] = {
195 {"help", no_argument, 0, 'h'},
196 {"cgs", no_argument, 0, 'c'},
197 {"geom", no_argument, 0, 'g'},
198 {"eos-file", required_argument, 0, 'f'},
199 {"eos-name", required_argument, 0, 'n'},
200 {"format", required_argument, 0, 'F'},
201 {"npts", required_argument, 0, 'N'},
202 {"polytrope", no_argument, 0, 'P'},
203 {"gamma", required_argument, 0, 'G'},
204 {"pressure", required_argument, 0, 'p'},
205 {"density", required_argument, 0, 'r'},
206 {"piecewisepolytrope", no_argument, 0, 'Q'},
207 {"logp1", required_argument, 0, 'q'},
208 {"gamma1", required_argument, 0, '1'},
209 {"gamma2", required_argument, 0, '2'},
210 {"gamma3", required_argument, 0, '3'},
211 {"4parameterspectraldecomposition", no_argument, 0, 'S'},
212 {"SDgamma0", required_argument, 0, 'w'},
213 {"SDgamma1", required_argument, 0, 'x'},
214 {"SDgamma2", required_argument, 0, 'y'},
215 {"SDgamma3", required_argument, 0, 'z'},
216 {0, 0, 0, 0}
217 };
218 char args[] = "hcgf:n:F:N:PG:p:r:Qq:1:2:3:Sw:x:y:z:";
219
220 /* quantities for 1-piece polytrope: */
221 int polytropeFlag = 0;
222 double Gamma = 0, reference_pressure_si = 0, reference_density_si = 0;
223
224 /* quantities for 4-parameter piecewise polytrope: */
225 int piecewisePolytropeFlag = 0;
226 double logp1_si = 0, gamma1 = 0, gamma2 = 0, gamma3 = 0;
227
228 /* quatities for 4-coeff. spectral decompositions */
229 int spectralFlag = 0;
230 double SDgamma0 = 0, SDgamma1 = 0, SDgamma2 = 0, SDgamma3 = 0;
231
232 while (1) {
233 int option_index = 0;
234 int c;
235
236 c = LALgetopt_long_only(argc, argv, args, long_options, &option_index);
237 if (c == -1) /* end of options */
238 break;
239
240 switch (c) {
241 case 0: /* if option set a flag, nothing else to do */
242 if (long_options[option_index].flag)
243 break;
244 else {
245 fprintf(stderr, "error parsing option %s with argument %s\n",
246 long_options[option_index].name, LALoptarg);
247 exit(1);
248 }
249 case 'h': /* help */
250 usage(argv[0]);
251 exit(0);
252 case 'c': /* cgs */
253 global_cgs = 1;
254 break;
255 case 'g': /* geom */
256 global_geom = 1;
257 break;
258 case 'f': /* eos-file */
260 break;
261 case 'n': /* eos-name */
263 break;
264 case 'F': /* format */
266 break;
267 case 'N': /* npts */
268 global_npts = strtol(LALoptarg, NULL, 0);
269 if (global_npts < 1) {
270 fprintf(stderr, "invalid number of points\n");
271 exit(1);
272 }
273 break;
274
275 /* using a 1-piece polytrope */
276 case 'P':
277 polytropeFlag = 1;
278 break;
279 case 'G':
280 Gamma = atof(LALoptarg);
281 break;
282 case 'p':
283 reference_pressure_si = atof(LALoptarg);
284 break;
285 case 'r':
286 reference_density_si = atof(LALoptarg);
287 break;
288
289 /* using a 4-piece polytrope */
290 case 'Q':
291 piecewisePolytropeFlag = 1;
292 break;
293 case 'q':
294 logp1_si = atof(LALoptarg);
295 break;
296 case '1':
297 gamma1 = atof(LALoptarg);
298 break;
299 case '2':
300 gamma2 = atof(LALoptarg);
301 break;
302 case '3':
303 gamma3 = atof(LALoptarg);
304 break;
305
306 /* using 4-parameter spectral decomposition */
307 case 'S':
308 spectralFlag = 1;
309 break;
310 case 'w':
311 SDgamma0 = atof(LALoptarg);
312 break;
313 case 'x':
314 SDgamma1 = atof(LALoptarg);
315 break;
316 case 'y':
317 SDgamma2 = atof(LALoptarg);
318 break;
319 case 'z':
320 SDgamma3 = atof(LALoptarg);
321 break;
322
323 default:
324 fprintf(stderr, "unknown error while parsing options\n");
325 exit(1);
326 }
327 }
328
329 /* set eos to 1-piece polytrope */
330 if (polytropeFlag == 1)
331 global_eos =
332 XLALSimNeutronStarEOSPolytrope(Gamma, reference_pressure_si,
333 reference_density_si);
334
335 /* set eos to 4-parameter piecewise polytrope */
336 if (piecewisePolytropeFlag == 1)
337 global_eos =
339 gamma1, gamma2, gamma3);
340
341 /* set eos to 4-parameter spectral decomposition */
342 if (spectralFlag == 1)
343 global_eos =
345 SDgamma1, SDgamma2, SDgamma3);
346
347 if (LALoptind < argc) {
348 fprintf(stderr, "extraneous command line arguments:\n");
349 while (LALoptind < argc)
350 fprintf(stderr, "%s\n", argv[LALoptind++]);
351 exit(1);
352 }
353
354 if (!global_eos) {
355 fprintf(stderr, "error: no equation of state selected\n");
356 usage(argv[0]);
357 exit(1);
358 }
359
360 return 0;
361}
362
363int usage(const char *program)
364{
365 int e, c;
366 fprintf(stderr, "usage: %s [options]\n", program);
367 fprintf(stderr,
368 "\t-h, --help \tprint this message and exit\n");
369 fprintf(stderr,
370 "\t-f FILE, --eos-file=FILE \tuse EOS with from data filename FILE\n");
371 fprintf(stderr,
372 "\t-n NAME, --eos-name=NAME \tuse EOS with name NAME\n");
373 fprintf(stderr, "\n");
374 fprintf(stderr,
375 "\t-P, --polytrope \tuse single polytrope\n");
376 fprintf(stderr, "\t-G GAMMA, --gamma=GAMMA \tadiabatic index\n");
377 fprintf(stderr,
378 "\t-p PRESSURE, --pressure=PRESSURE \tpressure at reference density\n");
379 fprintf(stderr,
380 "\t-r DENSITY, --density=DENSITY \treference density\n");
381 fprintf(stderr, "\n");
382 fprintf(stderr,
383 "\t-Q, --piecewisepolytrope \tuse 4-parameter piecewise polytrope (PRD 79, 124032 (2009))\n");
384 fprintf(stderr,
385 "\t-q log(p_1), --logp1=log(p_1) \tlog of pressure at rho_1=10^17.7 kg/m^3\n");
386 fprintf(stderr,
387 "\t-1 Gamma_1, --gamma1=Gamma_1 \tadiabatic index <10^17.7 kg/m^3\n");
388 fprintf(stderr,
389 "\t-2 Gamma_2, --gamma2=Gamma_2 \tadiabatic index 10^17.7--10^18 kg/m^3\n");
390 fprintf(stderr,
391 "\t-3 Gamma_3, --gamma3=Gamma_3 \tadiabatic index >10^18.0 kg/m^3\n");
392 fprintf(stderr, "\n");
393 fprintf(stderr,
394 "\t-S --4paramspectraldecomp \tuse 4-parameter spectral decomposition (PRD 82, 103011 (2010))\n");
395 fprintf(stderr,
396 "\t-w SDgamma0, --SDgamma0=SDgamma0 \tadiabatic index spectral decomposition coefficient 1 (4-coeff) 0.2--2.0\n");
397 fprintf(stderr,
398 "\t-x SDgamma1, --SDgamma1=SDgamma1 \tadiabatic index spectral decomposition coefficient 2 (4-coeff) -1.6--1.7\n");
399 fprintf(stderr,
400 "\t-y SDgamma2, --SDgamma2=SDgamma2 \tadiabatic index spectral decomposition coefficient 3 (4-coeff) -0.8--0.6\n");
401 fprintf(stderr,
402 "\t-z SDgamma3, --SDgamma3=SDgamma3 \tadiabatic index spectral decomposition coefficient 4 (4-coeff) -0.2--0.2\n");
403 fprintf(stderr, "\n");
404 fprintf(stderr, "\t-c, --cgs \tuse CGS units\n");
405 fprintf(stderr,
406 "\t-g, --geom \tuse geometerized units of length (G=c=1)\n");
407 fprintf(stderr,
408 "\t-N NPTS, --npts=NPTS \toutput NPTS points [%ld]\n",
410 fprintf(stderr,
411 "\t-F FORMAT, --format=FORMAT \toutput format FORMAT [\"%s\"]\n",
413 fprintf(stderr, "format string conversions:\n");
414 fprintf(stderr, "\t%%h\t is replaced by the pseudo-enthalpy\n");
415 fprintf(stderr, "\t%%p\t is replaced by the pressure\n");
416 fprintf(stderr, "\t%%e\t is replaced by the energy density\n");
417 fprintf(stderr, "\t%%r\t is replaced by the rest-mass density\n");
418 fprintf(stderr, "\t%%v\t is replaced by the speed of sound\n");
419 fprintf(stderr, "recognized tabulated equations of state:");
420 for (e = 0, c = 0; e < (int)(sizeof(lalSimNeutronStarEOSNames)/sizeof(*lalSimNeutronStarEOSNames)); ++e) {
421 c += fprintf(stderr, "%s%s", c ? ", " : "\n\t", lalSimNeutronStarEOSNames[e]);
422 if (c > 50)
423 c = 0;
424 }
425 fprintf(stderr, "\n");
426
427 return 0;
428}
void LALCheckMemoryLeaks(void)
#define c
const char * name
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
double i
Definition: bh_ringdown.c:118
double e
Definition: bh_ringdown.c:117
double XLALSimNeutronStarEOSRestMassDensityOfPseudoEnthalpy(double h, LALSimNeutronStarEOS *eos)
Returns the rest mass density (kg m^-3) at a given value of the dimensionless pseudo-enthalpy.
LALSimNeutronStarEOS * XLALSimNeutronStarEOSPolytrope(double Gamma, double reference_pressure_si, double reference_density_si)
Creates a polytrope Equation of State defined by p = K rho^Gamma.
double XLALSimNeutronStarEOSEnergyDensityDerivOfPressure(double p, LALSimNeutronStarEOS *eos)
Returns the gradient of the energy density with respect to the pressure (dimensionless) at a given va...
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.
double XLALSimNeutronStarEOSPressureOfPseudoEnthalpy(double h, LALSimNeutronStarEOS *eos)
Returns the pressure (Pa) at a given value of the dimensionless pseudo-enthalpy.
LALSimNeutronStarEOS * XLALSimNeutronStarEOS4ParameterSpectralDecomposition(double SDgamma0, double SDgamma1, double SDgamma2, double SDgamma3)
Reads 4 spectral decomposition eos parameters to make an eos.
double XLALSimNeutronStarEOSEnergyDensityDerivOfPressureGeometerized(double p, LALSimNeutronStarEOS *eos)
Returns the gradient of the energy density with respect to the pressure (dimensionless) at a given va...
double XLALSimNeutronStarEOSEnergyDensityOfPseudoEnthalpyGeometerized(double h, LALSimNeutronStarEOS *eos)
Returns the energy density in geometerized units (m^-2) at a given value of the dimensionless pseudo-...
double XLALSimNeutronStarEOSSpeedOfSound(double h, LALSimNeutronStarEOS *eos)
Returns the speed of sound (m s^-1) at a given value of the pseudo-enthalpy (dimensionless).
double XLALSimNeutronStarEOSRestMassDensityOfPseudoEnthalpyGeometerized(double h, LALSimNeutronStarEOS *eos)
Returns the rest mass density in geometerized units (m^-2) at a given value of the dimensionless pseu...
LALSimNeutronStarEOS * XLALSimNeutronStarEOSFromFile(const char *fname)
Reads a data file containing a tabulated equation of state.
double XLALSimNeutronStarEOSSpeedOfSoundGeometerized(double h, LALSimNeutronStarEOS *eos)
Returns the speed of sound in geometerized units (dimensionless) at a given value of the pseudo-entha...
LALSimNeutronStarEOS * XLALSimNeutronStarEOS4ParameterPiecewisePolytrope(double logp1_si, double gamma1, double gamma2, double gamma3)
Creates a 4-parameter piecewise-polytrope Equation of State.
double XLALSimNeutronStarEOSPressureOfPseudoEnthalpyGeometerized(double h, LALSimNeutronStarEOS *eos)
Returns the pressure in geometerized units (m^-2) at a given value of the dimensionless pseudo-enthal...
double XLALSimNeutronStarEOSMaxPseudoEnthalpy(LALSimNeutronStarEOS *eos)
Returns the maximum pseudo enthalpy of the EOS (dimensionless).
double XLALSimNeutronStarEOSEnergyDensityOfPseudoEnthalpy(double h, LALSimNeutronStarEOS *eos)
Returns the energy density (J m^-3) at a given value of the dimensionless pseudo-enthalpy.
void XLALDestroySimNeutronStarEOS(LALSimNeutronStarEOS *eos)
Frees the memory associated with a pointer to an EOS structure.
void XLALAbortErrorHandler(const char *func, const char *file, int line, int errnum)
XLALErrorHandlerType * XLALSetErrorHandler(XLALErrorHandlerType *newHandler)
char * program
Definition: inject.c:87
p
int main(int argc, char *argv[])
Definition: ns-eos-table.c:49
#define GRAM_PER_CENTIMETER_CUBED_SI
Definition: ns-eos-table.c:47
int usage(const char *program)
Definition: ns-eos-table.c:363
#define CENTIMETER_SI
Definition: ns-eos-table.c:45
long global_npts
Definition: ns-eos-table.c:42
const char *const default_fmt
Definition: ns-eos-table.c:38
int parseargs(int argc, char *argv[])
#define DYNE_PER_CENTIMETER_SQUARED_SI
Definition: ns-eos-table.c:46
const long default_npts
Definition: ns-eos-table.c:41
int global_cgs
Definition: ns-eos-table.c:34
const char * global_fmt
Definition: ns-eos-table.c:39
int output(const char *fmt, double h, double p, double epsilon, double rho, double dedp, double vsound)
Definition: ns-eos-table.c:110
int global_geom
Definition: ns-eos-table.c:35
LALSimNeutronStarEOS * global_eos
Definition: ns-eos-table.c:36
int * flag