diff --git a/ChemistryLib/CreateOutput.cpp b/ChemistryLib/CreateOutput.cpp index 310a2037b74c3fa60b55521e3156ae17c85fd95e..8fb9b53b4b32ad4edeab5bb3c89a0003a99572dc 100644 --- a/ChemistryLib/CreateOutput.cpp +++ b/ChemistryLib/CreateOutput.cpp @@ -7,7 +7,9 @@ * */ +#include <algorithm> #include <numeric> + #include "CreateOutput.h" namespace ChemistryLib @@ -21,20 +23,16 @@ std::unique_ptr<Output> createOutput( // Mark which phreeqc output items will be held. std::vector<OutputItem> accepted_items{{"pH", ItemType::pH}, {"pe", ItemType::pe}}; - for (auto const& component : components) - { - accepted_items.emplace_back(component.name, ItemType::Component); - } - for (auto const& equilibrium_phase : equilibrium_phases) - { - accepted_items.emplace_back(equilibrium_phase.name, - ItemType::EquilibriumPhase); - } - for (auto const& kinetic_reactant : kinetic_reactants) - { - accepted_items.emplace_back(kinetic_reactant.name, - ItemType::KineticReactant); - } + + auto accepted_item = [](auto const& item) { + return OutputItem(item.name, item.item_type); + }; + std::transform(components.begin(), components.end(), + std::back_inserter(accepted_items), accepted_item); + std::transform(equilibrium_phases.begin(), equilibrium_phases.end(), + std::back_inserter(accepted_items), accepted_item); + std::transform(kinetic_reactants.begin(), kinetic_reactants.end(), + std::back_inserter(accepted_items), accepted_item); // Record ids of which phreeqc output items will be dropped. BasicOutputSetups basic_output_setups(project_file_name); @@ -58,7 +56,7 @@ std::unique_ptr<Output> createOutput( dvalue_item_id += 2 * (i + 1); } - return std::make_unique<Output>(basic_output_setups, + return std::make_unique<Output>(std::move(basic_output_setups), std::move(accepted_items), std::move(dropped_item_ids)); } diff --git a/ChemistryLib/Output.h b/ChemistryLib/Output.h index 3af4978de90cd5d7235156e3795579c6a7c70878..cc5b1f2ea576b66e4114b7147005df78374ca2d8 100644 --- a/ChemistryLib/Output.h +++ b/ChemistryLib/Output.h @@ -76,10 +76,10 @@ struct OutputItem struct Output { - Output(BasicOutputSetups basic_output_setups_, + Output(BasicOutputSetups&& basic_output_setups_, std::vector<OutputItem>&& accepted_items_, std::vector<int>&& dropped_item_ids_) - : basic_output_setups(basic_output_setups_), + : basic_output_setups(std::move(basic_output_setups_)), accepted_items(std::move(accepted_items_)), dropped_item_ids(std::move(dropped_item_ids_)) { diff --git a/ChemistryLib/PhreeqcIO.h b/ChemistryLib/PhreeqcIO.h index 10e431d4bac321f953b642c459d5749a353ab01d..62d80eb31722707029d17d999bb007d36f2ea97c 100644 --- a/ChemistryLib/PhreeqcIO.h +++ b/ChemistryLib/PhreeqcIO.h @@ -80,6 +80,6 @@ private: std::unique_ptr<Output> const _output; std::vector<std::pair<int, std::string>> const& _process_id_to_component_name_map; - double _dt; + double _dt = std::numeric_limits<double>::quiet_NaN(); }; } // namespace ChemistryLib diff --git a/ChemistryLib/PhreeqcIOData/AqueousSolution.h b/ChemistryLib/PhreeqcIOData/AqueousSolution.h index 42844d77a7edb67a73f0acb6331fd6cdc7cdd6a7..403be34c2d0f19efcd0b5fa490cb06938c6b7076 100644 --- a/ChemistryLib/PhreeqcIOData/AqueousSolution.h +++ b/ChemistryLib/PhreeqcIOData/AqueousSolution.h @@ -13,6 +13,8 @@ #include <string> #include <vector> +#include "ChemistryLib/Output.h" + namespace ChemistryLib { struct Component @@ -20,7 +22,8 @@ struct Component explicit Component(std::string name_) : name(std::move(name_)) {} std::string const name; - double amount; + double amount = std::numeric_limits<double>::quiet_NaN(); + static const ItemType item_type = ItemType::Component; }; enum class MeansOfAdjustingCharge @@ -50,7 +53,7 @@ struct AqueousSolution double temperature; double pressure; - double pH; + double pH = std::numeric_limits<double>::quiet_NaN(); double pe; std::vector<Component> components; MeansOfAdjustingCharge const means_of_adjusting_charge; diff --git a/ChemistryLib/PhreeqcIOData/CreateReactionRate.cpp b/ChemistryLib/PhreeqcIOData/CreateReactionRate.cpp index d8688eaa203cb898279f4334e3cf959e8f843121..7d3a0b5a718917a35c4451cefcacf53d37f45b4e 100644 --- a/ChemistryLib/PhreeqcIOData/CreateReactionRate.cpp +++ b/ChemistryLib/PhreeqcIOData/CreateReactionRate.cpp @@ -29,17 +29,18 @@ std::vector<ReactionRate> createReactionRates( //! \ogs_file_param{prj__chemical_system__rates__rate__kinetic_reactant} rate_config.getConfigParameter<std::string>("kinetic_reactant"); - std::vector<std::string> expression_statements; auto const expression_config = //! \ogs_file_param{prj__chemical_system__rates__rate__expression} rate_config.getConfigSubtree("expression"); - for ( - auto const& expression_statement : + auto const& statements = //! \ogs_file_param{prj__chemical_system__rates__rate__expression__statement} - expression_config.getConfigParameterList<std::string>("statement")) - { - expression_statements.push_back(expression_statement); - } + expression_config.getConfigParameterList<std::string>("statement"); + + std::vector<std::string> expression_statements; + expression_statements.reserve(statements.size()); + std::copy(begin(statements), + end(statements), + back_inserter(expression_statements)); reaction_rates.emplace_back(std::move(kinetic_reactant), std::move(expression_statements)); diff --git a/ChemistryLib/PhreeqcIOData/EquilibriumPhase.h b/ChemistryLib/PhreeqcIOData/EquilibriumPhase.h index 21a2d206e8c67ab45602c822e0c7fd33ab27fb7b..b6eb94408aa0b31e12520b61a55835385b75950c 100644 --- a/ChemistryLib/PhreeqcIOData/EquilibriumPhase.h +++ b/ChemistryLib/PhreeqcIOData/EquilibriumPhase.h @@ -13,6 +13,8 @@ #include <string> #include <vector> +#include "ChemistryLib/Output.h" + namespace BaseLib { class ConfigTree; @@ -38,5 +40,6 @@ struct EquilibriumPhase std::string const name; double amount; double const saturation_index; + static const ItemType item_type = ItemType::EquilibriumPhase; }; } // namespace ChemistryLib diff --git a/ChemistryLib/PhreeqcIOData/KineticReactant.h b/ChemistryLib/PhreeqcIOData/KineticReactant.h index 0c51aa50a50bde5634c06ec1f5b943177976f3c9..5fd9418d8e7120cc958f4ef647cebe42eb8a52af 100644 --- a/ChemistryLib/PhreeqcIOData/KineticReactant.h +++ b/ChemistryLib/PhreeqcIOData/KineticReactant.h @@ -14,6 +14,8 @@ #include <string> #include <vector> +#include "ChemistryLib/Output.h" + namespace ChemistryLib { struct KineticReactant @@ -36,5 +38,6 @@ struct KineticReactant std::string const name; double amount; std::vector<double> const parameters; + static const ItemType item_type = ItemType::KineticReactant; }; } // namespace ChemistryLib