Skip to content

Commit

Permalink
Merge pull request #261 from VirtualPlanetaryLaboratory/FlareCleanup
Browse files Browse the repository at this point in the history
Flare cleanup
  • Loading branch information
RoryBarnes authored Feb 2, 2024
2 parents cefa35e + 644257b commit a0b4594
Show file tree
Hide file tree
Showing 17 changed files with 479 additions and 543 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- python-version: '3.10'

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -35,7 +35,7 @@ jobs:
- name: Set up Python
id: setup_python
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: vplanet
environment-file: environment.yml
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/memcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ jobs:
fail-fast: false

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
id: setup_python
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: vplanet
environment-file: environment.yml
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/pip-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
- os: ubuntu-22.04
python-version: '3.6'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: ${{ matrix.python }}
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
CIBW_SKIP: '*-manylinux_i686'
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl

Expand All @@ -62,23 +62,23 @@ jobs:
submodules: true
fetch-depth: 0

- uses: actions/setup-python@v3
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: ${{ matrix.python }}

- name: Build sdist
run: python setup.py sdist

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
path: dist/*.tar.gz

upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: artifact
path: dist
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
fail-fast: false

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
id: setup_python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -48,7 +48,7 @@ jobs:

- name: Check test ouptut created
id: check_test_file
uses: andstor/file-existence-action@v2
uses: andstor/file-existence-action@v3
with:
files: "/home/runner/work/vplanet/vplanet/junit/test-results.xml"
fail: true
Expand All @@ -64,6 +64,6 @@ jobs:
files: junit/test-*.xml

- name: CodeCov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
files: ./.coverage
19 changes: 4 additions & 15 deletions .github/workflows/tests-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ jobs:
strategy:
matrix:
os: [macos-11, macos-12, macos-13]
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11']

fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
id: setup_python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -37,19 +38,7 @@ jobs:
if: steps.setup_python.outcome == 'success'
run: make test

- name: Check test ouptut created
id: check_test_file
uses: andstor/file-existence-action@v2
with:
files: "/home/runner/work/vplanet/vplanet/junit/test-results.xml"
fail: true

- name: Get unique id
uses: Tiryoh/gha-jobid-action@v1
id: jobs

- name: Publish unit test results
uses: EnricoMi/publish-unit-test-result-action/composite@v2
if: always()
with:
files: junit/test-*.xml
12 changes: 4 additions & 8 deletions src/evolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,7 @@ void Evolve(BODY *body, CONTROL *control, FILES *files, MODULE *module,
}

/* Write out initial conditions */
WriteOutput(body, control, files, output, system, update, fnWrite,
control->Evolve.dTime, dDt);
WriteOutput(body, control, files, output, system, update, fnWrite);

/* If Runge-Kutta need to copy actual update to that in
control->Evolve. This transfer all the meta-data about the
Expand Down Expand Up @@ -670,9 +669,7 @@ void Evolve(BODY *body, CONTROL *control, FILES *files, MODULE *module,
/* Halt? */
if (fbCheckHalt(body, control, update, fnUpdate)) {
fdGetUpdateInfo(body, control, system, update, fnUpdate);
WriteOutput(body, control, files, output, system, update, fnWrite,
control->Evolve.dTime,
control->Io.dOutputTime / control->Evolve.nSteps);
WriteOutput(body, control, files, output, system, update, fnWrite);
return;
}

