forked from VirtualPlanetaryLaboratory/vplanet
-
Notifications
You must be signed in to change notification settings - Fork 2
/
verify.c
1192 lines (1041 loc) · 42.8 KB
/
verify.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 verify.c
@brief Validate the options. This will become a mess!
@author Rory Barnes ([RoryBarnes](https://github.com/RoryBarnes/))
@date May 7 2014
*/
#include "vplanet.h"
/*
* Utility functions
*/
/*! Check to see if two decimals numbers are equal (1) or not (0) */
int bFloatComparison(double x, double y) {
double dBigger;
double dRel_Tol;
if (fabs(x) > fabs(y)) {
dBigger = fabs(x);
} else {
dBigger = fabs(y);
}
dRel_Tol = 5 * dBigger * DBL_EPSILON;
if (dRel_Tol <= 10 * dTINY) {
dRel_Tol = 10 * dTINY;
}
if (fabs(x - y) <= dRel_Tol) {
return 1;
} else {
return 0;
}
}
/*
* Exit Calls
*/
int bFileExists(const char *filename) {
FILE *file;
if ((file = fopen(filename, "r"))) {
fclose(file);
return 1;
}
return 0;
}
void OverwriteExit(char cName[], char cFile[]) {
fprintf(stderr, "ERROR: %s is false and %s exists.\n", cName, cFile);
fprintf(stderr, "\tOveride with \"-f\" on the command line.\n");
exit(EXIT_INPUT);
}
/* XXX Should these be iLine+1? */
void DoubleLineExit(char cFile1[], char cFile2[], int iLine1, int iLine2) {
fprintf(stderr, "\tFile: %s, Line: %d.\n", cFile1, iLine1 + 1);
fprintf(stderr, "\tFile: %s, Line: %d.\n", cFile2, iLine2 + 1);
exit(EXIT_INPUT);
}
void VerifyOrbitExit(char cName1[], char cName2[], char cFile1[], char cFile2[],
int iLine1, int iLine2, int iVerbose) {
if (iVerbose >= VERBERR) {
fprintf(stderr, "ERROR: Cannot set both %s and %s.\n", cName1, cName2);
fprintf(stderr, "\tFile: %s, Line: %d.\n", cFile1, iLine1);
fprintf(stderr, "\tFile: %s, Line: %d.\n", cFile2, iLine2);
}
exit(EXIT_INPUT);
}
void VerifyBodyExit(char cName1[], char cName2[], char cFile[], int iLine1,
int iLine2, int iVerbose) {
if (iVerbose >= VERBERR) {
fprintf(stderr, "ERROR: Cannot set both %s and %s in same file.\n", cName1,
cName2);
fprintf(stderr, "\tFile: %s, Lines: %d and %d\n", cFile, iLine1, iLine2);
}
exit(EXIT_INPUT);
}
/** Print three lines that are in conflict
Only called if iVerbose >= VERBERR
*/
void TripleLineExit(char cFile[], int iLine1, int iLine2, int iLine3) {
fprintf(stderr, "\tFile: %s, Lines: %d, %d and %d.\n", cFile, iLine1, iLine2,
iLine3);
exit(EXIT_INPUT);
}
/* Do we need both these? */
void VerifyTripleExit(char cName1[], char cName2[], char cName3[], int iLine1,
int iLine2, int iLine3, char cFile[], int iVerbose) {
if (iVerbose >= VERBERR) {
fprintf(stderr, "ERROR: Cannot set %s, %s, and %s simultaneously.\n",
cName1, cName2, cName3);
TripleLineExit(cFile, iLine1, iLine2, iLine3);
}
}
void VerifyTwoOfThreeExit(char cName1[], char cName2[], char cName3[],
int iLine1, int iLine2, int iLine3, char cFile[],
int iVerbose) {
if (iVerbose >= VERBERR) {
fprintf(stderr, "ERROR: Can only set 2 of %s, %s, and %s.\n", cName1,
cName2, cName3);
}
TripleLineExit(cFile, iLine1, iLine2, iLine3);
}
void VerifyDynEllip(BODY *body, CONTROL *control, OPTIONS *options,
char cFile[], int iBody, int iVerbose) {
if (body[iBody].bCalcDynEllip == 1) {
/* check if bCalcDynEllip and dDynEllip are both set */
if (options[OPT_DYNELLIP].iLine[iBody + 1] > -1) {
if (iVerbose >= VERBINPUT) {
fprintf(stderr,
"INFO: %s set in file %s, but %s set to 1. %s will be "
"overridden.\n",
options[OPT_DYNELLIP].cName, cFile,
options[OPT_CALCDYNELLIP].cName, options[OPT_DYNELLIP].cName);
}
}
body[iBody].dDynEllip = CalcDynEllipEq(body, iBody);
}
}
/**
Verify the user did not use the same name for two bodies.
*/
void VerifyNames(BODY *body, CONTROL *control, OPTIONS *options) {
int iBody, jBody;
for (iBody = 0; iBody < control->Evolve.iNumBodies; iBody++) {
if (strlen(body[iBody].cName) == 0) {
if (control->Io.iVerbose > VERBINPUT) {
fprintf(stderr, "INFO: No input to %s in file %s, defaulting to %d/\n",
options[OPT_BODYNAME].cName,
options[OPT_BODYNAME].cFile[iBody] + 1, iBody);
}
sprintf(body[iBody].cName, "%d", iBody + 1);
}
for (jBody = iBody + 1; jBody < control->Evolve.iNumBodies; jBody++) {
if (strcmp(body[iBody].cName, body[jBody].cName) == 0) {
if (control->Io.iVerbose >= VERBERR) {
fprintf(stderr, "ERROR: Two bodies have the same name.\n");
DoubleLineExit(options[OPT_BODYNAME].cFile[iBody + 1],
options[OPT_BODYNAME].cFile[jBody + 1],
options[OPT_BODYNAME].iLine[iBody + 1],
options[OPT_BODYNAME].iLine[jBody + 1]);
}
}
}
}
}
/*
*
* Verify Orbit
*
*/
void VerifyOrbit(BODY *body, CONTROL *control, FILES files, OPTIONS *options,
int iBody) {
int iFile = iBody + 1, iVerbose;
double dSemi = 0, dMeanMotion = 0, dPeriod = 0;
// Body 0 is never an orbiter
if (iBody == 0) {
return;
}
iVerbose = control->Io.iVerbose;
/* !!!!! ------ Semi IS ALWAYS CORRECT AND IN BODY[iBody] ------- !!!!!! */
if (options[OPT_ORBSEMI].iLine[iFile] > -1 &&
options[OPT_ORBMEANMOTION].iLine[iFile] == -1 &&
options[OPT_ORBPER].iLine[iFile] == -1) {
dSemi = body[iBody].dSemi;
}
if (options[OPT_ORBSEMI].iLine[iFile] == -1 &&
options[OPT_ORBMEANMOTION].iLine[iFile] > -1 &&
options[OPT_ORBPER].iLine[iFile] == -1) {
dMeanMotion = body[iBody].dMeanMotion;
}
if (options[OPT_ORBSEMI].iLine[iFile] == -1 &&
options[OPT_ORBMEANMOTION].iLine[iFile] == -1 &&
options[OPT_ORBPER].iLine[iFile] > -1) {
dPeriod = body[iBody].dOrbPeriod;
}
/* Was Semi set and nothing else? */
if (dSemi > 0 && dMeanMotion == 0 && dPeriod == 0) {
if (body[iBody].bPoise) {
if (body[iBody].bBinary == 0) { // Not binary, regular single-star orbit
body[iBody].dMeanMotion = fdSemiToMeanMotion(
body[iBody].dSemi, body[0].dMass + body[iBody].dMass);
} else if (body[iBody].bBinary &&
body[iBody].iBodyType ==
0) { // Set mean motion for CBP
// (primary,iBody==0;planet,iBody > 1)
body[iBody].dMeanMotion = fdSemiToMeanMotion(
body[iBody].dSemi,
body[0].dMass + body[1].dMass + body[iBody].dMass);
} else if (body[iBody].bBinary && body[iBody].iBodyType == 1 &&
iBody == 1) { // Set mean motion for binary, info in secondary
body[iBody].dMeanMotion = fdSemiToMeanMotion(
body[iBody].dSemi, body[0].dMass + body[iBody].dMass);
}
} else if (body[iBody].bPoise == 0) {
if (body[iBody].bBinary != 1) {
if (iBody > 0) // No binary, regular planet
{
body[iBody].dMeanMotion = fdSemiToMeanMotion(
body[iBody].dSemi, body[0].dMass + body[iBody].dMass);
}
} else // Doing binary
{
if (body[iBody].iBodyType == 0) // CBP
{
body[iBody].dMeanMotion = fdSemiToMeanMotion(
body[iBody].dSemi,
body[0].dMass + body[1].dMass + body[iBody].dMass);
} else if (body[iBody].iBodyType == 1 &&
iBody == 1) // binary orbit info in secondary
{
body[iBody].dMeanMotion = fdSemiToMeanMotion(
body[iBody].dSemi, body[0].dMass + body[1].dMass);
}
}
}
return;
}
/* Was anything set? */
if (dSemi == 0 && dMeanMotion == 0 && dPeriod == 0) {
fprintf(stderr, "ERROR: Must set one of %s, %s or %s.\n",
options[OPT_ORBSEMI].cName, options[OPT_ORBMEANMOTION].cName,
options[OPT_ORBPER].cName);
exit(EXIT_INPUT);
}
/* If Semi set, was anything else? */
if (dSemi > 0) {
if (dMeanMotion > 0) {
VerifyOrbitExit(options[OPT_ORBSEMI].cName,
options[OPT_ORBMEANMOTION].cName, files.Infile[iFile].cIn,
files.Infile[iFile].cIn,
options[OPT_ORBSEMI].iLine[iFile],
options[OPT_ORBMEANMOTION].iLine[iFile], iVerbose);
}
if (dPeriod > 0) {
VerifyOrbitExit(options[OPT_ORBSEMI].cName, options[OPT_ORBPER].cName,
files.Infile[iFile].cIn, files.Infile[iFile].cIn,
options[OPT_ORBSEMI].iLine[iFile],
options[OPT_ORBPER].iLine[iFile], iVerbose);
}
}
/* Were MeanMotion and OrbPeriod both set? */
if (dPeriod > 0 && dMeanMotion > 0) {
VerifyOrbitExit(options[OPT_ORBMEANMOTION].cName, options[OPT_ORBPER].cName,
files.Infile[iFile].cIn, files.Infile[iFile].cIn,
options[OPT_ORBMEANMOTION].iLine[iFile],
options[OPT_ORBPER].iLine[iFile], iVerbose);
}
/* Only one option set */
if (dMeanMotion > 0) {
if (body[iBody].bBinary && body[iBody].iBodyType == 0) { // CBP
body[iBody].dSemi = fdMeanMotionToSemi(body[0].dMass + body[1].dMass,
body[iBody].dMass, dMeanMotion);
} else if (body[iBody].bBinary && iBody == 1) { // binary
body[iBody].dSemi =
fdMeanMotionToSemi(body[0].dMass, body[1].dMass, dMeanMotion);
} else if (body[iBody].bBinary && body[iBody].iBodyType == 1 &&
iBody == 0) {
} else {
body[iBody].dSemi =
fdMeanMotionToSemi(body[0].dMass, body[iBody].dMass, dMeanMotion);
}
}
if (dPeriod > 0) {
if (body[iBody].bBinary && body[iBody].iBodyType == 0) { // CBP
body[iBody].dSemi = fdPeriodToSemi(
dPeriod, (body[0].dMass + body[1].dMass + body[iBody].dMass));
} else if (body[iBody].bBinary && body[iBody].iBodyType == 1 &&
iBody == 1) { // binary
body[iBody].dSemi =
fdPeriodToSemi(dPeriod, (body[0].dMass + body[iBody].dMass));
} else if (body[iBody].bBinary && body[iBody].iBodyType == 1 &&
iBody == 0) {
} else {
body[iBody].dSemi =
fdPeriodToSemi(dPeriod, (body[0].dMass + body[iBody].dMass));
}
}
if (dSemi > 0) {
if (body[iBody].bBinary && body[iBody].iBodyType == 0) { // CBP
body[iBody].dSemi = dSemi;
} else if (body[iBody].bBinary && body[iBody].iBodyType == 1 &&
iBody == 1) { // binary
body[iBody].dSemi = dSemi;
} else if (body[iBody].bBinary && body[iBody].iBodyType == 1 &&
iBody == 0) {
} else {
body[iBody].dSemi = dSemi;
}
}
if (dMeanMotion == 0) {
if (body[iBody].bBinary && body[iBody].iBodyType == 0) { // CBP
body[iBody].dMeanMotion = fdSemiToMeanMotion(
body[iBody].dSemi,
body[0].dMass + body[1].dMass + body[iBody].dMass);
} else if (body[iBody].bBinary && body[iBody].iBodyType == 1 &&
iBody == 1) { // Primary
body[iBody].dMeanMotion = fdSemiToMeanMotion(
body[iBody].dSemi, body[0].dMass + body[1].dMass);
} else if (body[iBody].bBinary && body[iBody].iBodyType == 1 &&
iBody == 0) {
} else {
body[iBody].dMeanMotion = fdSemiToMeanMotion(
body[iBody].dSemi, body[0].dMass + body[iBody].dMass);
}
}
}
/*
*
* Verify Integration
*
*/
void IntegrationWarning(char cName1[], char cName2[], char cName3[],
char cFile[], int iLine, int iVerbose) {
if (iVerbose > VERBINPUT) {
fprintf(stderr,
"WARNING: %s set, but neither %s nor %s set (%s: Line %d).\n",
cName1, cName2, cName3, cFile, iLine);
}
/* Backward file name */
}
void VerifyIntegration(BODY *body, CONTROL *control, FILES *files,
OPTIONS *options, SYSTEM *system,
fnIntegrate *fnOneStep) {
int iFile, iFile1, iFile2;
char cTmp[OPTLEN];
// Initialize iDir to 0, i.e. assume no integrations requested to start
control->Evolve.iDir = 0;
/* Were both Forward and Backward Set? */
if (control->Evolve.bDoBackward && control->Evolve.bDoForward) {
fprintf(stderr, "ERROR: Both %s and %s set. Only one is allowed.\n",
options[OPT_BACK].cName, options[OPT_FORW].cName);
/* Now identify which files contained the two offending options */
for (iFile = 0; iFile < files->iNumInputs; iFile++) {
if (options[OPT_BACK].iLine[iFile] > 0) {
iFile1 = iFile; // Error of multiple occurences checked in Read
}
if (options[OPT_FORW].iLine[iFile] > 0) {
iFile2 = iFile; // Error of multiple occurences checked in Read
}
}
DoubleLineExit(
options[OPT_BACK].cFile[iFile1], options[OPT_FORW].cFile[iFile2],
options[OPT_BACK].iLine[iFile1], options[OPT_FORW].iLine[iFile2]);
}
/* Fix backward output file */
if (control->Evolve.bDoBackward) {
for (iFile = 1; iFile < files->iNumInputs; iFile++) {
if (options[OPT_OUTFILE].iLine[iFile] == -1) {
sprintf(files->Outfile[iFile - 1].cOut, "%s.%s.backward", system->cName,
body[iFile - 1].cName);
if (control->Io.iVerbose >= VERBINPUT) {
fprintf(stderr, "INFO: %s not set, defaulting to %s.\n",
options[OPT_OUTFILE].cName, files->Outfile[iFile - 1].cOut);
}
}
}
control->Evolve.iDir = -1;
}
/* Fix forward output file */
if (control->Evolve.bDoForward) {
for (iFile = 1; iFile < files->iNumInputs; iFile++) {
if (options[OPT_OUTFILE].iLine[iFile] == -1) {
sprintf(files->Outfile[iFile - 1].cOut, "%s.%s.forward", system->cName,
body[iFile - 1].cName);
if (control->Io.iVerbose >= VERBINPUT) {
fprintf(stderr, "INFO: %s not set, defaulting to %s.\n",
options[OPT_OUTFILE].cName, files->Outfile[iFile - 1].cOut);
}
}
}
control->Evolve.iDir = 1;
}
/* Check for file existence */
for (iFile = 0; iFile < files->iNumInputs - 1; iFile++) {
if (bFileExists(files->Outfile[iFile].cOut)) {
if (!control->Io.bOverwrite) {
OverwriteExit(options[OPT_OVERWRITE].cName, files->Outfile[iFile].cOut);
}
if (control->Io.iVerbose >= VERBINPUT) {
fprintf(stderr, "WARNING: %s exists.\n", files->Outfile[iFile].cOut);
}
unlink(files->Outfile[iFile].cOut);
}
}
/* Was DoBackward or DoForward NOT set? */
if (!control->Evolve.bDoBackward && !control->Evolve.bDoForward) {
for (iFile = 0; iFile < files->iNumInputs; iFile++) {
if (options[OPT_ETA].iLine[iFile] > -1) {
IntegrationWarning(options[OPT_ETA].cName, options[OPT_BACK].cName,
options[OPT_FORW].cName,
options[OPT_ETA].cFile[iFile],
options[OPT_ETA].iLine[iFile], control->Io.iVerbose);
}
if (options[OPT_OUTPUTTIME].iLine[iFile] > -1) {
IntegrationWarning(
options[OPT_OUTPUTTIME].cName, options[OPT_BACK].cName,
options[OPT_FORW].cName, options[OPT_OUTPUTTIME].cFile[iFile],
options[OPT_OUTPUTTIME].iLine[iFile], control->Io.iVerbose);
}
if (options[OPT_STOPTIME].iLine[iFile] > -1) {
IntegrationWarning(
options[OPT_STOPTIME].cName, options[OPT_BACK].cName,
options[OPT_FORW].cName, options[OPT_STOPTIME].cFile[iFile],
options[OPT_STOPTIME].iLine[iFile], control->Io.iVerbose);
}
if (options[OPT_TIMESTEP].iLine[iFile] > -1) {
IntegrationWarning(
options[OPT_TIMESTEP].cName, options[OPT_BACK].cName,
options[OPT_FORW].cName, options[OPT_TIMESTEP].cFile[iFile],
options[OPT_TIMESTEP].iLine[iFile], control->Io.iVerbose);
}
if (options[OPT_VARDT].iLine[iFile] > -1) {
IntegrationWarning(
options[OPT_VARDT].cName, options[OPT_BACK].cName,
options[OPT_FORW].cName, options[OPT_VARDT].cFile[iFile],
options[OPT_VARDT].iLine[iFile], control->Io.iVerbose);
}
if (options[OPT_OUTPUTORDER].iLine[iFile] > -1) {
IntegrationWarning(
options[OPT_OUTPUTORDER].cName, options[OPT_BACK].cName,
options[OPT_FORW].cName, options[OPT_OUTPUTORDER].cFile[iFile],
options[OPT_OUTPUTORDER].iLine[iFile], control->Io.iVerbose);
}
}
}
if (control->Evolve.iOneStep == EULER) {
*fnOneStep = &EulerStep;
} else if (control->Evolve.iOneStep == RUNGEKUTTA) {
*fnOneStep = &RungeKutta4Step;
} else {
/* Assign Default */
strcpy(cTmp, options[OPT_INTEGRATIONMETHOD].cDefault);
if (control->Io.iVerbose >= VERBINPUT) {
fprintf(stderr, "INFO: %s not set, defaulting to %s.\n",
options[OPT_INTEGRATIONMETHOD].cName,
options[OPT_INTEGRATIONMETHOD].cDefault);
}
if (memcmp(sLower(cTmp), "e", 1) == 0) {
control->Evolve.iOneStep = EULER;
*fnOneStep = &EulerStep;
}
if (memcmp(sLower(cTmp), "r", 1) == 0) {
control->Evolve.iOneStep = RUNGEKUTTA;
*fnOneStep = &RungeKutta4Step;
}
}
/* Make sure output interval is less than stop time */
if (control->Evolve.dStopTime < control->Io.dOutputTime) {
fprintf(stderr, "ERROR: %s < %s is not allowed.\n",
options[OPT_STOPTIME].cName, options[OPT_OUTPUTTIME].cName);
/* Now identify which files contained the two offending options */
for (iFile = 0; iFile < files->iNumInputs; iFile++) {
if (options[OPT_STOPTIME].iLine[iFile] > 0) {
iFile1 = iFile; // Error of multiple occurences checked in Read
}
if (options[OPT_OUTPUTTIME].iLine[iFile] > 0) {
iFile2 = iFile; // Error of multiple occurences checked in Read
}
}
DoubleLineExit(options[OPT_STOPTIME].cFile[iFile1],
options[OPT_STOPTIME].cFile[iFile2],
options[OPT_STOPTIME].iLine[iFile1],
options[OPT_OUTPUTTIME].iLine[iFile2]);
}
}
/*
*
* Mass-Radius Relationships
*
*/
void VerifyMassRad(BODY *body, CONTROL *control, OPTIONS *options, char cFile[],
int iBody) {
int iFile = iBody + 1, iVerbose;
iVerbose = control->Io.iVerbose;
/* !!!!!! --- Mass and Radius ARE ALWAYS UPDATED AND CORRECT --- !!!!!! */
/* First see if mass and radius and nothing else set, i.e. the user input the
* default parameters */
if (options[OPT_MASS].iLine[iFile] > -1 &&
options[OPT_RADIUS].iLine[iFile] > -1 &&
options[OPT_DENSITY].iLine[iFile] == -1 &&
options[OPT_MASSRAD].iLine[iFile] == -1) {
return;
}
/* Was anything set> */
if (options[OPT_MASS].iLine[iFile] == -1 &&
options[OPT_RADIUS].iLine[iFile] == -1 &&
options[OPT_DENSITY].iLine[iFile] == -1) {
if (iVerbose >= VERBERR) {
fprintf(stderr, "ERROR: Must set at least one of %s, %s, and %s.\n",
options[OPT_MASS].cName, options[OPT_RADIUS].cName,
options[OPT_DENSITY].cName);
}
exit(EXIT_INPUT);
}
/* Were all set? */
if (options[OPT_MASS].iLine[iFile] > -1 &&
options[OPT_RADIUS].iLine[iFile] > -1 &&
options[OPT_DENSITY].iLine[iFile] > -1) {
VerifyTripleExit(options[OPT_MASS].cName, options[OPT_RADIUS].cName,
options[OPT_DENSITY].cName, options[OPT_MASS].iLine[iFile],
options[OPT_RADIUS].iLine[iFile],
options[OPT_DENSITY].iLine[iFile], cFile, iVerbose);
exit(EXIT_INPUT);
}
/* Was mass set? */
if (options[OPT_MASS].iLine[iFile] > -1) {
/* Can only set 1 other */
if (options[OPT_RADIUS].iLine[iFile] > -1 &&
options[OPT_MASSRAD].iLine[iFile] > -1) {
VerifyTwoOfThreeExit(options[OPT_MASS].cName, options[OPT_RADIUS].cName,
options[OPT_MASSRAD].cName,
options[OPT_MASS].iLine[iFile],
options[OPT_RADIUS].iLine[iFile],
options[OPT_MASSRAD].iLine[iFile], cFile, iVerbose);
}
if (options[OPT_RADIUS].iLine[iFile] > -1 &&
options[OPT_DENSITY].iLine[iFile] > -1) {
VerifyTwoOfThreeExit(options[OPT_MASS].cName, options[OPT_RADIUS].cName,
options[OPT_DENSITY].cName,
options[OPT_MASS].iLine[iFile],
options[OPT_RADIUS].iLine[iFile],
options[OPT_DENSITY].iLine[iFile], cFile, iVerbose);
}
if (options[OPT_MASSRAD].iLine[iFile] > -1 &&
options[OPT_DENSITY].iLine[iFile] > -1) {
VerifyTwoOfThreeExit(options[OPT_MASS].cName, options[OPT_MASSRAD].cName,
options[OPT_DENSITY].cName,
options[OPT_MASS].iLine[iFile],
options[OPT_MASSRAD].iLine[iFile],
options[OPT_DENSITY].iLine[iFile], cFile, iVerbose);
}
/* Only Mass and something else set */
if (options[OPT_RADIUS].iLine[iFile] > -1) {
/* Mass and radius were the only two set - Nothing to do */
return;
}
if (options[OPT_DENSITY].iLine[iFile] > -1) {
/* Must get radius from density */
body->dRadius = fdDensityMassToRadius(body->dDensity, body->dMass);
}
if (options[OPT_MASSRAD].iLine[iFile] > -1) {
/* Must get radius from relationship */
body->dRadius = fdMassToRad(body->dMass, control->iMassRad[iBody]);
}
return;
}
/* Was radius set, but not mass? */
if (options[OPT_RADIUS].iLine[iFile] > -1) {
if (options[OPT_MASSRAD].iLine[iFile] >= -1 &&
options[OPT_DENSITY].iLine[iFile] >= -1) {
VerifyTwoOfThreeExit(options[OPT_MASS].cName, options[OPT_MASSRAD].cName,
options[OPT_DENSITY].cName,
options[OPT_MASS].iLine[iFile],
options[OPT_MASSRAD].iLine[iFile],
options[OPT_DENSITY].iLine[iFile], cFile, iVerbose);
}
/* Only Radius and something else set */
if (options[OPT_MASSRAD].iLine[iFile] > -1) {
/* Must get mass from relationship */
body->dMass = fdRadToMass(body->dRadius, control->iMassRad[iBody]);
}
if (options[OPT_DENSITY].iLine[iFile] > -1) {
/* Must get mass from density */
body->dMass = fdMassFromRadiusDensity(body->dRadius, body->dDensity);
}
}
}
/*
*
* Verify Rotation
*
*/
void VerifyObliquity(BODY *body, OPTIONS *options, int iBody, int iVerbose) {
if (options[OPT_COSOBL].iLine[iBody + 1] > -1) {
// Cos(obl) entered for this body
if (options[OPT_OBL].iLine[iBody + 1] > -1) {
if (iVerbose > VERBINPUT) {
fprintf(stderr, "ERROR: Cannot set %s and %s.\n",
options[OPT_OBL].cName, options[OPT_COSOBL].cName);
}
DoubleLineExit(options[OPT_OBL].cFile[iBody + 1],
options[OPT_COSOBL].cFile[iBody + 1],
options[OPT_OBL].iLine[iBody + 1],
options[OPT_COSOBL].iLine[iBody + 1]);
}
body[iBody].dObliquity = acos(body[iBody].dCosObl);
}
}
void VerifyRotationGeneral(BODY *body, OPTIONS *options, char cFile[],
int iBody, int iVerbose) {
/* Add 1, as this information could not have been set in primary input */
int iFileNum = iBody + 1;
/* Was more than one version set? */
/* !!!!!! ------ RotRate IS ALWAYS UPDATED AND CORRECT -------- !!!!!! */
if (options[OPT_ROTPER].iLine[iFileNum] >= 0) {
/* Rotation Period set -- if Rate or Vel set, exit */
if (options[OPT_ROTRATE].iLine[iFileNum] >= 0) {
VerifyBodyExit(options[OPT_ROTPER].cName, options[OPT_ROTRATE].cName,
cFile, options[OPT_ROTPER].iLine[iFileNum],
options[OPT_ROTRATE].iLine[iFileNum], iVerbose);
}
if (options[OPT_ROTVEL].iLine[iFileNum] >= 0) {
VerifyBodyExit(options[OPT_ROTPER].cName, options[OPT_ROTVEL].cName,
cFile, options[iBody].iLine[iFileNum],
options[OPT_ROTVEL].iLine[iFileNum], iVerbose);
}
}
if (options[OPT_ROTVEL].iLine[iFileNum] >= 0) {
/* Rotational Velocity set -- if Rate set, exit */
if (options[OPT_ROTRATE].iLine[iFileNum] >= 0) {
VerifyBodyExit(options[OPT_ROTRATE].cName, options[OPT_ROTVEL].cName,
cFile, options[OPT_ROTRATE].iLine[iFileNum],
options[OPT_ROTVEL].iLine[iFileNum], iVerbose);
}
}
if (options[OPT_ROTPER].iLine[iFileNum] == -1 &&
options[OPT_ROTVEL].iLine[iFileNum] == -1 &&
options[OPT_ROTRATE].iLine[iFileNum] == -1) {
/* Nothing set, print warning and return */
if (iVerbose >= VERBINPUT) {
fprintf(stderr,
"INFO: No rotational information set in file %s. Defaulting to "
"%s = %s.\n",
cFile, options[OPT_ROTRATE].cName, options[OPT_ROTRATE].cDefault);
}
body[iBody].dRotRate = options[OPT_ROTRATE].dDefault;
return;
}
/* dRotRate is the master parameter, so set it. */
if (options[OPT_ROTPER].iLine[iFileNum] >= 0) {
body[iBody].dRotRate = fdPerToFreq(body[iBody].dRotPer);
}
if (options[OPT_ROTVEL].iLine[iFileNum] >= 0) {
body[iBody].dRotRate =
fdRadiusRotVelToFreq(body[iBody].dRotVel, body[iBody].dRadius);
}
VerifyObliquity(body, options, iBody, iVerbose);
}
void VerifyImK2Env(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
SYSTEM *system, int iBody) {
// Is there an envelope? If so, fix its Im(k2)
if (body[iBody].bEnv) {
// they better have defined k2Env, tidalqenv, denvmass
if (options[OPT_TIDALQENV].iLine[iBody + 1] == -1) {
fprintf(stderr, "ERROR: %s = 1, but %s not set.\n",
options[OPT_ENVTIDES].cName, options[OPT_TIDALQENV].cName);
LineExit(files->Infile[iBody + 1].cIn,
options[OPT_ENVTIDES].iLine[iBody + 1]);
}
if (options[OPT_K2ENV].iLine[iBody + 1] == -1) {
fprintf(stderr, "ERROR: %s = 1, but %s not set.\n",
options[OPT_ENVTIDES].cName, options[OPT_K2ENV].cName);
LineExit(files->Infile[iBody + 1].cIn,
options[OPT_ENVTIDES].iLine[iBody + 1]);
}
if (options[OPT_ENVELOPEMASS].iLine[iBody + 1] == -1) {
fprintf(stderr, "ERROR: %s = 1, but %s not set.\n",
options[OPT_ENVTIDES].cName, options[OPT_ENVELOPEMASS].cName);
LineExit(files->Infile[iBody + 1].cIn,
options[OPT_ENVTIDES].iLine[iBody + 1]);
}
// Cannot set TidalQ and TidalQEnv
if (options[OPT_TIDALQ].iLine[iBody + 1] > -1 &&
options[OPT_TIDALQENV].iLine[iBody + 1] > -1) {
fprintf(stderr, "ERROR: Cannot set both %s and %s.\n",
options[OPT_TIDALQ].cName, options[OPT_TIDALQENV].cName);
DoubleLineExit(options[OPT_TIDALQ].cFile[iBody + 1],
options[OPT_TIDALQENV].cFile[iBody + 1],
options[OPT_TIDALQ].iLine[iBody + 1],
options[OPT_TIDALQENV].iLine[iBody + 1]);
}
// Cannot set K2 and K2Env
if (options[OPT_K2].iLine[iBody + 1] > -1 &&
options[OPT_K2ENV].iLine[iBody + 1] > -1) {
fprintf(stderr, "ERROR: Cannot set both %s and %s.\n",
options[OPT_K2].cName, options[OPT_K2ENV].cName);
DoubleLineExit(options[OPT_K2].cFile[iBody + 1],
options[OPT_K2ENV].cFile[iBody + 1],
options[OPT_K2].iLine[iBody + 1],
options[OPT_K2ENV].iLine[iBody + 1]);
}
// Everything OK, set dImK2Env
// Defining this here is OK until we have a real envelope model
body[iBody].dImK2Env = -body[iBody].dK2Env / body[iBody].dTidalQEnv;
} else {
// Set dImK2Env to 0, i.e. no Dissipation
body[iBody].dImK2Env = 0;
}
}
void VerifyImK2Ocean(BODY *body, CONTROL *control, FILES *files,
OPTIONS *options, SYSTEM *system, int iBody) {
// Is there an ocean? If so, fix its Im(k2)
if (body[iBody].bOcean) {
// they better have defined k2Ocean, tidalqOcean, dOceanmass
if (options[OPT_TIDALQOCEAN].iLine[iBody + 1] == -1) {
fprintf(stderr, "ERROR: %s = 1, but %s not set.\n",
options[OPT_OCEANTIDES].cName, options[OPT_TIDALQOCEAN].cName);
LineExit(files->Infile[iBody + 1].cIn,
options[OPT_OCEANTIDES].iLine[iBody + 1]);
}
if (options[OPT_K2OCEAN].iLine[iBody + 1] == -1) {
fprintf(stderr, "ERROR: %s = 1, but %s not set.\n",
options[OPT_OCEANTIDES].cName, options[OPT_K2OCEAN].cName);
LineExit(files->Infile[iBody + 1].cIn,
options[OPT_OCEANTIDES].iLine[iBody + 1]);
}
if (options[OPT_SURFACEWATERMASS].iLine[iBody + 1] == -1) {
fprintf(stderr, "ERROR: %s = 1, but %s not set.\n",
options[OPT_OCEANTIDES].cName,
options[OPT_SURFACEWATERMASS].cName);
LineExit(files->Infile[iBody + 1].cIn,
options[OPT_OCEANTIDES].iLine[iBody + 1]);
}
// Cannot set TidalQ and TidalQOcean
if (options[OPT_TIDALQ].iLine[iBody + 1] > -1 &&
options[OPT_TIDALQOCEAN].iLine[iBody + 1] > -1) {
fprintf(stderr, "ERROR: Cannot set both %s and %s.\n",
options[OPT_TIDALQ].cName, options[OPT_TIDALQOCEAN].cName);
DoubleLineExit(options[OPT_TIDALQ].cFile[iBody + 1],
options[OPT_TIDALQOCEAN].cFile[iBody + 1],
options[OPT_TIDALQ].iLine[iBody + 1],
options[OPT_TIDALQOCEAN].iLine[iBody + 1]);
}
// Cannot set K2 and K2Ocean
if (options[OPT_K2].iLine[iBody + 1] > -1 &&
options[OPT_K2OCEAN].iLine[iBody + 1] > -1) {
fprintf(stderr, "ERROR: Cannot set both %s and %s.\n",
options[OPT_K2].cName, options[OPT_K2OCEAN].cName);
DoubleLineExit(options[OPT_K2].cFile[iBody + 1],
options[OPT_K2OCEAN].cFile[iBody + 1],
options[OPT_K2].iLine[iBody + 1],
options[OPT_K2OCEAN].iLine[iBody + 1]);
}
// Everything OK, set dImK2Ocean
// Defining this here is OK until we have a real ocean model
body[iBody].dImK2Ocean = -body[iBody].dK2Ocean / body[iBody].dTidalQOcean;
} else {
// Set dImK2Ocean to 0, i.e. no Dissipation
body[iBody].dImK2Ocean = 0;
}
}
void VerifyImK2Mantle(BODY *body, CONTROL *control, FILES *files,
OPTIONS *options, SYSTEM *system, UPDATE *update,
int iBody) {
// Is there a mantle? If so, fix its Im(k2)
if (body[iBody].bMantle) {
if (options[OPT_TIDALQ].iLine[iBody + 1] > -1 &&
options[OPT_TIDALQMANTLE].iLine[iBody + 1] > -1) {
if (control->Io.iVerbose >= VERBINPUT) {
fprintf(stderr, "ERROR: Cannot set both %s and %s.\n",
options[OPT_TIDALQ].cName, options[OPT_TIDALQMANTLE].cName);
}
DoubleLineExit(options[OPT_TIDALQ].cFile[iBody + 1],
options[OPT_TIDALQMANTLE].cFile[iBody + 1],
options[OPT_TIDALQ].iLine[iBody + 1],
options[OPT_TIDALQMANTLE].iLine[iBody + 1]);
}
// Cannot set K2 and K2Mantle
if (options[OPT_K2].iLine[iBody + 1] > -1 &&
options[OPT_K2MANTLE].iLine[iBody + 1] > -1) {
if (control->Io.iVerbose >= VERBINPUT) {
fprintf(stderr, "ERROR: Cannot set both %s and %s.\n",
options[OPT_K2].cName, options[OPT_K2MANTLE].cName);
}
DoubleLineExit(options[OPT_K2].cFile[iBody + 1],
options[OPT_K2MANTLE].cFile[iBody + 1],
options[OPT_K2].iLine[iBody + 1],
options[OPT_K2MANTLE].iLine[iBody + 1]);
}
if (body[iBody].bThermint) {
// User set dTidalQMan
if (options[OPT_TIDALQMANTLE].iLine[iBody + 1] == -1) {
body[iBody].dTidalQMan = body[iBody].dTidalQ;
if (control->Io.iVerbose >= VERBALL) {
fprintf(stderr,
"INFO: %s set, but ThermInt computes it. Input value will be "
"ignored.\n",
options[OPT_TIDALQMANTLE].cName);
}
}
body[iBody].dK2Man = fdK2Man(body, iBody);
body[iBody].dImK2Man = fdImK2Man(body, iBody);
} else {
body[iBody].dImK2Man = -body[iBody].dK2Man / body[iBody].dTidalQMan;
body[iBody].dShmodUMan = 1; // Set to avoid division by zero in log file
body[iBody].dDynamViscos = 1; // Also used in log file
body[iBody].dStiffness = 1; // Ditto
}
} else {
body[iBody].dImK2Man = 0;
}
}
/**
Verify all input parameters related to tidal energy dissipation (Power) into
all regions of a planet. The parameter Im(k2) is set by the orbit and the
internal temperature in the layer, which is set by the tidal, secular, and
radiogenic heating rates. The heating is divided into layers: 1) Mantle, 2)
Ocean, and 3) Envelope, and may be calculated by the EqTide, RadHeat, and/or
ThermInt modules. Those modules in turn have different possibilities. By the
end of this function, the values of Im(k2) in all layers and the body as a
whole are set. */
void VerifyImK2(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
SYSTEM *system, UPDATE *update, int iBody) {
// First gather auxiliary properties for relevant modules
PropsAuxEqtide(body, &control->Evolve, &control->Io, update, iBody);
if (body[iBody].bThermint) {
fvPropsAuxThermint(body, &control->Evolve, &control->Io, update, iBody);
}
VerifyImK2Env(body, control, files, options, system, iBody);
VerifyImK2Ocean(body, control, files, options, system, iBody);
VerifyImK2Mantle(body, control, files, options, system, update, iBody);
// fdImK2Total determines which layers set (if any), and returns appropriate
// Im(k_2)
body[iBody].dImK2 = fdImK2Total(body, iBody);
if (control->Io.iVerbose > VERBPROG) {
fprintf(stderr, "%s's Im(k_2) verified.\n", body[iBody].cName);
}
/*
// now lets check there's actually an envelope
// there is not an envelope!!
if (!(body[iBody].dEnvelopeMass > body[iBody].dMinEnvelopeMass)) {
body[iBody].bEnv = 0;
}
else {
body[iBody].bEnv = 1;
body[iBody].dImK2Env = body[iBody].dK2Env / body[iBody].dTidalQEnv;
}
// what about an ocean?
if (!(body[iBody].dSurfaceWaterMass > body[iBody].dMinSurfaceWaterMass)) {
body[iBody].bOcean = 0;
}
else {
body[iBody].bOcean = 1;
body[iBody].dImK2Ocean = body[iBody].dK2Ocean / body[iBody].dTidalQOcean;
}
// there's definitely at least gonna be some rock...
body[iBody].dImK2Rock = body[iBody].dK2Rock / body[iBody].dTidalQRock;
// if there is an envelope/ocean, we calculate ImK2Env/ImK2Ocean
if (body[iBody].bEnv && (body[iBody].dTidalQ != body[iBody].dTidalQEnv)) {
if (control->Io.iVerbose > 1) {
fprintf(stderr,"Using dTidalQEnv for %s.\n",body[iBody].cName);
}
body[iBody].dTidalQ = body[iBody].dTidalQEnv;
body[iBody].dK2 = body[iBody].dK2Env;
body[iBody].dImK2Env = body[iBody].dK2Env / body[iBody].dTidalQEnv;
body[iBody].dImK2 = body[iBody].dImK2Env;
}
else {
if (body[iBody].bOcean && (body[iBody].dTidalQ !=
body[iBody].dTidalQOcean)) { fprintf(stderr,"Using dTidalQOcean for
%s.\n",body[iBody].cName); body[iBody].dTidalQ = body[iBody].dTidalQOcean;
body[iBody].dImK2Ocean = body[iBody].dK2Ocean /
body[iBody].dTidalQOcean; body[iBody].dImK2 = body[iBody].dImK2Ocean;
body[iBody].dK2 = body[iBody].dK2Ocean;
}
else if (!body[iBody].bEnv && !body[iBody].bOcean && (body[iBody].dTidalQ
!= body[iBody].dTidalQRock) && (iBody != 0)){ fprintf(stderr,"Using
dTidalQRock for %s.\n",body[iBody].cName);
// now we just use dTidalQRock and dK2Rock
body[iBody].dImK2Rock = body[iBody].dK2Rock / body[iBody].dTidalQRock;
body[iBody].dTidalQ = body[iBody].dTidalQRock;
body[iBody].dK2 = body[iBody].dK2Rock;
body[iBody].dImK2 = body[iBody].dImK2Rock;
}
}
*/
}
/*
*
* System-level verify routines
*
*/
/*! Initialize angular momentum for energy for conservation checks. Initialize
* here so anything that changes E, J is monitored to ensure conservation */
void InitializeConstants(BODY *body, UPDATE *update, CONTROL *control,
SYSTEM *system, OPTIONS *options) {
int iBody;
// Initially no lost angular momentum, energy
// Set to dTINY, not 0 since these are integrated
// and it being 0 can mess up the time step
for (iBody = 0; iBody < control->Evolve.iNumBodies; iBody++) {
body[iBody].dLostAngMom = dTINY;
body[iBody].dLostEng = dTINY;
}
// Compute initial total angular momentum
system->dTotAngMomInit = fdTotAngMom(body, control, system);
system->dTotAngMom = system->dTotAngMomInit;
// Compute initial total energy
system->dTotEnInit = fdTotEnergy(body, control, system);
system->dTotEn = system->dTotEnInit;
}