22 #define UNUSED __attribute__ ((unused))
37 #include <gsl/gsl_errno.h>
38 #include <gsl/gsl_bspline.h>
39 #include <gsl/gsl_blas.h>
40 #include <gsl/gsl_min.h>
41 #include <gsl/gsl_spline.h>
42 #include <gsl/gsl_poly.h>
43 #include <lal/Units.h>
44 #include <lal/SeqFactories.h>
45 #include <lal/LALConstants.h>
46 #include <lal/XLALError.h>
47 #include <lal/FrequencySeries.h>
49 #include <lal/StringInput.h>
50 #include <lal/Sequence.h>
51 #include <lal/LALStdio.h>
52 #include <lal/FileIO.h>
55 #ifdef LAL_HDF5_ENABLED
56 #include <lal/H5FileIO.h>
57 static const char SurDataHDF5[] =
"SEOBNRv4T_surrogate_v1.0.0.hdf5";
58 static const INT4 SurDataHDF5_VERSION_MAJOR = 1;
59 static const INT4 SurDataHDF5_VERSION_MINOR = 0;
60 static const INT4 SurDataHDF5_VERSION_MICRO = 0;
63 #include <lal/LALSimInspiral.h>
64 #include <lal/LALSimIMR.h>
71 #include <lal/LALConfig.h>
72 #ifdef LAL_PTHREAD_LOCK
78 #ifdef LAL_PTHREAD_LOCK
79 static pthread_once_t Surrogate_is_initialized = PTHREAD_ONCE_INIT;
120 typedef int (*
load_dataPtr)(
const char*, gsl_vector *, gsl_vector *, gsl_matrix *, gsl_matrix *, gsl_vector *);
131 gsl_vector *hyperparams,
137 gsl_vector *hyperparams,
139 gsl_vector *Kinv_dot_y,
161 gsl_matrix *kinv_dot_y_amp,
162 gsl_matrix *kinv_dot_y_phi,
164 gsl_vector *amp_at_EI_nodes,
165 gsl_vector *phi_at_EI_nodes,
170 UNUSED Surrogatedata_submodel **submodel,
171 UNUSED
const char dir[],
172 UNUSED
const char grp_name[]
178 Surrogatedata_submodel *sur,
213 static size_t NextPow2(
const size_t n);
236 fprintf(stderr,
"save_gsl_frequency_series: %s: %zu %zu\n",
filename,
x->size,
y->size);
238 for (
size_t i=0;
i<
x->size;
i++) {
239 fprintf(
fp,
"%g\t%g\n", gsl_vector_get(
x,
i), gsl_vector_get(
y,
i));
249 gsl_vector *vout = gsl_vector_alloc(n+1);
251 gsl_vector_set(vout, 0, value);
252 for (
int i=1;
i<=n;
i++)
253 gsl_vector_set(vout,
i, gsl_vector_get(v,
i-1));
262 gsl_vector *hyperparams,
282 double sigma_f = gsl_vector_get(hyperparams, 0);
283 double sigma_n = gsl_vector_get(hyperparams, hyperparams->size-1);
284 gsl_vector ls = gsl_vector_subvector(hyperparams, 1, hyperparams->size-2).vector;
287 "kernel(): dimensions of vectors x1, x2 and ls: %zu, %zu, %zu have to be consistent.\n",
288 x1->size, x2->size, ls.size);
292 if (gsl_vector_equal(x1, x2))
293 nugget = sigma_n*sigma_n;
295 gsl_vector_memcpy(work, x1);
296 gsl_vector_sub(work, x2);
297 gsl_vector_div(work, &ls);
298 double r = gsl_blas_dnrm2(work);
301 double matern = (1.0 + sqrt(5.0)*
r + 5.0*
r*
r/3.0) * exp(-sqrt(5.0)*
r);
305 return sigma_f*sigma_f * matern + nugget;
310 gsl_vector *hyperparams,
312 gsl_vector *Kinv_dot_y,
335 int n = x_train->size1;
336 gsl_vector *Kst = gsl_vector_alloc(n);
337 for (
int i=0;
i < n;
i++) {
338 gsl_vector
x = gsl_matrix_const_row(x_train,
i).vector;
339 double ker =
kernel(xst, &
x, hyperparams, work);
340 gsl_vector_set(Kst,
i, ker);
345 gsl_blas_ddot(Kst, Kinv_dot_y, &res);
346 gsl_vector_free(Kst);
376 const double a = 100.0;
377 return log10(lambda /
a + 1.0);
390 gsl_matrix *kinv_dot_y_amp,
391 gsl_matrix *kinv_dot_y_phi,
393 gsl_vector *amp_at_nodes,
394 gsl_vector *phi_at_nodes,
399 gsl_vector *xst = gsl_vector_alloc(5);
400 double q_inv = 1.0/
q;
401 gsl_vector_set(xst, 0, q_inv);
402 gsl_vector_set(xst, 1, chi1);
403 gsl_vector_set(xst, 2, chi2);
408 for (
size_t i=0;
i<amp_at_nodes->size;
i++) {
409 gsl_vector hyp_amp_i = gsl_matrix_const_row(hyp_amp,
i).vector;
410 gsl_vector kinv_dot_y_amp_i = gsl_matrix_const_row(kinv_dot_y_amp,
i).vector;
411 double pred =
gp_predict(xst, &hyp_amp_i, x_train, &kinv_dot_y_amp_i, work);
412 gsl_vector_set(amp_at_nodes,
i, pred);
416 for (
size_t i=0;
i<phi_at_nodes->size;
i++) {
417 gsl_vector hyp_phi_i = gsl_matrix_const_row(hyp_phi,
i).vector;
418 gsl_vector kinv_dot_y_phi_i = gsl_matrix_const_row(kinv_dot_y_phi,
i).vector;
419 double pred =
gp_predict(xst, &hyp_phi_i, x_train, &kinv_dot_y_phi_i, work);
420 gsl_vector_set(phi_at_nodes,
i, pred);
423 gsl_vector_free(xst);
430 Surrogatedata_submodel **submodel,
431 UNUSED
const char dir[],
432 UNUSED
const char grp_name[]
436 if(!submodel) exit(1);
439 *submodel =
XLALCalloc(1,
sizeof(Surrogatedata_submodel));
443 #ifdef LAL_HDF5_ENABLED
444 size_t size = strlen(dir) + strlen(SurDataHDF5) + 2;
446 snprintf(
path, size,
"%s/%s", dir, SurDataHDF5);
455 ReadHDF5RealMatrixDataset(root,
"hyp_amp", & (*submodel)->hyp_amp);
456 ReadHDF5RealMatrixDataset(root,
"hyp_phi", & (*submodel)->hyp_phi);
459 ReadHDF5RealMatrixDataset(root,
"kinv_dot_y_amp", & (*submodel)->kinv_dot_y_amp);
460 ReadHDF5RealMatrixDataset(root,
"kinv_dot_y_phi", & (*submodel)->kinv_dot_y_phi);
463 ReadHDF5RealMatrixDataset(root,
"x_train", & (*submodel)->x_train);
466 ReadHDF5RealVectorDataset(root,
"spline_nodes_amp", & (*submodel)->mf_amp);
467 ReadHDF5RealVectorDataset(root,
"spline_nodes_phase", & (*submodel)->mf_phi);
470 ReadHDF5RealVectorDataset(root,
"TF2_Mf_amp_cubic", & (*submodel)->TF2_mf_amp_cubic);
471 ReadHDF5RealVectorDataset(root,
"TF2_Mf_phi_cubic", & (*submodel)->TF2_mf_phi_cubic);
472 ReadHDF5RealVectorDataset(root,
"TF2_Mf_amp_linear", & (*submodel)->TF2_mf_amp_linear);
473 ReadHDF5RealVectorDataset(root,
"TF2_Mf_phi_linear", & (*submodel)->TF2_mf_phi_linear);
476 ReadHDF5RealVectorDataset(root,
"q_bounds", & (*submodel)->q_bounds);
477 ReadHDF5RealVectorDataset(root,
"chi1_bounds", & (*submodel)->chi1_bounds);
478 ReadHDF5RealVectorDataset(root,
"chi2_bounds", & (*submodel)->chi2_bounds);
479 ReadHDF5RealVectorDataset(root,
"lambda1_bounds", & (*submodel)->lambda1_bounds);
480 ReadHDF5RealVectorDataset(root,
"lambda2_bounds", & (*submodel)->lambda2_bounds);
483 double mf_min = gsl_vector_get( (*submodel)->mf_amp, 0);
485 (*submodel)->mf_phi = phi_nodes;
499 if(submodel->hyp_amp) gsl_matrix_free(submodel->hyp_amp);
500 if(submodel->hyp_phi) gsl_matrix_free(submodel->hyp_phi);
501 if(submodel->kinv_dot_y_amp) gsl_matrix_free(submodel->kinv_dot_y_amp);
502 if(submodel->kinv_dot_y_phi) gsl_matrix_free(submodel->kinv_dot_y_phi);
503 if(submodel->x_train) gsl_matrix_free(submodel->x_train);
504 if(submodel->mf_amp) gsl_vector_free(submodel->mf_amp);
505 if(submodel->mf_phi) gsl_vector_free(submodel->mf_phi);
506 if(submodel->TF2_mf_amp_cubic) gsl_vector_free(submodel->TF2_mf_amp_cubic);
507 if(submodel->TF2_mf_phi_cubic) gsl_vector_free(submodel->TF2_mf_phi_cubic);
508 if(submodel->TF2_mf_amp_linear) gsl_vector_free(submodel->TF2_mf_amp_linear);
509 if(submodel->TF2_mf_phi_linear) gsl_vector_free(submodel->TF2_mf_phi_linear);
511 if(submodel->q_bounds) gsl_vector_free(submodel->q_bounds);
512 if(submodel->chi1_bounds) gsl_vector_free(submodel->chi1_bounds);
513 if(submodel->chi2_bounds) gsl_vector_free(submodel->chi2_bounds);
514 if(submodel->lambda1_bounds) gsl_vector_free(submodel->lambda1_bounds);
515 if(submodel->lambda2_bounds) gsl_vector_free(submodel->lambda2_bounds);
520 UNUSED Surrogatedata *romdata,
521 UNUSED
const char dir[])
527 XLALPrintError(
"WARNING: You tried to setup the Surrogate model that was already initialised. Ignoring\n");
531 #ifdef LAL_HDF5_ENABLED
533 size_t size = strlen(dir) + strlen(SurDataHDF5) + 2;
535 snprintf(
path, size,
"%s/%s", dir, SurDataHDF5);
539 PrintInfoStringAttribute(
file,
"Email");
540 PrintInfoStringAttribute(
file,
"Description");
541 ret = ROM_check_version_number(
file, SurDataHDF5_VERSION_MAJOR,
542 SurDataHDF5_VERSION_MINOR,
543 SurDataHDF5_VERSION_MICRO);
566 (romdata)->
sub1 = NULL;
573 return 1 << (size_t) ceil(log2(n));
589 *PNphase = gsl_vector_alloc(Mfs->size);
602 if ((dquadmon1 > 0) || (dquadmon2 > 0)) {
603 XLALPrintInfo(
"Using quadrupole-monopole terms from fit: %g, %g\n", dquadmon1, dquadmon2);
608 double m1OverM =
q / (1.0+
q);
609 double m2OverM = 1.0 / (1.0+
q);
618 double m1M = m1OverM;
619 double m2M = m2OverM;
622 double chi1sq = chi1*chi1;
623 double chi2sq = chi2*chi2;
624 double qm_def1 = 1 + dquadmon1;
625 double qm_def2 = 1 + dquadmon2;
626 double eta =
q / ((1.0 +
q)*(1.0 +
q));
630 pn->v[6] -= pn_ss3 *
pn->v[0];
632 for (
size_t i=0;
i < Mfs->size;
i++) {
633 const double Mf = gsl_vector_get(Mfs,
i);
634 const double v = cbrt(
LAL_PI * Mf);
635 const double logv = log(v);
636 const double v2 = v * v;
637 const double v3 = v * v2;
638 const double v4 = v * v3;
639 const double v5 = v * v4;
640 const double v6 = v * v5;
641 const double v7 = v * v6;
642 const double v8 = v * v7;
643 const double v9 = v * v8;
644 const double v10 = v * v9;
645 const double v12 = v2 * v10;
646 double phasing = 0.0;
648 phasing +=
pn->v[7] * v7;
649 phasing += (
pn->v[6] +
pn->vlogv[6] * logv) * v6;
650 phasing += (
pn->v[5] +
pn->vlogv[5] * logv) * v5;
651 phasing +=
pn->v[4] * v4;
652 phasing +=
pn->v[3] * v3;
653 phasing +=
pn->v[2] * v2;
654 phasing +=
pn->v[1] * v;
658 phasing +=
pn->v[12] * v12;
659 phasing +=
pn->v[10] * v10;
663 gsl_vector_set(*PNphase,
i, -phasing);
681 *PNamp = gsl_vector_alloc(Mfs->size);
683 for (
size_t i=0;
i < Mfs->size;
i++) {
684 const double Mf = gsl_vector_get(Mfs,
i);
685 const double v = cbrt(
LAL_PI * Mf);
686 const double x = v*v;
688 double a00 = sqrt( (5.0*
LAL_PI/24.0)*eta );
689 double a10 = -323.0/224.0 + 451.0*eta/168.0;
690 double amp = -a00 * pow(
x, -7.0/4.0) * (1.0 + a10*
x);
691 gsl_vector_set(*PNamp,
i, amp);
698 Surrogatedata_submodel *sur,
706 double q_max = 1.0 / gsl_vector_get(sur->q_bounds, 0);
707 double q_min = 1.0 / gsl_vector_get(sur->q_bounds, 1);
709 double chi1_min = gsl_vector_get(sur->chi1_bounds, 0);
710 double chi1_max = gsl_vector_get(sur->chi1_bounds, 1);
711 double chi2_min = gsl_vector_get(sur->chi2_bounds, 0);
712 double chi2_max = gsl_vector_get(sur->chi2_bounds, 1);
714 double lambda1_min = gsl_vector_get(sur->lambda1_bounds, 0);
715 double lambda1_max = gsl_vector_get(sur->lambda1_bounds, 1);
716 double lambda2_min = gsl_vector_get(sur->lambda2_bounds, 0);
717 double lambda2_max = gsl_vector_get(sur->lambda2_bounds, 1);
719 if (q < q_min || q >
q_max) {
720 XLALPrintError(
"XLAL Error - %s: mass-ratio q (%f) out of bounds: [%f, %f]!\n", __func__,
q, q_min,
q_max);
724 if (chi1 < chi1_min || chi1 > chi1_max) {
725 XLALPrintError(
"XLAL Error - %s: aligned-spin chi1 (%f) out of bounds: [%f, %f]!\n", __func__, chi1, chi1_min, chi1_max);
729 if (chi2 < chi2_min || chi2 > chi2_max) {
730 XLALPrintError(
"XLAL Error - %s: aligned-spin chi2 (%f) out of bounds: [%f, %f]!\n", __func__, chi2, chi2_min, chi2_max);
734 if (lambda1 < lambda1_min || lambda1 > lambda1_max) {
735 XLALPrintError(
"XLAL Error - %s: tidal deformability lambda1 (%f) out of bounds: [%f, %f]!\n", __func__, lambda1, lambda1_min, lambda1_max);
739 if (lambda2 < lambda2_min || lambda2 > lambda2_max) {
740 XLALPrintError(
"XLAL Error - %s: tidal deformability lambda2 (%f) out of bounds: [%f, %f]!\n", __func__, lambda2, lambda2_min, lambda2_max);
775 if(!hptilde || !hctilde)
781 "Error setting up Surrogate data - check your $LAL_DATA_PATH\n");
784 if(*hptilde || *hctilde) {
785 XLALPrintError(
"(*hptilde) and (*hctilde) are supposed to be NULL, but got %p and %p",
786 (*hptilde), (*hctilde));
792 double q = (1.0 + sqrt(1.0 - 4.0*eta) - 2.0*eta) / (2.0*eta);
794 Surrogatedata_submodel *sur;
802 double fLow = freqs_in->
data[0];
803 double fHigh = freqs_in->
data[freqs_in->
length - 1];
808 int N_amp = sur->mf_amp->size;
809 int N_phi = sur->mf_phi->size;
812 gsl_vector *TF2_mf_amp = NULL;
813 gsl_vector *TF2_mf_phi = NULL;
814 const gsl_interp_type *spline_type = NULL;
815 switch (spline_order) {
817 TF2_mf_amp = sur->TF2_mf_amp_cubic;
818 TF2_mf_phi = sur->TF2_mf_phi_cubic;
819 spline_type = gsl_interp_cspline;
822 TF2_mf_amp = sur->TF2_mf_amp_linear;
823 TF2_mf_phi = sur->TF2_mf_phi_linear;
824 spline_type = gsl_interp_linear;
829 int N_amp_TF2 = TF2_mf_amp->size;
830 int N_phi_TF2 = TF2_mf_phi->size;
834 double Mf_TF2_min = fmax(gsl_vector_get(TF2_mf_amp, 0),
835 gsl_vector_get(TF2_mf_phi, 0));
836 double Mf_TF2_max = fmin(gsl_vector_get(TF2_mf_amp, N_amp_TF2-1),
837 gsl_vector_get(TF2_mf_phi, N_phi_TF2-1));
838 double Mf_sur_min = fmax(gsl_vector_get(sur->mf_amp, 0),
839 gsl_vector_get(sur->mf_phi, 0));
840 double Mf_sur_max = fmin(gsl_vector_get(sur->mf_amp, N_amp-1),
841 gsl_vector_get(sur->mf_phi, N_phi-1));
848 double fLow_geom = fLow * Mtot_sec;
849 double fHigh_geom = fHigh * Mtot_sec;
850 double fRef_geom = fRef * Mtot_sec;
851 double deltaF_geom = deltaF * Mtot_sec;
854 if (fLow_geom < Mf_TF2_min)
855 XLAL_ERROR(
XLAL_EDOM,
"Starting frequency Mflow=%g is smaller than lowest frequency in surrogate Mf=%g.\n", fLow_geom, Mf_TF2_min);
856 if (fHigh_geom == 0 || fHigh_geom > Mf_sur_max)
857 fHigh_geom = Mf_sur_max;
858 else if (fHigh_geom < Mf_sur_min)
859 XLAL_ERROR(
XLAL_EDOM,
"End frequency %g is smaller than surrogate starting frequency %g!\n", fHigh_geom, Mf_TF2_min);
860 if (fHigh_geom <= fLow_geom)
861 XLAL_ERROR(
XLAL_EDOM,
"End frequency %g is smaller than (or equal to) starting frequency %g!\n", fHigh_geom, fLow_geom);
862 if (fRef_geom > Mf_sur_max) {
863 XLALPrintWarning(
"Reference frequency Mf_ref=%g is greater than maximal frequency in surrogate Mf=%g. Starting at maximal frequency in ROM.\n", fRef_geom, Mf_sur_max);
864 fRef_geom = Mf_sur_max;
866 if (fRef_geom < Mf_TF2_min) {
867 XLALPrintWarning(
"Reference frequency Mf_ref=%g is smaller than lowest frequency in surrogate Mf=%g. Starting at lowest frequency in ROM.\n", fLow_geom, Mf_TF2_min);
868 fRef_geom = Mf_TF2_min;
872 gsl_vector *sur_amp_at_nodes = gsl_vector_alloc(N_amp);
873 gsl_vector *sur_phi_at_nodes_tmp = gsl_vector_alloc(N_phi - 1);
876 gsl_vector *work = gsl_vector_alloc(5);
879 q, chi1, chi2, lambda1, lambda2,
886 sur_phi_at_nodes_tmp,
890 gsl_vector_free(work);
893 gsl_vector_free(sur_amp_at_nodes);
894 gsl_vector_free(sur_phi_at_nodes_tmp);
903 gsl_interp_accel *acc_amp_sur = gsl_interp_accel_alloc();
904 gsl_spline *spline_amp_sur = gsl_spline_alloc(gsl_interp_cspline, N_amp);
905 gsl_spline_init(spline_amp_sur, gsl_vector_const_ptr(sur->mf_amp, 0),
906 gsl_vector_const_ptr(sur_amp_at_nodes, 0), N_amp);
908 gsl_interp_accel *acc_phi_sur = gsl_interp_accel_alloc();
909 gsl_spline *spline_phi_sur = gsl_spline_alloc(gsl_interp_cspline, N_phi);
910 gsl_spline_init(spline_phi_sur, gsl_vector_const_ptr(sur->mf_phi, 0),
911 gsl_vector_const_ptr(sur_phi_at_nodes, 0), N_phi);
913 gsl_vector_free(sur_amp_at_nodes);
914 gsl_vector_free(sur_phi_at_nodes);
918 gsl_vector *TF2_phi_at_nodes = NULL;
919 retcode |=
TaylorF2Phasing(Mtot,
q, chi1, chi2, lambda1, lambda2, TF2_mf_phi, &TF2_phi_at_nodes);
921 gsl_vector *TF2_amp_at_nodes = NULL;
925 gsl_vector_free(TF2_amp_at_nodes);
926 gsl_vector_free(TF2_phi_at_nodes);
935 gsl_interp_accel *acc_amp_TF2 = gsl_interp_accel_alloc();
936 gsl_spline *spline_amp_TF2 = gsl_spline_alloc(spline_type, N_amp_TF2);
937 gsl_vector *spline_amp_values = gsl_vector_alloc(N_amp_TF2);
938 for (
int i=0;
i<N_amp_TF2;
i++) {
939 double Mf = gsl_vector_get(TF2_mf_amp,
i);
940 double amp_i = gsl_vector_get(TF2_amp_at_nodes,
i);
941 if ((Mf >= Mf_sur_min) & (Mf <= Mf_sur_max))
942 amp_i *= exp(gsl_spline_eval(spline_amp_sur, Mf, acc_amp_sur));
943 gsl_vector_set(spline_amp_values,
i, amp_i);
945 gsl_spline_init(spline_amp_TF2, gsl_vector_const_ptr(TF2_mf_amp, 0),
946 gsl_vector_const_ptr(spline_amp_values, 0), N_amp_TF2);
949 gsl_interp_accel *acc_phi_TF2 = gsl_interp_accel_alloc();
950 gsl_spline *spline_phi_TF2 = gsl_spline_alloc(spline_type, N_phi_TF2);
951 gsl_vector *spline_phi_values = gsl_vector_alloc(N_phi_TF2);
952 for (
int i=0;
i<N_phi_TF2;
i++) {
953 double Mf = gsl_vector_get(TF2_mf_phi,
i);
954 double phi_i = gsl_vector_get(TF2_phi_at_nodes,
i);
955 if ((Mf >= Mf_sur_min) & (Mf <= Mf_sur_max))
956 phi_i += gsl_spline_eval(spline_phi_sur, Mf, acc_phi_sur);
957 gsl_vector_set(spline_phi_values,
i, phi_i);
959 gsl_spline_init(spline_phi_TF2, gsl_vector_const_ptr(TF2_mf_phi, 0),
960 gsl_vector_const_ptr(spline_phi_values, 0), N_phi_TF2);
962 gsl_vector_free(TF2_amp_at_nodes);
963 gsl_vector_free(TF2_phi_at_nodes);
964 gsl_vector_free(spline_amp_values);
965 gsl_vector_free(spline_phi_values);
967 gsl_spline_free(spline_amp_sur);
968 gsl_spline_free(spline_phi_sur);
969 gsl_interp_accel_free(acc_amp_sur);
970 gsl_interp_accel_free(acc_phi_sur);
980 npts =
NextPow2(fHigh_geom / deltaF_geom) + 1;
981 if (fHigh_geom < fHigh * Mtot_sec)
982 npts =
NextPow2(fHigh * Mtot_sec / deltaF_geom) + 1;
990 double fHigh_temp = fHigh_geom / Mtot_sec;
992 UINT4 iStop = (
UINT4) ceil(fHigh_temp / deltaF);
998 freqs->
data[
i-iStart] =
i*deltaF_geom;
1012 freqs->
data[
i] = freqs_in->
data[
i] * Mtot_sec;
1015 if (!(*hptilde) || !(*hctilde)) {
1017 gsl_interp_accel_free(acc_phi_TF2);
1018 gsl_spline_free(spline_phi_TF2);
1019 gsl_interp_accel_free(acc_amp_TF2);
1020 gsl_spline_free(spline_amp_TF2);
1023 memset((*hptilde)->data->data, 0, npts *
sizeof(
COMPLEX16));
1024 memset((*hctilde)->data->data, 0, npts *
sizeof(
COMPLEX16));
1029 COMPLEX16 *pdata=(*hptilde)->data->data;
1030 COMPLEX16 *cdata=(*hctilde)->data->data;
1032 REAL8 cosi = cos(inclination);
1033 REAL8 pcoef = 0.5*(1.0 + cosi*cosi);
1036 double amp0 = Mtot * Mtot_sec *
LAL_MRSUN_SI / (distance);
1039 double phase_change = 0.0;
1040 phase_change = gsl_spline_eval(spline_phi_TF2, fRef_geom, acc_phi_TF2) - 2*phiRef;
1044 Mf_sur_max = gsl_vector_get(sur->mf_phi, N_phi-1);
1045 double Mf_final = Mf_sur_max;
1049 double f = freqs->
data[
i];
1050 if (f > Mf_final)
continue;
1053 double A = gsl_spline_eval(spline_amp_TF2, f, acc_amp_TF2);
1054 double phase = gsl_spline_eval(spline_phi_TF2, f, acc_phi_TF2) - phase_change;
1055 COMPLEX16 htilde = amp0*A * (cos(phase) + I*sin(phase));
1056 pdata[j] = pcoef * htilde;
1057 cdata[j] = -I * ccoef * htilde;
1063 if (Mf_final > freqs->
data[L-1])
1064 Mf_final = freqs->
data[L-1];
1065 if (Mf_final < freqs->
data[0]) {
1067 gsl_interp_accel_free(acc_phi_TF2);
1068 gsl_spline_free(spline_phi_TF2);
1069 gsl_interp_accel_free(acc_amp_TF2);
1070 gsl_spline_free(spline_amp_TF2);
1078 REAL8 Mf_ISCO_Schwrazschild = 1.0 / (pow(6.,3./2.)*
LAL_PI);
1079 REAL8 t_corr = gsl_spline_eval_deriv(spline_phi_TF2, Mf_ISCO_Schwrazschild, acc_phi_TF2) / (2*
LAL_PI);
1083 double f = freqs->
data[
i] - fRef_geom;
1085 double phase_factor = -2*
LAL_PI * f * t_corr;
1086 COMPLEX16 t_factor = (cos(phase_factor) + I*sin(phase_factor));
1087 pdata[j] *= t_factor;
1088 cdata[j] *= t_factor;
1092 gsl_interp_accel_free(acc_phi_TF2);
1093 gsl_spline_free(spline_phi_TF2);
1094 gsl_interp_accel_free(acc_amp_TF2);
1095 gsl_spline_free(spline_amp_TF2);
1151 struct tagCOMPLEX16FrequencySeries **hptilde,
1152 struct tagCOMPLEX16FrequencySeries **hctilde,
1169 double m1temp = m1SI;
1170 double chi1temp = chi1;
1171 double lambda1temp = lambda1;
1177 lambda2 = lambda1temp;
1183 double Mtot = mass1+mass2;
1184 double eta = mass1 * mass2 / (Mtot*Mtot);
1190 #ifdef LAL_PTHREAD_LOCK
1198 "Error setting up Surrogate data - check your $LAL_DATA_PATH\n");
1203 int retcode =
SurrogateCore(hptilde, hctilde, phiRef, fRef, distance,
1204 inclination, Mtot_sec, eta, chi1, chi2,
1205 lambda1, lambda2, freqs, 0, spline_order);
1218 struct tagCOMPLEX16FrequencySeries **hptilde,
1219 struct tagCOMPLEX16FrequencySeries **hctilde,
1238 double m1temp = m1SI;
1239 double chi1temp = chi1;
1240 double lambda1temp = lambda1;
1246 lambda2 = lambda1temp;
1252 double Mtot = mass1+mass2;
1253 double eta = mass1 * mass2 / (Mtot*Mtot);
1260 #ifdef LAL_PTHREAD_LOCK
1270 freqs->
data[0] = fLow;
1271 freqs->
data[1] = fHigh;
1273 int retcode =
SurrogateCore(hptilde, hctilde, phiRef, fRef, distance,
1274 inclination, Mtot_sec, eta, chi1, chi2,
1275 lambda1, lambda2, freqs, deltaF, spline_order);
1292 #ifdef LAL_HDF5_ENABLED
1293 #define datafile SurDataHDF5
1297 char *dir = dirname(
path);
struct tagLALH5File LALH5File
void XLALDestroyDict(LALDict *dict)
LALDict * XLALCreateDict(void)
Auxiliary functions for SEOBNRv1/v2 reduced order modeling codes in LALSimIMRSEOBNRv2ROMDoubleSpin....
static UNUSED int Surrogate_Init(const char dir[])
Setup Surrogate model using data files installed in dir.
static UNUSED void save_gsl_frequency_series(const char filename[], gsl_vector *x, gsl_vector *y)
int(* load_dataPtr)(const char *, gsl_vector *, gsl_vector *, gsl_matrix *, gsl_matrix *, gsl_vector *)
static Surrogatedata __lalsim_SurrogateDS_data
static int GPR_evaluation_5D(double q, double chi1, double chi2, double lambda1, double lambda2, gsl_matrix *hyp_amp, gsl_matrix *hyp_phi, gsl_matrix *kinv_dot_y_amp, gsl_matrix *kinv_dot_y_phi, gsl_matrix *x_train, gsl_vector *amp_at_EI_nodes, gsl_vector *phi_at_EI_nodes, gsl_vector *work)
double gp_predict(gsl_vector *xst, gsl_vector *hyperparams, gsl_matrix *x_train, gsl_vector *Kinv_dot_y, gsl_vector *work)
static UNUSED int Surrogatedata_Init(Surrogatedata *romdata, const char dir[])
static UNUSED int Surrogatedata_Init_submodel(UNUSED Surrogatedata_submodel **submodel, UNUSED const char dir[], UNUSED const char grp_name[])
static UNUSED void Surrogatedata_Cleanup_submodel(Surrogatedata_submodel *submodel)
static UNUSED void Surrogatedata_Cleanup(Surrogatedata *romdata)
static int TaylorF2Amplitude1PN(double eta, gsl_vector *Mfs, gsl_vector **PNamp)
static UNUSED void Surrogate_Init_LALDATA(void)
Setup Surrogate model using data files installed in $LAL_DATA_PATH.
static double xi_of_lambda(double lambda)
Coordinate transformation.
static gsl_vector * gsl_vector_prepend_value(gsl_vector *v, double value)
double kernel(gsl_vector *x1, gsl_vector *x2, gsl_vector *hyperparams, gsl_vector *work)
static UNUSED bool Surrogate_IsSetup(void)
Helper function to check if the Surrogate model has been initialised.
static size_t NextPow2(const size_t n)
static UNUSED int CheckParameterSpaceBounds(Surrogatedata_submodel *sur, double q, double chi1, double chi2, double lambda1, double lambda2)
static UNUSED int SurrogateCore(COMPLEX16FrequencySeries **hptilde, COMPLEX16FrequencySeries **hctilde, double phiRef, double fRef, double distance, double inclination, double Mtot_sec, double eta, double chi1, double chi2, double lambda1, double lambda2, const REAL8Sequence *freqs, double deltaF, SEOBNRv4TSurrogate_spline_order spline_order)
Core function for computing the ROM waveform.
static int TaylorF2Phasing(double Mtot, double q, double chi1, double chi2, double lambda1, double lambda2, gsl_vector *Mfs, gsl_vector **PNphase)
static REAL8 UNUSED XLALSimInspiralTaylorF2Phasing_6PNS1S2OCoeff(REAL8 eta)
static REAL8 UNUSED XLALSimInspiralTaylorF2Phasing_6PNQM2SCoeff(REAL8 mByM)
static REAL8 UNUSED XLALSimInspiralTaylorF2Phasing_6PNSelf2SCoeff(REAL8 mByM)
REAL8 XLALSimUniversalRelationQuadMonVSlambda2Tidal(REAL8 lambda2bar)
#define XLAL_FILE_RESOLVE_PATH(fname)
COMPLEX16FrequencySeries * XLALCreateCOMPLEX16FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
void XLALH5FileClose(LALH5File UNUSED *file)
LALH5File * XLALH5GroupOpen(LALH5File UNUSED *file, const char UNUSED *name)
LALH5File * XLALH5FileOpen(const char UNUSED *path, const char UNUSED *mode)
void * XLALCalloc(size_t m, size_t n)
void * XLALMalloc(size_t n)
SEOBNRv4TSurrogate_spline_order
@ SEOBNRv4TSurrogate_CUBIC
use cubic splines in frequency
@ SEOBNRv4TSurrogate_LINEAR
use linear splines in frequency
int XLALSimIMRSEOBNRv4TSurrogateFrequencySequence(struct tagCOMPLEX16FrequencySeries **hptilde, struct tagCOMPLEX16FrequencySeries **hctilde, const REAL8Sequence *freqs, REAL8 phiRef, REAL8 fRef, REAL8 distance, REAL8 inclination, REAL8 m1SI, REAL8 m2SI, REAL8 chi1, REAL8 chi2, REAL8 lambda1, REAL8 lambda2, SEOBNRv4TSurrogate_spline_order spline_order)
Compute waveform in LAL format at specified frequencies for the SEOBNRv4T_surrogate model.
int XLALSimIMRSEOBNRv4TSurrogate(struct tagCOMPLEX16FrequencySeries **hptilde, struct tagCOMPLEX16FrequencySeries **hctilde, REAL8 phiRef, REAL8 deltaF, REAL8 fLow, REAL8 fHigh, REAL8 fRef, REAL8 distance, REAL8 inclination, REAL8 m1SI, REAL8 m2SI, REAL8 chi1, REAL8 chi2, REAL8 lambda1, REAL8 lambda2, SEOBNRv4TSurrogate_spline_order spline_order)
Compute waveform in LAL format for the SEOBNRv4T_surrogate model.
@ LAL_SIM_INSPIRAL_SPIN_ORDER_35PN
@ LAL_SIM_INSPIRAL_TIDAL_ORDER_6PN
int XLALSimInspiralTaylorF2AlignedPhasing(PNPhasingSeries **pfa, const REAL8 m1, const REAL8 m2, const REAL8 chi1, const REAL8 chi2, LALDict *extraPars)
Returns structure containing TaylorF2 phasing coefficients for given physical parameters.
void XLALDestroyREAL8Sequence(REAL8Sequence *sequence)
REAL8Sequence * XLALCreateREAL8Sequence(size_t length)
const LALUnit lalStrainUnit
const LALUnit lalSecondUnit
LALUnit * XLALUnitMultiply(LALUnit *output, const LALUnit *unit1, const LALUnit *unit2)
#define XLAL_ERROR_VOID(...)
int int int XLALPrintInfo(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
#define XLAL_CHECK(assertion,...)
#define XLAL_CHECK_ABORT(assertion)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
int int XLALPrintWarning(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
int pthread_once(pthread_once_t *once_control, void(*init_routine)(void))
gsl_vector * TF2_mf_amp_linear
gsl_matrix * kinv_dot_y_amp
gsl_vector * lambda2_bounds
gsl_vector * TF2_mf_amp_cubic
gsl_matrix * kinv_dot_y_phi
gsl_vector * TF2_mf_phi_cubic
gsl_vector * TF2_mf_phi_linear
gsl_vector * lambda1_bounds
Surrogatedata_submodel * sub1