Expand All @@ -686,12 +683,11 @@ void Evolve(BODY *body, CONTROL *control, FILES *files, MODULE *module,
/* Time for Output? */
if (control->Evolve.dTime >= control->Io.dNextOutput) {
control->Evolve.nSteps += nSteps;
WriteOutput(body, control, files, output, system, update, fnWrite,
control->Evolve.dTime,
control->Io.dOutputTime / control->Evolve.nSteps);
WriteOutput(body, control, files, output, system, update, fnWrite);
// Timesteps are synchronized with the output time, so this statement is
// sufficient
control->Io.dNextOutput += control->Io.dOutputTime;
//printf("%d\n",nSteps);
nSteps = 0;
}

Expand Down
58 changes: 27 additions & 31 deletions src/flare.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void BodyCopyFlare(BODY *dest, BODY *src, int foo, int iNumBodies, int iBody) {
dest[iBody].iFlareFFD = src[iBody].iFlareFFD;
dest[iBody].iFlareBandPass = src[iBody].iFlareBandPass;
// dest[iBody].iFlareSlopeUnits = src[iBody].iFlareSlopeUnits;
dest[iBody].dEnergyBin = src[iBody].dEnergyBin;
dest[iBody].iEnergyBin = src[iBody].iEnergyBin;
// dest[iBody].dFlareSlope = src[iBody].dFlareSlope;
// dest[iBody].dFlareYInt = src[iBody].dFlareYInt;
}
Expand All @@ -38,11 +38,11 @@ void ReadFlareEnergyBin(BODY *body,
int iFile) {
// This parameter cannot exist in primary file
int lTmp = -1;
double dTmp;
int iTmp;

AddOptionDouble(files->Infile[iFile].cIn,
AddOptionInt(files->Infile[iFile].cIn,
options->cName,
&dTmp,
&iTmp,
&lTmp,
control->Io.iVerbose);
if (lTmp >= 0) {
Expand All @@ -51,10 +51,10 @@ void ReadFlareEnergyBin(BODY *body,
files->Infile[iFile].cIn,
lTmp,
control->Io.iVerbose);
body[iFile - 1].dEnergyBin = dTmp;
body[iFile - 1].iEnergyBin = iTmp;
UpdateFoundOption(&files->Infile[iFile], options, lTmp, iFile);
} else if (iFile > 0)
body[iFile - 1].dEnergyBin = options->dDefault;
body[iFile - 1].iEnergyBin = (int)options->dDefault;
}

void ReadFlareFFD(BODY *body,
Expand Down Expand Up @@ -525,14 +525,15 @@ void InitializeOptionsFlare(OPTIONS *options, fnReadOption fnRead[]) {
sprintf(options[OPT_LXUVFLARECONST].cDimension, "energy/time");
fnRead[OPT_LXUVFLARECONST] = &ReadLXUVFlareConst;

// XXX Change to iEnergyBin for next major release
sprintf(options[OPT_FLAREENERGYBIN].cName, "dEnergyBin");
sprintf(options[OPT_FLAREENERGYBIN].cDescr,
"Number of energies consider between the minimum and maximum "
"energies to calculate the luminosity by flares");
sprintf(options[OPT_FLAREENERGYBIN].cDefault,
"100 energies between dFlareMinEnergy and dFlareMaxEnergy");
options[OPT_FLAREENERGYBIN].dDefault = 100.0;
options[OPT_FLAREENERGYBIN].iType = 2;
options[OPT_FLAREENERGYBIN].dDefault = 100;
options[OPT_FLAREENERGYBIN].iType = 1;
options[OPT_FLAREENERGYBIN].bMultiFile = 1;
options[OPT_FLAREENERGYBIN].dNeg = 1;
sprintf(options[OPT_FLAREENERGYBIN].cNeg, "None");
Expand Down Expand Up @@ -921,15 +922,15 @@ void InitializeBodyFlare(BODY *body, CONTROL *control, UPDATE *update,
int iBody, int iModule) {
// double *daEnergyERGXUV, *daLXUVFlare, *daFFD, *daEnergyJOUXUV, *daLogEner;
// double *daLogEnerXUV, *daEnergyERG, *daEnergyJOU, *daEnerJOU;
body[iBody].daEnergyERGXUV = malloc(body[iBody].dEnergyBin * sizeof(double));
body[iBody].daLXUVFlare = malloc(body[iBody].dEnergyBin * sizeof(double));
body[iBody].daFFD = malloc(body[iBody].dEnergyBin * sizeof(double));
body[iBody].daEnergyJOUXUV = malloc(body[iBody].dEnergyBin * sizeof(double));
body[iBody].daLogEner = malloc(body[iBody].dEnergyBin * sizeof(double));
body[iBody].daLogEnerXUV = malloc(body[iBody].dEnergyBin * sizeof(double));
body[iBody].daEnergyERG = malloc(body[iBody].dEnergyBin * sizeof(double));
body[iBody].daEnergyJOU = malloc(body[iBody].dEnergyBin * sizeof(double));
body[iBody].daEnerJOU = malloc(body[iBody].dEnergyBin * sizeof(double));
body[iBody].daEnergyERGXUV = malloc((body[iBody].iEnergyBin+1) * sizeof(double));
body[iBody].daLXUVFlare = malloc((body[iBody].iEnergyBin+1) * sizeof(double));
body[iBody].daEnergyJOUXUV = malloc((body[iBody].iEnergyBin+1) * sizeof(double));
body[iBody].daFFD = malloc((body[iBody].iEnergyBin+1) * sizeof(double));
body[iBody].daLogEner = malloc((body[iBody].iEnergyBin+1) * sizeof(double));
body[iBody].daLogEnerXUV = malloc((body[iBody].iEnergyBin+1) * sizeof(double));
body[iBody].daEnergyERG = malloc((body[iBody].iEnergyBin+1) * sizeof(double));
body[iBody].daEnergyJOU = malloc((body[iBody].iEnergyBin+1) * sizeof(double));
body[iBody].daEnerJOU = malloc((body[iBody].iEnergyBin+1) * sizeof(double));

body[iBody].dLXUVFlare = fdLXUVFlare(body, control->Evolve.dTimeStep, iBody);
}
Expand Down Expand Up @@ -1678,12 +1679,11 @@ double fdLXUVFlare(BODY *body, double dDeltaTime, int iBody) {
double dLXUVFlare = 0.0;
double dLogEnergyMinERG, dLogEnergyMaxERG, dEnergyMin, dEnergyMax,
dLogEnergyMin, dLogEnergyMax;
int iEnergyBin = 0;
int i, iLogEnergyMinERG, iLogEnergyMaxERG, iLogEnergyMin, iLogEnergyMax;
double dEnergyMinXUV, dEnergyMaxXUV, dLogEnergyMinXUV;
int iLogEnergyMinERGXUV, iLogEnergyMaxERGXUV, iLogEnergyMinXUV,
iLogEnergyMaxXUV;
double dEnergyStep, dEnergyStepXUV, dEnergyBin;
double dEnergyStep, dEnergyStepXUV;


// ######################### 1. Choosing how to calculate FFD: slopes(age) or
Expand Down Expand Up @@ -1715,10 +1715,6 @@ double fdLXUVFlare(BODY *body, double dDeltaTime, int iBody) {

dLogEnergyMinXUV = fdBandPassXUV(body, iBody, body[iBody].dFlareMinEnergy);

// Defining the array size (dEnergybin) of energies
dEnergyBin = body[iBody].dEnergyBin;
iEnergyBin = (int)dEnergyBin;

// Declaring the XUV Energy arrays of size dEnergyBin
// double daEnergyJOUXUV[iEnergyBin + 1], daLogEnerXUV[iEnergyBin + 1],
// daEnergyERGXUV[iEnergyBin + 1];
Expand All @@ -1738,7 +1734,7 @@ double fdLXUVFlare(BODY *body, double dDeltaTime, int iBody) {

// Defining the energy step used in line 1097, 1099, and 1101 to fill the
// energy arrays
dEnergyStep = (dLogEnergyMaxERG - dLogEnergyMinERG) / iEnergyBin;
dEnergyStep = (dLogEnergyMaxERG - dLogEnergyMinERG) / body[iBody].iEnergyBin;

// Declaring the Kepler Energy arrays of size iEnergyBin
// double daEnergyERG[iEnergyBin + 1], daEnergyJOU[iEnergyBin + 1],
Expand All @@ -1747,7 +1743,7 @@ double fdLXUVFlare(BODY *body, double dDeltaTime, int iBody) {
// ############################ 4. Filling the energy arrays
// ########################################################################

for (i = 0; i < iEnergyBin + 1; i++) {
for (i = 0; i < body[iBody].iEnergyBin + 1; i++) {
// XUV energy (energy_joules)
body[iBody].daEnergyJOUXUV[i] =
fdEnergyJoulesXUV(dLogEnergyMinXUV + i * dEnergyStep);
Expand All @@ -1762,8 +1758,8 @@ double fdLXUVFlare(BODY *body, double dDeltaTime, int iBody) {
body[iBody].dFlareEnergy3 = body[iBody].daEnerJOU[2];
body[iBody].dFlareEnergy4 = body[iBody].daEnerJOU[3];
body[iBody].dFlareEnergyMin = body[iBody].daEnerJOU[0];
body[iBody].dFlareEnergyMid = body[iBody].daEnerJOU[iEnergyBin / 2];
body[iBody].dFlareEnergyMax = body[iBody].daEnerJOU[iEnergyBin];
body[iBody].dFlareEnergyMid = body[iBody].daEnerJOU[(int)(body[iBody].iEnergyBin / 2.)];
body[iBody].dFlareEnergyMax = body[iBody].daEnerJOU[body[iBody].iEnergyBin];
// ############################ 5. Filling the FFD arrays
// ########################################################################

Expand All @@ -1772,7 +1768,7 @@ double fdLXUVFlare(BODY *body, double dDeltaTime, int iBody) {
// double daFFD[iEnergyBin + 1];

// When DAVENPORT or LACY are selected, we have to calculate the FFD first.
for (i = 0; i < iEnergyBin + 1; i++) {
for (i = 0; i < body[iBody].iEnergyBin + 1; i++) {
body[iBody].daFFD[i] = fdFFD(body, iBody, body[iBody].daLogEner[i],
dFlareSlope, dFlareYInt);
}
Expand All @@ -1782,15 +1778,15 @@ double fdLXUVFlare(BODY *body, double dDeltaTime, int iBody) {
body[iBody].dFlareFreq3 = body[iBody].daFFD[2];
body[iBody].dFlareFreq4 = body[iBody].daFFD[3];
body[iBody].dFlareFreqMin = body[iBody].daFFD[0];
body[iBody].dFlareFreqMid = body[iBody].daFFD[iEnergyBin / 2];
body[iBody].dFlareFreqMax = body[iBody].daFFD[iEnergyBin];
body[iBody].dFlareFreqMid = body[iBody].daFFD[(int)(body[iBody].iEnergyBin / 2)];
body[iBody].dFlareFreqMax = body[iBody].daFFD[body[iBody].iEnergyBin];
// ############################ 6. Calculating the XUV luminosity by flares
// ########################################################################
// double daLXUVFlare[iEnergyBin];

// Calculating the luminosity by flares for DAVENPORT or LACY mode
// if the user select to calculate the luminosity using a FFD model
for (i = 0; i < iEnergyBin; i++) {
for (i = 0; i < body[iBody].iEnergyBin; i++) {
body[iBody].daLXUVFlare[i] =
(body[iBody].daEnergyJOUXUV[i + 1] -
body[iBody].daEnergyJOUXUV[i]) *
Expand Down
3 changes: 1 addition & 2 deletions src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -2213,8 +2213,7 @@ void WriteLog(BODY *body, CONTROL *control, FILES *files, MODULE *module,
}

void WriteOutput(BODY *body, CONTROL *control, FILES *files, OUTPUT *output,
SYSTEM *system, UPDATE *update, fnWriteOutput *fnWrite,
double dTime, double dDt) {
SYSTEM *system, UPDATE *update, fnWriteOutput *fnWrite) {
int iBody, iCol, iOut, iSubOut, iExtra = 0, iGrid, iLat, jBody, j;
double dCol[NUMOPT], *dTmp, dGrid[NUMOPT];
FILE *fp;
Expand Down
2 changes: 1 addition & 1 deletion src/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void WriteLogEntry(BODY *, CONTROL *, OUTPUT *, SYSTEM *, UPDATE *,

void InitializeOutputFunctions(MODULE *, OUTPUT *, int);
void WriteOutput(BODY *, CONTROL *, FILES *, OUTPUT *, SYSTEM *, UPDATE *,
fnWriteOutput *, double, double);
fnWriteOutput *);
void WriteLog(BODY *, CONTROL *, FILES *, MODULE *, OPTIONS *, OUTPUT *,
SYSTEM *, UPDATE *, fnUpdateVariable ***, fnWriteOutput *, int);
void InitializeOutput(FILES*,OUTPUT *, fnWriteOutput *);
Expand Down
2 changes: 1 addition & 1 deletion src/vplanet.h
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ struct BODY {
int iFlareBandPass; /**< Option to choose in which band pass the input energy
are*/
int iFlareSlopeUnits; /**< Mode to choose in which units the FFD slopes are*/
double dEnergyBin; /**< Number of energies consider between the minimum and
int iEnergyBin; /**< Number of energies consider between the minimum and
maximum energies to calculate the luminosity by flares*/
double *daEnergyERG;
double *daEnergyJOU;
Expand Down
Loading

0 comments on commit a0b4594

Please sign in to comment.