Skip to content

Commit c2756c0

Browse files
authored
Merge pull request #290 from VirtualPlanetaryLaboratory/memcheck
Memcheck
2 parents b418c48 + e592635 commit c2756c0

File tree

38 files changed

+3461
-4127
lines changed

38 files changed

+3461
-4127
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ sanitize:
6565

6666
test:
6767
-gcc -o bin/vplanet src/*.c -lm -O3 -DGITVERSION=\"$(GITVERSION)\"
68-
-pytest
68+
-pytest --tb=short
6969

7070
coverage:
7171
-mkdir -p gcov && cd gcov && gcc -coverage -o ../bin/vplanet ../src/*.c -lm
72-
-python -m pytest -v tests --junitxml=junit/test-results.xml
72+
-python -m pytest --tb=short tests --junitxml=junit/test-results.xml
7373
-lcov --capture --directory gcov --output-file .coverage && genhtml .coverage --output-directory gcov/html
7474

7575
docs:

src/atmesc.c

Lines changed: 43 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,39 +1446,37 @@ double fdAtmEscXi(BODY *body, int iBody) {
14461446
return dXi;
14471447
}
14481448

1449-
double fdKTide(BODY *body, IO *io, int iBody) {
1449+
double fdKTide(BODY *body, IO *io, int iNumBodies, int iBody) {
14501450
double dKTide;
14511451

14521452
// For stars and circumbinary planets, assume no Ktide enhancement
14531453
if (body[iBody].bBinary && body[iBody].iBodyType == 0) {
14541454
dKTide = 1.0;
14551455
} else {
1456-
if (body[iBody].dAtmEscXi > 1) {
1457-
dKTide = (1 - 3 / (2 * body[iBody].dAtmEscXi) +
1458-
1 / (2 * pow(body[iBody].dAtmEscXi, 3)));
1459-
/*
1460-
fprintf(stderr,"%.5e: ",evolve->dTime/YEARSEC);
1461-
fprintf(stderr,"%.5e ",xi);
1462-
fprintf(stderr,"%.5e\n",body[iBody].dKTide);
1463-
*/
1464-
if (dKTide < body[iBody].dMinKTide) {
1465-
dKTide = body[iBody].dMinKTide;
1456+
if (iNumBodies > 1) {
1457+
if (body[iBody].dAtmEscXi > 1) {
1458+
dKTide = (1 - 3 / (2 * body[iBody].dAtmEscXi) +
1459+
1 / (2 * pow(body[iBody].dAtmEscXi, 3)));
1460+
if (dKTide < body[iBody].dMinKTide) {
1461+
dKTide = body[iBody].dMinKTide;
1462+
}
1463+
} else {
1464+
if (!io->baRocheMessage[iBody] && io->iVerbose >= VERBINPUT &&
1465+
(!body[iBody].bUseBondiLimited && !body[iBody].bAtmEscAuto)) {
1466+
fprintf(stderr,
1467+
"WARNING: Roche lobe radius is larger than %s's XUV radius. "
1468+
"Evolution may not be accurate.\n",
1469+
body[iBody].cName);
1470+
fprintf(stderr, "Consider setting bUseBondiLimited = 1 or bAtmEscAuto "
1471+
"= 1 to limit envelope mass loss.\n");
1472+
io->baRocheMessage[iBody] = 1;
1473+
}
1474+
// Fix dKTide to prevent infs when in Roche Lobe overflow
1475+
dKTide = 1.0;
14661476
}
14671477
} else {
1468-
if (!io->baRocheMessage[iBody] && io->iVerbose >= VERBINPUT &&
1469-
(!body[iBody].bUseBondiLimited && !body[iBody].bAtmEscAuto)) {
1470-
fprintf(stderr,
1471-
"WARNING: Roche lobe radius is larger than %s's XUV radius. "
1472-
"Evolution may not be accurate.\n",
1473-
body[iBody].cName);
1474-
fprintf(stderr, "Consider setting bUseBondiLimited = 1 or bAtmEscAuto "
1475-
"= 1 to limit envelope mass loss.\n");
1476-
io->baRocheMessage[iBody] = 1;
1477-
}
1478-
// Fix dKTide to prevent infs when in Roche Lobe overflow
14791478
dKTide = 1.0;
14801479
}
1481-
// body[iBody].dKTide = 1.0;
14821480
}
14831481

