Skip to content

Commit

Permalink
Added LuminosityInitial to BodyCopyStellar.
Browse files Browse the repository at this point in the history
The code is now memcheck clean!
  • Loading branch information
RoryBarnes committed Apr 18, 2024
1 parent c9c998e commit e592635
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
55 changes: 31 additions & 24 deletions src/atmesc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1446,34 +1446,37 @@ double fdAtmEscXi(BODY *body, int iBody) {
return dXi;
}

double fdKTide(BODY *body, IO *io, int iBody) {
double fdKTide(BODY *body, IO *io, int iNumBodies, int iBody) {
double dKTide;

// For stars and circumbinary planets, assume no Ktide enhancement
if (body[iBody].bBinary && body[iBody].iBodyType == 0) {
dKTide = 1.0;
} else {
if (body[iBody].dAtmEscXi > 1) {
dKTide = (1 - 3 / (2 * body[iBody].dAtmEscXi) +
1 / (2 * pow(body[iBody].dAtmEscXi, 3)));
if (dKTide < body[iBody].dMinKTide) {
dKTide = body[iBody].dMinKTide;
if (iNumBodies > 1) {
if (body[iBody].dAtmEscXi > 1) {
dKTide = (1 - 3 / (2 * body[iBody].dAtmEscXi) +
1 / (2 * pow(body[iBody].dAtmEscXi, 3)));
if (dKTide < body[iBody].dMinKTide) {
dKTide = body[iBody].dMinKTide;
}
} else {
if (!io->baRocheMessage[iBody] && io->iVerbose >= VERBINPUT &&
(!body[iBody].bUseBondiLimited && !body[iBody].bAtmEscAuto)) {
fprintf(stderr,
"WARNING: Roche lobe radius is larger than %s's XUV radius. "
"Evolution may not be accurate.\n",
body[iBody].cName);
fprintf(stderr, "Consider setting bUseBondiLimited = 1 or bAtmEscAuto "
"= 1 to limit envelope mass loss.\n");
io->baRocheMessage[iBody] = 1;
}
// Fix dKTide to prevent infs when in Roche Lobe overflow
dKTide = 1.0;
}
} else {
if (!io->baRocheMessage[iBody] && io->iVerbose >= VERBINPUT &&
(!body[iBody].bUseBondiLimited && !body[iBody].bAtmEscAuto)) {
fprintf(stderr,
"WARNING: Roche lobe radius is larger than %s's XUV radius. "
"Evolution may not be accurate.\n",
body[iBody].cName);
fprintf(stderr, "Consider setting bUseBondiLimited = 1 or bAtmEscAuto "
"= 1 to limit envelope mass loss.\n");
io->baRocheMessage[iBody] = 1;
}
// Fix dKTide to prevent infs when in Roche Lobe overflow
dKTide = 1.0;
}
// body[iBody].dKTide = 1.0;
}

return dKTide;
Expand Down Expand Up @@ -1728,7 +1731,7 @@ void fnPropsAuxAtmEsc(BODY *body, EVOLVE *evolve, IO *io, UPDATE *update,
body[iBody].dBondiRadius = fdBondiRadius(body, iBody);
body[iBody].dRocheRadius = fdRocheRadius(body, evolve->iNumBodies, iBody);
body[iBody].dAtmEscXi = fdAtmEscXi(body, iBody);
body[iBody].dKTide = fdKTide(body, io, iBody);
body[iBody].dKTide = fdKTide(body, io, evolve->iNumBodies, iBody);

// The XUV flux
if (body[iBody].bCalcFXUV) {
Expand Down Expand Up @@ -3424,11 +3427,15 @@ Modifier for H Ref Flux to include oxygen drag at a snapshot in time
void WriteHRefODragMod(BODY *body, CONTROL *control, OUTPUT *output,
SYSTEM *system, UNITS *units, UPDATE *update, int iBody,
double *dTmp, char cUnit[]) {
double rat = (body[iBody].dCrossoverMass / ATOMMASS - QOH) /
(body[iBody].dCrossoverMass / ATOMMASS - 1.);
double XO = fdAtomicOxygenMixingRatio(body[iBody].dSurfaceWaterMass,
body[iBody].dOxygenMass);
*dTmp = pow(1. + (XO / (1. - XO)) * QOH * rat, -1);
if (body[iBody].dCrossoverMass / ATOMMASS - 1. != 0) {
double rat = (body[iBody].dCrossoverMass / ATOMMASS - QOH) /
(body[iBody].dCrossoverMass / ATOMMASS - 1.);
double XO = fdAtomicOxygenMixingRatio(body[iBody].dSurfaceWaterMass,
body[iBody].dOxygenMass);
*dTmp = pow(1. + (XO / (1. - XO)) * QOH * rat, -1);
} else {
*dTmp = -1;
}
strcpy(cUnit, "");
}

Expand Down
2 changes: 1 addition & 1 deletion src/stellar.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void BodyCopyStellar(BODY *dest, BODY *src, int foo, int iNumBodies,
dest[iBody].dLXUV = src[iBody].dLXUV;
dest[iBody].bRossbyCut = src[iBody].bRossbyCut;
dest[iBody].bEvolveRG = src[iBody].bEvolveRG;
dest[iBody].dLuminosityInitial = src[iBody].dLuminosityInitial;
dest[iBody].dLuminosityAmplitude = src[iBody].dLuminosityAmplitude;
dest[iBody].dLuminosityFrequency = src[iBody].dLuminosityFrequency;
dest[iBody].dLuminosityPhase = src[iBody].dLuminosityPhase;
Expand Down Expand Up @@ -1524,7 +1525,6 @@ double fdTemperature(BODY *body, SYSTEM *system, int *iaBody) {
}
}
if (body[iaBody[0]].iStellarModel == STELLAR_MODEL_SINEWAVE) {
printf("%lf\n",body[iaBody[0]].dLuminosity);
foo = fdEffectiveTemperature(body,iaBody[0]);
return foo;
}
Expand Down

0 comments on commit e592635

Please sign in to comment.