Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error flow catching in code #142

Merged
merged 24 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cd2a828
FEAT: iErr (int) to didWork (bool)
aaronjridley Nov 10, 2023
edc6d9f
FEAT: iErr (int) to didWork (bool)
aaronjridley Nov 10, 2023
c0808cc
FEAT: iErr (int) to didWork (bool)
aaronjridley Nov 10, 2023
b504091
FEAT: iErr (int) to didWork (bool)
aaronjridley Nov 10, 2023
a259758
FEAT: iErr (int) to didWork (bool)
aaronjridley Nov 10, 2023
0353a3b
FEAT: use lower case to check for conditions
aaronjridley Nov 10, 2023
6ae7401
FEAT: function to make lower case
aaronjridley Nov 10, 2023
2a539e7
FEAT: add cmember to filename
aaronjridley Nov 10, 2023
a971d86
BUG: MSIS has temps below 200
aaronjridley Nov 10, 2023
89e8e13
FEAT: add get integer settings from 2 keys
aaronjridley Nov 10, 2023
600ca02
FEAT: iErr (int) to didWork (bool)
aaronjridley Nov 10, 2023
6cb1f15
FEAT: use get_settings to check for bad keys
aaronjridley Nov 10, 2023
8fe24bb
BUG: only 0th grid proc output and add cMember
aaronjridley Nov 10, 2023
ff9ba21
FEAT: better restart test with ensembles
aaronjridley Nov 10, 2023
7f73374
FEAT: read and plot log files
aaronjridley Nov 10, 2023
09024c7
BUG: didWork needs to be initialized
aaronjridley Nov 10, 2023
dcd15ff
BUG: catch bad dts
aaronjridley Nov 10, 2023
63e682b
BUG: return 0, since this is catch on other side
aaronjridley Nov 10, 2023
b162cfc
BUG: don't write header on restart
aaronjridley Nov 10, 2023
dd21954
BUG: on restart append to the log file
aaronjridley Nov 10, 2023
772726c
BUG: new exchange works with cubesphere
aaronjridley Nov 10, 2023
df231a0
BUG: crashes if trying to write std
aaronjridley Nov 10, 2023
89b227d
Merge branch 'develop' into error_flow
aaronjridley Nov 14, 2023
196e938
STY: astyle
aaronjridley Nov 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions include/advance.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
**/


int advance(Planets &planet,
Grid &gGrid,
Times &time,
Euv &euv,
Neutrals &neutrals,
Ions &ions,
Chemistry &chemistry,
Electrodynamics &electrodynamics,
Indices &indices,
Logfile &logfile);
bool advance(Planets &planet,
Grid &gGrid,
Times &time,
Euv &euv,
Neutrals &neutrals,
Ions &ions,
Chemistry &chemistry,
Electrodynamics &electrodynamics,
Indices &indices,
Logfile &logfile);

#endif // INCLUDE_ADVANCE_H_
14 changes: 7 additions & 7 deletions include/calc_euv.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
//
// -------------------------------------------------------------------------

int calc_euv(Planets planet,
Grid grid,
Times time,
Euv &euv,
Neutrals &neutrals,
Ions &ions,
Indices indices);
bool calc_euv(Planets planet,
Grid grid,
Times time,
Euv &euv,
Neutrals &neutrals,
Ions &ions,
Indices indices);