14841482
return dKTide;
@@ -1694,7 +1692,7 @@ void fnForceBehaviorAtmEsc(BODY *body, MODULE *module, EVOLVE *evolve, IO *io,
16941692
}
16951693
}
16961694

1697-
void AuxPropsLehmer17(BODY *body, int iBody) {
1695+
void AuxPropsLehmer17(BODY *body, EVOLVE *evolve, int iBody) {
16981696
if (body[iBody].bAutoThermTemp) {
16991697
body[iBody].dThermTemp = fdThermalTemp(body, iBody);
17001698
}
@@ -1706,7 +1704,7 @@ void AuxPropsLehmer17(BODY *body, int iBody) {
17061704
body[iBody].dPresSurf =
17071705
fdLehmerPres(body[iBody].dEnvelopeMass, body[iBody].dGravAccel,
17081706
body[iBody].dRadSolid);
1709-
body[iBody].dRadXUV = fdLehmerRadius(body, iBody);
1707+
body[iBody].dRadXUV = fdLehmerRadius(body, evolve->iNumBodies, iBody);
17101708
body[iBody].dRadius = body[iBody].dRadXUV / body[iBody].dXFrac;
17111709
}
17121710

@@ -1726,14 +1724,14 @@ void fnPropsAuxAtmEsc(BODY *body, EVOLVE *evolve, IO *io, UPDATE *update,
17261724
int iBody) {
17271725

17281726
if (body[iBody].iPlanetRadiusModel == ATMESC_LEHMER17) {
1729-
AuxPropsLehmer17(body, iBody);
1727+
AuxPropsLehmer17(body, evolve, iBody);
17301728
}
17311729

17321730
// Compute various radii of interest
17331731
body[iBody].dBondiRadius = fdBondiRadius(body, iBody);
1734-
body[iBody].dRocheRadius = fdRocheRadius(body, iBody);
1732+
body[iBody].dRocheRadius = fdRocheRadius(body, evolve->iNumBodies, iBody);
17351733
body[iBody].dAtmEscXi = fdAtmEscXi(body, iBody);
1736-
body[iBody].dKTide = fdKTide(body, io, iBody);
1734+
body[iBody].dKTide = fdKTide(body, io, evolve->iNumBodies, iBody);
17371735

17381736
// The XUV flux
17391737
if (body[iBody].bCalcFXUV) {
@@ -2133,7 +2131,7 @@ void VerifyAtmEsc(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
21332131

21342132
// Calculate auxiliary properties
21352133
body[iBody].dRadSolid = fdMassToRad_LehmerCatling17(body[iBody].dMass - body[iBody].dEnvelopeMass);
2136-
AuxPropsLehmer17(body,iBody);
2134+
AuxPropsLehmer17(body,&(control->Evolve), iBody);
21372135
} else {
21382136
fprintf(stderr,
21392137
"ERROR: The Lehmer & Catling (2017) model requires a star.\n");
@@ -2312,7 +2310,7 @@ void VerifyAtmEsc(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
23122310
// Setup radius and other radii of interest
23132311
VerifyRadiusAtmEsc(body, control, options, update, body[iBody].dAge, iBody);
23142312
body[iBody].dBondiRadius = fdBondiRadius(body, iBody);
2315-
body[iBody].dRocheRadius = fdRocheRadius(body, iBody);
2313+
body[iBody].dRocheRadius = fdRocheRadius(body, control->Evolve.iNumBodies, iBody);
23162314

23172315
control->fnForceBehavior[iBody][iModule] = &fnForceBehaviorAtmEsc;
23182316
control->fnPropsAux[iBody][iModule] = &fnPropsAuxAtmEsc;
@@ -3429,11 +3427,15 @@ Modifier for H Ref Flux to include oxygen drag at a snapshot in time
34293427
void WriteHRefODragMod(BODY *body, CONTROL *control, OUTPUT *output,
34303428
SYSTEM *system, UNITS *units, UPDATE *update, int iBody,
34313429
double *dTmp, char cUnit[]) {
3432-
double rat = (body[iBody].dCrossoverMass / ATOMMASS - QOH) /
3433-
(body[iBody].dCrossoverMass / ATOMMASS - 1.);
3434-
double XO = fdAtomicOxygenMixingRatio(body[iBody].dSurfaceWaterMass,
3435-
body[iBody].dOxygenMass);
3436-
*dTmp = pow(1. + (XO / (1. - XO)) * QOH * rat, -1);
3430+
if (body[iBody].dCrossoverMass / ATOMMASS - 1. != 0) {
3431+
double rat = (body[iBody].dCrossoverMass / ATOMMASS - QOH) /
3432+
(body[iBody].dCrossoverMass / ATOMMASS - 1.);
3433+
double XO = fdAtomicOxygenMixingRatio(body[iBody].dSurfaceWaterMass,
3434+
body[iBody].dOxygenMass);
3435+
*dTmp = pow(1. + (XO / (1. - XO)) * QOH * rat, -1);
3436+
} else {
3437+
*dTmp = -1;
3438+
}
34373439
strcpy(cUnit, "");
34383440
}
34393441

@@ -4082,7 +4084,7 @@ double fdPlanetRadius(BODY *body, SYSTEM *system, int *iaBody) {
40824084
body[iaBody[0]].dPresSurf =
40834085
fdLehmerPres(body[iaBody[0]].dEnvelopeMass,
40844086
body[iaBody[0]].dGravAccel, body[iaBody[0]].dRadSolid);
4085-
body[iaBody[0]].dRadXUV = fdLehmerRadius(body, iaBody[0]);
4087+
body[iaBody[0]].dRadXUV = fdLehmerRadius(body, system->iNumBodies, iaBody[0]);
40864088
}
40874089

40884090
double foo;
@@ -4134,6 +4136,11 @@ int fbDoesWaterEscape(BODY *body, EVOLVE *evolve, IO *io, int iBody) {
41344136
return 0;
41354137
}
41364138

4139+
/* If the central body is not a star, then allow water to escape */
4140+
if (!body[0].bStellar) {
4141+
return 1;
4142+
}
4143+
41374144
// 2. Check if planet is beyond RG limit; if user requested water loss to stop
41384145
// (the cold trap prevents water loss) then water does not escape.
41394146
// NOTE: The RG flux limit below is calculated based on body zero's
@@ -4363,62 +4370,7 @@ void fvLinearFit(double *x, double *y, int iLen, double *daCoeffs) {
43634370
daCoeffs[1] = yavg - daCoeffs[0] * xavg; // Intercept
43644371
}
43654372

4366-
/**
4367-
Calculate sound speed of a diatomic H (H2) isothermal gaseous atmosphere in
4368-
which the temperature is set by the local equilibrium temperature.
43694373

4370-
@param dTemp double stellar effective temperature
4371-
@param dRad double stellar radius
4372-
@param dSemi double planetary semi-major axis
4373-
4374-
@return sound speed
4375-
*/
4376-
double fdEqH2AtmosphereSoundSpeed(double dTemp, double dRad, double dSemi) {
4377-
4378-
double dCS = 2300.0 * sqrt(dTemp / 5800.0) * pow(dRad / RSUN, 0.25) *
4379-
pow(dSemi / (0.1 * AUM), 0.25);
4380-
return dCS;
4381-
}
4382-
4383-
/**
4384-
Calculate the Roche radius assuming body 0 is the host star using Eqn. 8 from
4385-
Luger et al. (2015)
4386-
4387-
@param body BODY struct
4388-
@param iBody int body indentifier
4389-
4390-
@return Body's Roche radius
4391-
*/
4392-
double fdRocheRadius(BODY *body, int iBody) {
4393-
double dRoche = pow(body[iBody].dMass / (3.0 * body[0].dMass), 1. / 3.) *
4394-
body[iBody].dSemi;
4395-
return dRoche;
4396-
}
4397-
4398-
/**
4399-
Calculate the Bondi radius assuming body 0 is the host star and that the
4400-
planetary atmosphere at the Bondi radius is diatomic H2 at the blackbody
4401-
equilibrium temperature set by thermal emission from the host star adapting
4402-
equation. Adapted from equations 2 and 4 from Owen & Wu (2016)
4403-
4404-
@param body BODY struct
4405-
@param iBody int body indentifier
4406-
4407-
@return Body's Bondi radius
4408-
*/
4409-
double fdBondiRadius(BODY *body, int iBody) {
4410-
double dBondiRadius;
4411-
// Compute sound speed in planet's atmosphere assuming a diatomic H atmosphere
4412-
// assuming body 0 is the star
4413-
if (body[0].bStellar) {
4414-
double dSoundSpeed = fdEqH2AtmosphereSoundSpeed(body[0].dTemperature, body[0].dRadius,
4415-
body[iBody].dSemi);
4416-
dBondiRadius = BIGG * body[iBody].dMass / (2.0 * dSoundSpeed * dSoundSpeed);
4417-
} else {
4418-
dBondiRadius = -1;
4419-
}
4420-
return dBondiRadius;
4421-
}
44224374

44234375
/**
44244376
Calculate the whether or not incident XUV flux exceeds critical flux between

src/atmesc.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,6 @@ double fdInsolation(BODY *, int, int);
227227
int fbDoesWaterEscape(BODY *, EVOLVE *, IO *, int);
228228
double fdPlanetRadius(BODY *, SYSTEM *, int *);
229229
double fdXUVEfficiencyBolmont2016(double);
230-
double fdBondiRadius(BODY *, int);
231-
double fdRocheRadius(BODY *, int);
232230
double fdBondiLimitedDmDt(BODY *, int);
233231
int fbRRCriticalFlux(BODY *, int);
234232
int fbBondiCriticalDmDt(BODY *, int);

src/body.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ double CalcDynEllipEq(BODY *body, int iBody) {
577577
@param dRadXUV radius from center of planet where optical depth of XUV is
578578
unity
579579
*/
580-
double fdLehmerRadius(BODY *body, int iBody) {
580+
double fdLehmerRadius(BODY *body, int iNumBodies, int iBody) {
581581
double dRadXUV, dRoche;
582582

583583
// Set floor for surface pressure to prevent overflow error
@@ -589,7 +589,7 @@ double fdLehmerRadius(BODY *body, int iBody) {
589589
} else {
590590
dRadXUV = body[iBody].dRadSolid;
591591
}
592-
dRoche = fdRocheRadius(body, iBody);
592+
dRoche = fdRocheRadius(body, iNumBodies, iBody);
593593
// printf("%lf %lf %lf %lf
594594
// %lf\n",body[iBody].dPresXUV,body[iBody].dPresSurf,body[iBody].dGravAccel,body[iBody].dEnvelopeMass,dRadXUV);
595595
if (dRadXUV <= 0) {
@@ -607,6 +607,24 @@ double fdLehmerRadius(BODY *body, int iBody) {
607607
return dRadXUV;
608608
}
609609

610+
/**
611+
Calculate sound speed of a diatomic H (H2) isothermal gaseous atmosphere in
612+
which the temperature is set by the local equilibrium temperature.
613+
614+
@param dTemp double stellar effective temperature
615+
@param dRad double stellar radius
616+
@param dSemi double planetary semi-major axis
617+
618+
@return sound speed
619+
*/
620+
double fdEqH2AtmosphereSoundSpeed(double dTemp, double dRad, double dSemi) {
621+
622+
double dCS = 2300.0 * sqrt(dTemp / 5800.0) * pow(dRad / RSUN, 0.25) *
623+
pow(dSemi / (0.1 * AUM), 0.25);
624+
return dCS;
625+
}
626+
627+
610628
/**
611629
Lehmer+ (2017)'s model for the pressure of a planet where it's losing its
612630
atmopshere due to XUV radiation.

src/body.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ double fdRadToMass_GordaSvech99(double);
8989
double fdRadToMass_ReidHawley(double);
9090
double fdRadToMass_Sotin07(double);
9191
double fdMassToRad_LehmerCatling17(double);
92-
double fdLehmerRadius(BODY *, int);
92+
double fdLehmerRadius(BODY *, int, int);
9393
double fdLehmerPres(double, double, double);
9494
double fdThermalTemp(BODY *, int);
95+
double fdEqH2AtmosphereSoundSpeed(double, double, double);
9596

9697
double fdImK2Total(BODY *, int);
9798
double fdImK2Man(BODY *, int);

0 commit comments

Comments
 (0)