FACT++  1.0
void palPertue ( double  date,
double  u[13],
int *  jstat 
)

Definition at line 212 of file palPertue.c.

References COPYSIGN, DMAX, DMIN, eraRxp(), NP, PAL__GCON, PAL__SPD, palDmoon(), palEpj(), palEpv(), palPlanet(), palPrec(), palPv2ue(), and palUe2pv().

Referenced by palPertel(), and t_planet().

212  {
213 
214  /* Distance from EMB at which Earth and Moon are treated separately */
215  const double RNE=1.0;
216 
217  /* Coincidence with major planet distance */
218  const double COINC=0.0001;
219 
220  /* Coefficient relating timestep to perturbing force */
221  const double TSC=1e-4;
222 
223  /* Minimum and maximum timestep (days) */
224  const double TSMIN = 0.01;
225  const double TSMAX = 10.0;
226 
227  /* Age limit for major-planet state vector (days) */
228  const double AGEPMO=5.0;
229 
230  /* Age limit for major-planet mean elements (days) */
231  const double AGEPEL=50.0;
232 
233  /* Margin for error when deciding whether to renew the planetary data */
234  const double TINY=1e-6;
235 
236  /* Age limit for the body's osculating elements (before rectification) */
237  const double AGEBEL=100.0;
238 
239  /* Gaussian gravitational constant squared */
240  const double GCON2 = PAL__GCON * PAL__GCON;
241 
242  /* The final epoch */
243  double TFINAL;
244 
245  /* The body's current universal elements */
246  double UL[13];
247 
248  /* Current reference epoch */
249  double T0;
250 
251  /* Timespan from latest orbit rectification to final epoch (days) */
252  double TSPAN;
253 
254  /* Time left to go before integration is complete */
255  double TLEFT;
256 
257  /* Time direction flag: +1=forwards, -1=backwards */
258  double FB;
259 
260  /* First-time flag */
261  int FIRST = 0;
262 
263  /*
264  * The current perturbations
265  */
266 
267  /* Epoch (days relative to current reference epoch) */
268  double RTN;
269  /* Position (AU) */
270  double PERP[3];
271  /* Velocity (AU/d) */
272  double PERV[3];
273  /* Acceleration (AU/d/d) */
274  double PERA[3];
275 
276  /* Length of current timestep (days), and half that */
277  double TS,HTS;
278 
279  /* Epoch of middle of timestep */
280  double T;
281 
282  /* Epoch of planetary mean elements */
283  double TPEL = 0.0;
284 
285  /* Planet number (1=Mercury, 2=Venus, 3=EMB...8=Neptune) */
286  int NP;
287 
288  /* Planetary universal orbital elements */
289  double UP[8][13];
290 
291  /* Epoch of planetary state vectors */
292  double TPMO = 0.0;
293 
294  /* State vectors for the major planets (AU,AU/s) */
295  double PVIN[8][6];
296 
297  /* Earth velocity and position vectors (AU,AU/s) */
298  double VB[3],PB[3],VH[3],PE[3];
299 
300  /* Moon geocentric state vector (AU,AU/s) and position part */
301  double PVM[6],PM[3];
302 
303  /* Date to J2000 de-precession matrix */
304  double PMAT[3][3];
305 
306  /*
307  * Correction terms for extrapolated major planet vectors
308  */
309 
310  /* Sun-to-planet distances squared multiplied by 3 */
311  double R2X3[8];
312  /* Sunward acceleration terms, G/2R^3 */
313  double GC[8];
314  /* Tangential-to-circular correction factor */
315  double FC;
316  /* Radial correction factor due to Sunwards acceleration */
317  double FG;
318 
319  /* The body's unperturbed and perturbed state vectors (AU,AU/s) */
320  double PV0[6],PV[6];
321 
322  /* The body's perturbed and unperturbed heliocentric distances (AU) cubed */
323  double R03,R3;
324 
325  /* The perturbating accelerations, indirect and direct */
326  double FI[3],FD[3];
327 
328  /* Sun-to-planet vector, and distance cubed */
329  double RHO[3],RHO3;
330 
331  /* Body-to-planet vector, and distance cubed */
332  double DELTA[3],DELTA3;
333 
334  /* Miscellaneous */
335  int I,J;
336  double R2,W,DT,DT2,R,FT;
337  int NE;
338 
339  /* Planetary inverse masses, Mercury through Neptune then Earth and Moon */
340  const double AMAS[10] = {
341  6023600., 408523.5, 328900.5, 3098710.,
342  1047.355, 3498.5, 22869., 19314.,
343  332946.038, 27068709.
344  };
345 
346  /* Preset the status to OK. */
347  *jstat = 0;
348 
349  /* Copy the final epoch. */
350  TFINAL = date;
351 
352  /* Copy the elements (which will be periodically updated). */
353  for (I=0; I<13; I++) {
354  UL[I] = u[I];
355  }
356 
357 /* Initialize the working reference epoch. */
358  T0=UL[2];
359 
360  /* Total timespan (days) and hence time left. */
361  TSPAN = TFINAL-T0;
362  TLEFT = TSPAN;
363 
364  /* Warn if excessive. */
365  if (fabs(TSPAN) > 36525.0) *jstat=101;
366 
367  /* Time direction: +1 for forwards, -1 for backwards. */
368  FB = COPYSIGN(1.0,TSPAN);
369 
370  /* Initialize relative epoch for start of current timestep. */
371  RTN = 0.0;
372 
373  /* Reset the perturbations (position, velocity, acceleration). */
374  for (I=0; I<3; I++) {
375  PERP[I] = 0.0;
376  PERV[I] = 0.0;
377  PERA[I] = 0.0;
378  }
379 
380  /* Set "first iteration" flag. */
381  FIRST = 1;
382 
383  /* Step through the time left. */
384  while (FB*TLEFT > 0.0) {
385 
386  /* Magnitude of current acceleration due to planetary attractions. */
387  if (FIRST) {
388  TS = TSMIN;
389  } else {
390  R2 = 0.0;
391  for (I=0; I<3; I++) {
392  W = FD[I];
393  R2 = R2+W*W;
394  }
395  W = sqrt(R2);
396 
397  /* Use the acceleration to decide how big a timestep can be tolerated. */
398  if (W != 0.0) {
399  TS = DMIN(TSMAX,DMAX(TSMIN,TSC/W));
400  } else {
401  TS = TSMAX;
402  }
403  }
404  TS = TS*FB;
405 
406  /* Override if final epoch is imminent. */
407  TLEFT = TSPAN-RTN;
408  if (fabs(TS) > fabs(TLEFT)) TS=TLEFT;
409 
410  /* Epoch of middle of timestep. */
411  HTS = TS/2.0;
412  T = T0+RTN+HTS;
413 
414  /* Is it time to recompute the major-planet elements? */
415  if (FIRST || fabs(T-TPEL)-AGEPEL >= TINY) {
416 
417  /* Yes: go forward in time by just under the maximum allowed. */
418  TPEL = T+FB*AGEPEL;
419 
420  /* Compute the state vector for the new epoch. */
421  for (NP=1; NP<=8; NP++) {
422  palPlanet(TPEL,NP,PV,&J);
423 
424  /* Warning if remote epoch, abort if error. */
425  if (J == 1) {
426  *jstat = 102;
427  } else if (J != 0) {
428  goto ABORT;
429  }
430 
431  /* Transform the vector into universal elements. */
432  palPv2ue(PV,TPEL,0.0,&(UP[NP-1][0]),&J);
433  if (J != 0) goto ABORT;
434  }
435  }
436 
437  /* Is it time to recompute the major-planet motions? */
438  if (FIRST || fabs(T-TPMO)-AGEPMO >= TINY) {
439 
440  /* Yes: look ahead. */
441  TPMO = T+FB*AGEPMO;
442 
443  /* Compute the motions of each planet (AU,AU/d). */
444  for (NP=1; NP<=8; NP++) {
445 
446  /* The planet's position and velocity (AU,AU/s). */
447  palUe2pv(TPMO,&(UP[NP-1][0]),&(PVIN[NP-1][0]),&J);
448  if (J != 0) goto ABORT;
449 
450  /* Scale velocity to AU/d. */
451  for (J=3; J<6; J++) {
452  PVIN[NP-1][J] = PVIN[NP-1][J]*PAL__SPD;
453  }
454 
455  /* Precompute also the extrapolation correction terms. */
456  R2 = 0.0;
457  for (I=0; I<3; I++) {
458  W = PVIN[NP-1][I];
459  R2 = R2+W*W;
460  }
461  R2X3[NP-1] = R2*3.0;
462  GC[NP-1] = GCON2/(2.0*R2*sqrt(R2));
463  }
464  }
465 
466  /* Reset the first-time flag. */
467  FIRST = 0;
468 
469  /* Unperturbed motion of the body at middle of timestep (AU,AU/s). */
470  palUe2pv(T,UL,PV0,&J);
471  if (J != 0) goto ABORT;
472 
473  /* Perturbed position of the body (AU) and heliocentric distance cubed. */
474  R2 = 0.0;
475  for (I=0; I<3; I++) {
476  W = PV0[I]+PERP[I]+(PERV[I]+PERA[I]*HTS/2.0)*HTS;
477  PV[I] = W;
478  R2 = R2+W*W;
479  }
480  R3 = R2*sqrt(R2);
481 
482  /* The body's unperturbed heliocentric distance cubed. */
483  R2 = 0.0;
484  for (I=0; I<3; I++) {
485  W = PV0[I];
486  R2 = R2+W*W;
487  }
488  R03 = R2*sqrt(R2);
489 
490  /* Compute indirect and initialize direct parts of the perturbation. */
491  for (I=0; I<3; I++) {
492  FI[I] = PV0[I]/R03-PV[I]/R3;
493  FD[I] = 0.0;
494  }
495 
496  /* Ready to compute the direct planetary effects. */
497 
498  /* Reset the "near-Earth" flag. */
499  NE = 0;
500 
501  /* Interval from state-vector epoch to middle of current timestep. */
502  DT = T-TPMO;
503  DT2 = DT*DT;
504 
505  /* Planet by planet, including separate Earth and Moon. */
506  for (NP=1; NP<10; NP++) {
507 
508  /* Which perturbing body? */
509  if (NP <= 8) {
510 
511  /* Planet: compute the extrapolation in longitude (squared). */
512  R2 = 0.0;
513  for (J=3; J<6; J++) {
514  W = PVIN[NP-1][J]*DT;
515  R2 = R2+W*W;
516  }
517 
518  /* Hence the tangential-to-circular correction factor. */
519  FC = 1.0+R2/R2X3[NP-1];
520 
521  /* The radial correction factor due to the inwards acceleration. */
522  FG = 1.0-GC[NP-1]*DT2;
523 
524  /* Planet's position. */
525  for (I=0; I<3; I++) {
526  RHO[I] = FG*(PVIN[NP-1][I]+FC*PVIN[NP-1][I+3]*DT);
527  }
528 
529  } else if (NE) {
530 
531  /* Near-Earth and either Earth or Moon. */
532 
533  if (NP == 9) {
534 
535  /* Earth: position. */
536  palEpv(T,PE,VH,PB,VB);
537  for (I=0; I<3; I++) {
538  RHO[I] = PE[I];
539  }
540 
541  } else {
542 
543  /* Moon: position. */
544  palPrec(palEpj(T),2000.0,PMAT);
545  palDmoon(T,PVM);
546  eraRxp(PMAT,PVM,PM);
547  for (I=0; I<3; I++) {
548  RHO[I] = PM[I]+PE[I];
549  }
550  }
551  }
552 
553  /* Proceed unless Earth or Moon and not the near-Earth case. */
554  if (NP <= 8 || NE) {
555 
556  /* Heliocentric distance cubed. */
557  R2 = 0.0;
558  for (I=0; I<3; I++) {
559  W = RHO[I];
560  R2 = R2+W*W;
561  }
562  R = sqrt(R2);
563  RHO3 = R2*R;
564 
565  /* Body-to-planet vector, and distance. */
566  R2 = 0.0;
567  for (I=0; I<3; I++) {
568  W = RHO[I]-PV[I];
569  DELTA[I] = W;
570  R2 = R2+W*W;
571  }
572  R = sqrt(R2);
573 
574  /* If this is the EMB, set the near-Earth flag appropriately. */
575  if (NP == 3 && R < RNE) NE = 1;
576 
577  /* Proceed unless EMB and this is the near-Earth case. */
578  if ( ! (NE && NP == 3) ) {
579 
580  /* If too close, ignore this planet and set a warning. */
581  if (R < COINC) {
582  *jstat = NP;
583 
584  } else {
585 
586  /* Accumulate "direct" part of perturbation acceleration. */
587  DELTA3 = R2*R;
588  W = AMAS[NP-1];
589  for (I=0; I<3; I++) {
590  FD[I] = FD[I]+(DELTA[I]/DELTA3-RHO[I]/RHO3)/W;
591  }
592  }
593  }
594  }
595  }
596 
597  /* Update the perturbations to the end of the timestep. */
598  RTN += TS;
599  for (I=0; I<3; I++) {
600  W = (FI[I]+FD[I])*GCON2;
601  FT = W*TS;
602  PERP[I] = PERP[I]+(PERV[I]+FT/2.0)*TS;
603  PERV[I] = PERV[I]+FT;
604  PERA[I] = W;
605  }
606 
607  /* Time still to go. */
608  TLEFT = TSPAN-RTN;
609 
610  /* Is it either time to rectify the orbit or the last time through? */
611  if (fabs(RTN) >= AGEBEL || FB*TLEFT <= 0.0) {
612 
613  /* Yes: update to the end of the current timestep. */
614  T0 += RTN;
615  RTN = 0.0;
616 
617  /* The body's unperturbed motion (AU,AU/s). */
618  palUe2pv(T0,UL,PV0,&J);
619  if (J != 0) goto ABORT;
620 
621  /* Add and re-initialize the perturbations. */
622  for (I=0; I<3; I++) {
623  J = I+3;
624  PV[I] = PV0[I]+PERP[I];
625  PV[J] = PV0[J]+PERV[I]/PAL__SPD;
626  PERP[I] = 0.0;
627  PERV[I] = 0.0;
628  PERA[I] = FD[I]*GCON2;
629  }
630 
631  /* Use the position and velocity to set up new universal elements. */
632  palPv2ue(PV,T0,0.0,UL,&J);
633  if (J != 0) goto ABORT;
634 
635  /* Adjust the timespan and time left. */
636  TSPAN = TFINAL-T0;
637  TLEFT = TSPAN;
638  }
639 
640  /* Next timestep. */
641  }
642 
643  /* Return the updated universal-element set. */
644  for (I=0; I<13; I++) {
645  u[I] = UL[I];
646  }
647 
648  /* Finished. */
649  return;
650 
651  /* Miscellaneous numerical error. */
652  ABORT:
653  *jstat = -1;
654  return;
655 }
void palPrec(double ep0, double ep1, double rmatp[3][3])
Definition: palPrec.c:76
double palEpj(double date)
Definition: palOne2One.c:1169
void palPv2ue(const double pv[6], double date, double pmass, double u[13], int *jstat)
Definition: palPv2ue.c:114
#define DMIN(A, B)
Definition: palmac.h:129
static const double PAL__GCON
Definition: palmac.h:117
void palDmoon(double date, double pv[6])
Definition: palDmoon.c:95
#define COPYSIGN(a, b)
Definition: palPertue.c:209
void palEpv(double date, double ph[3], double vh[3], double pb[3], double vb[3])
Definition: palEpv.c:79
void eraRxp(double r[3][3], double p[3], double rp[3])
Definition: rxp.c:3
#define DMAX(A, B)
Definition: palmac.h:126
void palPlanet(double date, int np, double pv[6], int *j)
Definition: palPlanet.c:82
#define NP
static const double PAL__SPD
Definition: palmac.h:102
void palUe2pv(double date, double u[13], double pv[], int *jstat)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: