forked from VirtualPlanetaryLaboratory/vplanet
-
Notifications
You must be signed in to change notification settings - Fork 2
/
distrot.c
2150 lines (1877 loc) · 82.1 KB
/
distrot.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
@file distrot.c
@brief Subroutines that control the integration of the obliquity model.
@author Russell Deitrick ([deitrr](https://github.com/deitrr/))
@date July 7 2015
*/
/* lines where something like iBody == 0 occurs
* ~149
* ~227
*/
#include "vplanet.h"
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void BodyCopyDistRot(BODY *dest, BODY *src, int iTideModel, int iNumBodies,
int iBody) {
int iIndex, iPert;
dest[iBody].dXobl = src[iBody].dXobl;
dest[iBody].dYobl = src[iBody].dYobl;
dest[iBody].dZobl = src[iBody].dZobl;
dest[iBody].dDynEllip = src[iBody].dDynEllip;
dest[iBody].bForcePrecRate = src[iBody].bForcePrecRate;
dest[iBody].dPrecRate = src[iBody].dPrecRate;
dest[iBody].iCurrentStep = src[iBody].iCurrentStep;
dest[iBody].bReadOrbitData = src[iBody].bReadOrbitData;
dest[iBody].bCalcDynEllip = src[iBody].bCalcDynEllip;
dest[iBody].dSpecMomInertia = src[iBody].dSpecMomInertia;
}
void InitializeUpdateTmpBodyDistRot(BODY *body, CONTROL *control,
UPDATE *update, int iBody) {
if (body[iBody].bReadOrbitData) {
int iLine;
control->Evolve.tmpBody[iBody].daSemiSeries =
malloc(body[iBody].iNLines * sizeof(double));
control->Evolve.tmpBody[iBody].daHeccSeries =
malloc(body[iBody].iNLines * sizeof(double));
control->Evolve.tmpBody[iBody].daKeccSeries =
malloc(body[iBody].iNLines * sizeof(double));
control->Evolve.tmpBody[iBody].daPincSeries =
malloc(body[iBody].iNLines * sizeof(double));
control->Evolve.tmpBody[iBody].daQincSeries =
malloc(body[iBody].iNLines * sizeof(double));
for (iLine = 0; iLine < body[iBody].iNLines; iLine++) {
control->Evolve.tmpBody[iBody].daSemiSeries[iLine] =
body[iBody].daSemiSeries[iLine];
control->Evolve.tmpBody[iBody].daHeccSeries[iLine] =
body[iBody].daHeccSeries[iLine];
control->Evolve.tmpBody[iBody].daKeccSeries[iLine] =
body[iBody].daKeccSeries[iLine];
control->Evolve.tmpBody[iBody].daPincSeries[iLine] =
body[iBody].daPincSeries[iLine];
control->Evolve.tmpBody[iBody].daQincSeries[iLine] =
body[iBody].daQincSeries[iLine];
}
}
}
/**************** DISTROT options ********************/
void ReadForcePrecRate(BODY *body, CONTROL *control, FILES *files,
OPTIONS *options, SYSTEM *system, int iFile) {
int lTmp = -1, bTmp;
AddOptionBool(files->Infile[iFile].cIn, options->cName, &bTmp, &lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp,
control->Io.iVerbose);
/* Option was found */
body[iFile - 1].bForcePrecRate = bTmp;
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else {
body[iFile - 1].bForcePrecRate = options->dDefault;
}
}
void ReadPrecRate(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
SYSTEM *system, int iFile) {
/* Cannot exist in primary file */
int lTmp = -1;
double dTmp;
AddOptionDouble(files->Infile[iFile].cIn, options->cName, &dTmp, &lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
/* Option was found */
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp,
control->Io.iVerbose);
body[iFile - 1].dPrecRate = dTmp;
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else {
AssignDefaultDouble(options, &body[iFile - 1].dPrecRate, files->iNumInputs);
}
}
void ReadSpecMomInertia(BODY *body, CONTROL *control, FILES *files,
OPTIONS *options, SYSTEM *system, int iFile) {
/* Cannot exist in primary file */
int lTmp = -1;
double dTmp;
AddOptionDouble(files->Infile[iFile].cIn, options->cName, &dTmp, &lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
/* Option was found */
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp,
control->Io.iVerbose);
body[iFile - 1].dSpecMomInertia = dTmp;
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else {
AssignDefaultDouble(options, &body[iFile - 1].dSpecMomInertia,
files->iNumInputs);
}
}
void ReadOrbitData(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
SYSTEM *system, int iFile) {
int lTmp = -1, bTmp;
AddOptionBool(files->Infile[iFile].cIn, options->cName, &bTmp, &lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp,
control->Io.iVerbose);
/* Option was found */
body[iFile - 1].bReadOrbitData = bTmp;
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else {
body[iFile - 1].bReadOrbitData = options->dDefault;
}
}
void ReadFileOrbitData(BODY *body, CONTROL *control, FILES *files,
OPTIONS *options, SYSTEM *system, int iFile) {
int lTmp = -1;
char cTmp[OPTLEN];
AddOptionString(files->Infile[iFile].cIn, options->cName, cTmp, &lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
/* Cannot exist in primary input file -- Each body has an output file */
NotPrimaryInput(iFile, options->cName, files->Infile[iFile].cIn, lTmp,
control->Io.iVerbose);
strcpy(body[iFile - 1].cFileOrbitData, cTmp);
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else if (iFile > 0) {
// sprintf(body[iFile-1].cFileOrbitData,"%s",options[OPT_FILEORBITDATA].cDefault);
strcpy(body[iFile - 1].cFileOrbitData, options->cDefault);
}
}
void InitializeOptionsDistRot(OPTIONS *options, fnReadOption fnRead[]) {
sprintf(options[OPT_DYNELLIP].cName, "dDynEllip");
sprintf(options[OPT_DYNELLIP].cDescr, "Planet's dynamical ellipticity");
sprintf(options[OPT_DYNELLIP].cDefault, "0.00328");
sprintf(options[OPT_DYNELLIP].cDimension, "nd");
options[OPT_DYNELLIP].dDefault = 0.00328;
options[OPT_DYNELLIP].iType = 2;
options[OPT_DYNELLIP].bMultiFile = 1;
fnRead[OPT_DYNELLIP] = &ReadDynEllip;
sprintf(options[OPT_CALCDYNELLIP].cName, "bCalcDynEllip");
sprintf(options[OPT_CALCDYNELLIP].cDescr,
"Calculate dynamical ellipticity from RotRate");
sprintf(options[OPT_CALCDYNELLIP].cDefault, "0");
options[OPT_CALCDYNELLIP].dDefault = 0;
options[OPT_CALCDYNELLIP].iType = 0;
options[OPT_CALCDYNELLIP].bMultiFile = 1;
fnRead[OPT_CALCDYNELLIP] = &ReadCalcDynEllip;
sprintf(
options[OPT_CALCDYNELLIP].cLongDescr,
"In DistRot, set this to 1 to force the equilibrium shape (dynamical \n"
"ellipticity) to be calculated based on the current rotation rate and "
"\n"
"hydrostatic equilibrium. Note that once the planet's rotation period "
"\n"
"exceeds 13 days, then the dynamical ellipticity will be held fixed \n"
"to match Venus' value. This calculation does not include tides. "
"Setting \n"
"this to 1 overrides %s.",
options[OPT_DYNELLIP].cName // XXX Check this!
);
sprintf(options[OPT_FORCEPRECRATE].cName, "bForcePrecRate");
sprintf(options[OPT_FORCEPRECRATE].cDescr,
"Set the axial precession to a fixed rate?");
sprintf(options[OPT_FORCEPRECRATE].cDefault, "0");
options[OPT_FORCEPRECRATE].dDefault = 0;
options[OPT_FORCEPRECRATE].iType = 0;
options[OPT_FORCEPRECRATE].bMultiFile = 1;
fnRead[OPT_FORCEPRECRATE] = &ReadForcePrecRate;
sprintf(options[OPT_FORCEPRECRATE].cLongDescr,
"In DisRot, set the axial precession rate to a fixed value. This "
"option \n"
"can mimic the forcing of a natural satellite, or be used for "
"testing.");
sprintf(options[OPT_PRECRATE].cName, "dPrecRate");
sprintf(options[OPT_PRECRATE].cDescr,
"Fixed rate of axial precession (angle/s)");
sprintf(options[OPT_PRECRATE].cDefault, "7.7261e-12");
sprintf(options[OPT_PRECRATE].cDimension, "angle/time");
options[OPT_PRECRATE].dDefault = 7.7261e-12;
options[OPT_PRECRATE].iType = 2;
options[OPT_PRECRATE].bMultiFile = 1;
fnRead[OPT_PRECRATE] = &ReadPrecRate;
sprintf(options[OPT_READORBITDATA].cLongDescr,
"Value of the body's axial precession frequency if %s is set to 1.\n"
"Default value is the modern Earth's value as driven by the Moon.",
options[OPT_FORCEPRECRATE].cName);
sprintf(options[OPT_SPECMOMINERTIA].cName, "dSpecMomInertia");
sprintf(options[OPT_SPECMOMINERTIA].cDescr,
"Specific moment of inertia of polar axis");
sprintf(options[OPT_SPECMOMINERTIA].cDefault, "0.33");
sprintf(options[OPT_SPECMOMINERTIA].cDimension, "nd");
options[OPT_SPECMOMINERTIA].dDefault = 0.33;
options[OPT_SPECMOMINERTIA].iType = 2;
options[OPT_SPECMOMINERTIA].bMultiFile = 1;
fnRead[OPT_SPECMOMINERTIA] = &ReadSpecMomInertia;
sprintf(options[OPT_FILEORBITDATA].cName, "sFileOrbitData");
// Define OPT_READORBITDATA so it can be used in the long help
sprintf(options[OPT_READORBITDATA].cName, "bReadOrbitData");
sprintf(options[OPT_FILEORBITDATA].cDescr,
"Name of file containing orbit time series");
sprintf(options[OPT_FILEORBITDATA].cDefault, "orbit.txt");
options[OPT_FILEORBITDATA].iType = 3;
fnRead[OPT_FILEORBITDATA] = &ReadFileOrbitData;
sprintf(
options[OPT_FILEORBITDATA].cLongDescr,
"File containing pre-computed orbital data. The file must have the \n"
"following format: Time SemiMajorAxis Eccentricity Inclination \n"
"ArgPericenter LongAscNode MeanAnomaly. The units of those \n"
"parameters is assumed to be the same as body being simulated. When \n"
"using this option, the integration must used a fixed timestep \n"
"(%s = 0), and the timestep (%s) must equal the cadence in the file, \n"
"with time units in the %s file assumed to be the same as for the \n"
"body file. See %s for more information.",
options[OPT_VARDT].cName, options[OPT_TIMESTEP].cName,
options[OPT_FILEORBITDATA].cName, options[OPT_READORBITDATA].cName);
// cName defined above
sprintf(options[OPT_READORBITDATA].cDescr,
"Read in orbital data for use with distrot?");
sprintf(options[OPT_READORBITDATA].cDefault, "0");
options[OPT_READORBITDATA].dDefault = 0;
options[OPT_READORBITDATA].iType = 0;
options[OPT_READORBITDATA].bMultiFile = 1;
fnRead[OPT_READORBITDATA] = &ReadOrbitData;
sprintf(options[OPT_READORBITDATA].cLongDescr,
"Rather than calculate orbital evolution with DistOrb or SpiNBody, "
"users \n"
"may read in a previously run simulation. See %s for more \n"
"information.",
options[OPT_FILEORBITDATA].cName);
}
void ReadOptionsDistRot(BODY *body, CONTROL *control, FILES *files,
OPTIONS *options, SYSTEM *system, fnReadOption fnRead[],
int iBody) {
int iOpt;
for (iOpt = OPTSTARTDISTROT; iOpt < OPTENDDISTROT; iOpt++) {
if (options[iOpt].iType != -1) {
fnRead[iOpt](body, control, files, &options[iOpt], system, iBody + 1);
}
}
}
/******************* Verify DISTROT ******************/
/* In the following, iBody is the current body number that is getting assigned,
iPert counts the number of bodies perturbing iBody, and iBodyPert is the
body number of the current perturbing body. */
/* The indexing gets REEAAALLY confusing here. iPert = 0 to iGravPerts-1
correspond to all perturbing planets, iPert = iGravPerts corresponds to the
stellar torque, and
iPert = iGravPerts+1 to the stellar general relativistic correction, if
applied */
void InitializeXoblDistRot(BODY *body, UPDATE *update, int iBody, int iPert) {
update[iBody]
.iaType[update[iBody].iXobl][update[iBody].iaXoblDistRot[iPert]] = 2;
update[iBody].padDXoblDtDistRot[iPert] =
&update[iBody].daDerivProc[update[iBody].iXobl]
[update[iBody].iaXoblDistRot[iPert]];
update[iBody]
.iNumBodies[update[iBody].iXobl][update[iBody].iaXoblDistRot[iPert]] =
2;
update[iBody]
.iaBody[update[iBody].iXobl][update[iBody].iaXoblDistRot[iPert]] =
malloc(update[iBody].iNumBodies[update[iBody].iXobl]
[update[iBody].iaXoblDistRot[iPert]] *
sizeof(int));
update[iBody]
.iaBody[update[iBody].iXobl][update[iBody].iaXoblDistRot[iPert]][0] =
iBody;
update[iBody]
.iaBody[update[iBody].iXobl][update[iBody].iaXoblDistRot[iPert]][1] =
body[iBody].iaGravPerts[iPert];
}
void InitializeYoblDistRot(BODY *body, UPDATE *update, int iBody, int iPert) {
update[iBody]
.iaType[update[iBody].iYobl][update[iBody].iaYoblDistRot[iPert]] = 2;
update[iBody].padDYoblDtDistRot[iPert] =
&update[iBody].daDerivProc[update[iBody].iYobl]
[update[iBody].iaYoblDistRot[iPert]];
update[iBody]
.iNumBodies[update[iBody].iYobl][update[iBody].iaYoblDistRot[iPert]] =
2;
update[iBody]
.iaBody[update[iBody].iYobl][update[iBody].iaYoblDistRot[iPert]] =
malloc(update[iBody].iNumBodies[update[iBody].iYobl]
[update[iBody].iaYoblDistRot[iPert]] *
sizeof(int));
update[iBody]
.iaBody[update[iBody].iYobl][update[iBody].iaYoblDistRot[iPert]][0] =
iBody;
update[iBody]
.iaBody[update[iBody].iYobl][update[iBody].iaYoblDistRot[iPert]][1] =
body[iBody].iaGravPerts[iPert];
}
void InitializeZoblDistRot(BODY *body, UPDATE *update, int iBody, int iPert) {
update[iBody]
.iaType[update[iBody].iZobl][update[iBody].iaZoblDistRot[iPert]] = 2;
update[iBody].padDZoblDtDistRot[iPert] =
&update[iBody].daDerivProc[update[iBody].iZobl]
[update[iBody].iaZoblDistRot[iPert]];
update[iBody]
.iNumBodies[update[iBody].iZobl][update[iBody].iaZoblDistRot[iPert]] =
2;
update[iBody]
.iaBody[update[iBody].iZobl][update[iBody].iaZoblDistRot[iPert]] =
malloc(update[iBody].iNumBodies[update[iBody].iZobl]
[update[iBody].iaZoblDistRot[iPert]] *
sizeof(int));
update[iBody]
.iaBody[update[iBody].iZobl][update[iBody].iaZoblDistRot[iPert]][0] =
iBody;
update[iBody]
.iaBody[update[iBody].iZobl][update[iBody].iaZoblDistRot[iPert]][1] =
body[iBody].iaGravPerts[iPert];
}
void InitializeXoblDistRotStar(BODY *body, UPDATE *update, int iBody,
int iPert) {
update[iBody]
.iaType[update[iBody].iXobl][update[iBody].iaXoblDistRot[iPert]] = 2;
update[iBody].padDXoblDtDistRot[iPert] =
&update[iBody].daDerivProc[update[iBody].iXobl]
[update[iBody].iaXoblDistRot[iPert]];
update[iBody]
.iNumBodies[update[iBody].iXobl][update[iBody].iaXoblDistRot[iPert]] =
2;
update[iBody]
.iaBody[update[iBody].iXobl][update[iBody].iaXoblDistRot[iPert]] =
malloc(update[iBody].iNumBodies[update[iBody].iXobl]
[update[iBody].iaXoblDistRot[iPert]] *
sizeof(int));
update[iBody]
.iaBody[update[iBody].iXobl][update[iBody].iaXoblDistRot[iPert]][0] =
iBody;
update[iBody]
.iaBody[update[iBody].iXobl][update[iBody].iaXoblDistRot[iPert]][1] = 0;
}
void InitializeYoblDistRotStar(BODY *body, UPDATE *update, int iBody,
int iPert) {
update[iBody]
.iaType[update[iBody].iYobl][update[iBody].iaYoblDistRot[iPert]] = 2;
update[iBody].padDYoblDtDistRot[iPert] =
&update[iBody].daDerivProc[update[iBody].iYobl]
[update[iBody].iaYoblDistRot[iPert]];
update[iBody]
.iNumBodies[update[iBody].iYobl][update[iBody].iaYoblDistRot[iPert]] =
2;
update[iBody]
.iaBody[update[iBody].iYobl][update[iBody].iaYoblDistRot[iPert]] =
malloc(update[iBody].iNumBodies[update[iBody].iYobl]
[update[iBody].iaYoblDistRot[iPert]] *
sizeof(int));
update[iBody]
.iaBody[update[iBody].iYobl][update[iBody].iaYoblDistRot[iPert]][0] =
iBody;
update[iBody]
.iaBody[update[iBody].iYobl][update[iBody].iaYoblDistRot[iPert]][1] = 0;
}
void VerifyOrbitData(BODY *body, CONTROL *control, OPTIONS *options,
int iBody) {
int iNLines, iLine, c, iNumColsFound, bFoo, iNumCols = 7;
double dttmp, datmp, detmp, ditmp, daptmp, dlatmp, dmatmp;
FILE *fileorb;
char cLine[LINE], cFoo[MAXARRAY][OPTLEN];
if (body[iBody].bReadOrbitData) {
if (options[OPT_FILEORBITDATA].iLine[iBody + 1] == -1) {
fprintf(stderr, "ERROR: Must set %s if using %s for file %s\n",
options[OPT_FILEORBITDATA].cName,
options[OPT_READORBITDATA].cName, body[iBody].cName);
exit(EXIT_INPUT);
} else {
fileorb = fopen(body[iBody].cFileOrbitData, "r");
if (fileorb == NULL) {
printf("ERROR: File %s not found.\n", body[iBody].cFileOrbitData);
exit(EXIT_INPUT);
}
// Check file has exactly 7 columns
if (fgets(cLine, LINE, fileorb) == NULL) {
fprintf(stderr,"ERROR: Unable to read line from orbit data file.");
exit(EXIT_INPUT);
}
GetWords(cLine, cFoo, &iNumColsFound, &bFoo);
if (iNumCols != iNumColsFound) {
if (control->Io.iVerbose >= VERBERR) {
fprintf(stderr,
"ERROR: Incorrect number of columns (%d) in %s file %s. "
"Must be exactly %d.\n",
iNumColsFound, options[OPT_READORBITDATA].cName,
body[iBody].cFileOrbitData, iNumCols);
}
exit(EXIT_INPUT);
}
iNLines = 1;
while ((c = getc(fileorb)) != EOF) {
if (c == '\n') {
iNLines++; // add 1 for each new line
}
}
rewind(fileorb);
body[iBody].iNLines = iNLines;
body[iBody].daTimeSeries = malloc(iNLines * sizeof(double));
body[iBody].daSemiSeries = malloc(iNLines * sizeof(double));
body[iBody].daEccSeries = malloc(iNLines * sizeof(double));
body[iBody].daIncSeries = malloc(iNLines * sizeof(double));
body[iBody].daArgPSeries = malloc(iNLines * sizeof(double));
body[iBody].daLongASeries = malloc(iNLines * sizeof(double));
body[iBody].daMeanASeries = malloc(iNLines * sizeof(double));
body[iBody].daHeccSeries = malloc(iNLines * sizeof(double));
body[iBody].daKeccSeries = malloc(iNLines * sizeof(double));
body[iBody].daPincSeries = malloc(iNLines * sizeof(double));
body[iBody].daQincSeries = malloc(iNLines * sizeof(double));
iLine = 0;
while (feof(fileorb) == 0) {
if (fscanf(fileorb, "%lf %lf %lf %lf %lf %lf %lf\n", &dttmp, &datmp, &detmp,
&ditmp, &daptmp, &dlatmp, &dmatmp) != 7) {
fprintf(stderr,"ERROR: Incorrect number of columns in orbit file.");
exit(EXIT_INPUT);
}
body[iBody].daTimeSeries[iLine] =
dttmp * fdUnitsTime(control->Units[iBody + 1].iTime);
body[iBody].daSemiSeries[iLine] =
datmp * fdUnitsLength(control->Units[iBody + 1].iLength);
body[iBody].daEccSeries[iLine] = detmp;
if (control->Units[iBody + 1].iAngle == 0) {
body[iBody].daIncSeries[iLine] = ditmp;
body[iBody].daArgPSeries[iLine] = daptmp;
body[iBody].daLongASeries[iLine] = dlatmp;
body[iBody].daMeanASeries[iLine] = dmatmp;
} else {
body[iBody].daIncSeries[iLine] = ditmp * DEGRAD;
body[iBody].daArgPSeries[iLine] = daptmp * DEGRAD;
body[iBody].daLongASeries[iLine] = dlatmp * DEGRAD;
body[iBody].daMeanASeries[iLine] = dmatmp * DEGRAD;
}
body[iBody].daHeccSeries[iLine] = body[iBody].daEccSeries[iLine] *
sin(body[iBody].daArgPSeries[iLine] +
body[iBody].daLongASeries[iLine]);
body[iBody].daKeccSeries[iLine] = body[iBody].daEccSeries[iLine] *
cos(body[iBody].daArgPSeries[iLine] +
body[iBody].daLongASeries[iLine]);
body[iBody].daPincSeries[iLine] =
sin(0.5 * body[iBody].daIncSeries[iLine]) *
sin(body[iBody].daLongASeries[iLine]);
body[iBody].daQincSeries[iLine] =
sin(0.5 * body[iBody].daIncSeries[iLine]) *
cos(body[iBody].daLongASeries[iLine]);
iLine++;
}
fclose(fileorb);
}
body[iBody].iCurrentStep = 0;
if (control->Evolve.bVarDt) {
fprintf(stderr,
"ERROR: Cannot use variable time step (%s = 1) if %s = 1\n",
options[OPT_VARDT].cName, options[OPT_READORBITDATA].cName);
exit(EXIT_INPUT);
}
if (control->Evolve.bDoForward) {
if (body[iBody].daTimeSeries[1] != control->Evolve.dTimeStep) {
fprintf(stderr,
"ERROR: Time step size (%s = %lf) must match orbital data "
"output time "
"(%lf) if %s = 1\n",
options[OPT_TIMESTEP].cName, control->Evolve.dTimeStep,
body[iBody].daTimeSeries[1], options[OPT_READORBITDATA].cName);
exit(EXIT_INPUT);
}
} else if (control->Evolve.bDoBackward) {
if (body[iBody].daTimeSeries[1] != -1 * control->Evolve.dTimeStep) {
fprintf(stderr,
"ERROR: Time step size (%s = %lf) must match orbital data "
"output time "
"(%lf) if %s = 1\n",
options[OPT_TIMESTEP].cName, control->Evolve.dTimeStep,
body[iBody].daTimeSeries[1], options[OPT_READORBITDATA].cName);
exit(EXIT_INPUT);
}
}
if (iNLines < (control->Evolve.dStopTime / control->Evolve.dTimeStep + 1)) {
fprintf(stderr,
"ERROR: Final time in %s is less than %s; simulation cannot be "
"completed.\n",
options[OPT_FILEORBITDATA].cName, options[OPT_STOPTIME].cName);
exit(EXIT_INPUT); // Should really be a DoubleLineExit
}
}
}
void AssignDistRotDerivatives(BODY *body, EVOLVE *evolve, UPDATE *update,
fnUpdateVariable ***fnUpdate, int iBody) {
int i, j = 0, iPert = 0, jBody = 0;
/* The indexing gets REEAAALLY confusing here. iPert = 0 to iGravPerts-1
* correspond to all perturbing planets, iPert = iGravPerts corresponds to the
* stellar torque, and iPert = iGravPerts+1 to the stellar general
* relativistic correction, if applied */
if (iBody >= 1) {
if (body[iBody].bReadOrbitData) {
fnUpdate[iBody][update[iBody].iXobl][update[iBody].iaXoblDistRot[0]] =
&fndDistRotExtDxDt;
fnUpdate[iBody][update[iBody].iYobl][update[iBody].iaYoblDistRot[0]] =
&fndDistRotExtDyDt;
fnUpdate[iBody][update[iBody].iZobl][update[iBody].iaZoblDistRot[0]] =
&fndDistRotExtDzDt;
} else {
if (evolve->iDistOrbModel == RD4) {
/* Body updates */
for (iPert = 0; iPert < body[iBody].iGravPerts; iPert++) {
/* x = sin(obl)*cos(pA) */
fnUpdate[iBody][update[iBody].iXobl]
[update[iBody].iaXoblDistRot[iPert]] = &fndDistRotRD4DxDt;
/* y = sin(obl)*sin(pA) */
fnUpdate[iBody][update[iBody].iYobl]
[update[iBody].iaYoblDistRot[iPert]] = &fndDistRotRD4DyDt;
/* z = cos(obl) */
fnUpdate[iBody][update[iBody].iZobl]
[update[iBody].iaZoblDistRot[iPert]] = &fndDistRotRD4DzDt;
}
/* Body updates for stellar torque, treating star as "perturber" (only
* needed for x and y -> pA) */
/* x = sin(obl)*cos(pA) */
fnUpdate[iBody][update[iBody].iXobl]
[update[iBody].iaXoblDistRot[body[iBody].iGravPerts]] =
&fndDistRotRD4DxDt;
/* y = sin(obl)*sin(pA) */
fnUpdate[iBody][update[iBody].iYobl]
[update[iBody].iaYoblDistRot[body[iBody].iGravPerts]] =
&fndDistRotRD4DyDt;
} else if (evolve->iDistOrbModel == LL2) {
/* Body updates */
for (iPert = 0; iPert < body[iBody].iGravPerts; iPert++) {
/* x = sin(obl)*cos(pA) */
fnUpdate[iBody][update[iBody].iXobl]
[update[iBody].iaXoblDistRot[iPert]] = &fndDistRotLL2DxDt;
/* y = sin(obl)*sin(pA) */
fnUpdate[iBody][update[iBody].iYobl]
[update[iBody].iaYoblDistRot[iPert]] = &fndDistRotLL2DyDt;
/* z = cos(obl) */
fnUpdate[iBody][update[iBody].iZobl]
[update[iBody].iaZoblDistRot[iPert]] = &fndDistRotLL2DzDt;
}
/* Body updates for stellar torque, treating star as "perturber" (only
* needed for x and y -> pA) */
/* x = sin(obl)*cos(pA) */
fnUpdate[iBody][update[iBody].iXobl]
[update[iBody].iaXoblDistRot[body[iBody].iGravPerts]] =
&fndDistRotLL2DxDt;
/* y = sin(obl)*sin(pA) */
fnUpdate[iBody][update[iBody].iYobl]
[update[iBody].iaYoblDistRot[body[iBody].iGravPerts]] =
&fndDistRotLL2DyDt;
}
}
if (body[iBody].bGRCorr) {
fnUpdate[iBody][update[iBody].iXobl]
[update[iBody].iaXoblDistRot[body[iBody].iGravPerts + 1]] =
&fndAxialGRDxDt;
fnUpdate[iBody][update[iBody].iYobl]
[update[iBody].iaYoblDistRot[body[iBody].iGravPerts + 1]] =
&fndAxialGRDyDt;
}
}
}
void NullDistRotDerivatives(BODY *body, EVOLVE *evolve, UPDATE *update,
fnUpdateVariable ***fnUpdate, int iBody) {
int i, j = 0, iPert = 0, jBody = 0;
/* The indexing gets REEAAALLY confusing here. iPert = 0 to iGravPerts-1
* correspond to all perturbing planets, iPert = iGravPerts corresponds to the
* stellar torque, and iPert = iGravPerts+1 to the stellar general
* relativistic correction, if applied */
if (iBody >= 1) {
if (body[iBody].bReadOrbitData) {
fnUpdate[iBody][update[iBody].iXobl][update[iBody].iaXoblDistRot[0]] =
&fndUpdateFunctionTiny;
fnUpdate[iBody][update[iBody].iYobl][update[iBody].iaYoblDistRot[0]] =
&fndUpdateFunctionTiny;
fnUpdate[iBody][update[iBody].iZobl][update[iBody].iaZoblDistRot[0]] =
&fndUpdateFunctionTiny;
} else {
if (evolve->iDistOrbModel == RD4) {
/* Body updates */
for (iPert = 0; iPert < body[iBody].iGravPerts; iPert++) {
/* x = sin(obl)*cos(pA) */
fnUpdate[iBody][update[iBody].iXobl]
[update[iBody].iaXoblDistRot[iPert]] = &fndUpdateFunctionTiny;
/* y = sin(obl)*sin(pA) */
fnUpdate[iBody][update[iBody].iYobl]
[update[iBody].iaYoblDistRot[iPert]] = &fndUpdateFunctionTiny;
/* z = cos(obl) */
fnUpdate[iBody][update[iBody].iZobl]
[update[iBody].iaZoblDistRot[iPert]] = &fndUpdateFunctionTiny;
}
/* Body updates for stellar torque, treating star as "perturber" (only
* needed for x and y -> pA) */
/* x = sin(obl)*cos(pA) */
fnUpdate[iBody][update[iBody].iXobl]
[update[iBody].iaXoblDistRot[body[iBody].iGravPerts]] =
&fndUpdateFunctionTiny;
/* y = sin(obl)*sin(pA) */
fnUpdate[iBody][update[iBody].iYobl]
[update[iBody].iaYoblDistRot[body[iBody].iGravPerts]] =
&fndUpdateFunctionTiny;
} else if (evolve->iDistOrbModel == LL2) {
/* Body updates */
for (iPert = 0; iPert < body[iBody].iGravPerts; iPert++) {
/* x = sin(obl)*cos(pA) */
fnUpdate[iBody][update[iBody].iXobl]
[update[iBody].iaXoblDistRot[iPert]] = &fndUpdateFunctionTiny;
/* y = sin(obl)*sin(pA) */
fnUpdate[iBody][update[iBody].iYobl]
[update[iBody].iaYoblDistRot[iPert]] = &fndUpdateFunctionTiny;
/* z = cos(obl) */
fnUpdate[iBody][update[iBody].iZobl]
[update[iBody].iaZoblDistRot[iPert]] = &fndUpdateFunctionTiny;
}
/* Body updates for stellar torque, treating star as "perturber" (only
* needed for x and y -> pA) */
/* x = sin(obl)*cos(pA) */
fnUpdate[iBody][update[iBody].iXobl]
[update[iBody].iaXoblDistRot[body[iBody].iGravPerts]] =
&fndUpdateFunctionTiny;
/* y = sin(obl)*sin(pA) */
fnUpdate[iBody][update[iBody].iYobl]
[update[iBody].iaYoblDistRot[body[iBody].iGravPerts]] =
&fndUpdateFunctionTiny;
}
}
if (body[iBody].bGRCorr) {
fnUpdate[iBody][update[iBody].iXobl]
[update[iBody].iaXoblDistRot[body[iBody].iGravPerts + 1]] =
&fndUpdateFunctionTiny;
fnUpdate[iBody][update[iBody].iYobl]
[update[iBody].iaYoblDistRot[body[iBody].iGravPerts + 1]] =
&fndUpdateFunctionTiny;
}
}
}
void VerifyDistRot(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
OUTPUT *output, SYSTEM *system, UPDATE *update, int iBody,
int iModule) {
int i, j = 0, iPert = 0, jBody = 0;
VerifyOrbitData(body, control, options, iBody);
/* The indexing gets REEAAALLY confusing here. iPert = 0 to iGravPerts-1
* correspond to all perturbing planets, iPert = iGravPerts corresponds to the
* stellar torque, and iPert = iGravPerts+1 to the stellar general
* relativistic correction, if applied */
if (iBody >= 1) {
control->fnPropsAux[iBody][iModule] = &PropsAuxDistRot;
VerifyDynEllip(body, control, options, files->Infile[iBody + 1].cIn, iBody,
control->Io.iVerbose);
if (body[iBody].bReadOrbitData) {
if (control->Io.iVerbose >= VERBINPUT) {
fprintf(
stderr,
"INFO: When reading in using %s to calculate "
"rotational evolution, Cassini parameters may not be correct.\n",
options[OPT_READORBITDATA].cName);
}
system->daLOrb = malloc(3 * sizeof(double));
body[iBody].daLOrb = malloc(3 * sizeof(double));
body[iBody].daLOrbTmp = malloc(3 * sizeof(double));
}
CalcXYZobl(body, iBody);
body[iBody].daLRot = malloc(3 * sizeof(double));
body[iBody].daLRotTmp = malloc(3 * sizeof(double));
if (body[iBody].bReadOrbitData) {
InitializeXoblDistRot(body, update, iBody, 0);
InitializeYoblDistRot(body, update, iBody, 0);
InitializeZoblDistRot(body, update, iBody, 0);
} else {
if (control->Evolve.iDistOrbModel == RD4) {
/* Body updates */
for (iPert = 0; iPert < body[iBody].iGravPerts; iPert++) {
/* x = sin(obl)*cos(pA) */
InitializeXoblDistRot(body, update, iBody, iPert);
/* y = sin(obl)*sin(pA) */
InitializeYoblDistRot(body, update, iBody, iPert);
/* z = cos(obl) */
InitializeZoblDistRot(body, update, iBody, iPert);
}
/* Body updates for stellar torque, treating star as "perturber" (only
* needed for x and y -> pA) */
/* x = sin(obl)*cos(pA) */
InitializeXoblDistRotStar(body, update, iBody, body[iBody].iGravPerts);
/* y = sin(obl)*sin(pA) */
InitializeYoblDistRotStar(body, update, iBody, body[iBody].iGravPerts);
} else if (control->Evolve.iDistOrbModel == LL2) {
/* Body updates */
for (iPert = 0; iPert < body[iBody].iGravPerts; iPert++) {
/* x = sin(obl)*cos(pA) */
InitializeXoblDistRot(body, update, iBody, iPert);
/* y = sin(obl)*sin(pA) */
InitializeYoblDistRot(body, update, iBody, iPert);
/* z = cos(obl) */
InitializeZoblDistRot(body, update, iBody, iPert);
}
/* Body updates for stellar torque, treating star as "perturber" (only
* needed for x and y -> pA) */
/* x = sin(obl)*cos(pA) */
InitializeXoblDistRotStar(body, update, iBody, body[iBody].iGravPerts);
/* y = sin(obl)*sin(pA) */
InitializeYoblDistRotStar(body, update, iBody, body[iBody].iGravPerts);
}
}
if (body[iBody].bGRCorr) {
InitializeXoblDistRotStar(body, update, iBody,
body[iBody].iGravPerts + 1);
InitializeYoblDistRotStar(body, update, iBody,
body[iBody].iGravPerts + 1);
}
}
control->fnForceBehavior[iBody][iModule] = &ForceBehaviorDistRot;
control->Evolve.fnBodyCopy[iBody][iModule] = &BodyCopyDistRot;
}
/***************** DISTROT Update *****************/
void InitializeUpdateDistRot(BODY *body, UPDATE *update, int iBody) {
if (iBody > 0) {
if (body[iBody].bReadOrbitData) {
body[iBody].iGravPerts = 0;
body[iBody].iaGravPerts = malloc(1 * sizeof(int));
body[iBody].iaGravPerts[0] = 0;
}
if (update[iBody].iNumXobl == 0) {
update[iBody].iNumVars++;
}
update[iBody].iNumXobl += body[iBody].iGravPerts + 1;
if (update[iBody].iNumYobl == 0) {
update[iBody].iNumVars++;
}
update[iBody].iNumYobl += body[iBody].iGravPerts + 1;
if (update[iBody].iNumZobl == 0) {
update[iBody].iNumVars++;
}
update[iBody].iNumZobl += body[iBody].iGravPerts;
if (body[iBody].bGRCorr) {
update[iBody].iNumXobl += 1;
update[iBody].iNumYobl += 1;
}
if (body[iBody].bReadOrbitData) {
update[iBody].iNumZobl += 1;
}
}
}
void FinalizeUpdateXoblDistRot(BODY *body, UPDATE *update, int *iEqn, int iVar,
int iBody, int iFoo) {
int iPert;
/* The indexing gets REEAAALLY confusing here. iPert = 0 to iGravPerts-1
* correspond to all perturbing planets, iPert = iGravPerts corresponds to the
* stellar torque, and iPert = iGravPerts+1 to the stellar general
* relativistic correction, if applied */
if (body[iBody].bGRCorr) {
update[iBody].padDXoblDtDistRot =
malloc((body[iBody].iGravPerts + 2) * sizeof(double *));
update[iBody].iaXoblDistRot =
malloc((body[iBody].iGravPerts + 2) * sizeof(int));
for (iPert = 0; iPert < body[iBody].iGravPerts + 2; iPert++) {
update[iBody].iaModule[iVar][*iEqn] = DISTROT;
update[iBody].iaXoblDistRot[iPert] = (*iEqn)++;
}
} else {
update[iBody].padDXoblDtDistRot =
malloc((body[iBody].iGravPerts + 1) * sizeof(double *));
update[iBody].iaXoblDistRot =
malloc((body[iBody].iGravPerts + 1) * sizeof(int));
for (iPert = 0; iPert < body[iBody].iGravPerts + 1; iPert++) {
update[iBody].iaModule[iVar][*iEqn] = DISTROT;
update[iBody].iaXoblDistRot[iPert] = (*iEqn)++;
}
}
}
void FinalizeUpdateYoblDistRot(BODY *body, UPDATE *update, int *iEqn, int iVar,
int iBody, int iFoo) {
int iPert;
/* The indexing gets REEAAALLY confusing here. iPert = 0 to iGravPerts-1
* correspond to all perturbing planets, iPert = iGravPerts corresponds to the
* stellar torque, and iPert = iGravPerts+1 to the stellar general
* relativistic correction, if applied */
if (body[iBody].bGRCorr) {
update[iBody].padDYoblDtDistRot =
malloc((body[iBody].iGravPerts + 2) * sizeof(double *));
update[iBody].iaYoblDistRot =
malloc((body[iBody].iGravPerts + 2) * sizeof(int));
for (iPert = 0; iPert < body[iBody].iGravPerts + 2; iPert++) {
update[iBody].iaModule[iVar][*iEqn] = DISTROT;
update[iBody].iaYoblDistRot[iPert] = (*iEqn)++;
}
} else {
update[iBody].padDYoblDtDistRot =
malloc((body[iBody].iGravPerts + 1) * sizeof(double *));
update[iBody].iaYoblDistRot =
malloc((body[iBody].iGravPerts + 1) * sizeof(int));
for (iPert = 0; iPert < body[iBody].iGravPerts + 1; iPert++) {
update[iBody].iaModule[iVar][*iEqn] = DISTROT;
update[iBody].iaYoblDistRot[iPert] = (*iEqn)++;
}
}
}
void FinalizeUpdateZoblDistRot(BODY *body, UPDATE *update, int *iEqn, int iVar,
int iBody, int iFoo) {
int iPert;
update[iBody].padDZoblDtDistRot =
malloc((body[iBody].iGravPerts) * sizeof(double *));
update[iBody].iaZoblDistRot = malloc((body[iBody].iGravPerts) * sizeof(int));
for (iPert = 0; iPert < body[iBody].iGravPerts; iPert++) {
update[iBody].iaModule[iVar][*iEqn] = DISTROT;
update[iBody].iaZoblDistRot[iPert] = (*iEqn)++;
}
}
/***************** DISTROT Halts *****************/
void CountHaltsDistRot(HALT *halt, int *iNumHalts) {
}
void VerifyHaltDistRot(BODY *body, CONTROL *control, OPTIONS *options,
int iBody, int *iHalt) {
}
/************* DISTROT Outputs ******************/
void WriteBodyDOblDtDistRot(BODY *body, CONTROL *control, OUTPUT *output,
SYSTEM *system, UNITS *units, UPDATE *update,
int iBody, double *dTmp, char cUnit[]) {
double dDeriv, dObldx, dObldy, dObldz;
int iPert;
if ((body[iBody].dXobl * body[iBody].dXobl +
body[iBody].dYobl * body[iBody].dYobl) > 0) {
dObldx = body[iBody].dXobl * body[iBody].dZobl /
(sqrt(body[iBody].dXobl * body[iBody].dXobl +
body[iBody].dYobl * body[iBody].dYobl) *
(body[iBody].dXobl * body[iBody].dXobl +
body[iBody].dYobl * body[iBody].dYobl +
body[iBody].dZobl * body[iBody].dZobl));
dObldy = body[iBody].dYobl * body[iBody].dZobl /
(sqrt(body[iBody].dXobl * body[iBody].dXobl +
body[iBody].dYobl * body[iBody].dYobl) *
(body[iBody].dXobl * body[iBody].dXobl +
body[iBody].dYobl * body[iBody].dYobl +
body[iBody].dZobl * body[iBody].dZobl));
} else {
dObldx = 0.0;
dObldy = 0.0;
}
dObldz = -sqrt(body[iBody].dXobl * body[iBody].dXobl +
body[iBody].dYobl * body[iBody].dYobl) /
(body[iBody].dXobl * body[iBody].dXobl +
body[iBody].dYobl * body[iBody].dYobl +
body[iBody].dZobl * body[iBody].dZobl);
/* Ensure that we don't overwrite derivative */
dDeriv = 0;
for (iPert = 0; iPert < body[iBody].iGravPerts; iPert++) {
dDeriv += dObldx * (*(update[iBody].padDXoblDtDistRot[iPert])) +
dObldy * (*(update[iBody].padDYoblDtDistRot[iPert])) +
dObldz * (*(update[iBody].padDZoblDtDistRot[iPert]));
}
*dTmp = dDeriv;
if (output->bDoNeg[iBody]) {
*dTmp *= output->dNeg;
strcpy(cUnit, output->cNeg);
} else {
*dTmp *= fdUnitsTime(units->iTime);
fsUnitsRate(units->iTime, cUnit);
*dTmp /= fdUnitsAngle(units->iAngle);
fsUnitsAngle(units->iAngle, cUnit);
}
}
void WriteOblTimeDistRot(BODY *body, CONTROL *control, OUTPUT *output,
SYSTEM *system, UNITS *units, UPDATE *update,
int iBody, double *dTmp, char cUnit[]) {
double dDeriv, dObldx, dObldy, dObldz;
int iPert;
if ((body[iBody].dXobl * body[iBody].dXobl +
body[iBody].dYobl * body[iBody].dYobl) > 0) {
dObldx = body[iBody].dXobl * body[iBody].dZobl /
(sqrt(body[iBody].dXobl * body[iBody].dXobl +
body[iBody].dYobl * body[iBody].dYobl) *
(body[iBody].dXobl * body[iBody].dXobl +
body[iBody].dYobl * body[iBody].dYobl +
body[iBody].dZobl * body[iBody].dZobl));
dObldy = body[iBody].dYobl * body[iBody].dZobl /
(sqrt(body[iBody].dXobl * body[iBody].dXobl +
body[iBody].dYobl * body[iBody].dYobl) *