OGS
CreatePiecewiseLinearCurve.cpp
Go to the documentation of this file.
1
13
#include "
CreatePiecewiseLinearCurve.h
"
14
15
#include <boost/endian/conversion.hpp>
16
#include <fstream>
17
#include <iostream>
18
#include <vector>
19
20
#include "
BaseLib/ConfigTree.h
"
21
#include "
BaseLib/Error.h
"
22
#include "
BaseLib/FileTools.h
"
23
#include "
BaseLib/StringTools.h
"
24
25
namespace
MathLib
26
{
27
PiecewiseLinearCurveConfig
parsePiecewiseLinearCurveConfig
(
28
BaseLib::ConfigTree
const
& config)
29
{
30
const
bool
read_from_file =
31
config.
getConfigParameter
<
bool
>(
"read_from_file"
,
false
);
32
33
std::vector<double> x;
34
std::vector<double> y;
35
36
if
(read_from_file ==
true
)
37
{
38
auto
const
coords_file_name =
40
config.
getConfigParameter
<std::string>(
"coords"
);
41
42
auto
const
values_file_name =
44
config.
getConfigParameter
<std::string>(
"values"
);
45
46
x =
BaseLib::readDoublesFromBinaryFile
(coords_file_name);
47
48
y =
BaseLib::readDoublesFromBinaryFile
(values_file_name);
49
}
50
else
51
{
52
x =
54
config.
getConfigParameter
<std::vector<double>>(
"coords"
);
55
y =
57
config.
getConfigParameter
<std::vector<double>>(
"values"
);
58
}
59
60
if
(x.empty() || y.empty())
61
{
62
OGS_FATAL
(
"The given coordinates or values vector is empty."
);
63
}
64
if
(x.size() != y.size())
65
{
66
OGS_FATAL
(
67
"The given coordinates and values vector sizes are "
68
"different."
);
69
}
70
71
return
{std::move(x), std::move(y)};
72
}
73
}
// namespace MathLib
ConfigTree.h
CreatePiecewiseLinearCurve.h
Error.h
OGS_FATAL
#define OGS_FATAL(...)
Definition
Error.h:26
FileTools.h
Filename manipulation routines.
StringTools.h
Definition of string helper functions.
BaseLib::ConfigTree
Definition
ConfigTree.h:107
BaseLib::ConfigTree::getConfigParameter
T getConfigParameter(std::string const ¶m) const
Definition
ConfigTree-impl.h:41
BaseLib::readDoublesFromBinaryFile
std::vector< double > readDoublesFromBinaryFile(const std::string &filename)
Definition
FileTools.cpp:283
MathLib
Definition
CreateComponent.h:32
MathLib::parsePiecewiseLinearCurveConfig
PiecewiseLinearCurveConfig parsePiecewiseLinearCurveConfig(BaseLib::ConfigTree const &config)
Definition
CreatePiecewiseLinearCurve.cpp:27
MathLib::PiecewiseLinearCurveConfig
Definition
CreatePiecewiseLinearCurve.h:27
MathLib
Curve
CreatePiecewiseLinearCurve.cpp
Generated by
1.10.0