Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-8a6b96f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ExtrapolatePulsarSpinsTest.c
Go to the documentation of this file.
1/*
2 *
3 * Copyright (C) 2005 Reinhard Prix
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with with program; see the file COPYING. If not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 * MA 02110-1301 USA
19 */
20
21/*********************************************************************************/
22/**
23 * \author Reinhard Prix
24 * \file
25 * \brief Test for ExtrapolatePulsarSpins().
26 *
27 */
28#include <math.h>
29
30#include <lal/Date.h>
31#include <lal/AVFactories.h>
32#include <lal/PulsarDataTypes.h>
33#include <lal/ExtrapolatePulsarSpins.h>
34
35#define RELERROR(x, y) fabs( 2.0 * ((x) - (y)) / ( (x) + (y) ) )
36
37/**
38 * Very simple test: given spin-params at \f$ \tau_0 \f$ , extrapolate them to
39 * \f$ \tau_1 \f$ and compare to reference-result...
40 */
41int main( void )
42{
43 PulsarSpins result;
44 PulsarSpins fkdot0, fkdot1;
45 REAL8 tolerance = 1.0e-12;
46 REAL8 tolerancePhi = 1.0e-6;
47
48 PulsarSpinRange range0, range2;
49 PulsarSpinRange rangeResult;
50
51 const LIGOTimeGPS epoch0 = {714180733, 0};
52 const LIGOTimeGPS epoch1 = {714180733 + 94608000, 0}; /* 3 years later */
53 const LIGOTimeGPS epoch2 = {714180733 - 94608000, 0}; /* 3 years earlier */
54
55 const REAL8 dtau10 = XLALGPSDiff( &epoch1, &epoch0 );
56 const REAL8 dtau20 = XLALGPSDiff( &epoch2, &epoch0 );
57
58 /* set up initial spin-values */
59 XLAL_INIT_MEM( fkdot0 );
60 fkdot0[0] = 300.0;
61 fkdot0[1] = -1.e-7;
62 fkdot0[2] = 1e-15;
63 fkdot0[3] = -1e-22;
64
65 /* Result: (from ExtrPulsarSpins.m) */
66 XLAL_INIT_MEM( result );
67 result[0] = 2.809011145986047e+02;
68 result[1] = -4.529256832000000e-07;
69 result[2] = -8.460800000000001e-15;
70 result[3] = -1.000000000000000e-22;
71
72 /* first propagate single spin-vector */
73 printf( " \n ----- Test1: XLALExtrapolatePulsarSpinsTODO() ----- \n" );
74 printf( "Input @ tau0 = %d.%09d : [%.10g, %.10g, %.10g, %.10g ]\n",
75 epoch0.gpsSeconds, epoch0.gpsNanoSeconds,
76 fkdot0[0], fkdot0[1], fkdot0[2], fkdot0[3] );
77
79
80 printf( "Output2@ tau1 = %d.%09d : [%.10g, %.10g, %.10g, %.10g]\n",
81 epoch1.gpsSeconds, epoch1.gpsNanoSeconds,
82 fkdot1[0], fkdot1[1], fkdot1[2], fkdot1[3] );
83
84 printf( "Reference-result: : [%.10g, %.10g, %.10g, %.10g]\n",
85 result[0], result[1], result[2], result[3] );
86
87 if ( ( RELERROR( fkdot1[0], result[0] ) > tolerance ) ||
88 ( RELERROR( fkdot1[1], result[1] ) > tolerance ) ||
89 ( RELERROR( fkdot1[2], result[2] ) > tolerance ) ||
90 ( RELERROR( fkdot1[3], result[3] ) > tolerance ) ) {
91 XLAL_ERROR_MAIN( XLAL_ETOL, "\nRelative error of XLALExtrapolatePulsarSpins() exceeds tolerance of %g \n\n", tolerance );
92 } else {
93 printf( "\n ==> OK. XLALExtrapolatePulsarSpins() lies within %g of the reference-result!\n", tolerance );
94 }
95
96 /* ----- propagate phase from epoch1 --> epoch0, given fkdot0 ----- */
97 {
98 REAL8 phi1Result = 3.951107892803490; /* from ExtrapolatePulsarSpins.m */
100
101 phi0 = 1;
103
104 printf( "\nExtrapolated phase phi1 = %.16f, Reference-result = %.16f\n", phi1, phi1Result );
105 if ( RELERROR( phi1, phi1Result ) > tolerancePhi ) {
106 XLAL_ERROR_MAIN( XLAL_ETOL, "\nRelative error of XLALExtrapolatePulsarPhase() exceeds tolerance of %g \n\n", tolerancePhi );
107 } else {
108 printf( "\n ==> OK. XLALExtrapolatePulsarPhase() lies within %g of the reference-result!\n", tolerancePhi );
109 }
110 }
111
112 /* ----- now test XLALExtrapolatePulsarSpinRange() ----- */
113 /* set up initial spin-range */
114 range0.refTime = epoch0;
115 XLAL_INIT_MEM( range0.fkdot );
116 range0.fkdot[0] = fkdot0[0];
117 range0.fkdot[1] = fkdot0[1];
118 range0.fkdot[2] = fkdot0[2];
119 range0.fkdot[3] = fkdot0[3];
120
121 XLAL_INIT_MEM( range0.fkdotBand );
122 range0.fkdotBand[0] = 0;
123 range0.fkdotBand[1] = -1.0e-7;
124 range0.fkdotBand[2] = 1.0e-15;
125 range0.fkdotBand[3] = -1.0e-22;
126
127 /* set up the range reference-result (from ExtrapolatePulsarSpins.m) */
128 rangeResult.refTime.gpsSeconds = 619572733;
129 rangeResult.refTime.gpsNanoSeconds = 0;
130
131 XLAL_INIT_MEM( rangeResult.fkdot );
132 rangeResult.fkdot[0] = 3.280495590653952e+02;
133 rangeResult.fkdot[1] = -1.284283366400000e-06;
134 rangeResult.fkdot[2] = 1.046080000000000e-14;
135 rangeResult.fkdot[3] = -2.000000000000000e-22;
136
137 XLAL_INIT_MEM( rangeResult.fkdotBand );
138 rangeResult.fkdotBand[0] = 2.804955906539521e+01;
139 rangeResult.fkdotBand[1] = 6.421416832000000e-07;
140 rangeResult.fkdotBand[2] = 1.046080000000000e-14;
141 rangeResult.fkdotBand[3] = 1.000000000000000e-22;
142
143 printf( " \n ----- Test2: XLALExtrapolatePulsarSpinRangeTODO() ----- \n" );
144 printf( "Input: epoch = %d.%09d \n", range0.refTime.gpsSeconds, range0.refTime.gpsNanoSeconds );
145 printf( "Input: fkdot = [%.10g, %.10g, %.10g, %.10g ]\n",
146 range0.fkdot[0], range0.fkdot[1], range0.fkdot[2], range0.fkdot[3] );
147 printf( "Input: fkdotBand = [%.10g, %.10g, %.10g, %.10g ]\n",
148 range0.fkdotBand[0], range0.fkdotBand[1], range0.fkdotBand[2], range0.fkdotBand[3] );
149
151
152 printf( "\n" );
153 printf( "Output: epoch = %d.%09d \n", range2.refTime.gpsSeconds, range2.refTime.gpsNanoSeconds );
154 printf( "Output: fkdot = [%.10g, %.10g, %.10g, %.10g ]\n",
155 range2.fkdot[0], range2.fkdot[1], range2.fkdot[2], range2.fkdot[3] );
156 printf( "Output: fkdotBand = [%.10g, %.10g, %.10g, %.10g ]\n",
157 range2.fkdotBand[0], range2.fkdotBand[1], range2.fkdotBand[2], range2.fkdotBand[3] );
158
159 printf( "\n" );
160 printf( "Octave : fkdot = [%.10g, %.10g, %.10g, %.10g ]\n",
161 rangeResult.fkdot[0], rangeResult.fkdot[1], rangeResult.fkdot[2], rangeResult.fkdot[3] );
162 printf( "Octave : fkdotBand = [%.10g, %.10g, %.10g, %.10g ]\n",
163 rangeResult.fkdotBand[0], rangeResult.fkdotBand[1], rangeResult.fkdotBand[2], rangeResult.fkdotBand[3] );
164
165 if ( ( range2.refTime.gpsSeconds != rangeResult.refTime.gpsSeconds )
166 || ( range2.refTime.gpsNanoSeconds != rangeResult.refTime.gpsNanoSeconds ) ) {
167 XLAL_ERROR_MAIN( XLAL_ETIME, "\nOutput-range has wrong epoch\n" );
168 }
169
170 if ( ( RELERROR( range2.fkdot[0], rangeResult.fkdot[0] ) > tolerance ) ||
171 ( RELERROR( range2.fkdot[1], rangeResult.fkdot[1] ) > tolerance ) ||
172 ( RELERROR( range2.fkdot[2], rangeResult.fkdot[2] ) > tolerance ) ||
173 ( RELERROR( range2.fkdot[3], rangeResult.fkdot[3] ) > tolerance ) ||
174
175 ( RELERROR( range2.fkdotBand[0], rangeResult.fkdotBand[0] ) > tolerance ) ||
176 ( RELERROR( range2.fkdotBand[1], rangeResult.fkdotBand[1] ) > tolerance ) ||
177 ( RELERROR( range2.fkdotBand[2], rangeResult.fkdotBand[2] ) > tolerance ) ||
178 ( RELERROR( range2.fkdotBand[3], rangeResult.fkdotBand[3] ) > tolerance )
179 ) {
180 XLAL_ERROR_MAIN( XLAL_ETOL, "\nRelative error of XLALExtrapolatePulsarSpinRange() exceeds tolerance of %g \n", tolerance );
181 } else {
182 printf( "\n ==> OK. XLALExtrapolatePulsarSpinRange() lies within %g of the reference-result!\n\n", tolerance );
183 }
184
186
187 return XLAL_SUCCESS;
188
189} /* main() */
int main(void)
Very simple test: given spin-params at , extrapolate them to and compare to reference-result....
#define RELERROR(x, y)
void LALCheckMemoryLeaks(void)
double e
int XLALExtrapolatePulsarPhase(REAL8 *phi1, const PulsarSpins fkdot1, const REAL8 phi0, const REAL8 dtau)
Extrapolate phase from to , given the spins fkdot1 at .
int XLALExtrapolatePulsarSpinRange(PulsarSpinRange *range1, const PulsarSpinRange *range0, const REAL8 dtau)
General pulsar-spin extrapolation function: given a "spin-range" (ie spins + spin-bands) range0 at ti...
int XLALExtrapolatePulsarSpins(PulsarSpins fkdot1, const PulsarSpins fkdot0, REAL8 dtau)
Extrapolate the Pulsar spin-parameters (fkdot0) from the initial reference-epoch to the new referen...
#define XLAL_INIT_MEM(x)
double REAL8
REAL8 PulsarSpins[PULSAR_MAX_SPINS]
Typedef for fixed-size array holding GW frequency and derivatives fk = d^k Freq/dt^k|(tau_ref)
#define XLAL_CHECK_MAIN(assertion,...)
#define XLAL_ERROR_MAIN(...)
XLAL_SUCCESS
XLAL_EFUNC
XLAL_ETOL
XLAL_ETIME
REAL8 XLALGPSDiff(const LIGOTimeGPS *t1, const LIGOTimeGPS *t0)
phi1
INT4 gpsNanoSeconds
Contains a "spin-range", ie spins and corresponding bands at a given (SSB) reference GPS-time .
PulsarSpins fkdot
Vector of spin-values .
LIGOTimeGPS refTime
SSB reference GPS-time at which spin-range is defined.
PulsarSpins fkdotBand
Vector of spin-bands , MUST be same length as fkdot.