From b1962a4eef1736b4944adc6898019e0ed7727364 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Wed, 5 Jun 2019 17:01:28 +0200 Subject: [PATCH] [CL] Extract create reaction rate. --- ChemistryLib/CreatePhreeqcIO.cpp | 1 + .../PhreeqcIOData/CreateReactionRate.cpp | 50 +++++++++++++++++++ .../PhreeqcIOData/CreateReactionRate.h | 29 +++++++++++ ChemistryLib/PhreeqcIOData/ReactionRate.cpp | 37 -------------- ChemistryLib/PhreeqcIOData/ReactionRate.h | 9 ---- 5 files changed, 80 insertions(+), 46 deletions(-) create mode 100644 ChemistryLib/PhreeqcIOData/CreateReactionRate.cpp create mode 100644 ChemistryLib/PhreeqcIOData/CreateReactionRate.h diff --git a/ChemistryLib/CreatePhreeqcIO.cpp b/ChemistryLib/CreatePhreeqcIO.cpp index 261d52e1470..9100dc63a6f 100644 --- a/ChemistryLib/CreatePhreeqcIO.cpp +++ b/ChemistryLib/CreatePhreeqcIO.cpp @@ -18,6 +18,7 @@ #include "PhreeqcIOData/CreateAqueousSolution.h" #include "PhreeqcIOData/CreateEquilibriumPhase.h" #include "PhreeqcIOData/CreateKineticReactant.h" +#include "PhreeqcIOData/CreateReactionRate.h" #include "PhreeqcIOData/EquilibriumPhase.h" #include "PhreeqcIOData/KineticReactant.h" #include "PhreeqcIOData/ReactionRate.h" diff --git a/ChemistryLib/PhreeqcIOData/CreateReactionRate.cpp b/ChemistryLib/PhreeqcIOData/CreateReactionRate.cpp new file mode 100644 index 00000000000..d8688eaa203 --- /dev/null +++ b/ChemistryLib/PhreeqcIOData/CreateReactionRate.cpp @@ -0,0 +1,50 @@ +/** + * \copyright + * Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#include "BaseLib/ConfigTree.h" +#include "ReactionRate.h" + +namespace ChemistryLib +{ +std::vector<ReactionRate> createReactionRates( + boost::optional<BaseLib::ConfigTree> const& config) +{ + if (!config) + { + return {}; + } + + std::vector<ReactionRate> reaction_rates; + for (auto const& rate_config : + //! \ogs_file_param{prj__chemical_system__rates__rate} + config->getConfigSubtreeList("rate")) + { + auto kinetic_reactant = + //! \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 : + //! \ogs_file_param{prj__chemical_system__rates__rate__expression__statement} + expression_config.getConfigParameterList<std::string>("statement")) + { + expression_statements.push_back(expression_statement); + } + + reaction_rates.emplace_back(std::move(kinetic_reactant), + std::move(expression_statements)); + } + + return reaction_rates; +} +} // namespace ChemistryLib diff --git a/ChemistryLib/PhreeqcIOData/CreateReactionRate.h b/ChemistryLib/PhreeqcIOData/CreateReactionRate.h new file mode 100644 index 00000000000..98092ffd2ec --- /dev/null +++ b/ChemistryLib/PhreeqcIOData/CreateReactionRate.h @@ -0,0 +1,29 @@ +/** + * \copyright + * Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#pragma once + +#include <boost/optional/optional.hpp> +#include <vector> + +namespace BaseLib +{ +class ConfigTree; +} + +namespace ChemistryLib +{ +struct ReactionRate; +} + +namespace ChemistryLib +{ +std::vector<ReactionRate> createReactionRates( + boost::optional<BaseLib::ConfigTree> const& config); +} // namespace ChemistryLib diff --git a/ChemistryLib/PhreeqcIOData/ReactionRate.cpp b/ChemistryLib/PhreeqcIOData/ReactionRate.cpp index 00331c51f0e..4de068ca057 100644 --- a/ChemistryLib/PhreeqcIOData/ReactionRate.cpp +++ b/ChemistryLib/PhreeqcIOData/ReactionRate.cpp @@ -10,46 +10,9 @@ #include <fstream> #include "ReactionRate.h" -#include "BaseLib/ConfigTreeUtil.h" namespace ChemistryLib { -std::vector<ReactionRate> createReactionRates( - boost::optional<BaseLib::ConfigTree> const& config) -{ - if (!config) - { - return {}; - } - - std::vector<ReactionRate> reaction_rates; - for (auto const& rate_config : - //! \ogs_file_param{prj__chemical_system__rates__rate} - config->getConfigSubtreeList("rate")) - { - auto kinetic_reactant = - //! \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 : - //! \ogs_file_param{prj__chemical_system__rates__rate__expression__statement} - expression_config.getConfigParameterList<std::string>("statement")) - { - expression_statements.push_back(expression_statement); - } - - reaction_rates.emplace_back(std::move(kinetic_reactant), - std::move(expression_statements)); - } - - return reaction_rates; -} - std::ofstream& operator<<(std::ofstream& out, std::vector<ReactionRate> const& reaction_rates) { diff --git a/ChemistryLib/PhreeqcIOData/ReactionRate.h b/ChemistryLib/PhreeqcIOData/ReactionRate.h index 6d6649f44c0..e894488c8b4 100644 --- a/ChemistryLib/PhreeqcIOData/ReactionRate.h +++ b/ChemistryLib/PhreeqcIOData/ReactionRate.h @@ -9,16 +9,10 @@ #pragma once -#include <boost/optional/optional.hpp> #include <iosfwd> #include <string> #include <vector> -namespace BaseLib -{ -class ConfigTree; -} - namespace ChemistryLib { struct ReactionRate @@ -37,7 +31,4 @@ struct ReactionRate std::string const kinetic_reactant; std::vector<std::string> const expression_statements; }; - -std::vector<ReactionRate> createReactionRates( - boost::optional<BaseLib::ConfigTree> const& config); } // namespace ChemistryLib -- GitLab