Skip to content

Commit 1a19756

Browse files
authored
Merge pull request #172 from t-barnard/tayler_branch
Fix Chemistry (Speed and Display) - Tayler Barnard
2 parents ca9f01f + 8f3a9b7 commit 1a19756

File tree

6 files changed

+59
-48
lines changed

6 files changed

+59
-48
lines changed

include/chemistry.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ class Chemistry {
104104
int read_chemistry_file(Neutrals neutrals,
105105
Ions ions);
106106

107-
reaction_type interpret_reaction_line(Neutrals neutrals,
108-
Ions ions,
109-
std::vector<std::string> line,
110-
json headers);
111-
112-
void find_species_id(std::string name,
113-
Neutrals neutrals,
114-
Ions ions,
107+
reaction_type interpret_reaction_line(const Neutrals &neutrals,
108+
const Ions &ions,
109+
const std::vector<std::string> &line,
110+
const json &headers);
111+
112+
void find_species_id(const std::string &name,
113+
const Neutrals &neutrals,
114+
const Ions &ions,
115115
int &id_,
116116
bool &IsNeutral);
117117

include/ions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class Ions {
304304
\brief Get the ID of the ion species with the given name
305305
\param name a string that describes the species
306306
**/
307-
int get_species_id(std::string name);
307+
int get_species_id(const std::string &name)const;
308308

309309
/**********************************************************************
310310
\brief Calculates the electric field

include/neutrals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ class Neutrals {
453453
\brief Get the species ID number (int) given the species name (string)
454454
\param name string holding the species name (e.g., "O+")
455455
**/
456-
int get_species_id(std::string name);
456+
int get_species_id(const std::string &name) const;
457457

458458
/*****************************************************************************
459459
\brief Checks for nans and +/- infinities in density, temp, and velocity

src/chemistry.cpp

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
Chemistry::Chemistry(Neutrals neutrals,
2424
Ions ions) {
2525

26-
std::string function = "Chemistry::Chemistry";
27-
static int iFunction = -1;
28-
report.enter(function, iFunction);
26+
std::string function = "Chemistry::Chemistry"; //record current function
27+
static int iFunction = -1; //usually -1 for report function
28+
report.enter(function, iFunction); //keeps track of functions for: verbose levels, etc.
2929

30-
if (read_chemistry_file(neutrals, ions) > 0) {
30+
if (read_chemistry_file(neutrals, ions) > 0) { //searching for valid chem file
3131
report.print(0, "Could not read chemistry file!");
32-
throw std::invalid_argument( "Invalid chemistry file" );
32+
throw std::invalid_argument( "Invalid chemistry file" ); //throw & catch can be used for error handling
3333
}
3434

35-
report.exit(function);
35+
report.exit(function);//done with this function, see report.cpp
3636
return;
3737
}
3838

@@ -414,8 +414,8 @@ int Chemistry::read_chemistry_file(Neutrals neutrals,
414414
throw std::invalid_argument( "Invalid chemistry file" );
415415
}
416416

417-
int iRate_ = headers["rate"];
418-
int iLoss1_ = headers["loss1"];
417+
int iRate_ = headers["rate"];//record column index of reaction rate in csv file
418+
int iLoss1_ = headers["loss1"];//record column index of loss1
419419

420420
if (!check_chemistry_file(headers, csv, report)) {
421421
iErr = 1;
@@ -425,7 +425,7 @@ int Chemistry::read_chemistry_file(Neutrals neutrals,
425425
nReactions = 0;
426426

427427
// Skip 2 lines of headers!
428-
for (int iLine = 2; iLine < nLines; iLine++) {
428+
for (int iLine = 2; iLine < nLines; iLine++) {//run for [54] reactions
429429
// Some final rows can have comments in them, so we want to
430430
// skip anything where the length of the string in column 2
431431
// is == 0:
@@ -444,7 +444,7 @@ int Chemistry::read_chemistry_file(Neutrals neutrals,
444444
if (headers.contains("uncertainty")) {
445445
if (csv[iLine][headers["uncertainty"]].length() > 0) {
446446
// uncertainty column exists!
447-
json values = input.get_perturb_values();
447+
json values = input.get_perturb_values(); //(inputs.cpp)
448448

449449
if (values.contains("Chemistry")) {
450450
json chemistryList = values["Chemistry"];
@@ -512,7 +512,7 @@ int Chemistry::read_chemistry_file(Neutrals neutrals,
512512
reactions.push_back(reaction);
513513
nReactions++;
514514
}
515-
}
515+
} //end run through reactions------------------------------------------------------------------------------
516516
}
517517
} else {
518518
report.print(0, "Could not open good chemistry file!");
@@ -529,10 +529,10 @@ int Chemistry::read_chemistry_file(Neutrals neutrals,
529529
// Interpret a comma separated line of the chemical reaction file
530530
// -----------------------------------------------------------------------------
531531

532-
Chemistry::reaction_type Chemistry::interpret_reaction_line(Neutrals neutrals,
533-
Ions ions,
534-
std::vector<std::string> line,
535-
json headers) {
532+
Chemistry::reaction_type Chemistry::interpret_reaction_line(const Neutrals &neutrals,
533+
const Ions &ions,
534+
const std::vector<std::string> &line,
535+
const json &headers) {
536536

537537
std::string function = "Chemistry::interpret_reaction_line";
538538
static int iFunction = -1;
@@ -545,9 +545,9 @@ Chemistry::reaction_type Chemistry::interpret_reaction_line(Neutrals neutrals,
545545
bool IsNeutral;
546546

547547
// Losses (left side) first:
548-
reaction.nLosses = 0;
548+
reaction.nLosses = 0; //nlosses = # of losses in reaction
549549

550-
for (i = headers["loss1"]; i < headers["loss3"]; i++) {
550+
for (i = headers["loss1"]; i < headers["loss3"]; i++) { // loss 1,2,3
551551
find_species_id(line[i], neutrals, ions, id_, IsNeutral);
552552

553553
if (id_ >= 0) {
@@ -634,9 +634,9 @@ Chemistry::reaction_type Chemistry::interpret_reaction_line(Neutrals neutrals,
634634
// Match a string to the neutral or ion species
635635
// -----------------------------------------------------------------------------
636636

637-
void Chemistry::find_species_id(std::string name,
638-
Neutrals neutrals,
639-
Ions ions,
637+
void Chemistry::find_species_id(const std::string &name,
638+
const Neutrals &neutrals,
639+
const Ions &ions,
640640
int &id_,
641641
bool &IsNeutral) {
642642

@@ -647,13 +647,13 @@ void Chemistry::find_species_id(std::string name,
647647
int iSpecies;
648648
IsNeutral = false;
649649

650-
id_ = neutrals.get_species_id(name);
650+
id_ = neutrals.get_species_id(name); //from earth.in, starts at 0 w/ first species under "#NEUTRALS",(neutrals.cpp)
651651

652652
if (id_ > -1)
653653
IsNeutral = true;
654654

655655
else
656-
id_ = ions.get_species_id(name);
656+
id_ = ions.get_species_id(name);//from earth.in, starts at 0 w/ first species under "#IONS",(ions.cpp)
657657

658658
report.exit(function);
659659
return;
@@ -670,28 +670,39 @@ void Chemistry::display_reaction(Chemistry::reaction_type reaction) {
670670
std::cout << "Number of Losses : " << reaction.nLosses << "\n";
671671
std::cout << "Number of Sources : " << reaction.nSources << "\n";
672672

673-
for (i = 0; i < reaction.nLosses; i++)
674-
std::cout << reaction.losses_names[i] << " + ";
675-
676-
std::cout << " -> ";
673+
for (i = 0; i < reaction.nLosses; i++) // First line for reaction
674+
if (i < reaction.nLosses - 1) {//
675+
std::cout << reaction.losses_names[i] << " + ";
676+
} else {//
677+
std::cout << reaction.losses_names[i] << " -> ";
678+
}
677679

678680
for (i = 0; i < reaction.nSources; i++)
679-
std::cout << reaction.sources_names[i] << " + ";
680-
681-
std::cout << " ( RR : " << reaction.rate << ")\n";
681+
if (i < reaction.nSources - 1) {//
682+
std::cout << reaction.sources_names[i] << " + ";
683+
} else {//
684+
std::cout << reaction.sources_names[i] << " (RR : " << reaction.rate << ")\n";
685+
}
682686

683-
for (i = 0; i < reaction.nLosses; i++)
684-
std::cout << reaction.losses_ids[i]
687+
for (i = 0; i < reaction.nLosses; i++)//Second line for reaction
688+
if (i < reaction.nLosses - 1) {//
689+
std::cout << reaction.losses_ids[i]
685690
<< "(" << reaction.losses_IsNeutral[i] << ")" << " + ";
686-
687-
std::cout << " -> ";
691+
} else {//
692+
std::cout << reaction.losses_ids[i]
693+
<< "(" << reaction.losses_IsNeutral[i] << ")" << " -> ";
694+
}
688695

689696
for (i = 0; i < reaction.nSources; i++)
690-
std::cout << reaction.sources_ids[i]
697+
if (i < reaction.nSources - 1) {//
698+
std::cout << reaction.sources_ids[i]
699+
<< "(" << reaction.sources_IsNeutral[i] << ")" << " + ";
700+
} else {//
701+
std::cout << reaction.sources_ids[i]
691702
<< "(" << reaction.sources_IsNeutral[i]
692-
<< ")" << " + ";
703+
<< ")" << " (RR : " << reaction.rate << ")\n";
704+
}
693705

694-
std::cout << " ( RR : " << reaction.rate << ")\n";
695706

696707
if (reaction.type > 0) {
697708
std::cout << "Temperature Dependence: ("

src/ions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ void Ions::fill_electrons() {
495495
// Will return nSpecies for electrons
496496
//----------------------------------------------------------------------
497497

498-
int Ions::get_species_id(std::string name) {
498+
int Ions::get_species_id(const std::string &name) const{
499499

500500
std::string function = "Ions::get_species_id";
501501
static int iFunction = -1;

src/neutrals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ bool Neutrals::check_for_nonfinites(std::string location) {
397397
// This will return -1 if the species is not found or name is empty
398398
//----------------------------------------------------------------------
399399

400-
int Neutrals::get_species_id(std::string name) {
400+
int Neutrals::get_species_id(const std::string &name) const {
401401

402402
std::string function = "Neutrals::get_species_id";
403403
static int iFunction = -1;

0 commit comments

Comments
 (0)