OGS
CreatePiecewiseLinearCurve.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
5
6#include <boost/endian/conversion.hpp>
7#include <fstream>
8#include <iostream>
9#include <vector>
10
11#include "BaseLib/ConfigTree.h"
12#include "BaseLib/Error.h"
13#include "BaseLib/FileTools.h"
14#include "BaseLib/StringTools.h"
15
16namespace MathLib
17{
19 BaseLib::ConfigTree const& config)
20{
21 const bool read_from_file =
23 config.getConfigParameter<bool>("read_from_file", false);
24
25 std::vector<double> x;
26 std::vector<double> y;
27
28 if (read_from_file)
29 {
30 auto const coords_file_name =
32 config.getConfigParameter<std::string>("coords");
33
34 auto const values_file_name =
36 config.getConfigParameter<std::string>("values");
37
39 coords_file_name, config.projectDirectory().string());
40
42 values_file_name, config.projectDirectory().string());
43 }
44 else
45 {
46 x =
48 config.getConfigParameter<std::vector<double>>("coords");
49 y =
51 config.getConfigParameter<std::vector<double>>("values");
52 }
53
54 if (x.empty() || y.empty())
55 {
56 OGS_FATAL("The given coordinates or values vector is empty.");
57 }
58 if (x.size() != y.size())
59 {
61 "The given coordinates and values vector sizes are "
62 "different.");
63 }
64
65 return {std::move(x), std::move(y)};
66}
67} // namespace MathLib
#define OGS_FATAL(...)
Definition Error.h:10
std::filesystem::path projectDirectory() const
T getConfigParameter(std::string const &param) const
std::vector< double > readDoublesFromBinaryFile(const std::string &filename, const std::string &project_directory)
PiecewiseLinearCurveConfig parsePiecewiseLinearCurveConfig(BaseLib::ConfigTree const &config)