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