OGS
CreateInitialAqueousSolution.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
7#include "BaseLib/Error.h"
11
12namespace ChemistryLib
13{
14namespace PhreeqcKernelData
15{
17 BaseLib::ConfigTree const& config,
18 std::vector<std::pair<int, std::string>> const&
19 process_id_to_component_name_map)
20{
21 std::map<std::string, cxxISolutionComp> components;
23 auto comp_config = config.getConfigSubtree("components");
24 for (
25 auto const& component_config :
27 comp_config.getConfigSubtreeList("component"))
28 {
29 auto const component_name = component_config.getValue<std::string>();
30 Component component(component_name);
31 components.emplace(component_name, component);
32 }
33
34 for (auto const& component : components)
35 {
36 auto process_id_to_component_name_pair =
37 std::find_if(process_id_to_component_name_map.begin(),
38 process_id_to_component_name_map.end(),
39 [&component](auto const& pair)
40 { return pair.second == component.first; });
41
42 if (process_id_to_component_name_pair ==
43 process_id_to_component_name_map.end())
44 {
46 "Component {:s} given in <solution>/<components> is not found "
47 "in specified coupled processes (see "
48 "<process>/<process_variables>/<concentration>).",
49 component.first);
50 }
51 }
52
53 if (components.size() + 1 != process_id_to_component_name_map.size())
54 {
56 "The number of components given in <solution>/<components> is not "
57 "in line with the number of transport processes - 1 which stands "
58 "for the transport process of hydrogen.");
59 }
60
61 auto const charge_balance = createChargeBalance(config);
62 if (charge_balance == ChargeBalance::pH)
63 {
64 Component component("H(1)");
65 component.Set_equation_name("charge");
66 components.emplace("H(1)", component);
67 }
68 if (charge_balance == ChargeBalance::pe)
69 {
71 "Adjusting pe value for charge balance is unsupported yet with the "
72 "chemical solver 'PhreeqcKernel'. Please use the chemical solver "
73 "'Phreeqc' for this functionality.");
74 }
75
76 return InitialAqueousSolution(components);
77}
78} // namespace PhreeqcKernelData
79} // namespace ChemistryLib
#define OGS_FATAL(...)
Definition Error.h:19
ConfigTree getConfigSubtree(std::string const &root) const
InitialAqueousSolution createInitialAqueousSolution(BaseLib::ConfigTree const &config, std::vector< std::pair< int, std::string > > const &process_id_to_component_name_map)
ChargeBalance createChargeBalance(BaseLib::ConfigTree const &config)