Velocity.c

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2005 Badri Krishnan, Alicia Sintes  
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with with program; see the file COPYING. If not, write to the 
00016  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
00017  *  MA  02111-1307  USA
00018  */
00019 
00020 /** 
00021  *
00022  *  \file Velocity.c
00023  *  \author Badri Krishnan and Alicia Sintes
00024     \ingroup pulsarHough
00025     \brief Functions for calculating detector velocity and positions at a given
00026     time or averaged over a time interval.  This is a wrapper for the 
00027     LALBarycenter routines. 
00028 
00029  *  $Id: Velocity.c,v 1.11 2006/02/11 09:45:11 badri Exp $
00030     \description 
00031 
00032     The function LALDetectorVel() finds the velocity of a given detector at a
00033     given time. It is basically a wrapper for LALBarycenter.
00034     The output is of the form REAL8 vector v[3] and the input is a
00035     time LIGOTimeGPS , the detector LALDetector, 
00036     and the ephemeris EphemerisData from LALInitBarycenter.
00037     
00038     The function LALAvgDetectorVel() outputs the
00039     average velocity REAL8 v[3] of the detector during a time interval. 
00040     The input structure is of type VelocityPar
00041     containing all the required parmaters.
00042 
00043     The analogous functions for calculating the average position and 
00044     position are LALAvgDetectorPos() and LALDetectorPos().  The average 
00045     position is calculated by a numerical integration using the 
00046     trapezoidal rule with a user-specified fractional accuracy. 
00047 
00048 
00049  *
00050  *
00051  */
00052 
00053 /************************************<lalVerbatim file="VelocityCV">
00054 Authors: Krishnan, B., Sintes, A.M.
00055 $Id: Velocity.c,v 1.11 2006/02/11 09:45:11 badri Exp $
00056 *************************************</lalVerbatim> */
00057 
00058 /* <lalLaTeX>  **********************************************
00059 
00060 \subsection{Module \texttt{Velocity.c}}
00061 \label{ss:Velocity.c}
00062 Computation of instant and averaged velocities of a given detector and the
00063 like.
00064 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00065 \subsubsection*{Prototypes}
00066 \vspace{0.1in}
00067 \input{VelocityD}
00068 \index{\verb&LALDetectorVel()&}
00069 \index{\verb&LALAvgDetectorVel()&}
00070 
00071 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00072 \subsubsection*{Description}
00073 The function \verb@LALDetectorVel@ finds the velocity of a given detector at a
00074 given time. It is basically a wrapper for LALBarycenter.
00075 The output is of the form \verb@REAL8  v[3]@, and the input is a
00076 time \verb@LIGOTimeGPS  *time@, the detector \verb@LALDetector detector@, 
00077 and the ephemeris \verb@EphemerisData *edat@ from LALInitBarycenter
00078 
00079 The function \verb@LALAvgDetectorVel@ outputs the
00080 average velocity \verb@REAL8 v[3]@ of the detector during a time interval by using
00081 the trapeziodal rule. The input structure is of type \verb@VelocityPar *in@
00082 containing all the required parmaters.
00083 
00084 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00085 \subsubsection*{Uses}
00086 \begin{verbatim}
00087 LALFloatToGPS()
00088 LALMalloc() 
00089 LALBarycenterEarth() 
00090 LALBarycenter() 
00091 LALFree()
00092 \end{verbatim}
00093 
00094 %%%%%%%%%%%%%%%%%%%
00095 \subsubsection*{Notes}
00096 %%
00097 \vfill{\footnotesize\input{VelocityCV}}
00098 ********************************************** </lalLaTeX> */
00099 
00100 
00101 #include <lal/Velocity.h> 
00102 /* #include "./Velocity.h" */
00103 
00104 NRCSID (VELOCITYC, "$Id: Velocity.c,v 1.11 2006/02/11 09:45:11 badri Exp $");
00105 
00106 /*
00107  * The functions that make up the guts of this module
00108  */
00109 
00110 
00111 /** Given a detector and a time interval, this function outputs the 
00112  *   average velocity of the detector delta x/delta t during the interval 
00113  */   
00114 /* *******************************  <lalVerbatim file="VelocityD"> */   
00115 void LALAvgDetectorVel( LALStatus *status, 
00116                         REAL8 v[3], /**< [out] velocity vector */
00117                         VelocityPar *in /**< [in] input parameter structure */ )
00118 { /*-------------------------------------------------</lalVerbatim> */
00119 
00120   REAL8           pos1[3], pos2[3];
00121   REAL8           tBase;
00122   LIGOTimeGPS     t0gps, tgps;
00123   REAL8           t0; 
00124   REAL8           t, ts, tn; 
00125   INT4            n; 
00126   LALDetector     detector;
00127   EphemerisData   *edat;
00128 
00129   /*---------------------------------------------------------------*/
00130 
00131   INITSTATUS (status, "LALAvgDetectorVel", VELOCITYC);
00132   ATTATCHSTATUSPTR (status);
00133 
00134   /* check that arguments are not null */
00135   ASSERT(in, status, VELOCITYH_ENULL, VELOCITYH_MSGENULL);
00136 
00137   /* copy input values */
00138   tBase = in->tBase;
00139   t0gps = in->startTime;
00140   detector = in->detector;
00141   edat = in->edat;
00142 
00143   /* basic checks that input values are sane */
00144   ASSERT(tBase > 0.0, status, VELOCITYH_EVAL, VELOCITYH_MSGEVAL);
00145 
00146   /* calculate starting time as float */
00147   ts = (REAL8)(t0gps.gpsSeconds) * 1.00;
00148   tn = (REAL8)(t0gps.gpsNanoSeconds) * 1.00E-9;
00149   t0 = ts + tn;
00150 
00151   /* calculate finish time */
00152   t = t0 + tBase;
00153   TRY( LALFloatToGPS( status->statusPtr, &tgps, &t), status);
00154 
00155   /* calculate position at start and finish time */
00156   TRY( LALDetectorPos( status->statusPtr, pos1, &t0gps, detector, edat), status);
00157   TRY( LALDetectorPos( status->statusPtr, pos2, &tgps, detector, edat), status);
00158 
00159   /* now calculate average velocity */
00160   for (n=0; n<3; n++)
00161     {
00162       v[n] = (pos2[n] - pos1[n])/tBase;
00163     }
00164 
00165   DETATCHSTATUSPTR (status);
00166 
00167   RETURN (status);
00168 }
00169 
00170 
00171 
00172 /** Given a detector and a time interval, this function outputs the 
00173  *  average position of the detector during the interval by using 
00174  *  the trapeziodal rule for a given fractional accuracy. 
00175  */
00176 /* *******************************  <lalVerbatim file="VelocityD"> */   
00177 void LALAvgDetectorPos( LALStatus *status, 
00178                         REAL8 x[3], 
00179                         VelocityPar *in)
00180 { /*-------------------------------------------------</lalVerbatim> */
00181 
00182   REAL8           trapSum[3], average[3], tempVel[3]; 
00183   REAL8           tBase, vTol, rTol, oldVeloMod, newVeloMod;
00184   LIGOTimeGPS     t0gps, tgps;
00185   REAL8           t0; 
00186   REAL8           t, ts, tn; 
00187   INT4            n, k, points; 
00188   LALDetector     detector;
00189   EphemerisData   *edat;
00190 
00191 
00192 
00193   /*---------------------------------------------------------------*/
00194 
00195   INITSTATUS (status, "LALAvgDetectorPos", VELOCITYC);
00196   ATTATCHSTATUSPTR (status);
00197 
00198   /* check that arguments are not null */
00199   ASSERT(in, status, VELOCITYH_ENULL, VELOCITYH_MSGENULL);
00200 
00201   /* copy input values */
00202   tBase = in->tBase;
00203   vTol = in->vTol;
00204   t0gps = in->startTime;
00205   detector = in->detector;
00206   edat = in->edat;
00207 
00208   /* check that input values make sense */
00209   ASSERT(tBase > 0.0, status, VELOCITYH_EVAL, VELOCITYH_MSGEVAL);
00210   ASSERT(vTol > 0.0, status, VELOCITYH_EVAL, VELOCITYH_MSGEVAL);
00211   ASSERT(vTol < 1.0, status, VELOCITYH_EVAL, VELOCITYH_MSGEVAL);
00212 
00213 
00214   /* calculate starting time as float */
00215   ts = (REAL8)(t0gps.gpsSeconds) * 1.00;
00216   tn = (REAL8)(t0gps.gpsNanoSeconds) * 1.00E-9;
00217   t0 = ts + tn;
00218 
00219   /* calculate finish time */
00220   t = t0 + tBase;
00221   TRY( LALFloatToGPS( status->statusPtr, &tgps, &t), status);
00222 
00223 
00224   /* The first approximation: (b-a)^-1 * int(f(x),x=a..b) = 0.5*(f(a)+f(b)) */
00225   /* calculate velocity at starting time */
00226   TRY( LALDetectorPos( status->statusPtr, tempVel, &t0gps, detector, edat), status);
00227   for (n=0; n<3; n++) trapSum[n] = 0.5 * tempVel[n]; 
00228 
00229   /*calculate velocity at finish time */
00230   
00231   TRY( LALDetectorPos( status->statusPtr, tempVel, &tgps, detector, edat), status);
00232   
00233   /* first approximation to average */  
00234   for (n=0; n<3; n++) 
00235     {
00236       trapSum[n] += 0.5 * tempVel[n];
00237       average[n] = trapSum[n];
00238     }
00239   
00240   points = 1;
00241   /* now add more points and stop when desired accuracy is reached*/ 
00242   do {
00243     points *= 2;
00244     for (k=1; k<points; k+=2)
00245       {
00246         t = t0 + 1.0 * k * tBase / (1.0 * points);
00247         TRY( LALFloatToGPS( status->statusPtr, &tgps, &t), status);
00248         TRY( LALDetectorPos( status->statusPtr, tempVel, &tgps, detector, edat), status);
00249         for (n=0; n<3; n++) trapSum[n] += tempVel[n];
00250       }
00251     oldVeloMod = newVeloMod = 0.0;
00252     for (n=0; n<3; n++) 
00253       {
00254         oldVeloMod += average[n]*average[n];
00255         average[n] = trapSum[n] / (1.0*points);
00256         newVeloMod += average[n]*average[n];
00257       }
00258     /* now calculate the fractional change in magnitude of average */
00259     /* is it sufficient to require the magnitude to converge or should
00260        we look at the individual components? */
00261     rTol = fabs((sqrt(oldVeloMod) - sqrt(newVeloMod))) / (sqrt(oldVeloMod));      
00262   } while (rTol > vTol);
00263     
00264   /* copy the result to the output structure */
00265   for (n=0; n<3; n++) x[n] = average[n]; 
00266 
00267   DETATCHSTATUSPTR (status);
00268 
00269   RETURN (status);
00270 }
00271 
00272 
00273 
00274 
00275 /** This finds velocity of a given detector at a given time 
00276 */
00277 /* *******************************  <lalVerbatim file="VelocityD"> */
00278 void LALDetectorVel(LALStatus    *status, 
00279                     REAL8        v[3], 
00280                     LIGOTimeGPS  *time0, 
00281                     LALDetector  detector,
00282                     EphemerisData *edat)
00283 { /*-------------------------------------------------</lalVerbatim> */
00284 
00285   INT4  i;
00286   EmissionTime     *emit=NULL;
00287   EarthState       *earth=NULL;
00288   BarycenterInput  baryinput;
00289 
00290   /*----------------------------------------------------------------*/
00291  
00292   INITSTATUS ( status, "LALDetectorVel", VELOCITYC);
00293   ATTATCHSTATUSPTR (status);
00294 
00295   ASSERT (time0, status, VELOCITYH_ENULL, VELOCITYH_MSGENULL);
00296   ASSERT (edat, status, VELOCITYH_ENULL, VELOCITYH_MSGENULL);
00297 
00298   emit = (EmissionTime *)LALMalloc(sizeof(EmissionTime));
00299   earth = (EarthState *)LALMalloc(sizeof(EarthState));
00300 
00301   /* detector info */
00302   baryinput.site.location[0] = detector.location[0]/LAL_C_SI;
00303   baryinput.site.location[1] = detector.location[1]/LAL_C_SI;
00304   baryinput.site.location[2] = detector.location[2]/LAL_C_SI;
00305   
00306   /* set other barycentering info */
00307   baryinput.tgps = *time0;
00308   baryinput.dInv = 0.0;
00309 
00310   /* for the purposes of calculating the velocity of the earth */
00311   /* at some given time, the position of the source in the sky should not matter. */
00312   /* So, for this function, we set alpha and delta to zero as inputs to the */
00313   /* barycenter routines  */  
00314   baryinput.alpha = 0.0;
00315   baryinput.delta = 0.0; 
00316   
00317   /* call barycentering routines to calculate velocities */
00318   TRY( LALBarycenterEarth( status->statusPtr, earth, time0, edat), status);
00319   TRY( LALBarycenter( status->statusPtr, emit, &baryinput, earth), status);
00320   
00321   /* set values of velocity for all the SFT's */
00322   for (i=0; i < 3; i++) { v[i] = emit->vDetector[i]; }
00323 
00324   LALFree(emit);
00325   LALFree(earth); 
00326 
00327   DETATCHSTATUSPTR (status);
00328   RETURN (status);
00329 }
00330 
00331 
00332 
00333 /**< This finds velocity of a given detector at a given time 
00334  */
00335 /* *******************************  <lalVerbatim file="VelocityD"> */
00336 void LALDetectorPos(LALStatus    *status, 
00337                     REAL8        x[3], 
00338                     LIGOTimeGPS  *time0, 
00339                     LALDetector  detector,
00340                     EphemerisData *edat)
00341 { /*-------------------------------------------------</lalVerbatim> */
00342 
00343   INT4  i;
00344   EmissionTime     *emit=NULL;
00345   EarthState       *earth=NULL;
00346   BarycenterInput  baryinput;
00347 
00348   /*----------------------------------------------------------------*/
00349  
00350   INITSTATUS ( status, "LALDetectorPos", VELOCITYC);
00351   ATTATCHSTATUSPTR (status);
00352 
00353   ASSERT (time0, status, VELOCITYH_ENULL, VELOCITYH_MSGENULL);
00354   ASSERT (edat, status, VELOCITYH_ENULL, VELOCITYH_MSGENULL);
00355 
00356   emit = (EmissionTime *)LALMalloc(sizeof(EmissionTime));
00357   earth = (EarthState *)LALMalloc(sizeof(EarthState));
00358 
00359   /* detector info */
00360   baryinput.site.location[0] = detector.location[0]/LAL_C_SI;
00361   baryinput.site.location[1] = detector.location[1]/LAL_C_SI;
00362   baryinput.site.location[2] = detector.location[2]/LAL_C_SI;
00363   
00364   /* set other barycentering info */
00365   baryinput.tgps = *time0;
00366   baryinput.dInv = 0;  
00367 
00368   /* for the purposes of calculating the velocity of the earth */
00369   /* at some given time, the position of the source in the sky should not matter. */
00370   /* So, for this function, we set alpha and delta to zero as inputs to the */
00371   /* barycenter routines  */  
00372   baryinput.alpha = 0.0;
00373   baryinput.delta = 0.0; 
00374   
00375   /* call barycentering routines to calculate velocities */
00376   TRY( LALBarycenterEarth( status->statusPtr, earth, time0, edat), status);
00377   TRY( LALBarycenter( status->statusPtr, emit, &baryinput, earth), status);
00378   
00379   /* set values of velocity for all the SFT's */
00380   for (i=0; i < 3; i++) { x[i] = emit->rDetector[i]; }
00381 
00382   LALFree(emit);
00383   LALFree(earth); 
00384 
00385   DETATCHSTATUSPTR (status);
00386   RETURN (status);
00387 }
00388 
00389 
00390 
00391 
00392 
00393 
00394 
00395 
00396 

Generated on Thu Aug 28 03:13:07 2008 for LAL by  doxygen 1.5.2