OGS
CreateCurve.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
4#include "CreateCurve.h"
5
6#include <unordered_set>
7
8#include "BaseLib/Algorithm.h"
10#include "Curve.h"
13
14namespace MaterialPropertyLib
15{
16std::unique_ptr<Curve> createCurve(
17 BaseLib::ConfigTree const& config,
18 std::map<std::string,
19 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
20 curves)
21{
23 config.checkConfigParameter("type", "Curve");
24
25 // Second access for storage.
27 auto property_name = config.peekConfigParameter<std::string>("name");
28
29 DBUG("Create Curve {:s}.", property_name);
30
32 auto curve_name = config.getConfigParameter<std::string>("curve");
33 DBUG("Using curve '{:s}'", curve_name);
34
35 auto const& curve =
36 *BaseLib::getOrError(curves, curve_name, "Could not find curve.");
37
38 auto const independent_variable_string =
40 config.getConfigParameter<std::string>("independent_variable");
41 DBUG("Using independent_variable '{:s}'", independent_variable_string);
42
43 static const std::unordered_set<std::string> filter_not_variables = {
44 "t", "x", "y", "z"};
45 MaterialPropertyLib::StringOrVariable independent_variable;
46 if (filter_not_variables.contains(independent_variable_string))
47 {
48 independent_variable = independent_variable_string;
49 }
50 else
51 {
53 independent_variable_string);
54 }
55
56 return std::make_unique<Curve>(
57 std::move(property_name), independent_variable, curve);
58}
59
60} // namespace MaterialPropertyLib
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
T peekConfigParameter(std::string const &param) const
T getConfigParameter(std::string const &param) const
void checkConfigParameter(std::string const &param, std::string_view const value) const
OGS_NO_DANGLING Map::mapped_type & getOrError(Map &map, Key const &key, std::string const &error_message)
Definition Algorithm.h:111
std::unique_ptr< Curve > createCurve(BaseLib::ConfigTree const &config, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)
std::variant< std::string, Variable > StringOrVariable
Definition Curve.h:12
Variable convertStringToVariable(std::string const &string)