CreateKineticReactant.cpp 3.39 KB
Newer Older
1
/**
2
 * \file
3
 * \copyright
4
 * Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
5
6
7
8
9
10
 *            Distributed under a Modified BSD License.
 *              See accompanying file LICENSE.txt or
 *              http://www.opengeosys.org/project/license
 *
 */

11
12
13
#include "CreateKineticReactant.h"

#include <optional>
14

15
16
#include "BaseLib/ConfigTree.h"
#include "KineticReactant.h"
17
#include "MeshLib/Mesh.h"
18
19
20

namespace ChemistryLib
{
renchao.lu's avatar
renchao.lu committed
21
22
namespace PhreeqcIOData
{
23
std::vector<KineticReactant> createKineticReactants(
24
    std::optional<BaseLib::ConfigTree> const& config, MeshLib::Mesh& mesh)
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{
    if (!config)
    {
        return {};
    }

    std::vector<KineticReactant> kinetic_reactants;
    for (
        auto const& reactant_config :
        //! \ogs_file_param{prj__chemical_system__kinetic_reactants__kinetic_reactant}
        config->getConfigSubtreeList("kinetic_reactant"))
    {
        //! \ogs_file_param{prj__chemical_system__kinetic_reactants__kinetic_reactant__name}
        auto name = reactant_config.getConfigParameter<std::string>("name");

renchao.lu's avatar
renchao.lu committed
40
41
42
43
44
        auto chemical_formula =
            //! \ogs_file_param{prj__chemical_system__kinetic_reactants__kinetic_reactant__chemical_formula}
            reactant_config.getConfigParameter<std::string>("chemical_formula",
                                                            "");

45
46
        auto parameters =
            //! \ogs_file_param{prj__chemical_system__kinetic_reactants__kinetic_reactant__parameters}
47
48
            reactant_config.getConfigParameter<std::vector<double>>(
                "parameters", {});
49

50
51
52
53
        bool const fix_amount =
            //! \ogs_file_param{prj__chemical_system__kinetic_reactants__kinetic_reactant__fix_amount}
            reactant_config.getConfigParameter<bool>("fix_amount", false);

renchao.lu's avatar
renchao.lu committed
54
        auto molality = MeshLib::getOrCreateMeshProperty<double>(
Renchao Lu's avatar
Renchao Lu committed
55
            mesh, name, MeshLib::MeshItemType::IntegrationPoint, 1);
renchao.lu's avatar
renchao.lu committed
56

57
58
59
        auto molality_prev = MeshLib::getOrCreateMeshProperty<double>(
            mesh, name + "_prev", MeshLib::MeshItemType::IntegrationPoint, 1);

60
61
62
        auto volume_fraction = MeshLib::getOrCreateMeshProperty<double>(
            mesh, "phi_" + name, MeshLib::MeshItemType::IntegrationPoint, 1);

63
64
65
66
67
68
        auto volume_fraction_prev = MeshLib::getOrCreateMeshProperty<double>(
            mesh,
            "phi_" + name + "_prev",
            MeshLib::MeshItemType::IntegrationPoint,
            1);

renchao.lu's avatar
renchao.lu committed
69
        auto mesh_prop_molality = MeshLib::getOrCreateMeshProperty<double>(
70
            mesh, name + "_avg", MeshLib::MeshItemType::Cell, 1);
renchao.lu's avatar
renchao.lu committed
71
        mesh_prop_molality->resize(mesh.getNumberOfElements());
72

73
74
75
76
77
78
79
        if (chemical_formula.empty() && fix_amount)
        {
            OGS_FATAL(
                "fix_amount can only be used if a chemical_formula has been "
                "defined");
        }

renchao.lu's avatar
renchao.lu committed
80
81
        kinetic_reactants.emplace_back(std::move(name),
                                       std::move(chemical_formula),
renchao.lu's avatar
renchao.lu committed
82
                                       molality,
83
                                       molality_prev,
84
                                       volume_fraction,
85
                                       volume_fraction_prev,
renchao.lu's avatar
renchao.lu committed
86
                                       mesh_prop_molality,
87
88
                                       std::move(parameters),
                                       fix_amount);
89
90
91
92
    }

    return kinetic_reactants;
}
renchao.lu's avatar
renchao.lu committed
93
}  // namespace PhreeqcIOData
94
}  // namespace ChemistryLib