23
23
Chemistry::Chemistry (Neutrals neutrals,
24
24
Ions ions) {
25
25
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.
29
29
30
- if (read_chemistry_file (neutrals, ions) > 0 ) {
30
+ if (read_chemistry_file (neutrals, ions) > 0 ) { // searching for valid chem file
31
31
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
33
33
}
34
34
35
- report.exit (function);
35
+ report.exit (function);// done with this function, see report.cpp
36
36
return ;
37
37
}
38
38
@@ -414,8 +414,8 @@ int Chemistry::read_chemistry_file(Neutrals neutrals,
414
414
throw std::invalid_argument ( " Invalid chemistry file" );
415
415
}
416
416
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
419
419
420
420
if (!check_chemistry_file (headers, csv, report)) {
421
421
iErr = 1 ;
@@ -425,7 +425,7 @@ int Chemistry::read_chemistry_file(Neutrals neutrals,
425
425
nReactions = 0 ;
426
426
427
427
// 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
429
429
// Some final rows can have comments in them, so we want to
430
430
// skip anything where the length of the string in column 2
431
431
// is == 0:
@@ -444,7 +444,7 @@ int Chemistry::read_chemistry_file(Neutrals neutrals,
444
444
if (headers.contains (" uncertainty" )) {
445
445
if (csv[iLine][headers[" uncertainty" ]].length () > 0 ) {
446
446
// uncertainty column exists!
447
- json values = input.get_perturb_values ();
447
+ json values = input.get_perturb_values (); // (inputs.cpp)
448
448
449
449
if (values.contains (" Chemistry" )) {
450
450
json chemistryList = values[" Chemistry" ];
@@ -512,7 +512,7 @@ int Chemistry::read_chemistry_file(Neutrals neutrals,
512
512
reactions.push_back (reaction);
513
513
nReactions++;
514
514
}
515
- }
515
+ } // end run through reactions------------------------------------------------------------------------------
516
516
}
517
517
} else {
518
518
report.print (0 , " Could not open good chemistry file!" );
@@ -529,10 +529,10 @@ int Chemistry::read_chemistry_file(Neutrals neutrals,
529
529
// Interpret a comma separated line of the chemical reaction file
530
530
// -----------------------------------------------------------------------------
531
531
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) {
536
536
537
537
std::string function = " Chemistry::interpret_reaction_line" ;
538
538
static int iFunction = -1 ;
@@ -545,9 +545,9 @@ Chemistry::reaction_type Chemistry::interpret_reaction_line(Neutrals neutrals,
545
545
bool IsNeutral;
546
546
547
547
// Losses (left side) first:
548
- reaction.nLosses = 0 ;
548
+ reaction.nLosses = 0 ; // nlosses = # of losses in reaction
549
549
550
- for (i = headers[" loss1" ]; i < headers[" loss3" ]; i++) {
550
+ for (i = headers[" loss1" ]; i < headers[" loss3" ]; i++) { // loss 1,2,3
551
551
find_species_id (line[i], neutrals, ions, id_, IsNeutral);
552
552
553
553
if (id_ >= 0 ) {
@@ -634,9 +634,9 @@ Chemistry::reaction_type Chemistry::interpret_reaction_line(Neutrals neutrals,
634
634
// Match a string to the neutral or ion species
635
635
// -----------------------------------------------------------------------------
636
636
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,
640
640
int &id_,
641
641
bool &IsNeutral) {
642
642
@@ -647,13 +647,13 @@ void Chemistry::find_species_id(std::string name,
647
647
int iSpecies;
648
648
IsNeutral = false ;
649
649
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)
651
651
652
652
if (id_ > -1 )
653
653
IsNeutral = true ;
654
654
655
655
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)
657
657
658
658
report.exit (function);
659
659
return ;
@@ -670,28 +670,39 @@ void Chemistry::display_reaction(Chemistry::reaction_type reaction) {
670
670
std::cout << " Number of Losses : " << reaction.nLosses << " \n " ;
671
671
std::cout << " Number of Sources : " << reaction.nSources << " \n " ;
672
672
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
+ }
677
679
678
680
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
+ }
682
686
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]
685
690
<< " (" << reaction.losses_IsNeutral [i] << " )" << " + " ;
686
-
687
- std::cout << " -> " ;
691
+ } else {//
692
+ std::cout << reaction.losses_ids [i]
693
+ << " (" << reaction.losses_IsNeutral [i] << " )" << " -> " ;
694
+ }
688
695
689
696
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]
691
702
<< " (" << reaction.sources_IsNeutral [i]
692
- << " )" << " + " ;
703
+ << " )" << " (RR : " << reaction.rate << " )\n " ;
704
+ }
693
705
694
- std::cout << " ( RR : " << reaction.rate << " )\n " ;
695
706
696
707
if (reaction.type > 0 ) {
697
708
std::cout << " Temperature Dependence: ("
0 commit comments