OGS
PhreeqcIOData/CreateEquilibriumReactants.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
6#include <optional>
7
10#include "MeshLib/Mesh.h"
12
13namespace ChemistryLib
14{
15namespace PhreeqcIOData
16{
17std::vector<EquilibriumReactant> createEquilibriumReactants(
18 std::optional<BaseLib::ConfigTree> const& config, MeshLib::Mesh& mesh)
19{
20 if (!config)
21 {
22 return {};
23 }
24
25 std::vector<EquilibriumReactant> equilibrium_reactants;
26 for (
27 auto const& equilibrium_reactant_config :
29 config->getConfigSubtreeList("phase_component"))
30 {
31 auto name =
33 equilibrium_reactant_config.getConfigParameter<std::string>("name");
34
35 double const saturation_index =
37 equilibrium_reactant_config.getConfigParameter<double>(
38 "saturation_index");
39
40 auto reaction_irreversibility =
42 equilibrium_reactant_config.getConfigParameter<std::string>(
43 "reaction_irreversibility", "");
44
45 if (!reaction_irreversibility.empty() &&
46 (reaction_irreversibility != "dissolve_only" &&
47 reaction_irreversibility != "precipitate_only"))
48 {
50 "{:s}: reaction direction only allows `dissolve_only` or "
51 "`precipitate_only`",
52 name);
53 }
54
57
59 mesh, name + "_prev", MeshLib::MeshItemType::IntegrationPoint, 1);
60
61 auto volume_fraction = MeshLib::getOrCreateMeshProperty<double>(
62 mesh, "phi_" + name, MeshLib::MeshItemType::IntegrationPoint, 1);
63
64 auto volume_fraction_prev = MeshLib::getOrCreateMeshProperty<double>(
65 mesh,
66 "phi_" + name + "_prev",
68 1);
69
70 auto mesh_prop_molality = MeshLib::getOrCreateMeshProperty<double>(
71 mesh, name + "_avg", MeshLib::MeshItemType::Cell, 1);
72 mesh_prop_molality->resize(mesh.getNumberOfElements());
73
74 equilibrium_reactants.emplace_back(std::move(name),
75 molality,
76 molality_prev,
77 volume_fraction,
78 volume_fraction_prev,
79 mesh_prop_molality,
80 saturation_index,
81 std::move(reaction_irreversibility));
82 }
83
84 return equilibrium_reactants;
85}
86} // namespace PhreeqcIOData
87} // namespace ChemistryLib
#define OGS_FATAL(...)
Definition Error.h:19
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:88
std::vector< EquilibriumReactant > createEquilibriumReactants(std::optional< BaseLib::ConfigTree > const &config, MeshLib::Mesh &mesh)
PropertyVector< T > * getOrCreateMeshProperty(Mesh &mesh, std::string const &property_name, MeshItemType const item_type, int const number_of_components)