diff --git a/ChemistryLib/CreatePhreeqcIO.cpp b/ChemistryLib/CreatePhreeqcIO.cpp index c0b5b273fc7993d26b999a85cc36f28f6674b7c4..6cb59c8a4eeb11f1f256c56997a91c1a860e51e7 100644 --- a/ChemistryLib/CreatePhreeqcIO.cpp +++ b/ChemistryLib/CreatePhreeqcIO.cpp @@ -15,6 +15,7 @@ #include "CreatePhreeqcIO.h" #include "PhreeqcIO.h" #include "PhreeqcIOData/AqueousSolution.h" +#include "PhreeqcIOData/CreateAqueousSolution.h" #include "PhreeqcIOData/EquilibriumPhase.h" #include "PhreeqcIOData/KineticReactant.h" #include "PhreeqcIOData/ReactionRate.h" diff --git a/ChemistryLib/PhreeqcIOData/AqueousSolution.cpp b/ChemistryLib/PhreeqcIOData/AqueousSolution.cpp index 8867e80dd97f30618d8d33a1b243e750f9a02654..932f3f6882b2da4078e5a33a9a07aef6be757c47 100644 --- a/ChemistryLib/PhreeqcIOData/AqueousSolution.cpp +++ b/ChemistryLib/PhreeqcIOData/AqueousSolution.cpp @@ -10,73 +10,9 @@ #include <fstream> #include "AqueousSolution.h" -#include "BaseLib/ConfigTreeUtil.h" namespace ChemistryLib { -AqueousSolution createAqueousSolution(BaseLib::ConfigTree const& config) -{ - //! \ogs_file_param{prj__chemical_system__solution__temperature} - auto const temperature = config.getConfigParameter<double>("temperature"); - - //! \ogs_file_param{prj__chemical_system__solution__pressure} - auto const pressure = config.getConfigParameter<double>("pressure"); - - //! \ogs_file_param{prj__chemical_system__solution__pe} - auto const pe = config.getConfigParameter<double>("pe"); - - //! \ogs_file_param{prj__chemical_system__solution__components} - auto comp_config = config.getConfigSubtree("components"); - - std::vector<Component> components; - for ( - auto const& component_name : - //! \ogs_file_param{prj__chemical_system__solution__components__component} - comp_config.getConfigParameterList<std::string>("component")) - { - components.emplace_back(component_name); - } - - // conversion the variable 'means_of_adjusting_charge' from std::string to - // enumerate class. - auto const means_of_adjusting_charge_in_str = - //! \ogs_file_param{prj__chemical_system__solution__means_of_adjusting_charge} - config.getConfigParameterOptional<std::string>( - "means_of_adjusting_charge"); - - MeansOfAdjustingCharge means_of_adjusting_charge; - if (means_of_adjusting_charge_in_str) - { - if (*means_of_adjusting_charge_in_str == "pH") - { - means_of_adjusting_charge = MeansOfAdjustingCharge::pH; - } - else if (*means_of_adjusting_charge_in_str == "pe") - { - means_of_adjusting_charge = MeansOfAdjustingCharge::pe; - } - else - { - OGS_FATAL( - "Error in specifying means of adjusting charge. Achieving " - "charge balance is currently supported with the way of " - "adjusting pH value or pe value."); - } - } - else - { - means_of_adjusting_charge = MeansOfAdjustingCharge::Unspecified; - } - - AqueousSolution aqueous_solution(temperature, - pressure, - pe, - std::move(components), - means_of_adjusting_charge); - - return aqueous_solution; -} - std::ofstream& operator<<(std::ofstream& out, AqueousSolution const& aqueous_solution) { diff --git a/ChemistryLib/PhreeqcIOData/AqueousSolution.h b/ChemistryLib/PhreeqcIOData/AqueousSolution.h index cbcd675fad169265eb532e5b2f3404507c3e6614..42844d77a7edb67a73f0acb6331fd6cdc7cdd6a7 100644 --- a/ChemistryLib/PhreeqcIOData/AqueousSolution.h +++ b/ChemistryLib/PhreeqcIOData/AqueousSolution.h @@ -9,18 +9,10 @@ #pragma once -#include <boost/optional/optional.hpp> #include <iosfwd> #include <string> #include <vector> -#include "BaseLib/Error.h" - -namespace BaseLib -{ -class ConfigTree; -} - namespace ChemistryLib { struct Component @@ -63,6 +55,4 @@ struct AqueousSolution std::vector<Component> components; MeansOfAdjustingCharge const means_of_adjusting_charge; }; - -AqueousSolution createAqueousSolution(BaseLib::ConfigTree const& config); } // namespace ChemistryLib diff --git a/ChemistryLib/PhreeqcIOData/CreateAqueousSolution.cpp b/ChemistryLib/PhreeqcIOData/CreateAqueousSolution.cpp new file mode 100644 index 0000000000000000000000000000000000000000..27946a8ac1b3b63e1b742b69ccf0d14f9cd460f3 --- /dev/null +++ b/ChemistryLib/PhreeqcIOData/CreateAqueousSolution.cpp @@ -0,0 +1,73 @@ +/** + * \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 "AqueousSolution.h" +#include "BaseLib/ConfigTree.h" +#include "BaseLib/Error.h" + +namespace ChemistryLib +{ +AqueousSolution createAqueousSolution(BaseLib::ConfigTree const& config) +{ + //! \ogs_file_param{prj__chemical_system__solution__temperature} + auto const temperature = config.getConfigParameter<double>("temperature"); + + //! \ogs_file_param{prj__chemical_system__solution__pressure} + auto const pressure = config.getConfigParameter<double>("pressure"); + + //! \ogs_file_param{prj__chemical_system__solution__pe} + auto const pe = config.getConfigParameter<double>("pe"); + + //! \ogs_file_param{prj__chemical_system__solution__components} + auto comp_config = config.getConfigSubtree("components"); + + std::vector<Component> components; + for ( + auto const& component_name : + //! \ogs_file_param{prj__chemical_system__solution__components__component} + comp_config.getConfigParameterList<std::string>("component")) + { + components.emplace_back(component_name); + } + + // conversion the variable 'means_of_adjusting_charge' from std::string to + // enumerate class. + auto const means_of_adjusting_charge_in_str = + //! \ogs_file_param{prj__chemical_system__solution__means_of_adjusting_charge} + config.getConfigParameterOptional<std::string>( + "means_of_adjusting_charge"); + + MeansOfAdjustingCharge means_of_adjusting_charge; + if (means_of_adjusting_charge_in_str) + { + if (*means_of_adjusting_charge_in_str == "pH") + { + means_of_adjusting_charge = MeansOfAdjustingCharge::pH; + } + else if (*means_of_adjusting_charge_in_str == "pe") + { + means_of_adjusting_charge = MeansOfAdjustingCharge::pe; + } + else + { + OGS_FATAL( + "Error in specifying means of adjusting charge. Achieving " + "charge balance is currently supported with the way of " + "adjusting pH value or pe value."); + } + } + else + { + means_of_adjusting_charge = MeansOfAdjustingCharge::Unspecified; + } + + return {temperature, pressure, pe, std::move(components), + means_of_adjusting_charge}; +} +} // namespace ChemistryLib diff --git a/ChemistryLib/PhreeqcIOData/CreateAqueousSolution.h b/ChemistryLib/PhreeqcIOData/CreateAqueousSolution.h new file mode 100644 index 0000000000000000000000000000000000000000..ca1fa63545f0413637dffaf42cd9a0cbbb070c96 --- /dev/null +++ b/ChemistryLib/PhreeqcIOData/CreateAqueousSolution.h @@ -0,0 +1,25 @@ +/** + * \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 + +namespace BaseLib +{ +class ConfigTree; +} + +namespace ChemistryLib +{ +struct AqueousSolution; +} + +namespace ChemistryLib +{ +AqueousSolution createAqueousSolution(BaseLib::ConfigTree const& config); +} // namespace ChemistryLib