29 std::size_t
const num_chemical_systems,
30 std::vector<std::pair<int, std::string>>
const&
31 process_id_to_component_name_map,
32 std::string
const& database,
34 std::unique_ptr<EquilibriumReactants>&& equilibrium_reactants,
35 std::unique_ptr<Kinetics>&& kinetic_reactants,
36 std::vector<ReactionRate>&& reaction_rates)
38 _initial_aqueous_solution(aqueous_solution.getInitialAqueousSolution()),
39 _aqueous_solution(aqueous_solution.castToBaseClassNoninitialized()),
40 _reaction_rates(std::move(reaction_rates))
47 for (std::size_t chemical_system_id = 0;
48 chemical_system_id < num_chemical_systems;
52 Rxn_solution_map.emplace(chemical_system_id,
55 use.Set_solution_in(
true);
58 if (equilibrium_reactants)
62 for (std::size_t chemical_system_id = 0;
63 chemical_system_id < num_chemical_systems;
66 equilibrium_reactants->setChemicalSystemID(chemical_system_id);
67 Rxn_pp_assemblage_map.emplace(
68 chemical_system_id, *equilibrium_reactants->castToBaseClass());
71 equilibrium_reactants.reset(
nullptr);
73 use.Set_pp_assemblage_in(
true);
77 if (kinetic_reactants)
79 for (std::size_t chemical_system_id = 0;
80 chemical_system_id < num_chemical_systems;
83 kinetic_reactants->setChemicalSystemID(chemical_system_id);
84 Rxn_kinetics_map.emplace(chemical_system_id,
85 *kinetic_reactants->castToBaseClass());
88 kinetic_reactants.reset(
nullptr);
90 use.Set_kinetics_in(
true);
100 for (
auto const& map_pair : process_id_to_component_name_map)
102 auto const transport_process_id = map_pair.first;
103 auto const& transport_process_variable = map_pair.second;
105 auto master_species =
106 master_bsearch(transport_process_variable.c_str());
151 rates[rate_id].name = reaction_rate.kinetic_reactant.data();
154 rates[rate_id].commands =
static_cast<char*
>(
155 malloc(
sizeof(
char) * reaction_rate.commands().size() + 1));
156 if (rates[rate_id].commands ==
nullptr)
158 OGS_FATAL(
"Could not allocate memory for rate[{:d}] commands.",
161 reaction_rate.commands().copy(rates[rate_id].commands,
163 rates[rate_id].commands[reaction_rate.commands().size()] =
'\0';
165 rates[rate_id].new_def = 1;
166 rates[rate_id].linebase =
nullptr;
167 rates[rate_id].varbase =
nullptr;
168 rates[rate_id].loopbase =
nullptr;
191 std::vector<GlobalVector*>
const& process_solutions)
193 assert(!process_solutions.empty());
195 std::size_t
const num_chemical_systems = process_solutions[0]->size();
196 for (std::size_t chemical_system_id = 0;
197 chemical_system_id < num_chemical_systems;
198 ++chemical_system_id)
200 auto& aqueous_solution = Rxn_solution_map[chemical_system_id];
202 auto initial_aqueous_solution =
205 auto& components = initial_aqueous_solution->Get_comps();
210 auto const transport_process_id = map_pair.first;
211 auto const& master_species = map_pair.second;
213 auto& transport_process_solution =
214 process_solutions[transport_process_id];
216 char const*
const element_name = master_species->elt->name;
217 auto const concentration =
218 transport_process_solution->get(chemical_system_id);
222 double const pH = -std::log10(concentration);
223 aqueous_solution.Set_ph(
pH);
226 auto hydrogen = components.find(
"H(1)");
227 if (hydrogen != components.end())
229 hydrogen->second.Set_input_conc(
pH);
236 components[element_name].Set_input_conc(concentration);
266 if (process_solutions.empty())
268 OGS_FATAL(
"About to access an empty process solutions vector.");
270 std::size_t
const num_chemical_systems = process_solutions[0]->size();
271 for (std::size_t chemical_system_id = 0;
272 chemical_system_id < num_chemical_systems;
273 ++chemical_system_id)
275 Rxn_new_solution.insert(chemical_system_id);
277 use.Set_n_solution_user(chemical_system_id);
279 if (!Rxn_pp_assemblage_map.empty())
281 Rxn_new_pp_assemblage.insert(chemical_system_id);
282 use.Set_pp_assemblage_in(
true);
283 use.Set_n_pp_assemblage_user(chemical_system_id);
286 if (!Rxn_kinetics_map.empty())
288 use.Set_kinetics_in(
true);
289 use.Set_n_kinetics_user(chemical_system_id);
292 initial_solutions(
false);
298 reset(chemical_system_id);
305 Rxn_new_solution.clear();
310 Rxn_solution_map[chemical_system_id].Set_n_user_both(
312 Rxn_solution_map[chemical_system_id].Set_pe(-s_eminus->la);
316 if (!Rxn_pp_assemblage_map.empty())
318 Rxn_new_pp_assemblage.clear();
319 for (
int j = 0; j < count_unknowns; j++)
321 if (x ==
nullptr || x[j]->type != PP)
324 auto& phase_components = Rxn_pp_assemblage_map[chemical_system_id]
325 .Get_pp_assemblage_comps();
326 phase_components[x[j]->pp_assemblage_comp_name].Set_moles(
332 if (!Rxn_kinetics_map.empty())
334 Rxn_kinetics_map[chemical_system_id].Get_steps().clear();
339 std::vector<GlobalVector*>
const& process_solutions,
340 std::size_t
const node_id)
344 auto const transport_process_id = map_pair.first;
345 auto const& master_species = map_pair.second;
347 auto& transport_process_solution =
348 process_solutions[transport_process_id];
350 char const*
const element_name = master_species->elt->name;
354 auto const hydrogen_concentration = std::pow(10, s_hplus->la);
355 transport_process_solution->set(node_id, hydrogen_concentration);
360 auto const concentration =
361 master_species->primary
362 ? master_species->total_primary / mass_water_aq_x
363 : master_species->total / mass_water_aq_x;
364 transport_process_solution->set(node_id, concentration);