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>
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>
57static const char SurDataHDF5[] =
"SEOBNRv4T_surrogate_v2.0.0.hdf5";
60#include <lal/LALSimInspiral.h>
61#include <lal/LALSimIMR.h>
69#include <lal/LALConfig.h>
70#ifdef LAL_PTHREAD_LOCK
76#ifdef LAL_PTHREAD_LOCK
77static pthread_once_t Surrogate_is_initialized = PTHREAD_ONCE_INIT;
118typedef int (*
load_dataPtr)(
const char*, gsl_vector *, gsl_vector *, gsl_matrix *, gsl_matrix *, gsl_vector *);
129 gsl_vector *hyperparams,
135 gsl_vector *hyperparams,
137 gsl_vector *Kinv_dot_y,
159 gsl_matrix *kinv_dot_y_amp,
160 gsl_matrix *kinv_dot_y_phi,
162 gsl_vector *amp_at_EI_nodes,
163 gsl_vector *phi_at_EI_nodes,
168 UNUSED Surrogatedata_submodel **submodel,
169 UNUSED
const char dir[],
170 UNUSED
const char grp_name[]
176 Surrogatedata_submodel *sur,
211static size_t NextPow2(
const size_t n);
234 fprintf(stderr,
"save_gsl_frequency_series: %s: %zu %zu\n",
filename,
x->size,
y->size);
236 for (
size_t i=0;
i<
x->size;
i++) {
237 fprintf(
fp,
"%g\t%g\n", gsl_vector_get(
x,
i), gsl_vector_get(
y,
i));
247 gsl_vector *vout = gsl_vector_alloc(n+1);
249 gsl_vector_set(vout, 0, value);
250 for (
int i=1;
i<=n;
i++)
251 gsl_vector_set(vout,
i, gsl_vector_get(v,
i-1));
260 gsl_vector *hyperparams,
280 double sigma_f = gsl_vector_get(hyperparams, 0);
281 double sigma_n = gsl_vector_get(hyperparams, hyperparams->size-1);
282 gsl_vector ls = gsl_vector_subvector(hyperparams, 1, hyperparams->size-2).vector;
285 "kernel(): dimensions of vectors x1, x2 and ls: %zu, %zu, %zu have to be consistent.\n",
286 x1->size, x2->size, ls.size);
290 if (gsl_vector_equal(x1, x2))
291 nugget = sigma_n*sigma_n;
293 gsl_vector_memcpy(work, x1);
294 gsl_vector_sub(work, x2);
295 gsl_vector_div(work, &ls);
296 double r = gsl_blas_dnrm2(work);
299 double matern = (1.0 + sqrt(5.0)*
r + 5.0*
r*
r/3.0) * exp(-sqrt(5.0)*
r);
303 return sigma_f*sigma_f * matern + nugget;
308 gsl_vector *hyperparams,
310 gsl_vector *Kinv_dot_y,
333 int n = x_train->size1;
334 gsl_vector *Kst = gsl_vector_alloc(n);
335 for (
int i=0;
i < n;
i++) {
336 gsl_vector
x = gsl_matrix_const_row(x_train,
i).vector;
337 double ker =
kernel(xst, &
x, hyperparams, work);
338 gsl_vector_set(Kst,
i, ker);
343 gsl_blas_ddot(Kst, Kinv_dot_y, &res);
344 gsl_vector_free(Kst);
374 const double a = 100.0;
375 return log10(lambda /
a + 1.0);
388 gsl_matrix *kinv_dot_y_amp,
389 gsl_matrix *kinv_dot_y_phi,
391 gsl_vector *amp_at_nodes,
392 gsl_vector *phi_at_nodes,
397 gsl_vector *xst = gsl_vector_alloc(5);
398 double q_inv = 1.0/
q;
399 gsl_vector_set(xst, 0, q_inv);
400 gsl_vector_set(xst, 1, chi1);
401 gsl_vector_set(xst, 2, chi2);
406 for (
size_t i=0;
i<amp_at_nodes->size;
i++) {
407 gsl_vector hyp_amp_i = gsl_matrix_const_row(hyp_amp,
i).vector;
408 gsl_vector kinv_dot_y_amp_i = gsl_matrix_const_row(kinv_dot_y_amp,
i).vector;
409 double pred =
gp_predict(xst, &hyp_amp_i, x_train, &kinv_dot_y_amp_i, work);
410 gsl_vector_set(amp_at_nodes,
i, pred);
414 for (
size_t i=0;
i<phi_at_nodes->size;
i++) {
415 gsl_vector hyp_phi_i = gsl_matrix_const_row(hyp_phi,
i).vector;
416 gsl_vector kinv_dot_y_phi_i = gsl_matrix_const_row(kinv_dot_y_phi,
i).vector;
417 double pred =
gp_predict(xst, &hyp_phi_i, x_train, &kinv_dot_y_phi_i, work);
418 gsl_vector_set(phi_at_nodes,
i, pred);
421 gsl_vector_free(xst);
428 Surrogatedata_submodel **submodel,
429 UNUSED
const char dir[],
430 UNUSED
const char grp_name[]
434 if(!submodel) exit(1);
437 *submodel =
XLALCalloc(1,
sizeof(Surrogatedata_submodel));
441#ifdef LAL_HDF5_ENABLED
442 size_t size = strlen(dir) + strlen(SurDataHDF5) + 2;
444 snprintf(
path, size,
"%s/%s", dir, SurDataHDF5);
453 ReadHDF5RealMatrixDataset(root,
"hyp_amp", & (*submodel)->hyp_amp);
454 ReadHDF5RealMatrixDataset(root,
"hyp_phi", & (*submodel)->hyp_phi);
457 ReadHDF5RealMatrixDataset(root,
"kinv_dot_y_amp", & (*submodel)->kinv_dot_y_amp);
458 ReadHDF5RealMatrixDataset(root,
"kinv_dot_y_phi", & (*submodel)->kinv_dot_y_phi);
461 ReadHDF5RealMatrixDataset(root,
"x_train", & (*submodel)->x_train);
464 ReadHDF5RealVectorDataset(root,
"spline_nodes_amp", & (*submodel)->mf_amp);
465 ReadHDF5RealVectorDataset(root,
"spline_nodes_phase", & (*submodel)->mf_phi);
468 ReadHDF5RealVectorDataset(root,
"TF2_Mf_amp_cubic", & (*submodel)->TF2_mf_amp_cubic);
469 ReadHDF5RealVectorDataset(root,
"TF2_Mf_phi_cubic", & (*submodel)->TF2_mf_phi_cubic);
470 ReadHDF5RealVectorDataset(root,
"TF2_Mf_amp_linear", & (*submodel)->TF2_mf_amp_linear);
471 ReadHDF5RealVectorDataset(root,
"TF2_Mf_phi_linear", & (*submodel)->TF2_mf_phi_linear);
474 ReadHDF5RealVectorDataset(root,
"q_bounds", & (*submodel)->q_bounds);
475 ReadHDF5RealVectorDataset(root,
"chi1_bounds", & (*submodel)->chi1_bounds);
476 ReadHDF5RealVectorDataset(root,
"chi2_bounds", & (*submodel)->chi2_bounds);
477 ReadHDF5RealVectorDataset(root,
"lambda1_bounds", & (*submodel)->lambda1_bounds);
478 ReadHDF5RealVectorDataset(root,
"lambda2_bounds", & (*submodel)->lambda2_bounds);
481 double mf_min = gsl_vector_get( (*submodel)->mf_amp, 0);
483 (*submodel)->mf_phi = phi_nodes;
497 if(submodel->hyp_amp) gsl_matrix_free(submodel->hyp_amp);
498 if(submodel->hyp_phi) gsl_matrix_free(submodel->hyp_phi);
499 if(submodel->kinv_dot_y_amp) gsl_matrix_free(submodel->kinv_dot_y_amp);
500 if(submodel->kinv_dot_y_phi) gsl_matrix_free(submodel->kinv_dot_y_phi);
501 if(submodel->x_train) gsl_matrix_free(submodel->x_train);
502 if(submodel->mf_amp) gsl_vector_free(submodel->mf_amp);
503 if(submodel->mf_phi) gsl_vector_free(submodel->mf_phi);
504 if(submodel->TF2_mf_amp_cubic) gsl_vector_free(submodel->TF2_mf_amp_cubic);
505 if(submodel->TF2_mf_phi_cubic) gsl_vector_free(submodel->TF2_mf_phi_cubic);
506 if(submodel->TF2_mf_amp_linear) gsl_vector_free(submodel->TF2_mf_amp_linear);
507 if(submodel->TF2_mf_phi_linear) gsl_vector_free(submodel->TF2_mf_phi_linear);
509 if(submodel->q_bounds) gsl_vector_free(submodel->q_bounds);
510 if(submodel->chi1_bounds) gsl_vector_free(submodel->chi1_bounds);
511 if(submodel->chi2_bounds) gsl_vector_free(submodel->chi2_bounds);
512 if(submodel->lambda1_bounds) gsl_vector_free(submodel->lambda1_bounds);
513 if(submodel->lambda2_bounds) gsl_vector_free(submodel->lambda2_bounds);
518 UNUSED Surrogatedata *romdata,
519 UNUSED
const char dir[])
525 XLALPrintError(
"WARNING: You tried to setup the Surrogate model that was already initialised. Ignoring\n");
529#ifdef LAL_HDF5_ENABLED
531 size_t size = strlen(dir) + strlen(SurDataHDF5) + 2;
533 snprintf(
path, size,
"%s/%s", dir, SurDataHDF5);
537 PrintInfoStringAttribute(
file,
"Email");
538 PrintInfoStringAttribute(
file,
"Description");
539 ret = ROM_check_canonical_file_basename(
file,SurDataHDF5,
"CANONICAL_FILE_BASENAME");
562 (romdata)->
sub1 = NULL;
569 return 1 << (size_t) ceil(log2(n));
585 *PNphase = gsl_vector_alloc(Mfs->size);
598 if ((dquadmon1 > 0) || (dquadmon2 > 0)) {
599 XLALPrintInfo(
"Using quadrupole-monopole terms from fit: %g, %g\n", dquadmon1, dquadmon2);
604 double m1OverM =
q / (1.0+
q);
605 double m2OverM = 1.0 / (1.0+
q);
614 double m1M = m1OverM;
615 double m2M = m2OverM;
618 double chi1sq = chi1*chi1;
619 double chi2sq = chi2*chi2;
620 double qm_def1 = 1 + dquadmon1;
621 double qm_def2 = 1 + dquadmon2;
622 double eta =
q / ((1.0 +
q)*(1.0 +
q));
626 pn->v[6] -= pn_ss3 *
pn->v[0];
628 for (
size_t i=0;
i < Mfs->size;
i++) {
629 const double Mf = gsl_vector_get(Mfs,
i);
630 const double v = cbrt(
LAL_PI * Mf);
631 const double logv = log(v);
632 const double v2 = v * v;
633 const double v3 = v * v2;
634 const double v4 = v * v3;
635 const double v5 = v * v4;
636 const double v6 = v * v5;
637 const double v7 = v * v6;
638 const double v8 = v * v7;
639 const double v9 = v * v8;
640 const double v10 = v * v9;
641 const double v12 = v2 * v10;
642 double phasing = 0.0;
644 phasing +=
pn->v[7] * v7;
645 phasing += (
pn->v[6] +
pn->vlogv[6] * logv) * v6;
646 phasing += (
pn->v[5] +
pn->vlogv[5] * logv) * v5;
647 phasing +=
pn->v[4] * v4;
648 phasing +=
pn->v[3] * v3;
649 phasing +=
pn->v[2] * v2;
650 phasing +=
pn->v[1] * v;
654 phasing +=
pn->v[12] * v12;
655 phasing +=
pn->v[10] * v10;
659 gsl_vector_set(*PNphase,
i, -phasing);
677 *PNamp = gsl_vector_alloc(Mfs->size);
679 for (
size_t i=0;
i < Mfs->size;
i++) {
680 const double Mf = gsl_vector_get(Mfs,
i);
681 const double v = cbrt(
LAL_PI * Mf);
682 const double x = v*v;
684 double a00 = sqrt( (5.0*
LAL_PI/24.0)*eta );
685 double a10 = -323.0/224.0 + 451.0*eta/168.0;
686 double amp = -a00 * pow(
x, -7.0/4.0) * (1.0 + a10*
x);
687 gsl_vector_set(*PNamp,
i, amp);
694 Surrogatedata_submodel *sur,
702 double q_max = 1.0 / gsl_vector_get(sur->q_bounds, 0);
703 double q_min = 1.0 / gsl_vector_get(sur->q_bounds, 1);
705 double chi1_min = gsl_vector_get(sur->chi1_bounds, 0);
706 double chi1_max = gsl_vector_get(sur->chi1_bounds, 1);
707 double chi2_min = gsl_vector_get(sur->chi2_bounds, 0);
708 double chi2_max = gsl_vector_get(sur->chi2_bounds, 1);
710 double lambda1_min = gsl_vector_get(sur->lambda1_bounds, 0);
711 double lambda1_max = gsl_vector_get(sur->lambda1_bounds, 1);
712 double lambda2_min = gsl_vector_get(sur->lambda2_bounds, 0);
713 double lambda2_max = gsl_vector_get(sur->lambda2_bounds, 1);
715 if (q < q_min || q >
q_max) {
716 XLALPrintError(
"XLAL Error - %s: mass-ratio q (%f) out of bounds: [%f, %f]!\n", __func__,
q, q_min,
q_max);
720 if (chi1 < chi1_min || chi1 > chi1_max) {
721 XLALPrintError(
"XLAL Error - %s: aligned-spin chi1 (%f) out of bounds: [%f, %f]!\n", __func__, chi1, chi1_min, chi1_max);
725 if (chi2 < chi2_min || chi2 > chi2_max) {
726 XLALPrintError(
"XLAL Error - %s: aligned-spin chi2 (%f) out of bounds: [%f, %f]!\n", __func__, chi2, chi2_min, chi2_max);
730 if (lambda1 < lambda1_min || lambda1 > lambda1_max) {
731 XLALPrintError(
"XLAL Error - %s: tidal deformability lambda1 (%f) out of bounds: [%f, %f]!\n", __func__, lambda1, lambda1_min, lambda1_max);
735 if (lambda2 < lambda2_min || lambda2 > lambda2_max) {
736 XLALPrintError(
"XLAL Error - %s: tidal deformability lambda2 (%f) out of bounds: [%f, %f]!\n", __func__, lambda2, lambda2_min, lambda2_max);
771 if(!hptilde || !hctilde)
777 "Error setting up Surrogate data - check your $LAL_DATA_PATH\n");
780 if(*hptilde || *hctilde) {
781 XLALPrintError(
"(*hptilde) and (*hctilde) are supposed to be NULL, but got %p and %p",
782 (*hptilde), (*hctilde));
788 double q = (1.0 + sqrt(1.0 - 4.0*eta) - 2.0*eta) / (2.0*eta);
790 Surrogatedata_submodel *sur;
798 double fLow = freqs_in->
data[0];
799 double fHigh = freqs_in->
data[freqs_in->
length - 1];
804 int N_amp = sur->mf_amp->size;
805 int N_phi = sur->mf_phi->size;
808 gsl_vector *TF2_mf_amp = NULL;
809 gsl_vector *TF2_mf_phi = NULL;
810 const gsl_interp_type *spline_type = NULL;
811 switch (spline_order) {
813 TF2_mf_amp = sur->TF2_mf_amp_cubic;
814 TF2_mf_phi = sur->TF2_mf_phi_cubic;
815 spline_type = gsl_interp_cspline;
818 TF2_mf_amp = sur->TF2_mf_amp_linear;
819 TF2_mf_phi = sur->TF2_mf_phi_linear;
820 spline_type = gsl_interp_linear;
825 int N_amp_TF2 = TF2_mf_amp->size;
826 int N_phi_TF2 = TF2_mf_phi->size;
830 double Mf_TF2_min = fmax(gsl_vector_get(TF2_mf_amp, 0),
831 gsl_vector_get(TF2_mf_phi, 0));
832 double Mf_TF2_max = fmin(gsl_vector_get(TF2_mf_amp, N_amp_TF2-1),
833 gsl_vector_get(TF2_mf_phi, N_phi_TF2-1));
834 double Mf_sur_min = fmax(gsl_vector_get(sur->mf_amp, 0),
835 gsl_vector_get(sur->mf_phi, 0));
836 double Mf_sur_max = fmin(gsl_vector_get(sur->mf_amp, N_amp-1),
837 gsl_vector_get(sur->mf_phi, N_phi-1));
844 double fLow_geom = fLow * Mtot_sec;
845 double fHigh_geom = fHigh * Mtot_sec;
846 double fRef_geom = fRef * Mtot_sec;
847 double deltaF_geom = deltaF * Mtot_sec;
850 if (fLow_geom < Mf_TF2_min)
851 XLAL_ERROR(
XLAL_EDOM,
"Starting frequency Mflow=%g is smaller than lowest frequency in surrogate Mf=%g.\n", fLow_geom, Mf_TF2_min);
852 if (fHigh_geom == 0 || fHigh_geom > Mf_sur_max)
853 fHigh_geom = Mf_sur_max;
854 else if (fHigh_geom < Mf_sur_min)
855 XLAL_ERROR(
XLAL_EDOM,
"End frequency %g is smaller than surrogate starting frequency %g!\n", fHigh_geom, Mf_TF2_min);
856 if (fHigh_geom <= fLow_geom)
857 XLAL_ERROR(
XLAL_EDOM,
"End frequency %g is smaller than (or equal to) starting frequency %g!\n", fHigh_geom, fLow_geom);
858 if (fRef_geom > Mf_sur_max) {
859 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);
860 fRef_geom = Mf_sur_max;
862 if (fRef_geom < Mf_TF2_min) {
863 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);
864 fRef_geom = Mf_TF2_min;
868 gsl_vector *sur_amp_at_nodes = gsl_vector_alloc(N_amp);
869 gsl_vector *sur_phi_at_nodes_tmp = gsl_vector_alloc(N_phi - 1);
872 gsl_vector *work = gsl_vector_alloc(5);
875 q, chi1, chi2, lambda1, lambda2,
882 sur_phi_at_nodes_tmp,
886 gsl_vector_free(work);
889 gsl_vector_free(sur_amp_at_nodes);
890 gsl_vector_free(sur_phi_at_nodes_tmp);
899 gsl_interp_accel *acc_amp_sur = gsl_interp_accel_alloc();
900 gsl_spline *spline_amp_sur = gsl_spline_alloc(gsl_interp_cspline, N_amp);
901 gsl_spline_init(spline_amp_sur, gsl_vector_const_ptr(sur->mf_amp, 0),
902 gsl_vector_const_ptr(sur_amp_at_nodes, 0), N_amp);
904 gsl_interp_accel *acc_phi_sur = gsl_interp_accel_alloc();
905 gsl_spline *spline_phi_sur = gsl_spline_alloc(gsl_interp_cspline, N_phi);
906 gsl_spline_init(spline_phi_sur, gsl_vector_const_ptr(sur->mf_phi, 0),
907 gsl_vector_const_ptr(sur_phi_at_nodes, 0), N_phi);
909 gsl_vector_free(sur_amp_at_nodes);
910 gsl_vector_free(sur_phi_at_nodes);
914 gsl_vector *TF2_phi_at_nodes = NULL;
915 retcode |=
TaylorF2Phasing(Mtot,
q, chi1, chi2, lambda1, lambda2, TF2_mf_phi, &TF2_phi_at_nodes);
917 gsl_vector *TF2_amp_at_nodes = NULL;
921 gsl_vector_free(TF2_amp_at_nodes);
922 gsl_vector_free(TF2_phi_at_nodes);
931 gsl_interp_accel *acc_amp_TF2 = gsl_interp_accel_alloc();
932 gsl_spline *spline_amp_TF2 = gsl_spline_alloc(spline_type, N_amp_TF2);
933 gsl_vector *spline_amp_values = gsl_vector_alloc(N_amp_TF2);
934 for (
int i=0;
i<N_amp_TF2;
i++) {
935 double Mf = gsl_vector_get(TF2_mf_amp,
i);
936 double amp_i = gsl_vector_get(TF2_amp_at_nodes,
i);
937 if ((Mf >= Mf_sur_min) & (Mf <= Mf_sur_max))
938 amp_i *= exp(gsl_spline_eval(spline_amp_sur, Mf, acc_amp_sur));
939 gsl_vector_set(spline_amp_values,
i, amp_i);
941 gsl_spline_init(spline_amp_TF2, gsl_vector_const_ptr(TF2_mf_amp, 0),
942 gsl_vector_const_ptr(spline_amp_values, 0), N_amp_TF2);
945 gsl_interp_accel *acc_phi_TF2 = gsl_interp_accel_alloc();
946 gsl_spline *spline_phi_TF2 = gsl_spline_alloc(spline_type, N_phi_TF2);
947 gsl_vector *spline_phi_values = gsl_vector_alloc(N_phi_TF2);
948 for (
int i=0;
i<N_phi_TF2;
i++) {
949 double Mf = gsl_vector_get(TF2_mf_phi,
i);
950 double phi_i = gsl_vector_get(TF2_phi_at_nodes,
i);
951 if ((Mf >= Mf_sur_min) & (Mf <= Mf_sur_max))
952 phi_i += gsl_spline_eval(spline_phi_sur, Mf, acc_phi_sur);
953 gsl_vector_set(spline_phi_values,
i, phi_i);
955 gsl_spline_init(spline_phi_TF2, gsl_vector_const_ptr(TF2_mf_phi, 0),
956 gsl_vector_const_ptr(spline_phi_values, 0), N_phi_TF2);
958 gsl_vector_free(TF2_amp_at_nodes);
959 gsl_vector_free(TF2_phi_at_nodes);
960 gsl_vector_free(spline_amp_values);
961 gsl_vector_free(spline_phi_values);
963 gsl_spline_free(spline_amp_sur);
964 gsl_spline_free(spline_phi_sur);
965 gsl_interp_accel_free(acc_amp_sur);
966 gsl_interp_accel_free(acc_phi_sur);
976 npts =
NextPow2(fHigh_geom / deltaF_geom) + 1;
977 if (fHigh_geom < fHigh * Mtot_sec)
978 npts =
NextPow2(fHigh * Mtot_sec / deltaF_geom) + 1;
986 double fHigh_temp = fHigh_geom / Mtot_sec;
988 UINT4 iStop = (
UINT4) ceil(fHigh_temp / deltaF);
994 freqs->
data[
i-iStart] =
i*deltaF_geom;
1008 freqs->
data[
i] = freqs_in->
data[
i] * Mtot_sec;
1011 if (!(*hptilde) || !(*hctilde)) {
1013 gsl_interp_accel_free(acc_phi_TF2);
1014 gsl_spline_free(spline_phi_TF2);
1015 gsl_interp_accel_free(acc_amp_TF2);
1016 gsl_spline_free(spline_amp_TF2);
1019 memset((*hptilde)->data->data, 0, npts *
sizeof(
COMPLEX16));
1020 memset((*hctilde)->data->data, 0, npts *
sizeof(
COMPLEX16));
1025 COMPLEX16 *pdata=(*hptilde)->data->data;
1026 COMPLEX16 *cdata=(*hctilde)->data->data;
1028 REAL8 cosi = cos(inclination);
1029 REAL8 pcoef = 0.5*(1.0 + cosi*cosi);
1032 double amp0 = Mtot * Mtot_sec *
LAL_MRSUN_SI / (distance);
1035 double phase_change = 0.0;
1036 phase_change = gsl_spline_eval(spline_phi_TF2, fRef_geom, acc_phi_TF2) - 2*phiRef;
1040 Mf_sur_max = gsl_vector_get(sur->mf_phi, N_phi-1);
1041 double Mf_final = Mf_sur_max;
1045 double f = freqs->
data[
i];
1046 if (f > Mf_final)
continue;
1049 double A = gsl_spline_eval(spline_amp_TF2, f, acc_amp_TF2);
1050 double phase = gsl_spline_eval(spline_phi_TF2, f, acc_phi_TF2) - phase_change;
1051 COMPLEX16 htilde = amp0*A * (cos(phase) + I*sin(phase));
1052 pdata[j] = pcoef * htilde;
1053 cdata[j] = -I * ccoef * htilde;
1059 if (Mf_final > freqs->
data[L-1])
1060 Mf_final = freqs->
data[L-1];
1061 if (Mf_final < freqs->
data[0]) {
1063 gsl_interp_accel_free(acc_phi_TF2);
1064 gsl_spline_free(spline_phi_TF2);
1065 gsl_interp_accel_free(acc_amp_TF2);
1066 gsl_spline_free(spline_amp_TF2);
1074 REAL8 Mf_ISCO_Schwrazschild = 1.0 / (pow(6.,3./2.)*
LAL_PI);
1075 REAL8 t_corr = gsl_spline_eval_deriv(spline_phi_TF2, Mf_ISCO_Schwrazschild, acc_phi_TF2) / (2*
LAL_PI);
1079 double f = freqs->
data[
i] - fRef_geom;
1081 double phase_factor = -2*
LAL_PI * f * t_corr;
1082 COMPLEX16 t_factor = (cos(phase_factor) + I*sin(phase_factor));
1083 pdata[j] *= t_factor;
1084 cdata[j] *= t_factor;
1088 gsl_interp_accel_free(acc_phi_TF2);
1089 gsl_spline_free(spline_phi_TF2);
1090 gsl_interp_accel_free(acc_amp_TF2);
1091 gsl_spline_free(spline_amp_TF2);
1152 struct tagCOMPLEX16FrequencySeries **hptilde,
1153 struct tagCOMPLEX16FrequencySeries **hctilde,
1170 double m1temp = m1SI;
1171 double chi1temp = chi1;
1172 double lambda1temp = lambda1;
1178 lambda2 = lambda1temp;
1184 double Mtot = mass1+mass2;
1185 double eta = mass1 * mass2 / (Mtot*Mtot);
1191#ifdef LAL_PTHREAD_LOCK
1199 "Error setting up Surrogate data - check your $LAL_DATA_PATH\n");
1204 int retcode =
SurrogateCore(hptilde, hctilde, phiRef, fRef, distance,
1205 inclination, Mtot_sec, eta, chi1, chi2,
1206 lambda1, lambda2, freqs, 0, spline_order);
1219 struct tagCOMPLEX16FrequencySeries **hptilde,
1220 struct tagCOMPLEX16FrequencySeries **hctilde,
1239 double m1temp = m1SI;
1240 double chi1temp = chi1;
1241 double lambda1temp = lambda1;
1247 lambda2 = lambda1temp;
1253 double Mtot = mass1+mass2;
1254 double eta = mass1 * mass2 / (Mtot*Mtot);
1261#ifdef LAL_PTHREAD_LOCK
1271 freqs->
data[0] = fLow;
1272 freqs->
data[1] = fHigh;
1274 int retcode =
SurrogateCore(hptilde, hctilde, phiRef, fRef, distance,
1275 inclination, Mtot_sec, eta, chi1, chi2,
1276 lambda1, lambda2, freqs, deltaF, spline_order);
1293#ifdef LAL_HDF5_ENABLED
1294#define datafile SurDataHDF5
1298 "Unable to resolve data file '%s' in $LAL_DATA_PATH.\n"
1299 "Note: LALSuite versions >= 7.25 require data files that are publicly available at:\n"
1300 "https://git.ligo.org/waveforms/software/lalsuite-waveform-data\n"
1301 "and on Zenodo at: https://zenodo.org/records/14999310.\n"
1302 "For earlier LALSuite versions, use the files in lalsuite-extra, available at:\n"
1303 "https://git.ligo.org/lscsoft/lalsuite-extra\n",
1305 char *dir = dirname(
path);
struct tagLALH5File LALH5File
void XLALDestroyDict(LALDict *dict)
LALDict * XLALCreateDict(void)
Auxiliary functions related to HDF5 waveform data files.
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 * XLALMalloc(size_t n)
void * XLALCalloc(size_t m, 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)
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