Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Velocity.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2005 Badri Krishnan, Alicia Sintes
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 <lal/Velocity.h>
21
22/*
23 * The functions that make up the guts of this module
24 */
25
26/** \addtogroup Velocity_h */
27/** @{ */
28
29/**
30 * This function outputs the
31 * average velocity REAL8 v[3] of the detector during a time interval.
32 * The input structure is of type VelocityPar containing all the required parmaters.
33 */
34void LALAvgDetectorVel( LALStatus *status, /**< pointer to LALStatus structure */
35 REAL8 v[3], /**< [out] velocity vector */
36 VelocityPar *in /**< [in] input parameter structure */ )
37{
38
39 REAL8 pos1[3], pos2[3];
40 REAL8 tBase;
41 LIGOTimeGPS t0gps, tgps;
42 REAL8 t0;
43 REAL8 t, ts, tn;
44 INT4 n;
47
48 /*---------------------------------------------------------------*/
49
52
53 /* check that arguments are not null */
55
56 /* copy input values */
57 tBase = in->tBase;
58 t0gps = in->startTime;
59 detector = in->detector;
60 edat = in->edat;
61
62 /* basic checks that input values are sane */
64
65 /* calculate starting time as float */
66 ts = ( REAL8 )( t0gps.gpsSeconds ) * 1.00;
67 tn = ( REAL8 )( t0gps.gpsNanoSeconds ) * 1.00E-9;
68 t0 = ts + tn;
69
70 /* calculate finish time */
71 t = t0 + tBase;
72 XLALGPSSetREAL8( &tgps, t );
73
74 /* calculate position at start and finish time */
75 TRY( LALDetectorPos( status->statusPtr, pos1, &t0gps, detector, edat ), status );
76 TRY( LALDetectorPos( status->statusPtr, pos2, &tgps, detector, edat ), status );
77
78 /* now calculate average velocity */
79 for ( n = 0; n < 3; n++ ) {
80 v[n] = ( pos2[n] - pos1[n] ) / tBase;
81 }
82
84
85 RETURN( status );
86}
87
88
89
90/**
91 * Given a detector and a time interval, this function outputs the
92 * average position of the detector during the interval by using
93 * the trapeziodal rule for a given fractional accuracy.
94 */
96 REAL8 x[3],
97 VelocityPar *in )
98{
99
100 REAL8 trapSum[3], average[3], tempVel[3];
101 REAL8 tBase, vTol, rTol, oldVeloMod, newVeloMod;
102 LIGOTimeGPS t0gps, tgps;
103 REAL8 t0;
104 REAL8 t, ts, tn;
105 INT4 n, k, points;
108
109
110
111 /*---------------------------------------------------------------*/
112
115
116 /* check that arguments are not null */
118
119 /* copy input values */
120 tBase = in->tBase;
121 vTol = in->vTol;
122 t0gps = in->startTime;
123 detector = in->detector;
124 edat = in->edat;
125
126 /* check that input values make sense */
130
131
132 /* calculate starting time as float */
133 ts = ( REAL8 )( t0gps.gpsSeconds ) * 1.00;
134 tn = ( REAL8 )( t0gps.gpsNanoSeconds ) * 1.00E-9;
135 t0 = ts + tn;
136
137 /* calculate finish time */
138 t = t0 + tBase;
139 XLALGPSSetREAL8( &tgps, t );
140
141
142 /* The first approximation: (b-a)^-1 * int(f(x),x=a..b) = 0.5*(f(a)+f(b)) */
143 /* calculate velocity at starting time */
144 TRY( LALDetectorPos( status->statusPtr, tempVel, &t0gps, detector, edat ), status );
145 for ( n = 0; n < 3; n++ ) {
146 trapSum[n] = 0.5 * tempVel[n];
147 }
148
149 /*calculate velocity at finish time */
150
151 TRY( LALDetectorPos( status->statusPtr, tempVel, &tgps, detector, edat ), status );
152
153 /* first approximation to average */
154 for ( n = 0; n < 3; n++ ) {
155 trapSum[n] += 0.5 * tempVel[n];
156 average[n] = trapSum[n];
157 }
158
159 points = 1;
160 /* now add more points and stop when desired accuracy is reached*/
161 do {
162 points *= 2;
163 for ( k = 1; k < points; k += 2 ) {
164 t = t0 + 1.0 * k * tBase / ( 1.0 * points );
165 XLALGPSSetREAL8( &tgps, t );
166 TRY( LALDetectorPos( status->statusPtr, tempVel, &tgps, detector, edat ), status );
167 for ( n = 0; n < 3; n++ ) {
168 trapSum[n] += tempVel[n];
169 }
170 }
171 oldVeloMod = newVeloMod = 0.0;
172 for ( n = 0; n < 3; n++ ) {
173 oldVeloMod += average[n] * average[n];
174 average[n] = trapSum[n] / ( 1.0 * points );
175 newVeloMod += average[n] * average[n];
176 }
177 /* now calculate the fractional change in magnitude of average */
178 /* is it sufficient to require the magnitude to converge or should
179 we look at the individual components? */
180 rTol = fabs( ( sqrt( oldVeloMod ) - sqrt( newVeloMod ) ) ) / ( sqrt( oldVeloMod ) );
181 } while ( rTol > vTol );
182
183 /* copy the result to the output structure */
184 for ( n = 0; n < 3; n++ ) {
185 x[n] = average[n];
186 }
187
189
190 RETURN( status );
191}
192
193/**
194 * This function finds the velocity of a given detector at a
195 * given time. It is basically a wrapper for XLALBarycenter().
196 * The output is of the form REAL8 vector v[3] and the input is a
197 * time LIGOTimeGPS , the detector LALDetector,
198 * and the ephemeris EphemerisData from XLALInitBarycenter().
199 */
201 REAL8 v[3],
202 LIGOTimeGPS *time0,
205{
206
207 INT4 i;
208 EmissionTime *emit = NULL;
209 EarthState *earth = NULL;
210 BarycenterInput baryinput;
211
212 /*----------------------------------------------------------------*/
213
216
219
220 emit = ( EmissionTime * )LALMalloc( sizeof( EmissionTime ) );
221 earth = ( EarthState * )LALMalloc( sizeof( EarthState ) );
222
223 /* detector info */
224 baryinput.site.location[0] = detector.location[0] / LAL_C_SI;
225 baryinput.site.location[1] = detector.location[1] / LAL_C_SI;
226 baryinput.site.location[2] = detector.location[2] / LAL_C_SI;
227
228 /* set other barycentering info */
229 baryinput.tgps = *time0;
230 baryinput.dInv = 0.0;
231
232 /* for the purposes of calculating the velocity of the earth */
233 /* at some given time, the position of the source in the sky should not matter. */
234 /* So, for this function, we set alpha and delta to zero as inputs to the */
235 /* barycenter routines */
236 baryinput.alpha = 0.0;
237 baryinput.delta = 0.0;
238
239 /* call barycentering routines to calculate velocities */
241 XLAL_CHECK_LAL( status, XLALBarycenter( emit, &baryinput, earth ) == XLAL_SUCCESS, XLAL_EFUNC );
242
243 /* set values of velocity for all the SFT's */
244 for ( i = 0; i < 3; i++ ) {
245 v[i] = emit->vDetector[i];
246 }
247
248 LALFree( emit );
249 LALFree( earth );
250
252 RETURN( status );
253}
254
255
256
257/** This finds velocity of a given detector at a given time */
259 REAL8 x[3],
260 LIGOTimeGPS *time0,
263{
264
265 INT4 i;
266 EmissionTime *emit = NULL;
267 EarthState *earth = NULL;
268 BarycenterInput baryinput;
269
270 /*----------------------------------------------------------------*/
271
274
277
278 emit = ( EmissionTime * )LALMalloc( sizeof( EmissionTime ) );
279 earth = ( EarthState * )LALMalloc( sizeof( EarthState ) );
280
281 /* detector info */
282 baryinput.site.location[0] = detector.location[0] / LAL_C_SI;
283 baryinput.site.location[1] = detector.location[1] / LAL_C_SI;
284 baryinput.site.location[2] = detector.location[2] / LAL_C_SI;
285
286 /* set other barycentering info */
287 baryinput.tgps = *time0;
288 baryinput.dInv = 0;
289
290 /* for the purposes of calculating the velocity of the earth */
291 /* at some given time, the position of the source in the sky should not matter. */
292 /* So, for this function, we set alpha and delta to zero as inputs to the */
293 /* barycenter routines */
294 baryinput.alpha = 0.0;
295 baryinput.delta = 0.0;
296
297 /* call barycentering routines to calculate velocities */
299 XLAL_CHECK_LAL( status, XLALBarycenter( emit, &baryinput, earth ) == XLAL_SUCCESS, XLAL_EFUNC );
300
301 /* set values of velocity for all the SFT's */
302 for ( i = 0; i < 3; i++ ) {
303 x[i] = emit->rDetector[i];
304 }
305
306 LALFree( emit );
307 LALFree( earth );
308
310 RETURN( status );
311}
312
313/** @} */
int k
#define LALMalloc(n)
#define LALFree(p)
#define XLAL_CHECK_LAL(sp, assertion,...)
#define TRY(func, statusptr)
#define ATTATCHSTATUSPTR(statusptr)
#define ASSERT(assertion, statusptr, code, mesg)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
int XLALBarycenterEarth(EarthState *earth, const LIGOTimeGPS *tGPS, const EphemerisData *edat)
Computes the position and orientation of the Earth, at some arrival time , specified LIGOTimeGPS inp...
Definition: LALBarycenter.c:78
int XLALBarycenter(EmissionTime *emit, const BarycenterInput *baryinput, const EarthState *earth)
Transforms from detector arrival time in GPS (as specified in the LIGOTimeGPS structure) to pulse em...
double REAL8
int32_t INT4
void LALDetectorVel(LALStatus *status, REAL8 v[3], LIGOTimeGPS *time0, LALDetector detector, EphemerisData *edat)
This function finds the velocity of a given detector at a given time.
Definition: Velocity.c:200
void LALDetectorPos(LALStatus *status, REAL8 x[3], LIGOTimeGPS *time0, LALDetector detector, EphemerisData *edat)
This finds velocity of a given detector at a given time.
Definition: Velocity.c:258
void LALAvgDetectorVel(LALStatus *status, REAL8 v[3], VelocityPar *in)
This function outputs the average velocity REAL8 v[3] of the detector during a time interval.
Definition: Velocity.c:34
#define VELOCITYH_ENULL
Definition: Velocity.h:70
#define VELOCITYH_MSGEVAL
Definition: Velocity.h:73
#define VELOCITYH_MSGENULL
Definition: Velocity.h:72
#define VELOCITYH_EVAL
Definition: Velocity.h:71
void LALAvgDetectorPos(LALStatus *status, REAL8 x[3], VelocityPar *in)
Given a detector and a time interval, this function outputs the average position of the detector duri...
Definition: Velocity.c:95
XLAL_SUCCESS
XLAL_EFUNC
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
n
ts
double t0
Basic input structure to LALBarycenter.c.
REAL8 alpha
Source right ascension in ICRS J2000 coords (radians).
REAL8 dInv
1/(distance to source), in 1/sec.
LIGOTimeGPS tgps
input GPS arrival time.
REAL8 delta
Source declination in ICRS J2000 coords (radians)
LALDetector site
detector site info.
Basic output structure of LALBarycenterEarth.c.
Basic output structure produced by LALBarycenter.c.
REAL8 rDetector[3]
Cartesian coords (0=x,1=y,2=z) of detector position at $t_a$ (GPS), in ICRS J2000 coords.
REAL8 vDetector[3]
This structure contains all information about the center-of-mass positions of the Earth and Sun,...
REAL8 location[3]
INT4 gpsNanoSeconds
This structure stores the parameters required by XLALBarycenter() to calculate Earth velocity at a gi...
Definition: Velocity.h:84
EphemerisData * edat
ephemeris data pointer from XLALInitBarycenter()
Definition: Velocity.h:86
LALDetector detector
the detector
Definition: Velocity.h:85
REAL8 tBase
duration of interval
Definition: Velocity.h:88
LIGOTimeGPS startTime
start of time interval
Definition: Velocity.h:87
REAL8 vTol
fractional accuracy required for velocity (redundant for average velocity calculation)
Definition: Velocity.h:89