Commit 7924c03b authored by John Douglas Veitch's avatar John Douglas Veitch

Merge branch 'lalinference_o2+spectral' into 'lalinference_o2'

Lalinference o2+spectral

See merge request !256
parents 3df73e79 03fe1bd8
......@@ -288,6 +288,12 @@ adapt-temps=
#gamma2 gamma2 [1.1,4.5]
#gamma3 gamma3 [1.1,4.5]
#Equation of State parameters (requires --4SpectralDecomp):
#SDgamma0 SDgamma0 [0.2,2.0]
#SDgamma1 SDgamma1 [-1.6,1.7]
#SDgamma2 SDgamma2 [-0.6,0.6]
#SDgamma3 SDgamma3 [-0.02,0.02]
# Settings for allowed component masses in Solar Masses, with default values
#comp-max=30.0
#comp-min=1.0
......
......@@ -2310,7 +2310,7 @@ void LALInferenceLambdaTsEta2Lambdas(REAL8 lambdaT, REAL8 dLambdaT, REAL8 eta, R
return;
}
/* Find lambda1,2(m1,2|eos) */
/* Find lambda1,2(m1,2|eos) for 4-piece polytrope EOS model */
void LALInferenceLogp1GammasMasses2Lambdas(REAL8 logp1,REAL8 gamma1,REAL8 gamma2,REAL8 gamma3, REAL8 mass1, REAL8 mass2, REAL8 *lambda1, REAL8 *lambda2){
// Convert to SI
......@@ -2341,6 +2341,36 @@ XLALDestroySimNeutronStarFamily(fam);
XLALDestroySimNeutronStarEOS(eos);
}
/* Find lambda1,2(m1,2|eos) for 4-piece polytrope EOS model */
void LALInferenceSDGammasMasses2Lambdas(REAL8 gamma[], REAL8 mass1, REAL8 mass2, REAL8 *lambda1, REAL8 *lambda2, int size){
// Convert to SI
double mass1_kg=mass1*LAL_MSUN_SI;
double mass2_kg=mass2*LAL_MSUN_SI;
// Make eos
LALSimNeutronStarEOS *eos = NULL;
LALSimNeutronStarFamily *fam = NULL;
eos = XLALSimNeutronStarEOSSpectralDecomposition(gamma,size);
fam = XLALCreateSimNeutronStarFamily(eos);
// Calculating lambda1(m1|eos)
double r = XLALSimNeutronStarRadius(mass1_kg, fam);
double k = XLALSimNeutronStarLoveNumberK2(mass1_kg, fam);
double c = mass1 * LAL_MRSUN_SI / r;
*lambda1= (2.0/3.0) * k / pow(c , 5.0);
// Calculating lambda2(m1|eos)
r = XLALSimNeutronStarRadius(mass2_kg, fam);
k = XLALSimNeutronStarLoveNumberK2(mass2_kg, fam);
c = mass2 * LAL_MRSUN_SI / r;
*lambda2= (2.0/3.0) * k / pow(c , 5.0);
// Clean up
XLALDestroySimNeutronStarFamily(fam);
XLALDestroySimNeutronStarEOS(eos);
}
/* Checks if EOS allows for acausal speed of sound and unphysical maximum masses */
int LALInferenceEOSPhysicalCheck(LALInferenceVariables *params, ProcessParamsTable *commandLine){
int ret;
......@@ -2362,7 +2392,22 @@ if(LALInferenceCheckVariable(params, "logp1") && LALInferenceCheckVariable(param
// Make 4-piece polytrope eos
eos = XLALSimNeutronStarEOS4ParameterPiecewisePolytrope(logp1_si,gamma1,gamma2,gamma3);
fam = XLALCreateSimNeutronStarFamily(eos);
}
// Else if using 4-coeff spectral eos params...
else if( LALInferenceCheckVariable(params,"SDgamma0") && LALInferenceCheckVariable(params,"SDgamma1") && LALInferenceCheckVariable(params,"SDgamma2") && LALInferenceCheckVariable(params,"SDgamma3"))
{
// Retrieve EOS params from params linked list
double SDgamma0=*(double *)LALInferenceGetVariable(params,"SDgamma0");
double SDgamma1=*(double *)LALInferenceGetVariable(params,"SDgamma1");
double SDgamma2=*(double *)LALInferenceGetVariable(params,"SDgamma2");
double SDgamma3=*(double *)LALInferenceGetVariable(params,"SDgamma3");
double gamma[]={SDgamma0,SDgamma1,SDgamma2,SDgamma3};
if(LALInferenceSDGammaCheck(gamma, 4) == XLAL_FAILURE)
return XLAL_FAILURE;
// Make 4-piece polytrope eos
eos = XLALSimNeutronStarEOSSpectralDecomposition(gamma,4);
}
// Else fail, since you need an eos
else {
......@@ -2370,6 +2415,49 @@ else {
return XLAL_FAILURE;
}
/* FIXME: This is a little clunky,
Check to make sure family will contain
enough pts for cspline interpolation */
size_t ndat = 100;
double *pdat;
double *mdat;
double *rdat;
double *kdat;
pdat = LALMalloc(ndat * sizeof(pdat));
mdat = LALMalloc(ndat * sizeof(mdat));
rdat = LALMalloc(ndat * sizeof(rdat));
kdat = LALMalloc(ndat * sizeof(kdat));
// Ensure mass turnover does not happen too soon
const double logpmin = 75.5;
double logpmax = log(XLALSimNeutronStarEOSMaxPressure(eos));
double dlogp = (logpmax - logpmin) / 100;
// Need at least 4 points
for (int i = 0; i < 4; ++i) {
pdat[i] = exp(logpmin + i * dlogp);
XLALSimNeutronStarTOVODEIntegrate(&rdat[i], &mdat[i],
&kdat[i], pdat[i], eos);
/* determine if maximum mass has been found */
if (mdat[i] <= mdat[i-1]){
fprintf(stdout,"EOS has too few points. Sample rejected.\n");
// Clean up
LALFree(pdat);
LALFree(mdat);
LALFree(rdat);
LALFree(kdat);
XLALDestroySimNeutronStarFamily(fam);
XLALDestroySimNeutronStarEOS(eos);
return XLAL_FAILURE;
}
}
// Clean up
LALFree(pdat);
LALFree(mdat);
LALFree(rdat);
LALFree(kdat);
fam = XLALCreateSimNeutronStarFamily(eos);
// Determine which mass parameterization is used
double mass1 = 0.;
double mass2 = 0.;
......@@ -2395,6 +2483,9 @@ else if(LALInferenceCheckVariable(params, "chirpmass") && LALInferenceCheckVaria
else {
// Else fail
fprintf(stdout,"ERROR: NO MASS PARAMETERS FOUND\n");
// Clean up
XLALDestroySimNeutronStarFamily(fam);
XLALDestroySimNeutronStarEOS(eos);
return XLAL_FAILURE;
}
......@@ -2426,15 +2517,75 @@ if(mass1_kg <= max_mass_kg && mass2_kg <= max_mass_kg && mass1_kg >= min_mass_kg
ret=XLAL_SUCCESS;
// Else fail
}else{
// Clean up
XLALDestroySimNeutronStarFamily(fam);
XLALDestroySimNeutronStarEOS(eos);
ret=XLAL_FAILURE;
}
// Clean up
XLALDestroySimNeutronStarFamily(fam);
XLALDestroySimNeutronStarEOS(eos);
LALCheckMemoryLeaks();
return ret;
}
// Determines if current spectral parameters are within Adiabatic 'prior' range
int LALInferenceSDGammaCheck(double gamma[], int size) {
int i;
int ret = XLAL_SUCCESS;
double p0 = 4.43784199e-13;
double xmax = 12.3081;
double pmax = p0 * exp(xmax);
size_t ndat = 500;
double *pdat;
double *adat;
double *xdat;
pdat = XLALCalloc(ndat, sizeof(*pdat));
adat = XLALCalloc(ndat, sizeof(*adat));
xdat = XLALCalloc(ndat, sizeof(*xdat));
// Generating higher density portion of EOS with spectral decomposition
double logpmax = log(pmax);
double logp0 = log(p0);
double dlogp = (logpmax-logp0)/ndat;
// Calculating pressure and adiabatic index table
for(i = 0;i < (int) ndat;i++)
{
pdat[i] = exp(logp0 + dlogp*i);
xdat[i] = log(pdat[i]/p0);
adat[i] = AdiabaticIndex(gamma, xdat[i], size);
}
// Make sure all values are within Adiabatic Prior range
for(i = 0;i<(int) ndat;i++) {
// FIXME: Should make range adjustable from the commandline
if(adat[i] < 0.6 || adat[i] > 4.5) {
ret = XLAL_FAILURE;
break;
}
}
LALFree(pdat);
LALFree(xdat);
LALFree(adat);
LALCheckMemoryLeaks();
return ret;
}
/* Specral decomposition of eos's adiabatic index */
double AdiabaticIndex(double gamma[],double x, int size)
{
double Gamma, logGamma = 0;
int i;
for(i=0;i<size;i++)
{
logGamma += gamma[i]*pow(x,(double) i);
}
Gamma = exp(logGamma);
return Gamma;
}
static void deleteCell(LALInferenceKDTree *cell) {
if (cell == NULL) {
......
......@@ -881,9 +881,18 @@ void LALInferenceLambdaTsEta2Lambdas(REAL8 lambdaT, REAL8 dLambdaT, REAL8 eta, R
/** Calculate lambda1,2(m1,2|eos(logp1,gamma1,gamma2,gamma3)) */
void LALInferenceLogp1GammasMasses2Lambdas(REAL8 logp1, REAL8 gamma1, REAL8 gamma2, REAL8 gamma3, REAL8 mass1, REAL8 mass2, REAL8 *lambda1, REAL8 *lambda2);
/** Check for causality violation and mass conflict given masses and eos **/
/** Convert from spectral parameters to lambda1, lambda2 */
void LALInferenceSDGammasMasses2Lambdas(REAL8 gamma[], REAL8 mass1, REAL8 mass2, REAL8 *lambda1, REAL8 *lambda2, int size);
/** Check for causality violation and mass conflict given masses and eos */
int LALInferenceEOSPhysicalCheck(LALInferenceVariables *params, ProcessParamsTable *commandLine);
/** Specral decomposition of eos's adiabatic index */
double AdiabaticIndex(double gamma[],double x, int size);
/** Determine if the Adiabatic index is within 'prior' range */
int LALInferenceSDGammaCheck(double gamma[], int size);
/**
* The kD trees in LALInference are composed of cells. Each cell
* represents a rectangular region in parameter space, defined by
......
......@@ -736,6 +736,7 @@ LALInferenceModel *LALInferenceInitCBCModel(LALInferenceRunState *state) {
(--tidal) Enables tidal corrections, only with LALSimulation.\n\
(--tidalT) Enables reparmeterized tidal corrections, only with LALSimulation.\n\
(--4PolyEOS) Enables 4-piece polytropic EOS parmeterization, only with LALSimulation.\n\
(--4SpectralDecomp) Enables 4-coeff. spectral decomposition EOS parmeterization, only with LALSimulation.\n\
(--spinOrder PNorder) Specify twice the PN order (e.g. 5 <==> 2.5PN) of spin effects to use, only for LALSimulation (default: -1 <==> Use all spin effects).\n\
(--tidalOrder PNorder) Specify twice the PN order (e.g. 10 <==> 5PN) of tidal effects to use, only for LALSimulation (default: -1 <==> Use all tidal effects).\n\
(--numreldata FileName) Location of NR data file for NR waveforms (with NR_hdf5 approx).\n\
......@@ -780,6 +781,11 @@ LALInferenceModel *LALInferenceInitCBCModel(LALInferenceRunState *state) {
gamma1 gamma1.\n\
gamma2 gamma2.\n\
gamma3 gamma3.\n\
(requires --4SpectralDecomp):\n\
SDgamma0 SDgamma0.\n\
SDgamma1 SDgamma1.\n\
SDgamma2 SDgamma2.\n\
SDgamma3 SDgamma3.\n\
----------------------------------------------\n\
--- Prior Ranges -----------------------------\n\
----------------------------------------------\n\
......@@ -867,6 +873,14 @@ LALInferenceModel *LALInferenceInitCBCModel(LALInferenceRunState *state) {
REAL8 gamma2Max=4.5;
REAL8 gamma3Min=1.1;
REAL8 gamma3Max=4.5;
REAL8 SDgamma0Min=0.2;
REAL8 SDgamma0Max=2.0;
REAL8 SDgamma1Min=-1.6;
REAL8 SDgamma1Max=1.7;
REAL8 SDgamma2Min=-0.6;
REAL8 SDgamma2Max=0.6;
REAL8 SDgamma3Min=-0.02;
REAL8 SDgamma3Max=0.02;
gsl_rng *GSLrandom=state->GSLrandom;
REAL8 endtime=0.0, timeParam=0.0;
REAL8 timeMin=endtime-dt,timeMax=endtime+dt;
......@@ -1337,8 +1351,23 @@ LALInferenceModel *LALInferenceInitCBCModel(LALInferenceRunState *state) {
}
// For EOS, must pick to either use tidal, tidalT, or 4-piece polytrope parameters; otherwise throw error message
if(LALInferenceGetProcParamVal(commandLine,"--tidalT")&&LALInferenceGetProcParamVal(commandLine,"--tidal")&&LALInferenceGetProcParamVal(commandLine,"--4PolyEOS")){
XLALPrintError("Error: cannot use more than one of --tidalT and --tidal and --4PolyEOS.\n");
if(LALInferenceGetProcParamVal(commandLine,"--tidalT")&&LALInferenceGetProcParamVal(commandLine,"--tidal")){
XLALPrintError("Error: cannot use more than one of --tidalT and --tidal and --4PolyEOS and --4SpectralDecomp.\n");
XLAL_ERROR_NULL(XLAL_EINVAL);
} else if(LALInferenceGetProcParamVal(commandLine,"--tidalT")&&LALInferenceGetProcParamVal(commandLine,"--4PolyEOS")){
XLALPrintError("Error: cannot use more than one of --tidalT and --tidal and --4PolyEOS and --4SpectralDecomp.\n");
XLAL_ERROR_NULL(XLAL_EINVAL);
} else if(LALInferenceGetProcParamVal(commandLine,"--tidalT")&&LALInferenceGetProcParamVal(commandLine,"--4SpectralDecomp")){
XLALPrintError("Error: cannot use more than one of --tidalT and --tidal and --4PolyEOS and --4SpectralDecomp.\n");
XLAL_ERROR_NULL(XLAL_EINVAL);
} else if(LALInferenceGetProcParamVal(commandLine,"--tidal")&&LALInferenceGetProcParamVal(commandLine,"--4PolyEOS")){
XLALPrintError("Error: cannot use more than one of --tidalT and --tidal and --4PolyEOS and --4SpectralDecomp.\n");
XLAL_ERROR_NULL(XLAL_EINVAL);
} else if(LALInferenceGetProcParamVal(commandLine,"--tidal")&&LALInferenceGetProcParamVal(commandLine,"--4SpectralDecomp")){
XLALPrintError("Error: cannot use more than one of --tidalT and --tidal and --4PolyEOS and --4SpectralDecomp.\n");
XLAL_ERROR_NULL(XLAL_EINVAL);
} else if(LALInferenceGetProcParamVal(commandLine,"--4PolyEOS")&&LALInferenceGetProcParamVal(commandLine,"--4SpectralDecomp")){
XLALPrintError("Error: cannot use more than one of --tidalT and --tidal and --4PolyEOS and --4SpectralDecomp.\n");
XLAL_ERROR_NULL(XLAL_EINVAL);
} else if(LALInferenceGetProcParamVal(commandLine,"--tidalT")){
LALInferenceRegisterUniformVariableREAL8(state, model->params, "lambdaT", zero, lambdaTMin, lambdaTMax, LALINFERENCE_PARAM_LINEAR);
......@@ -1353,6 +1382,12 @@ LALInferenceModel *LALInferenceInitCBCModel(LALInferenceRunState *state) {
LALInferenceRegisterUniformVariableREAL8(state, model->params, "gamma1", zero, gamma1Min, gamma1Max, LALINFERENCE_PARAM_LINEAR);
LALInferenceRegisterUniformVariableREAL8(state, model->params, "gamma2", zero, gamma2Min, gamma2Max, LALINFERENCE_PARAM_LINEAR);
LALInferenceRegisterUniformVariableREAL8(state, model->params, "gamma3", zero, gamma3Min, gamma3Max, LALINFERENCE_PARAM_LINEAR);
// Pull in spectral decomposition parameters (SDgamma0,SDgamma1,SDgamma2,SDgamma3)
} else if(LALInferenceGetProcParamVal(commandLine,"--4SpectralDecomp")){
LALInferenceRegisterUniformVariableREAL8(state, model->params, "SDgamma0", zero, SDgamma0Min, SDgamma0Max, LALINFERENCE_PARAM_LINEAR);
LALInferenceRegisterUniformVariableREAL8(state, model->params, "SDgamma1", zero, SDgamma1Min, SDgamma1Max, LALINFERENCE_PARAM_LINEAR);
LALInferenceRegisterUniformVariableREAL8(state, model->params, "SDgamma2", zero, SDgamma2Min, SDgamma2Max, LALINFERENCE_PARAM_LINEAR);
LALInferenceRegisterUniformVariableREAL8(state, model->params, "SDgamma3", zero, SDgamma3Min, SDgamma3Max, LALINFERENCE_PARAM_LINEAR);
}
LALSimInspiralSpinOrder spinO = LAL_SIM_INSPIRAL_SPIN_ORDER_ALL;
......
......@@ -96,7 +96,7 @@ const char *const splineCalibrationProposalName = "SplineCalibration";
const char *const distanceLikelihoodProposalName = "DistanceLikelihood";
static const char *intrinsicNames[] = {"chirpmass", "q", "eta", "mass1", "mass2", "a_spin1", "a_spin2",
"tilt_spin1", "tilt_spin2", "phi12", "phi_jl", "frequency", "quality", "duration","polar_angle", "phase", "polar_eccentricity","dchi0","dchi1","dchi2","dchi3","dchi4","dchi5","dchi5l","dchi6","dchi6l","dchi7","aPPE","alphaPPE","bPPE","betaPPE","betaStep","fStep","dxi1","dxi2","dxi3","dxi4","dxi5","dxi6","dalpha1","dalpha2","dalpha3","dalpha4","dalpha5","dbeta1","dbeta2","dbeta3","dsigma1","dsigma2","dsigma3","dsigma4",NULL};
"tilt_spin1", "tilt_spin2", "phi12", "phi_jl", "frequency", "quality", "duration","polar_angle", "phase", "polar_eccentricity","dchi0","dchi1","dchi2","dchi3","dchi4","dchi5","dchi5l","dchi6","dchi6l","dchi7","aPPE","alphaPPE","bPPE","betaPPE","betaStep","fStep","dxi1","dxi2","dxi3","dxi4","dxi5","dxi6","dalpha1","dalpha2","dalpha3","dalpha4","dalpha5","dbeta1","dbeta2","dbeta3","dsigma1","dsigma2","dsigma3","dsigma4","lambda1","lambda2","lambdaT","dlambdaT","logp1", "gamma1", "gamma2", "gamma3", "SDgamma0","SDgamma1","SDgamma2","SDgamma3",NULL};
static const char *extrinsicNames[] = {"rightascension", "declination", "cosalpha", "azimuth", "polarisation", "distance",
"logdistance", "time", "costheta_jn", "t0", "theta","hrss", "loghrss", NULL};
......@@ -1270,7 +1270,8 @@ REAL8 LALInferenceDrawApproxPrior(LALInferenceThreadState *thread,
const char *flat_params[] = {"q", "eta", "t0", "azimuth", "cosalpha", "time", "phase", "polarisation",
"rightascension", "costheta_jn", "phi_jl",
"phi12", "a_spin1", "a_spin2", "logp1", "gamma1", "gamma2", "gamma3", NULL};
"phi12", "a_spin1", "a_spin2", "logp1", "gamma1", "gamma2", "gamma3",
"SDgamma0","SDgamma1","SDgamma2","SDgamma3", NULL};
LALInferenceVariables *args = thread->proposalArgs;
......
......@@ -546,6 +546,10 @@ void LALInferencePrintDataWithInjection(LALInferenceIFOData *IFOdata, ProcessPar
(--inj-gamma1) value of gamma1 to be injected (0)\n\
(--inj-gamma2) value of gamma2 to be injected (0)\n\
(--inj-gamma3) value of gamma3 to be injected (0)\n\
(--inj-SDgamma0) value of SDgamma0 to be injected (0)\n\
(--inj-SDgamma1) value of SDgamma1 to be injected (0)\n\
(--inj-SDgamma2) value of SDgamma2 to be injected (0)\n\
(--inj-SDgamma3) value of SDgamma3 to be injected (0)\n\
(--inj-spinOrder PNorder) Specify twice the injection PN order (e.g. 5 <==> 2.5PN)\n\
of spin effects effects to use, only for LALSimulation\n\
(default: -1 <==> Use all spin effects).\n\
......@@ -1634,6 +1638,25 @@ void LALInferenceInjectInspiralSignal(LALInferenceIFOData *IFOdata, ProcessParam
injEvent->gamma3= gamma3;
*/
}
// Inject 4-coef. spectral eos
REAL8 SDgamma0=0.0;
REAL8 SDgamma1=0.0;
REAL8 SDgamma2=0.0;
REAL8 SDgamma3=0.0;
if(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma0") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma1") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma2") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma3")){
SDgamma0= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma0")->value);
SDgamma1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma1")->value);
SDgamma2= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma2")->value);
SDgamma3= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma3")->value);
REAL8 gamma[]={SDgamma0,SDgamma1,SDgamma2,SDgamma3};
LALInferenceSDGammasMasses2Lambdas(gamma,m1,m2,&lambda1,&lambda2,4);
fprintf(stdout,"Injection SDgamma0 set to %lf\n",SDgamma0);
fprintf(stdout,"Injection SDgamma1 set to %lf\n",SDgamma1);
fprintf(stdout,"Injection SDgamma2 set to %lf\n",SDgamma2);
fprintf(stdout,"Injection SDgamma3 set to %lf\n",SDgamma3);
fprintf(stdout,"lambda1 set to %f\n",lambda1);
fprintf(stdout,"lambda2 set to %f\n",lambda2);
}
REAL8 fref = 100.;
if(LALInferenceGetProcParamVal(commandLine,"--inj-fref")) {
......@@ -2353,6 +2376,25 @@ void InjectFD(LALInferenceIFOData *IFOdata, SimInspiralTable *inj_table, Process
fprintf(stdout,"lambda1 set to %f\n",lambda1);
fprintf(stdout,"lambda2 set to %f\n",lambda2);
}
// Inject 4-coef. spectral eos
REAL8 SDgamma0=0.0;
REAL8 SDgamma1=0.0;
REAL8 SDgamma2=0.0;
REAL8 SDgamma3=0.0;
if(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma0") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma1") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma2") && LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma3")){
SDgamma0= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma0")->value);
SDgamma1= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma1")->value);
SDgamma2= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma2")->value);
SDgamma3= atof(LALInferenceGetProcParamVal(commandLine,"--inj-SDgamma3")->value);
REAL8 gamma[]={SDgamma0,SDgamma1,SDgamma2,SDgamma3};
LALInferenceSDGammasMasses2Lambdas(gamma,inj_table->mass1,inj_table->mass2,&lambda1,&lambda2,4);
fprintf(stdout,"Injection SDgamma0 set to %lf\n",SDgamma0);
fprintf(stdout,"Injection SDgamma1 set to %lf\n",SDgamma1);
fprintf(stdout,"Injection SDgamma2 set to %lf\n",SDgamma2);
fprintf(stdout,"Injection SDgamma3 set to %lf\n",SDgamma3);
fprintf(stdout,"lambda1 set to %f\n",lambda1);
fprintf(stdout,"lambda2 set to %f\n",lambda2);
}
/* Set up wave flags */
LALSimInspiralWaveformFlags *waveFlags = XLALSimInspiralCreateWaveformFlags();
......
......@@ -363,6 +363,20 @@ void LALInferenceROQWrapperForXLALSimInspiralChooseFDWaveformSequence(LALInferen
LALInferenceLogp1GammasMasses2Lambdas(logp1,gamma1,gamma2,gamma3,m1,m2,&lambda1,&lambda2);
}
/* ==== SPECTRAL DECOMPOSITION PARAMETERS ==== */
REAL8 SDgamma0 = 0.;
REAL8 SDgamma1 = 0.;
REAL8 SDgamma2 = 0.;
REAL8 SDgamma3 = 0.;
/* Checks for 4 spectral parameters */
if(!LALInferenceCheckVariable(model->params, "logp1")&&LALInferenceCheckVariable(model->params, "SDgamma0")&&LALInferenceCheckVariable(model->params, "SDgamma1")&&LALInferenceCheckVariable(model->params, "SDgamma2")&&LALInferenceCheckVariable(model->params,"SDgamma3")){
SDgamma0 = *(REAL8*) LALInferenceGetVariable(model->params,"SDgamma0");
SDgamma1 = *(REAL8*) LALInferenceGetVariable(model->params,"SDgamma1");
SDgamma2 = *(REAL8*) LALInferenceGetVariable(model->params,"SDgamma2");
SDgamma3 = *(REAL8*) LALInferenceGetVariable(model->params,"SDgamma3");
REAL8 gamma[] = {SDgamma0,SDgamma1,SDgamma2,SDgamma3};
LALInferenceSDGammasMasses2Lambdas(gamma,m1,m2,&lambda1,&lambda2,4);
}
/* Only use GR templates */
LALSimInspiralTestGRParam *nonGRparams = NULL;
......@@ -805,6 +819,21 @@ void LALInferenceTemplateXLALSimInspiralChooseWaveform(LALInferenceModel *model)
LALInferenceLogp1GammasMasses2Lambdas(logp1,gamma1,gamma2,gamma3,m1,m2,&lambda1,&lambda2);
}
/* ==== SPECTRAL DECOMPOSITION PARAMETERS ==== */
REAL8 SDgamma0 = 0.;
REAL8 SDgamma1 = 0.;
REAL8 SDgamma2 = 0.;
REAL8 SDgamma3 = 0.;
/* Checks for 4 spectral parameters */
if(!LALInferenceCheckVariable(model->params, "logp1")&&LALInferenceCheckVariable(model->params, "SDgamma0")&&LALInferenceCheckVariable(model->params, "SDgamma1")&&LALInferenceCheckVariable(model->params, "SDgamma2")&&LALInferenceCheckVariable(model->params,"SDgamma3")){
SDgamma0 = *(REAL8*) LALInferenceGetVariable(model->params,"SDgamma0");
SDgamma1 = *(REAL8*) LALInferenceGetVariable(model->params,"SDgamma1");
SDgamma2 = *(REAL8*) LALInferenceGetVariable(model->params,"SDgamma2");
SDgamma3 = *(REAL8*) LALInferenceGetVariable(model->params,"SDgamma3");
REAL8 gamma[] = {SDgamma0,SDgamma1,SDgamma2,SDgamma3};
LALInferenceSDGammasMasses2Lambdas(gamma,m1,m2,&lambda1,&lambda2,4);
}
/* Only use GR templates */
LALSimInspiralTestGRParam *nonGRparams = NULL;
......@@ -1301,6 +1330,20 @@ void LALInferenceTemplateXLALSimInspiralChooseWaveformPhaseInterpolated(LALInfer
LALInferenceLogp1GammasMasses2Lambdas(logp1,gamma1,gamma2,gamma3,m1,m2,&lambda1,&lambda2);
}
/* ==== SPECTRAL DECOMPOSITION PARAMETERS ==== */
REAL8 SDgamma0 = 0.;
REAL8 SDgamma1 = 0.;
REAL8 SDgamma2 = 0.;
REAL8 SDgamma3 = 0.;
if(!LALInferenceCheckVariable(model->params, "logp1")&&LALInferenceCheckVariable(model->params, "SDgamma0")&&LALInferenceCheckVariable(model->params, "SDgamma1")&&LALInferenceCheckVariable(model->params, "SDgamma2")&&LALInferenceCheckVariable(model->params,"SDgamma3")){
SDgamma0 = *(REAL8*) LALInferenceGetVariable(model->params,"SDgamma0");
SDgamma1 = *(REAL8*) LALInferenceGetVariable(model->params,"SDgamma1");
SDgamma2 = *(REAL8*) LALInferenceGetVariable(model->params,"SDgamma2");
SDgamma3 = *(REAL8*) LALInferenceGetVariable(model->params,"SDgamma3");
REAL8 gamma[] = {SDgamma0,SDgamma1,SDgamma2,SDgamma3};
LALInferenceSDGammasMasses2Lambdas(gamma,m1,m2,&lambda1,&lambda2,4);
}
/* Only use GR templates */
LALSimInspiralTestGRParam *nonGRparams = NULL;
/* Fill in the extra parameters for testing GR, if necessary */
......
......@@ -61,12 +61,19 @@ typedef struct tagLALSimNeutronStarFamily LALSimNeutronStarFamily;
void XLALDestroySimNeutronStarEOS(LALSimNeutronStarEOS * eos);
char *XLALSimNeutronStarEOSName(LALSimNeutronStarEOS * eos);
/** FIXME: Constructed for python wrappers */
LALSimNeutronStarEOS *XLALSimNeutronStarEOSSpectralDecomposition_for_plot(
double SDgamma0, double SDgamma1, double SDgamma2, double SDgamma3,
int size);
LALSimNeutronStarEOS *XLALSimNeutronStarEOSByName(const char *name);
LALSimNeutronStarEOS *XLALSimNeutronStarEOSFromFile(const char *fname);
LALSimNeutronStarEOS *XLALSimNeutronStarEOSPolytrope(double Gamma,
double reference_pressure_si, double reference_density_si);
LALSimNeutronStarEOS *XLALSimNeutronStarEOS4ParameterPiecewisePolytrope(double
logp1_si, double gamma1, double gamma2, double gamma3);
LALSimNeutronStarEOS *XLALSimNeutronStarEOSSpectralDecomposition(double
gamma[], int size);
double XLALSimNeutronStarEOSMaxPressure(LALSimNeutronStarEOS * eos);
double XLALSimNeutronStarEOSMaxPressureGeometerized(LALSimNeutronStarEOS *
......
......@@ -28,6 +28,10 @@
#include <lal/LALSimReadData.h>
#include <gsl/gsl_interp.h>
void GLBoundConversion(double a, double b, double abcissae[],int nEval);
double AdiabaticIndex(double gamma[],double x, int size);
void resetAbcissae(double abcissae[]);
static double eos_e_of_p_spectral_decomposition(double x, double gamma[],int size, double p0, double e0);
/** @cond */
/* Contents of the tabular equation of state data structure. */
......@@ -201,9 +205,7 @@ static LALSimNeutronStarEOS *eos_alloc_tabular(double *pdat, double *edat,
LALSimNeutronStarEOSDataTabular *data;
size_t i;
double *hdat;
double dhdp;
double *rhodat;
double integrand_im1, integrand_i, integral;
eos = LALCalloc(1, sizeof(*eos));
data = LALCalloc(1, sizeof(*data));
......@@ -221,31 +223,43 @@ static LALSimNeutronStarEOS *eos_alloc_tabular(double *pdat, double *edat,
eos->dedp_of_p = eos_dedp_of_p_tabular;
eos->v_of_h = eos_v_of_h_tabular;
/* compute enthalpy data by integrating (trapezoid rule) */
/* compute pseudo-enthalpy h from dhdp */
/* Integrate in log space:
dhdp = 1 / [e(p) + p]
h(p) = h(p0) + \int_p0^p dhdp dp
h(p) = h(p0) + \int_ln(p0)^ln(p) exp[ln(p) + ln(dhdp)] dln(p)
*/
double * integrand;
double * log_pdat;
log_pdat = XLALCalloc(ndat-1, sizeof(*log_pdat));
integrand = LALMalloc((ndat-1) * sizeof(*integrand));
for (i = 0; i < ndat-1; ++i) {
log_pdat[i] = log(pdat[i+1]);
integrand[i] = exp(log_pdat[i] + log(1.0 / (edat[i+1] + pdat[i+1])));
}
gsl_interp_accel * dhdp_of_p_acc_temp = gsl_interp_accel_alloc();
gsl_interp * dhdp_of_p_interp_temp = gsl_interp_alloc(gsl_interp_linear, ndat-1);
gsl_interp_init(dhdp_of_p_interp_temp, log_pdat, integrand, ndat-1);
hdat = LALMalloc(ndat * sizeof(*hdat));
hdat[0] = 0.0;
dhdp = 1.0 / (edat[1] + pdat[1]); /* first deriv is at second point */
for (i = 1; i < ndat; ++i) {
double prev = dhdp;
dhdp = 1.0 / (edat[i] + pdat[i]);
hdat[i] = hdat[i - 1] + 0.5 * (prev + dhdp) * (pdat[i] - pdat[i - 1]);
// Do first point by hand
hdat[1] = hdat[0] + 0.5 * (1./(pdat[1]+edat[1])) * (pdat[1] - pdat[0]);
for (i = 1; i < ndat-1; ++i) {
hdat[i+1] = gsl_interp_eval_integ(dhdp_of_p_interp_temp, log_pdat, integrand,
log_pdat[0], log_pdat[i], dhdp_of_p_acc_temp);
}
gsl_interp_free(dhdp_of_p_interp_temp);
gsl_interp_accel_free(dhdp_of_p_acc_temp);
LALFree(log_pdat);
LALFree(integrand);
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* CALCULATION OF RHO CURRENTLY RETURNS GARBAGE */
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* compute rest-mass density by integrating (trapezoid rule) */
/* rho_i = rho_{i-1} exp(int_{e_{i-1}}^{e_i} de/(e+p)) */
// Find rho from e, p, and h
rhodat = LALMalloc(ndat * sizeof(*hdat));
rhodat[0] = 0.0;
rhodat[1] = edat[1]; /* essentially the same at low density */
integrand_im1 = 1.0 / (edat[1] + pdat[1]);
for (i = 2; i < ndat; i++) {
integrand_i = 1.0 / (edat[i] + pdat[i]);
integral =
0.5 * (integrand_im1 + integrand_i) * (edat[i] - edat[i - 1]);
integrand_im1 = integrand_i;
rhodat[i] = rhodat[i - 1] * exp(integral);
for (i=0; i < ndat; i++){
rhodat[i] = (edat[i]+pdat[i])/exp(hdat[i]);
}
data->hdat = hdat;
......@@ -382,5 +396,238 @@ LALSimNeutronStarEOS *XLALSimNeutronStarEOSByName(const char *name)
XLAL_ERROR_NULL(XLAL_ENAME);
}
/* Returns energy density given a pressure and spectral decomposition parameters */
static double eos_e_of_p_spectral_decomposition(double x, double gamma[], int size, double p0, double e0)
{
// Integration/Placeholder variables
int i;
int j;
int nEval = 10;
double Integrand;
double IPrime;