CreateKineticReactant.cpp 2.76 KB
Newer Older
1
/**
2
 * \file
3
 * \copyright
4
 * Copyright (c) 2012-2020, 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
#include <boost/optional/optional.hpp>

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

namespace ChemistryLib
{
renchao.lu's avatar
renchao.lu committed
20
21
namespace PhreeqcIOData
{
22
std::vector<KineticReactant> createKineticReactants(
Renchao Lu's avatar
Renchao Lu committed
23
    boost::optional<BaseLib::ConfigTree> const& config, MeshLib::Mesh& mesh)
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{
    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
39
40
41
42
43
        auto chemical_formula =
            //! \ogs_file_param{prj__chemical_system__kinetic_reactants__kinetic_reactant__chemical_formula}
            reactant_config.getConfigParameter<std::string>("chemical_formula",
                                                            "");

44
45
46
47
48
49
        double const initial_amount =
            //! \ogs_file_param{prj__chemical_system__kinetic_reactants__kinetic_reactant__initial_amount}
            reactant_config.getConfigParameter<double>("initial_amount");

        auto parameters =
            //! \ogs_file_param{prj__chemical_system__kinetic_reactants__kinetic_reactant__parameters}
50
51
            reactant_config.getConfigParameter<std::vector<double>>(
                "parameters", {});
52

53
54
55
56
        bool const fix_amount =
            //! \ogs_file_param{prj__chemical_system__kinetic_reactants__kinetic_reactant__fix_amount}
            reactant_config.getConfigParameter<bool>("fix_amount", false);

57
        auto amount = MeshLib::getOrCreateMeshProperty<double>(
Renchao Lu's avatar
Renchao Lu committed
58
            mesh, name, MeshLib::MeshItemType::IntegrationPoint, 1);
renchao.lu's avatar
renchao.lu committed
59

60
61
62
63
64
65
66
        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
67
68
        kinetic_reactants.emplace_back(std::move(name),
                                       std::move(chemical_formula),
69
                                       amount,
70
                                       initial_amount,
71
72
                                       std::move(parameters),
                                       fix_amount);
73
74
75
76
    }

    return kinetic_reactants;
}
renchao.lu's avatar
renchao.lu committed
77
}  // namespace PhreeqcIOData
78
}  // namespace ChemistryLib