Skip to content
Snippets Groups Projects
Unverified Commit f8a501e0 authored by Dmitri Naumov's avatar Dmitri Naumov Committed by GitHub
Browse files

Merge pull request #2522 from renchao-lu/SmallFixesPhreeqcInterface

Fixed a few cppcheck/clang-tidy warnings in chemistry library
parents f24b2e34 d0d1dc44
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
* *
*/ */
#include <algorithm>
#include <numeric> #include <numeric>
#include "CreateOutput.h" #include "CreateOutput.h"
namespace ChemistryLib namespace ChemistryLib
...@@ -21,20 +23,16 @@ std::unique_ptr<Output> createOutput( ...@@ -21,20 +23,16 @@ std::unique_ptr<Output> createOutput(
// Mark which phreeqc output items will be held. // Mark which phreeqc output items will be held.
std::vector<OutputItem> accepted_items{{"pH", ItemType::pH}, std::vector<OutputItem> accepted_items{{"pH", ItemType::pH},
{"pe", ItemType::pe}}; {"pe", ItemType::pe}};
for (auto const& component : components)
{ auto accepted_item = [](auto const& item) {
accepted_items.emplace_back(component.name, ItemType::Component); return OutputItem(item.name, item.item_type);
} };
for (auto const& equilibrium_phase : equilibrium_phases) std::transform(components.begin(), components.end(),
{ std::back_inserter(accepted_items), accepted_item);
accepted_items.emplace_back(equilibrium_phase.name, std::transform(equilibrium_phases.begin(), equilibrium_phases.end(),
ItemType::EquilibriumPhase); std::back_inserter(accepted_items), accepted_item);
} std::transform(kinetic_reactants.begin(), kinetic_reactants.end(),
for (auto const& kinetic_reactant : kinetic_reactants) std::back_inserter(accepted_items), accepted_item);
{
accepted_items.emplace_back(kinetic_reactant.name,
ItemType::KineticReactant);
}
// Record ids of which phreeqc output items will be dropped. // Record ids of which phreeqc output items will be dropped.
BasicOutputSetups basic_output_setups(project_file_name); BasicOutputSetups basic_output_setups(project_file_name);
...@@ -58,7 +56,7 @@ std::unique_ptr<Output> createOutput( ...@@ -58,7 +56,7 @@ std::unique_ptr<Output> createOutput(
dvalue_item_id += 2 * (i + 1); 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(accepted_items),
std::move(dropped_item_ids)); std::move(dropped_item_ids));
} }
......
...@@ -76,10 +76,10 @@ struct OutputItem ...@@ -76,10 +76,10 @@ struct OutputItem
struct Output struct Output
{ {
Output(BasicOutputSetups basic_output_setups_, Output(BasicOutputSetups&& basic_output_setups_,
std::vector<OutputItem>&& accepted_items_, std::vector<OutputItem>&& accepted_items_,
std::vector<int>&& dropped_item_ids_) 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_)), accepted_items(std::move(accepted_items_)),
dropped_item_ids(std::move(dropped_item_ids_)) dropped_item_ids(std::move(dropped_item_ids_))
{ {
......
...@@ -80,6 +80,6 @@ private: ...@@ -80,6 +80,6 @@ private:
std::unique_ptr<Output> const _output; std::unique_ptr<Output> const _output;
std::vector<std::pair<int, std::string>> const& std::vector<std::pair<int, std::string>> const&
_process_id_to_component_name_map; _process_id_to_component_name_map;
double _dt; double _dt = std::numeric_limits<double>::quiet_NaN();
}; };
} // namespace ChemistryLib } // namespace ChemistryLib
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "ChemistryLib/Output.h"
namespace ChemistryLib namespace ChemistryLib
{ {
struct Component struct Component
...@@ -20,7 +22,8 @@ struct Component ...@@ -20,7 +22,8 @@ struct Component
explicit Component(std::string name_) : name(std::move(name_)) {} explicit Component(std::string name_) : name(std::move(name_)) {}
std::string const 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 enum class MeansOfAdjustingCharge
...@@ -50,7 +53,7 @@ struct AqueousSolution ...@@ -50,7 +53,7 @@ struct AqueousSolution
double temperature; double temperature;
double pressure; double pressure;
double pH; double pH = std::numeric_limits<double>::quiet_NaN();
double pe; double pe;
std::vector<Component> components; std::vector<Component> components;
MeansOfAdjustingCharge const means_of_adjusting_charge; MeansOfAdjustingCharge const means_of_adjusting_charge;
......
...@@ -29,17 +29,18 @@ std::vector<ReactionRate> createReactionRates( ...@@ -29,17 +29,18 @@ std::vector<ReactionRate> createReactionRates(
//! \ogs_file_param{prj__chemical_system__rates__rate__kinetic_reactant} //! \ogs_file_param{prj__chemical_system__rates__rate__kinetic_reactant}
rate_config.getConfigParameter<std::string>("kinetic_reactant"); rate_config.getConfigParameter<std::string>("kinetic_reactant");
std::vector<std::string> expression_statements;
auto const expression_config = auto const expression_config =
//! \ogs_file_param{prj__chemical_system__rates__rate__expression} //! \ogs_file_param{prj__chemical_system__rates__rate__expression}
rate_config.getConfigSubtree("expression"); rate_config.getConfigSubtree("expression");
for ( auto const& statements =
auto const& expression_statement :
//! \ogs_file_param{prj__chemical_system__rates__rate__expression__statement} //! \ogs_file_param{prj__chemical_system__rates__rate__expression__statement}
expression_config.getConfigParameterList<std::string>("statement")) expression_config.getConfigParameterList<std::string>("statement");
{
expression_statements.push_back(expression_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), reaction_rates.emplace_back(std::move(kinetic_reactant),
std::move(expression_statements)); std::move(expression_statements));
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "ChemistryLib/Output.h"
namespace BaseLib namespace BaseLib
{ {
class ConfigTree; class ConfigTree;
...@@ -38,5 +40,6 @@ struct EquilibriumPhase ...@@ -38,5 +40,6 @@ struct EquilibriumPhase
std::string const name; std::string const name;
double amount; double amount;
double const saturation_index; double const saturation_index;
static const ItemType item_type = ItemType::EquilibriumPhase;
}; };
} // namespace ChemistryLib } // namespace ChemistryLib
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "ChemistryLib/Output.h"
namespace ChemistryLib namespace ChemistryLib
{ {
struct KineticReactant struct KineticReactant
...@@ -36,5 +38,6 @@ struct KineticReactant ...@@ -36,5 +38,6 @@ struct KineticReactant
std::string const name; std::string const name;
double amount; double amount;
std::vector<double> const parameters; std::vector<double> const parameters;
static const ItemType item_type = ItemType::KineticReactant;
}; };
} // namespace ChemistryLib } // namespace ChemistryLib
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment