From 86e626db49e32cd07f7ef8dc03314474cde9da53 Mon Sep 17 00:00:00 2001 From: renchao_lu <renchao.lu@gmail.com> Date: Tue, 4 Jun 2019 18:09:00 +0200 Subject: [PATCH] [CL] Create class Reaction Rate. --- ChemistryLib/PhreeqcIOData/ReactionRate.cpp | 46 +++++++++++++++++++++ ChemistryLib/PhreeqcIOData/ReactionRate.h | 39 +++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 ChemistryLib/PhreeqcIOData/ReactionRate.cpp create mode 100644 ChemistryLib/PhreeqcIOData/ReactionRate.h diff --git a/ChemistryLib/PhreeqcIOData/ReactionRate.cpp b/ChemistryLib/PhreeqcIOData/ReactionRate.cpp new file mode 100644 index 00000000000..000ab116a30 --- /dev/null +++ b/ChemistryLib/PhreeqcIOData/ReactionRate.cpp @@ -0,0 +1,46 @@ +/** + * \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 "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; +} +} // namespace ChemistryLib diff --git a/ChemistryLib/PhreeqcIOData/ReactionRate.h b/ChemistryLib/PhreeqcIOData/ReactionRate.h new file mode 100644 index 00000000000..6dc7761ff8b --- /dev/null +++ b/ChemistryLib/PhreeqcIOData/ReactionRate.h @@ -0,0 +1,39 @@ +/** + * \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 <string> +#include <vector> + +namespace BaseLib +{ +class ConfigTree; +} + +namespace ChemistryLib +{ +struct ReactionRate +{ + ReactionRate(std::string kinetic_reactant_, + std::vector<std::string> + expression_statements_) + : kinetic_reactant(std::move(kinetic_reactant_)), + expression_statements(std::move(expression_statements_)) + { + } + + 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