void calc_ionization_heating(Euv euv,
Neutrals &neutrals,
Expand Down
8 changes: 4 additions & 4 deletions include/electrodynamics.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class Electrodynamics {
\param ions Going to set the potential and aurora
**/

int update(Planets planet,
Grid gGrid,
Times time,
Ions &ions);
bool update(Planets planet,
Grid gGrid,
Times time,
Ions &ions);

/**************************************************************
\brief used in main.cpp to ensure electrodynamics times and
Expand Down
11 changes: 5 additions & 6 deletions include/euv.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,28 @@ class Euv {
\param time The times within the model (dt is needed)
\param indices Need the F107 and F107a
**/
int euvac(Times time, Indices indices);
bool euvac(Times time, Indices indices);

/**********************************************************************
\brief Compute the EUV spectrum given F107 and F107a
\param time The times within the model (dt is needed)
\param indices Need the F107 and F107a
**/
int solomon_hfg(Times time, Indices indices);
bool solomon_hfg(Times time, Indices indices);

/**********************************************************************
\brief Compute the EUV spectrum given F107 and F107a (new version)
\param time The times within the model (dt is needed)
\param indices Need the F107 and F107a
**/
int neuvac(Times time, Indices indices);
bool neuvac(Times time, Indices indices);

/**********************************************************************
\brief Scale the EUV spectrum given the star - planet distance
\param planet needed to compute the star - planet distance
\param time Needed to compute orbital position around star
**/
int scale_from_1au(Planets planet, Times time);
void scale_from_1au(Planets planet, Times time);

/**********************************************************************
\brief Pairs rows in the EUV CSV file with neutral and ions
Expand All @@ -142,8 +142,7 @@ class Euv {
\param neutrals Needs names of the neutrals, stores lines in Neutrals
\param ions Needs names of the ions
**/
bool pair_euv(Neutrals &neutrals,
Ions ions);
bool pair_euv(Neutrals &neutrals, Ions ions);

/**********************************************************************
\brief Check to see if internal state of class is ok
Expand Down
1 change: 1 addition & 0 deletions include/inputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class Inputs {

std::string get_settings_str(std::string key1);
std::string get_settings_str(std::string key1, std::string key2);
int get_settings(std::string key1, std::string key2);
bool check_settings(std::string key1, std::string key2);
bool check_settings(std::string key1);
std::string check_settings_str(std::string key1, std::string key2);
Expand Down
6 changes: 3 additions & 3 deletions include/neutrals.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ class Neutrals {
\param time contains information about the current time
\param indices used to help set initial conditions
**/
int initial_conditions(Grid grid,
Times time,
Indices indices);
bool initial_conditions(Grid grid,
Times time,
Indices indices);

/**********************************************************************
\brief temporary function to set neutral densities with in the model
Expand Down
18 changes: 9 additions & 9 deletions include/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,22 @@ class OutputContainer {
/**********************************************************************
\brief write a file with the information in the container
**/
void write();
bool write();

/**********************************************************************
\brief write a json header file with the information in the container
**/
int write_container_header();
bool write_container_header();

/**********************************************************************
\brief write a binary file with the information in the container
**/
int write_container_binary();
bool write_container_binary();

/**********************************************************************
\brief write a netcdf file with the information in the container
**/
int write_container_netcdf();
bool write_container_netcdf();

/**********************************************************************
\brief read from a file an load into the container
Expand Down Expand Up @@ -222,11 +222,11 @@ class OutputContainer {
\param planet information about the planet
**/

int output(const Neutrals &neutrals,
const Ions &ions,
const Grid &grid,
Times time,
const Planets &planet);
bool output(const Neutrals &neutrals,
const Ions &ions,
const Grid &grid,
Times time,
const Planets &planet);

void output_binary_3d(std::ofstream &binary,
arma_cube value);
Expand Down
7 changes: 7 additions & 0 deletions include/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ struct mat_2x2{
arma_mat A22;
};

// -----------------------------------------------------------------------------
// add cMember into a string just before last period
// -----------------------------------------------------------------------------

std::string add_cmember(std::string inString);


// ----------------------------------------------------------------------
// Display an armadillo vector
// ----------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions include/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "aether.h"
using namespace arma;

std::string mklower(std::string inString);
std::string mkupper(std::string inString);

void copy_cube_to_array(arma_cube cube_in,
float *array_out);

Expand Down
120 changes: 66 additions & 54 deletions src/advance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
// so many inputs because it alters all of the states in the model.
// -----------------------------------------------------------------------------

int advance(Planets &planet,
Grid &gGrid,
Times &time,
Euv &euv,
Neutrals &neutrals,
Ions &ions,
Chemistry &chemistry,
Electrodynamics &electrodynamics,
Indices &indices,
Logfile &logfile) {

int iErr = 0;
bool advance(Planets &planet,
Grid &gGrid,
Times &time,
Euv &euv,
Neutrals &neutrals,
Ions &ions,
Chemistry &chemistry,
Electrodynamics &electrodynamics,
Indices &indices,
Logfile &logfile) {

bool didWork = true;

std::string function = "advance";
static int iFunction = -1;
Expand All @@ -38,14 +38,13 @@ int advance(Planets &planet,
gGrid.calc_sza(planet, time);
neutrals.calc_mass_density();
neutrals.calc_mean_major_mass();

neutrals.calc_specific_heat();
neutrals.calc_concentration();
neutrals.calc_pressure();
neutrals.calc_bulk_velocity();
neutrals.calc_kappa_eddy();

neutrals.calc_cMax();

precision_t dtNeutral = neutrals.calc_dt(gGrid);
precision_t dtIon = 100.0;
time.calc_dt(dtNeutral, dtIon);
Expand All @@ -57,68 +56,81 @@ int advance(Planets &planet,
// first

neutrals.calc_scale_height(gGrid);
neutrals.set_bcs(gGrid, time, indices);
didWork = neutrals.set_bcs(gGrid, time, indices);

if (input.get_nAltsGeo() > 1)
neutrals.advect_vertical(gGrid, time);

// ------------------------------------
// Calculate source terms next:

iErr = calc_euv(planet,
gGrid,
time,
euv,
neutrals,
ions,
indices);
if (didWork)
didWork = calc_euv(planet,
gGrid,
time,
euv,
neutrals,
ions,
indices);

iErr = electrodynamics.update(planet,
gGrid,
time,
ions);
calc_ion_neutral_coll_freq(neutrals, ions);
ions.calc_ion_drift(neutrals, gGrid, time.get_dt());
if (didWork)
didWork = electrodynamics.update(planet,
gGrid,
time,
ions);

calc_aurora(gGrid, neutrals, ions);
if (didWork) {
calc_ion_neutral_coll_freq(neutrals, ions);
ions.calc_ion_drift(neutrals, gGrid, time.get_dt());

// Calculate some neutral source terms:
neutrals.calc_conduction(gGrid, time);
chemistry.calc_chemistry(neutrals, ions, time, gGrid);
calc_aurora(gGrid, neutrals, ions);

if (input.get_O_cooling())
neutrals.calc_O_cool();
// Calculate some neutral source terms:
neutrals.calc_conduction(gGrid, time);
chemistry.calc_chemistry(neutrals, ions, time, gGrid);

if (input.get_NO_cooling())
neutrals.calc_NO_cool();
if (input.get_O_cooling())
neutrals.calc_O_cool();

neutrals.calc_conduction(gGrid, time);
chemistry.calc_chemistry(neutrals, ions, time, gGrid);
if (input.get_NO_cooling())
neutrals.calc_NO_cool();

neutrals.vertical_momentum_eddy(gGrid);
calc_ion_collisions(neutrals, ions);
calc_neutral_friction(neutrals);
neutrals.calc_conduction(gGrid, time);
chemistry.calc_chemistry(neutrals, ions, time, gGrid);

neutrals.add_sources(time);
neutrals.vertical_momentum_eddy(gGrid);
calc_ion_collisions(neutrals, ions);
calc_neutral_friction(neutrals);

ions.calc_ion_temperature(neutrals, gGrid, time);
ions.calc_electron_temperature(neutrals, gGrid);
neutrals.add_sources(time);

neutrals.exchange(gGrid);
ions.calc_ion_temperature(neutrals, gGrid, time);
ions.calc_electron_temperature(neutrals, gGrid);

time.increment_time();
if (input.get_is_cubesphere())
neutrals.exchange(gGrid);
else
neutrals.exchange_old(gGrid);

if (time.check_time_gate(input.get_dt_write_restarts())) {
report.print(3, "Writing restart files");
neutrals.restart_file(input.get_restartout_dir(), DoWrite);
ions.restart_file(input.get_restartout_dir(), DoWrite);
time.restart_file(input.get_restartout_dir(), DoWrite);
time.increment_time();

if (time.check_time_gate(input.get_dt_write_restarts())) {
report.print(3, "Writing restart files");
neutrals.restart_file(input.get_restartout_dir(), DoWrite);
ions.restart_file(input.get_restartout_dir(), DoWrite);
time.restart_file(input.get_restartout_dir(), DoWrite);
}
}

iErr = output(neutrals, ions, gGrid, time, planet);
if (didWork)
didWork = output(neutrals, ions, gGrid, time, planet);

if (didWork)
didWork = logfile.write_logfile(indices, neutrals, ions, gGrid, time);

logfile.write_logfile(indices, neutrals, ions, gGrid, time);
if (!didWork)
report.error("Error in Advance!");

report.exit(function);
return iErr;
return didWork;
}
Loading
Loading