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 =
22 config.getConfigParameter<bool>("read_from_file", false);
23
24 std::vector<double> x;
25 std::vector<double> y;
26
27 if (read_from_file == true)
28 {
29 auto const coords_file_name =
31 config.getConfigParameter<std::string>("coords");
32
33 auto const values_file_name =
35 config.getConfigParameter<std::string>("values");
36
38 coords_file_name, config.projectDirectory().string());
39
41 values_file_name, config.projectDirectory().string());
42 }
43 else
44 {
45 x =
47 config.getConfigParameter<std::vector<double>>("coords");
48 y =
50 config.getConfigParameter<std::vector<double>>("values");
51 }
52
53 if (x.empty() || y.empty())
54 {
55 OGS_FATAL("The given coordinates or values vector is empty.");
56 }
57 if (x.size() != y.size())
58 {
60 "The given coordinates and values vector sizes are "
61 "different.");
62 }
63
64 return {std::move(x), std::move(y)};
65}
66} // namespace MathLib
#define OGS_FATAL(...)
Definition Error.h:19
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)