ryujin 2.1.1 revision 003d8fa0b21a2fd867c2893d046eb34a0f9e932c
cubic_spline.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 2020 - 2021 by the ryujin authors
4//
5
6#pragma once
7
8#include <compile_time_options.h>
9
10#ifdef DEAL_II_WITH_GSL
11#include <gsl/gsl_spline.h>
12
13namespace ryujin
14{
31 {
32 public:
39 CubicSpline(const std::vector<double> &x,
40 const std::vector<double> &y) noexcept
41 : x_(x)
42 , y_(y)
43 {
44 AssertNothrow(x_.size() == y_.size(), dealii::ExcInternalError());
45 AssertNothrow(x_.size() >= 2, dealii::ExcInternalError());
46 AssertNothrow(std::is_sorted(x_.begin(), x_.end()),
47 dealii::ExcInternalError());
48
49 spline = gsl_spline_alloc(gsl_interp_cspline, x_.size());
50 gsl_spline_init(spline, x_.data(), y_.data(), x_.size());
51
52 accel = gsl_interp_accel_alloc();
53 }
54
59 : CubicSpline(copy.x_, copy.y_)
60 {
61 }
62
66 CubicSpline &operator=(const CubicSpline &) = delete;
67
72 {
73 gsl_interp_accel_free(accel);
74 gsl_spline_free(spline);
75 }
76
83 inline double eval(double x) const
84 {
85 return gsl_spline_eval(spline, x, accel);
86 }
87
88 private:
89 const std::vector<double> x_;
90 const std::vector<double> y_;
91 gsl_spline *spline;
92 mutable gsl_interp_accel *accel;
93 };
94} // namespace ryujin
95
96#endif
CubicSpline & operator=(const CubicSpline &)=delete
CubicSpline(const CubicSpline &copy)
Definition: cubic_spline.h:58
double eval(double x) const
Definition: cubic_spline.h:83
CubicSpline(const std::vector< double > &x, const std::vector< double > &y) noexcept
Definition: cubic_spline.h:39