LALInspiralWave3.c

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 Stas Babak, David Churches, B.S. Sathyaprakash, Craig Robinson , Thomas Cokelaer
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 /*  <lalVerbatim file="LALInspiralWave3CV">
00021 
00022 Author: Sathyaprakash, B. S.
00023 $Id: LALInspiralWave3.c,v 1.27 2008/03/06 13:04:51 sathya Exp $
00024 </lalVerbatim>  */
00025 
00026 /*  <lalLaTeX>
00027 
00028 \subsection{Module \texttt{LALInspiralWave3.c} and \texttt{LALInspiralWave3Templates.c}}
00029 These modules generate a time-domain chirp waveform of type {\tt TaylorT3}.
00030 
00031 
00032 \subsubsection*{Prototypes}
00033 \vspace{0.1in}
00034 \input{LALInspiralWave3CP}
00035 \index{\verb&LALInspiralWave3()&}
00036 \begin{itemize}
00037 \item {\tt output:} Output containing the inspiral waveform.
00038 \item {\tt params:} Input containing binary chirp parameters.
00039 \end{itemize}
00040 \vspace{0.1in}
00041 \input{LALInspiralWave3TemplatesCP}
00042 \index{\verb&LALInspiralWave3Templates()&}
00043 \begin{itemize}
00044 \item {\tt output1:} Output containing the 0-phase inspiral waveform.
00045 \item {\tt output2:} Output containing the $\pi/2$-phase inspiral waveform.
00046 \item {\tt params:} Input containing binary chirp parameters.
00047 \end{itemize}
00048 
00049 
00050 \subsubsection*{Description}
00051 {\tt LALInspiralWave3} generates {\tt TaylorT3} approximant which
00052 corresponds to the case wherein 
00053 the phase of the waveform is given as an explicit function of time
00054 as in Equation (\ref{eq:InspiralWavePhase3}). 
00055 
00056 {\tt LALInspiralWave3Templates} simultaneously generates 
00057 two inspiral waveforms and the two differ in 
00058 phase by $\pi/2$.  
00059  
00060 \subsubsection*{Algorithm}
00061 
00062 \subsubsection*{Uses}
00063 
00064 \texttt{LALInspiralParameterCalc} \\
00065 \texttt{LALInspiralChooseModel} \\
00066 \texttt{LALInspiralSetup} \\
00067 \texttt{LALInspiralPhasing3} (via expnFunc)\\
00068 \texttt{LALInspiralFrequency3}. (via expnFunc)\\
00069 
00070 
00071 \subsubsection*{Notes}
00072 
00073 \vfill{\footnotesize\input{LALInspiralWave3CV}}
00074 
00075 </lalLaTeX>  */
00076 
00077 #include <lal/LALStdlib.h>
00078 #include <lal/LALInspiral.h>
00079 #include <lal/FindRoot.h>
00080 #include <lal/Units.h>
00081 #include <lal/SeqFactories.h>
00082 
00083 
00084 typedef struct
00085 {
00086         void (*func)(LALStatus *status, REAL8 *f, REAL8 tC, expnCoeffs *ak);
00087         expnCoeffs ak;
00088 } 
00089 ChirptimeFromFreqIn;
00090 
00091 static void LALInspiralFrequency3Wrapper(LALStatus *status, REAL8 *f, REAL8 tC, void *pars);
00092 
00093 static void
00094 LALInspiralWave3Engine(
00095                 LALStatus        *status,
00096                 REAL4Vector      *output1,
00097                 REAL4Vector      *output2,
00098                 REAL4Vector      *h,
00099                 REAL4Vector      *a,
00100                 REAL4Vector      *ff,
00101                 REAL8Vector      *phi,
00102                 UINT4            *countback,
00103                 InspiralTemplate *params,
00104                 InspiralInit     *paramsInit
00105                 );
00106 
00107 NRCSID (LALINSPIRALWAVE3C, "$Id: LALInspiralWave3.c,v 1.27 2008/03/06 13:04:51 sathya Exp $");
00108 
00109 /*  <lalVerbatim file="LALInspiralWave3CP"> */
00110 
00111 void 
00112 LALInspiralWave3 (
00113    LALStatus        *status,
00114    REAL4Vector      *output, 
00115    InspiralTemplate *params
00116    )
00117 
00118 { /* </lalVerbatim>  */
00119 
00120   
00121   UINT4 count;
00122   InspiralInit paramsInit;
00123 
00124   INITSTATUS (status, "LALInspiralWave3", LALINSPIRALWAVE3C);
00125   ATTATCHSTATUSPTR(status);
00126 
00127   ASSERT(output, status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL);
00128   ASSERT(output->data, status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL);
00129   ASSERT(params, status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL);
00130   ASSERT(params->nStartPad >= 0, status, LALINSPIRALH_ESIZE, LALINSPIRALH_MSGESIZE);
00131   ASSERT(params->fLower > 0, status, LALINSPIRALH_ESIZE, LALINSPIRALH_MSGESIZE);
00132   ASSERT(params->tSampling > 0, status, LALINSPIRALH_ESIZE, LALINSPIRALH_MSGESIZE);
00133   
00134   LALInspiralSetup (status->statusPtr, &(paramsInit.ak), params);
00135   CHECKSTATUSPTR(status);
00136   LALInspiralChooseModel(status->statusPtr, &(paramsInit.func),
00137                                          &(paramsInit.ak), params);
00138   CHECKSTATUSPTR(status);
00139 
00140 
00141   LALInspiralParameterCalc (status->statusPtr, params);
00142   CHECKSTATUSPTR(status);
00143 
00144   ASSERT(params->totalMass >0., status, LALINSPIRALH_ESIZE, LALINSPIRALH_MSGESIZE);
00145   ASSERT(params->eta >= 0, status, LALINSPIRALH_ESIZE, LALINSPIRALH_MSGESIZE);
00146 
00147   memset( output->data, 0, output->length * sizeof(REAL4) );
00148 
00149   /* Call the engine function */
00150   LALInspiralWave3Engine(status->statusPtr, output, NULL, NULL, 
00151                         NULL, NULL, NULL, &count, params, &paramsInit);
00152 
00153   CHECKSTATUSPTR(status);
00154 
00155   DETATCHSTATUSPTR(status);
00156   RETURN(status);
00157 }
00158 
00159 static void LALInspiralFrequency3Wrapper(LALStatus *status, REAL8 *f, REAL8 tC, void *pars)
00160 {
00161 
00162   ChirptimeFromFreqIn *in;
00163   REAL8 freq;
00164   INITSTATUS (status, "LALInspiralWave3", LALINSPIRALWAVE3C);
00165   ATTATCHSTATUSPTR(status);
00166 
00167   in = (ChirptimeFromFreqIn *) pars;
00168   in->func(status->statusPtr, &freq, tC, &(in->ak));
00169   *f = freq - in->ak.f0;
00170 
00171   /*
00172   fprintf(stderr, "Here freq=%e f=%e tc=%e f0=%e\n", freq, *f, tC, in->ak.f0);
00173    */
00174 
00175   DETATCHSTATUSPTR(status);
00176   RETURN(status);
00177 }
00178 
00179 NRCSID (LALINSPIRALWAVE3TEMPLATESC, "$Id: LALInspiralWave3.c,v 1.27 2008/03/06 13:04:51 sathya Exp $");
00180 
00181 /*  <lalVerbatim file="LALInspiralWave3TemplatesCP"> */
00182 
00183 void 
00184 LALInspiralWave3Templates (
00185    LALStatus        *status,
00186    REAL4Vector      *output1, 
00187    REAL4Vector      *output2, 
00188    InspiralTemplate *params
00189    )
00190 
00191 { /* </lalVerbatim>  */
00192 
00193   UINT4 count;
00194 
00195   InspiralInit paramsInit;
00196 
00197   INITSTATUS (status, "LALInspiralWave3Templates", LALINSPIRALWAVE3TEMPLATESC);
00198   ATTATCHSTATUSPTR(status);
00199 
00200   ASSERT(output1, status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL);
00201   ASSERT(output2, status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL);
00202   ASSERT(output1->data, status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL);
00203   ASSERT(output2->data, status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL);
00204   ASSERT(params, status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL); 
00205   ASSERT(params->nStartPad >= 0, status, LALINSPIRALH_ESIZE, LALINSPIRALH_MSGESIZE);
00206   ASSERT(params->fLower > 0, status, LALINSPIRALH_ESIZE, LALINSPIRALH_MSGESIZE);
00207   ASSERT(params->tSampling > 0, status, LALINSPIRALH_ESIZE, LALINSPIRALH_MSGESIZE);
00208 
00209   LALInspiralSetup (status->statusPtr, &(paramsInit.ak), params);
00210   CHECKSTATUSPTR(status);
00211   LALInspiralChooseModel(status->statusPtr, &(paramsInit.func), 
00212                                         &(paramsInit.ak), params);
00213   CHECKSTATUSPTR(status);
00214 
00215 /* Calculate the three unknown paramaters in (m1,m2,M,eta,mu) from the two
00216    which are given.  */
00217 
00218   LALInspiralParameterCalc (status->statusPtr, params);
00219   CHECKSTATUSPTR(status);
00220 
00221   ASSERT(params->totalMass >0., status, LALINSPIRALH_ESIZE, LALINSPIRALH_MSGESIZE);
00222   ASSERT(params->eta >= 0, status, LALINSPIRALH_ESIZE, LALINSPIRALH_MSGESIZE);
00223 
00224   /* Initialise the waveforms to zero */
00225   memset(output1->data, 0, output1->length * sizeof(REAL4));
00226   memset(output2->data, 0, output2->length * sizeof(REAL4));
00227 
00228   /* Call the engine function */
00229   LALInspiralWave3Engine(status->statusPtr, output1, output2, NULL, 
00230                             NULL, NULL, NULL, &count, params, &paramsInit);
00231   CHECKSTATUSPTR(status);
00232 
00233   DETATCHSTATUSPTR(status);
00234   RETURN(status);
00235 }
00236 
00237 
00238 
00239 
00240 
00241 NRCSID (LALINSPIRALWAVE3FORINJECTIONC, "$Id: LALInspiralWave3.c,v 1.27 2008/03/06 13:04:51 sathya Exp $");
00242 
00243 /*  <lalVerbatim file="LALInspiralWave3ForInjectionCP"> */
00244 
00245 void 
00246 LALInspiralWave3ForInjection (
00247                               LALStatus        *status,
00248                               CoherentGW       *waveform,   
00249                               InspiralTemplate *params,
00250                               PPNParamStruc  *ppnParams)
00251      
00252      /* </lalVerbatim>  */
00253 {
00254   
00255   UINT4 count, i;
00256   REAL4Vector *h=NULL;
00257   REAL4Vector *a=NULL;
00258   REAL4Vector *ff=NULL ;
00259   REAL8Vector *phiv=NULL;
00260   CreateVectorSequenceIn in;
00261 
00262   REAL8 phiC;/* phase at coalescence */
00263   CHAR message[256];
00264 
00265   
00266   InspiralInit paramsInit;  
00267   
00268  /** -- -- */
00269   INITSTATUS (status, "LALInspiralWave3ForInjection", LALINSPIRALWAVE3FORINJECTIONC);
00270   ATTATCHSTATUSPTR(status);
00271   
00272   /* Make sure parameter and waveform structures exist. */
00273   ASSERT( params, status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL );
00274   ASSERT(waveform, status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL);  
00275   ASSERT( !( waveform->h ), status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL );
00276   ASSERT( !( waveform->a ), status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL );
00277   ASSERT( !( waveform->f ), status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL );
00278   ASSERT( !( waveform->phi ), status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL );
00279   ASSERT( !( waveform->shift ), status, LALINSPIRALH_ENULL, LALINSPIRALH_MSGENULL );
00280   
00281   params->ampOrder = 0;
00282   sprintf(message, "WARNING: Amp Order has been reset to %d", params->ampOrder);
00283   LALInfo(status, message);
00284   /* Compute some parameters*/
00285   LALInspiralInit(status->statusPtr, params, &paramsInit);
00286   CHECKSTATUSPTR(status);   
00287 
00288   if (paramsInit.nbins==0)
00289     {
00290       DETATCHSTATUSPTR(status);
00291       RETURN (status);
00292       
00293     }
00294   
00295   /* Now we can allocate memory and vector for coherentGW structure*/     
00296   LALSCreateVector(status->statusPtr, &ff, paramsInit.nbins);
00297   CHECKSTATUSPTR(status);   
00298   LALSCreateVector(status->statusPtr, &a, 2*paramsInit.nbins);
00299   CHECKSTATUSPTR(status);   
00300   LALDCreateVector(status->statusPtr, &phiv, paramsInit.nbins);
00301   CHECKSTATUSPTR(status);
00302 
00303  /* By default the waveform is empty */
00304  
00305   memset(ff->data, 0, ff->length * sizeof(REAL4));
00306   memset(a->data,  0, a->length * sizeof(REAL4));
00307   memset(phiv->data, 0, phiv->length * sizeof(REAL8));
00308 
00309   if( params->ampOrder )
00310   {
00311      LALSCreateVector(status->statusPtr, &h, 2*paramsInit.nbins);
00312      CHECKSTATUSPTR(status);   
00313      memset(h->data,  0, h->length * sizeof(REAL4));
00314   }
00315 
00316   /* Call the engine function */
00317   LALInspiralWave3Engine(status->statusPtr, NULL, NULL, h, a, ff, phiv, &count, params, &paramsInit);
00318   BEGINFAIL( status ) {
00319      LALSDestroyVector(status->statusPtr, &ff);
00320      CHECKSTATUSPTR(status);
00321      LALSDestroyVector(status->statusPtr, &a);
00322      CHECKSTATUSPTR(status);
00323      LALDDestroyVector(status->statusPtr, &phiv);
00324      CHECKSTATUSPTR(status);
00325      if( params->ampOrder )
00326      {
00327        LALSDestroyVector(status->statusPtr, &h);
00328        CHECKSTATUSPTR(status);
00329      }
00330   }
00331   ENDFAIL(status);
00332 
00333   /* Check an empty waveform hasn't been returned */
00334   for (i = 0; i < phiv->length; i++)
00335   {
00336     if (phiv->data[i] != 0.0) break;
00337     /* If the waveform returned is empty, return now */
00338     if (i == phiv->length - 1)
00339     {
00340       LALSDestroyVector(status->statusPtr, &ff);
00341       CHECKSTATUSPTR(status);
00342       LALSDestroyVector(status->statusPtr, &a);
00343       CHECKSTATUSPTR(status);
00344       LALDDestroyVector(status->statusPtr, &phiv);
00345       CHECKSTATUSPTR(status);
00346 
00347       DETATCHSTATUSPTR(status);
00348       RETURN(status);
00349     }
00350   }
00351 
00352   /*  if ( (phase/2./LAL_PI) < 2. ){
00353     sprintf(message, "The waveform has only %lf cycles; we don't keep waveform with less than 2 cycles.", 
00354                (double)phase/2./(double)LAL_PI );
00355     LALWarning(status, message);
00356 
00357 
00358   }
00359   else*/
00360     {
00361       
00362       /*wrap the phase vector*/
00363       phiC =  phiv->data[count-1] ;
00364       for (i=0; i<count;i++)
00365         {
00366           phiv->data[i] =  phiv->data[i] -phiC + ppnParams->phi;
00367         }
00368       /* Allocate the waveform structures. */
00369       if ( ( waveform->a = (REAL4TimeVectorSeries *)
00370              LALMalloc( sizeof(REAL4TimeVectorSeries) ) ) == NULL ) {
00371         ABORT( status, LALINSPIRALH_EMEM,
00372                LALINSPIRALH_MSGEMEM );
00373       }
00374       memset( waveform->a, 0, sizeof(REAL4TimeVectorSeries) );
00375       if ( ( waveform->f = (REAL4TimeSeries *)
00376              LALMalloc( sizeof(REAL4TimeSeries) ) ) == NULL ) {
00377         LALFree( waveform->a ); waveform->a = NULL;
00378         ABORT( status, LALINSPIRALH_EMEM,
00379                LALINSPIRALH_MSGEMEM );
00380       }
00381       memset( waveform->f, 0, sizeof(REAL4TimeSeries) );
00382       if ( ( waveform->phi = (REAL8TimeSeries *)
00383              LALMalloc( sizeof(REAL8TimeSeries) ) ) == NULL ) {
00384         LALFree( waveform->a ); waveform->a = NULL;
00385         LALFree( waveform->f ); waveform->f = NULL;
00386         ABORT( status, LALINSPIRALH_EMEM,
00387                LALINSPIRALH_MSGEMEM );
00388       }
00389       memset( waveform->phi, 0, sizeof(REAL8TimeSeries) );
00390       
00391       
00392       
00393       in.length = (UINT4)count;
00394       in.vectorLength = 2;
00395       LALSCreateVectorSequence( status->statusPtr,
00396                                 &( waveform->a->data ), &in );
00397       CHECKSTATUSPTR(status);      
00398       LALSCreateVector( status->statusPtr,
00399                         &( waveform->f->data ), count);
00400       CHECKSTATUSPTR(status);      
00401       LALDCreateVector( status->statusPtr,
00402                         &( waveform->phi->data ), count );
00403       CHECKSTATUSPTR(status);        
00404       
00405       
00406   
00407       
00408       memcpy(waveform->f->data->data , ff->data, count*(sizeof(REAL4)));
00409       memcpy(waveform->a->data->data , a->data, 2*count*(sizeof(REAL4)));
00410       memcpy(waveform->phi->data->data ,phiv->data, count*(sizeof(REAL8)));
00411       
00412       
00413       
00414       
00415       waveform->a->deltaT = waveform->f->deltaT = waveform->phi->deltaT
00416         = 1./params->tSampling;
00417       
00418       waveform->a->sampleUnits = lalStrainUnit;
00419       waveform->f->sampleUnits = lalHertzUnit;
00420       waveform->phi->sampleUnits = lalDimensionlessUnit;  
00421       waveform->position = ppnParams->position;
00422       waveform->psi = ppnParams->psi;
00423 
00424       LALSnprintf( waveform->a->name, LALNameLength, "T3 inspiral amplitudes" );
00425       LALSnprintf( waveform->f->name, LALNameLength, "T3 inspiral frequency" );
00426       LALSnprintf( waveform->phi->name, LALNameLength, "T3  inspiral phase" );
00427       
00428       /* --- fill some output ---*/
00429       
00430       ppnParams->tc     = (double)(count-1) / params->tSampling ;
00431       ppnParams->length = count;
00432       ppnParams->dfdt   = ((REAL4)(waveform->f->data->data[count-1] 
00433                                    - waveform->f->data->data[count-2]))
00434         * ppnParams->deltaT;
00435       ppnParams->fStop  = params->fFinal;
00436       ppnParams->termCode        = GENERATEPPNINSPIRALH_EFSTOP;
00437       ppnParams->termDescription = GENERATEPPNINSPIRALH_MSGEFSTOP;
00438       
00439       ppnParams->fStart   = ppnParams->fStartIn;
00440 
00441       if( params->ampOrder )
00442       {
00443         if ( ( waveform->h = (REAL4TimeVectorSeries *)
00444                LALMalloc( sizeof(REAL4TimeVectorSeries) ) ) == NULL ) 
00445         {
00446           ABORT( status, LALINSPIRALH_EMEM, LALINSPIRALH_MSGEMEM );
00447         }
00448         memset( waveform->h, 0, sizeof(REAL4TimeVectorSeries) );
00449         LALSCreateVectorSequence( status->statusPtr,
00450                                   &( waveform->h->data ), &in );
00451         CHECKSTATUSPTR(status);      
00452         memcpy(waveform->h->data->data , h->data, 2*count*(sizeof(REAL4)));
00453         waveform->h->deltaT = 1./params->tSampling;
00454         waveform->h->sampleUnits = lalStrainUnit;
00455         LALSnprintf( waveform->h->name, LALNameLength, "T3 inspiral polarizations" );
00456         LALSDestroyVector(status->statusPtr, &h);
00457         CHECKSTATUSPTR(status);
00458       } 
00459     }    /*end of coherentGW storage */ 
00460 
00461 
00462   /* --- free memory --- */
00463   LALSDestroyVector(status->statusPtr, &ff);
00464   CHECKSTATUSPTR(status);
00465   LALSDestroyVector(status->statusPtr, &a);
00466   CHECKSTATUSPTR(status);
00467   LALDDestroyVector(status->statusPtr, &phiv);
00468   CHECKSTATUSPTR(status);
00469 
00470 
00471 
00472   DETATCHSTATUSPTR(status);
00473   RETURN(status);
00474 }
00475 
00476 
00477 /* Engine function used to generate the waveforms */
00478 static void
00479 LALInspiralWave3Engine(
00480                 LALStatus        *status,
00481                 REAL4Vector      *output1,
00482                 REAL4Vector      *output2,
00483                 REAL4Vector      *h,
00484                 REAL4Vector      *a,
00485                 REAL4Vector      *ff,
00486                 REAL8Vector      *phiv,
00487                 UINT4            *countback,
00488                 InspiralTemplate *params,
00489                 InspiralInit     *paramsInit
00490                 )
00491 
00492 {
00493   INT4 i, startShift, count;
00494   REAL8 dt, fu, ieta, eta, tc, totalMass, t, td, c1, phi0, phi1, phi;
00495   REAL8 v, f, fHigh, amp, tmax, fOld, phase, omega;
00496   DFindRootIn rootIn;
00497   expnFunc func;
00498   expnCoeffs ak;
00499   ChirptimeFromFreqIn timeIn;
00500   void *pars;
00501 
00502   REAL8 temp, tempMax=0, tempMin = 0;
00503   
00504   /* Only used in injection case */
00505   REAL8 unitHz = 0.;
00506   REAL8 f2a = 0.;
00507   REAL8 mu = 0.;
00508   REAL8 mTot = 0.;
00509   REAL8 cosI = 0.;/* cosine of system inclination */
00510   REAL8 etab = 0.;
00511   REAL8 fFac = 0.; /* SI normalization for f and t */
00512   REAL8 f2aFac = 0.;/* factor multiplying f in amplitude function */
00513   REAL8 apFac = 0., acFac = 0.;/* extra factor in plus and cross amplitudes */
00514 
00515 
00516   INITSTATUS (status, "LALInspiralWave3Engine", LALINSPIRALWAVE3TEMPLATESC);
00517   ATTATCHSTATUSPTR(status);
00518 
00519   ak   = paramsInit->ak;
00520   func = paramsInit->func;
00521 
00522   if (output2 || a)
00523       params->nStartPad = 0; /* must be zero for templates and injections */
00524 
00525   /* Only in injection case.. */
00526   if (a || h)
00527   {
00528     mTot   =  params->mass1 + params->mass2;
00529     etab   =  params->mass1 * params->mass2;
00530     etab  /= mTot;
00531     etab  /= mTot;
00532     unitHz = (mTot) *LAL_MTSUN_SI*(REAL8)LAL_PI;
00533     cosI   = cos( params->inclination );
00534     mu     = etab * mTot;
00535     fFac   = 1.0 / ( 4.0*LAL_TWOPI*LAL_MTSUN_SI*mTot );
00536     f2aFac = LAL_PI*LAL_MTSUN_SI*mTot*fFac;
00537     apFac  = acFac = -2.0 * mu * LAL_MRSUN_SI/params->distance;
00538     apFac *= 1.0 + cosI*cosI;
00539     acFac *= 2.0 * cosI;
00540   }
00541 
00542   dt = 1.0/(params->tSampling);    /* sampling rate  */
00543   fu = params->fCutoff;            /* upper frequency cutoff  */
00544   phi = params->startPhase;        /* initial phase  */
00545   startShift = params->nStartPad;  /* number of zeros at the start of the wave  */
00546 
00547 
00548   tc=params->tC;       /* Instant of coalescence of the compact objects */
00549   eta = params->eta;   /* Symmetric mass ratio  */
00550   ieta = params->ieta;
00551   totalMass = (params->totalMass)*LAL_MTSUN_SI; /* mass of the system in seconds */
00552 
00553 
00554 /* 
00555    If flso is less than the user inputted upper frequency cutoff fu, 
00556    then the waveforn is truncated at f=flso.  
00557 */
00558 
00559   if (fu) 
00560      fHigh = (fu < ak.flso) ? fu : ak.flso; 
00561   else 
00562      fHigh = ak.flso;
00563 
00564 /* 
00565    Check that the highest frequency is less than half the sampling frequency - 
00566    the Nyquist theorum 
00567 */
00568 
00569   ASSERT(fHigh < 0.5/dt, status, LALINSPIRALH_ESIZE, LALINSPIRALH_MSGESIZE);
00570   ASSERT(fHigh > params->fLower, status, LALINSPIRALH_ESIZE, LALINSPIRALH_MSGESIZE);
00571 
00572 /* Here's the part which calculates the waveform */
00573 
00574   c1 = eta/(5.*totalMass);
00575 
00576   i = startShift;
00577 
00578   /*
00579    * In Jan 2003 we realized that the tC determined as a sum of chirp times is
00580    * not quite the tC that should enter the definition of Theta in the expression
00581    * for the frequency as a function of time (see DIS3, 2000). This is because
00582    * chirp times are obtained by inverting t(f). Rather tC should be obtained by
00583    * solving the equation f0 - f(tC) = 0. This is what is implemented below.
00584    */
00585                                                                                                                              
00586   timeIn.func = func.frequency3;
00587   timeIn.ak = ak;
00588   rootIn.function = &LALInspiralFrequency3Wrapper;
00589   rootIn.xmin = c1*params->tC/2.;
00590   rootIn.xmax = c1*params->tC*2.;
00591   rootIn.xacc = 1.e-6;
00592   pars = (void*) &timeIn;
00593   /* tc is the instant of coalescence */
00594 
00595   rootIn.xmax = c1*params->tC*3 + 5.; /* we add 5 so that if tC is small then xmax
00596                                          is always greater than a given value (here 5)*/
00597                                                                                                                              
00598   /* for x in [rootIn.xmin, rootIn.xmax], we search the value which gives the max frequency.
00599    and keep the corresponding rootIn.xmin. */
00600                                                                                                                              
00601                                                                                                                              
00602                                                                                                                              
00603   for (tc = c1*params->tC/1000.; tc < rootIn.xmax; tc+=c1*params->tC/1000.){
00604     LALInspiralFrequency3Wrapper(status->statusPtr, &temp,  tc , pars);
00605     if (temp > tempMax) {
00606       rootIn.xmin = tc;
00607       tempMax = temp;
00608     }
00609     if (temp < tempMin) {
00610       tempMin = temp;
00611     }
00612   }
00613                                                                                                                              
00614   /* if we have found a value positive then everything should be fine in the
00615      BissectionFindRoot function */
00616   if (tempMax > 0  &&  tempMin < 0){
00617     LALDBisectionFindRoot (status->statusPtr, &tc, &rootIn, pars);
00618     CHECKSTATUSPTR(status);
00619   }
00620   else if (a)
00621   {
00622     /* Otherwise we return an empty waveform for injection */
00623     DETATCHSTATUSPTR( status );
00624     RETURN( status );
00625   }
00626   else
00627     /* Or abort if not injection */
00628     ABORT( status, LALINSPIRALH_EROOTINIT, LALINSPIRALH_MSGEROOTINIT );
00629                                                                                                                              
00630   tc /= c1;
00631                                                                                                                              
00632   tc += params->startTime;       /* Add user given startTime to instant of
00633                                      coalescence of the compact objects */
00634 
00635   t=0.0;
00636   td = c1*(tc-t);
00637   func.phasing3(status->statusPtr, &phase, td, &ak);
00638   CHECKSTATUSPTR(status);
00639   func.frequency3(status->statusPtr, &f, td, &ak);
00640   CHECKSTATUSPTR(status);
00641   phi0=-phase+phi;
00642   phi1=phi0+LAL_PI_2;
00643 
00644   count = 0;
00645   tmax = tc - dt;
00646   fOld = 0.0;
00647 
00648 /* We stop if any of the following conditions fail */
00649 
00650   while (f < fHigh && t < tmax && f > fOld) 
00651   {
00652     /* Check we don't write past the end of the vector */
00653     if ((output1 && ((UINT4)i >= output1->length)) || (ff && ((UINT4)count >= ff->length)))
00654     {
00655         ABORT(status, LALINSPIRALH_EVECTOR, LALINSPIRALH_MSGEVECTOR);
00656     }
00657 
00658     fOld = f; 
00659     v = pow(f*LAL_PI*totalMass, oneby3);
00660     amp = params->signalAmplitude * v*v;
00661     if (output1)
00662     { 
00663       output1->data[i] = (REAL4) amp * cos(phase+phi0);
00664       if (output2)
00665         output2->data[i] = (REAL4) amp * cos(phase+phi1);
00666     }
00667     else if (a) 
00668     {
00669       int ice, ico;
00670       ice = 2*count;
00671       ico = ice + 1;
00672       omega = v*v*v;
00673       
00674       ff->data[count] = (REAL4)(omega/unitHz);
00675       f2a = pow(f2aFac * omega, 2. / 3.);
00676 
00677       a->data[ice]          = (REAL4)(4.*apFac * f2a);
00678       a->data[ico]        = (REAL4)(4.*acFac * f2a);
00679       phiv->data[count]          = (REAL8)(phase);
00680 
00681       if (h)
00682       {
00683         h->data[ice] = LALInspiralHPlusPolarization( phase, v, params );
00684         h->data[ico] = LALInspiralHCrossPolarization( phase, v, params );
00685       }
00686     }
00687     ++i;
00688     ++count;
00689     t=count*dt;
00690     td = c1*(tc-t);
00691     func.phasing3(status->statusPtr, &phase, td, &ak);
00692     CHECKSTATUSPTR(status);
00693     func.frequency3(status->statusPtr, &f, td, &ak);
00694     CHECKSTATUSPTR(status); 
00695   }
00696   params->fFinal = fOld;
00697   if (output1 && !output2) params->tC = t;  
00698 /*
00699   fprintf(stderr, "%e %e\n", f, fHigh);
00700 */
00701   *countback = count;
00702 
00703   DETATCHSTATUSPTR(status);
00704   RETURN(status);
00705 }

Generated on Mon Oct 6 02:31:47 2008 for LAL by  doxygen 1.5.2