Skip to content

Commit c16fdbe

Browse files
authored
Merge pull request #329 from VirtualPlanetaryLaboratory/StopAge
Stop age
2 parents aaebd00 + f6ef1f6 commit c16fdbe

File tree

8 files changed

+787
-462
lines changed

8 files changed

+787
-462
lines changed

src/evolve.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
#define EULER 1
1515
#define RUNGEKUTTA 2
1616

17+
#define NO_INTEGRATION 0
18+
#define FORWARD_INTEGRATION 1
19+
#define BACKWARD_INTEGRATION -1
20+
1721
/* @cond DOXYGEN_OVERRIDE */
1822

19-
double fdTrapezoidalArea(double,double,double);
23+
double fdTrapezoidalArea(double, double, double);
2024
void PropertiesAuxiliary(BODY *, CONTROL *, SYSTEM *, UPDATE *);
2125
void fdGetUpdateInfo(BODY *, CONTROL *, SYSTEM *, UPDATE *,
2226
fnUpdateVariable ***);

src/options.c

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,6 @@ void ReadUnitTemp(CONTROL *control, FILES *files, OPTIONS *options, int iFile) {
10781078

10791079
void ReadSystemName(CONTROL *control, FILES *files, OPTIONS *options,
10801080
SYSTEM *system, int iFile) {
1081-
/* System Name */
10821081
int lTmp = -1;
10831082
char cTmp[OPTLEN];
10841083

@@ -1092,6 +1091,28 @@ void ReadSystemName(CONTROL *control, FILES *files, OPTIONS *options,
10921091
}
10931092
}
10941093

1094+
void ReadSystemAge(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
1095+
SYSTEM *system, int iFile) {
1096+
int lTmp = -1;
1097+
double dTmp;
1098+
1099+
AddOptionDouble(files->Infile[iFile].cIn, options->cName, &dTmp, &lTmp,
1100+
control->Io.iVerbose);
1101+
if (lTmp >= 0) {
1102+
CheckDuplication(files, options, files->Infile[iFile].cIn, lTmp,
1103+
control->Io.iVerbose);
1104+
if (dTmp < 0) {
1105+
system->dAge = dTmp * dNegativeDouble(*options, files->Infile[iFile].cIn,
1106+
control->Io.iVerbose);
1107+
} else {
1108+
system->dAge = dTmp * fdUnitsTime(control->Units[iFile].iTime);
1109+
}
1110+
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
1111+
} else if (iFile > 0) {
1112+
AssignDefaultDouble(options, &system->dAge, files->iNumInputs);
1113+
}
1114+
}
1115+
10951116
void ReadBodyFileNames(BODY **body, CONTROL *control, FILES *files,
10961117
OPTIONS *options, char *cFile, char ***saBodyFiles,
10971118
int *iNumLines, int *iaLines) {
@@ -1442,8 +1463,6 @@ void ReadOutputTime(BODY *body, CONTROL *control, FILES *files,
14421463
}
14431464
}
14441465

1445-
/* Backward integration stop time */
1446-
14471466
void ReadStopTime(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
14481467
SYSTEM *system, int iFile) {
14491468
/* This parameter can exist in any file, but only once */
@@ -1470,6 +1489,32 @@ void ReadStopTime(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
14701489
}
14711490
}
14721491

1492+
void ReadStopAge(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
1493+
SYSTEM *system, int iFile) {
1494+
/* This parameter can exist in any file, but only once */
1495+
int lTmp = -1;
1496+
double dTmp;
1497+
1498+
AddOptionDouble(files->Infile[iFile].cIn, options->cName, &dTmp, &lTmp,
1499+
control->Io.iVerbose);
1500+
if (lTmp >= 0) {
1501+
/* Option was found */
1502+
CheckDuplication(files, options, files->Infile[iFile].cIn, lTmp,
1503+
control->Io.iVerbose);
1504+
if (dTmp < 0) {
1505+
if (control->Io.iVerbose >= VERBERR) {
1506+
fprintf(stderr, "ERROR: %s must be greater than 0.\n", options->cName);
1507+
}
1508+
LineExit(files->Infile[iFile].cIn, lTmp);
1509+
}
1510+
/* Convert stop time to cgs */
1511+
control->Evolve.dStopAge = dTmp * fdUnitsTime(control->Units[iFile].iTime);
1512+
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
1513+
} else {
1514+
AssignDefaultDouble(options, &control->Evolve.dStopAge, files->iNumInputs);
1515+
}
1516+
}
1517+
14731518
/* Integration timestep */
14741519

14751520
void ReadTimeStep(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
@@ -2617,7 +2662,7 @@ void fvAllocateOutputArrays(char ****saMatch, char ***saOutput, int **baNeg,
26172662

26182663
for (iIndex = 0; iIndex < iNumArgs; iIndex++) {
26192664
(*saMatch)[iIndex] =
2620-
malloc(MAXARRAY * sizeof(char*)); // Could be this many matches
2665+
malloc(MAXARRAY * sizeof(char *)); // Could be this many matches
26212666
for (iMatch = 0; iMatch < MAXARRAY; iMatch++) {
26222667
(*saMatch)[iIndex][iMatch] = NULL;
26232668
}
@@ -3712,7 +3757,7 @@ void InitializeOptionsGeneral(OPTIONS *options, fnReadOption fnRead[]) {
37123757
*/
37133758

37143759
fvFormattedString(&options[OPT_AGE].cName, "dAge");
3715-
fvFormattedString(&options[OPT_AGE].cDescr, "System Age");
3760+
fvFormattedString(&options[OPT_AGE].cDescr, "Body's Age");
37163761
fvFormattedString(&options[OPT_AGE].cDefault, "0");
37173762
fvFormattedString(&options[OPT_AGE].cNeg, "Gyr");
37183763
fvFormattedString(&options[OPT_AGE].cDimension, "time");
@@ -3724,6 +3769,20 @@ void InitializeOptionsGeneral(OPTIONS *options, fnReadOption fnRead[]) {
37243769
options[OPT_AGE].iFileType = 2;
37253770
fnRead[OPT_AGE] = &ReadAge;
37263771

3772+
int iOpt = OPT_SYSTEMAGE;
3773+
fvFormattedString(&options[iOpt].cName, "dSystemAge");
3774+
fvFormattedString(&options[iOpt].cDescr, "System Age");
3775+
fvFormattedString(&options[iOpt].cDefault, "0");
3776+
fvFormattedString(&options[iOpt].cNeg, "1 Gyr");
3777+
fvFormattedString(&options[iOpt].cDimension, "time");
3778+
options[iOpt].dDefault = 0;
3779+
options[iOpt].iType = 2;
3780+
options[iOpt].iModuleBit = 0;
3781+
options[iOpt].bNeg = 1;
3782+
options[iOpt].dNeg = 1e9 * YEARSEC;
3783+
options[iOpt].iFileType = 2;
3784+
fnRead[iOpt] = &ReadSystemAge;
3785+
37273786
fvFormattedString(&options[OPT_ALBEDOGLOBAL].cName, "dAlbedoGlobal");
37283787
fvFormattedString(&options[OPT_ALBEDOGLOBAL].cDescr,
37293788
"Globally averaged albedo");
@@ -3805,6 +3864,20 @@ void InitializeOptionsGeneral(OPTIONS *options, fnReadOption fnRead[]) {
38053864
options[OPT_STOPTIME].iFileType = 2;
38063865
fnRead[OPT_STOPTIME] = &ReadStopTime;
38073866

3867+
iOpt = OPT_STOPAGE;
3868+
fvFormattedString(&options[iOpt].cName, "dStopAge");
3869+
fvFormattedString(&options[iOpt].cDescr, "Age to stop integration");
3870+
fvFormattedString(&options[iOpt].cDefault, "10 Gigayears");
3871+
fvFormattedString(&options[iOpt].cNeg, "Years");
3872+
fvFormattedString(&options[iOpt].cDimension, "time");
3873+
options[iOpt].dDefault = 1e10 * YEARSEC;
3874+
options[iOpt].iType = 2;
3875+
options[iOpt].iModuleBit = 0;
3876+
options[iOpt].bNeg = 1;
3877+
options[iOpt].dNeg = YEARSEC;
3878+
options[iOpt].iFileType = 2;
3879+
fnRead[iOpt] = &ReadStopAge;
3880+
38083881
fvFormattedString(&options[OPT_TIMESTEP].cName, "dTimeStep");
38093882
fvFormattedString(&options[OPT_TIMESTEP].cDescr, "Integration Timestep");
38103883
fvFormattedString(&options[OPT_TIMESTEP].cDefault, "1 year");

src/options.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
// Regular Options
3131

3232
#define OPT_AGE 100
33+
#define OPT_SYSTEMAGE 102
3334
#define OPT_ALBEDOGLOBAL 105
3435

3536
#define OPT_BACK 110
3637
#define OPT_OUTFILE 120
3738
#define OPT_ETA 130
3839
#define OPT_OUTPUTTIME 140
3940
#define OPT_STOPTIME 150
41+
#define OPT_STOPAGE 155
4042
#define OPT_TIMESTEP 160
4143
#define OPT_VARDT 170
4244
#define OPT_BODYNAME 180
@@ -128,8 +130,7 @@ void ReadOptions(BODY **, CONTROL *, FILES *, MODULE *, OPTIONS *, OUTPUT *,
128130
SYSTEM *, UPDATE **, fnReadOption *, char[]);
129131

130132
double dNegativeDouble(OPTIONS, char[], int);
131-
void AddOptionStringArray(char[], char[], char***, int *, int *,
132-
int *, int);
133+
void AddOptionStringArray(char[], char[], char ***, int *, int *, int *, int);
133134
void AddOptionDoubleArray(char[], char[], double *, int *, int *, int *, int);
134135
void NotPrimaryInput(int, char[], char[], int, int);
135136
void AddOptionDouble(char[], char[], double *, int *, int);

0 commit comments

Comments
 (0)