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

10
11
#include <boost/optional/optional.hpp>

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

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

42
43
44
45
46
47
        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}
48
49
            reactant_config.getConfigParameter<std::vector<double>>(
                "parameters", {});
50

51
52
53
54
55
56
57
        auto amount = MeshLib::getOrCreateMeshProperty<double>(
            const_cast<MeshLib::Mesh&>(mesh),
            name,
            MeshLib::MeshItemType::Node,
            1);
        std::fill(std::begin(*amount), std::end(*amount), initial_amount);

renchao.lu's avatar
renchao.lu committed
58
59
        kinetic_reactants.emplace_back(std::move(name),
                                       std::move(chemical_formula),
60
                                       amount,
renchao.lu's avatar
renchao.lu committed
61
                                       std::move(parameters));
62
63
64
65
66
    }

    return kinetic_reactants;
}
}  // namespace ChemistryLib