Vulcan
Aerospace Engineering Utilities Built on Janus
Loading...
Searching...
No Matches
TableInterpolator.hpp
Go to the documentation of this file.
1// Vulcan Table Interpolation Wrapper
2// Thin wrappers around janus::Interpolator and janus::ScatteredInterpolator
3// for atmospheric/aero property lookups
4#pragma once
5
6#include <janus/math/Interpolate.hpp>
7#include <janus/math/ScatteredInterpolator.hpp>
8#include <vector>
9
10namespace vulcan {
11
12// Re-export RBF kernel types for convenience
13using janus::RBFKernel;
14
15// ============================================================================
16// Table1D - One-dimensional table interpolation
17// ============================================================================
18
37class Table1D {
38 private:
39 janus::Interpolator m_interp;
40
41 public:
51 const janus::NumericVector &x, const janus::NumericVector &y,
52 janus::InterpolationMethod method = janus::InterpolationMethod::Linear)
53 : m_interp(x, y, method) {}
54
64 template <janus::JanusScalar Scalar>
65 Scalar operator()(const Scalar &x) const {
66 return m_interp(x);
67 }
68
76 template <typename Derived>
77 auto operator()(const Eigen::MatrixBase<Derived> &x) const {
78 return m_interp(x);
79 }
80
84 janus::InterpolationMethod method() const { return m_interp.method(); }
85
89 bool valid() const { return m_interp.valid(); }
90};
91
92// ============================================================================
93// TableND - N-dimensional table interpolation
94// ============================================================================
95
123class TableND {
124 private:
125 janus::Interpolator m_interp;
126 int m_dims;
127
128 public:
139 const std::vector<janus::NumericVector> &grid_points,
140 const janus::NumericVector &values,
141 janus::InterpolationMethod method = janus::InterpolationMethod::Linear)
142 : m_interp(grid_points, values, method),
143 m_dims(static_cast<int>(grid_points.size())) {}
144
152 template <janus::JanusScalar Scalar>
153 Scalar operator()(const janus::JanusVector<Scalar> &x) const {
154 return m_interp(x);
155 }
156
164 template <typename Derived>
165 auto operator()(const Eigen::MatrixBase<Derived> &x) const {
166 return m_interp(x);
167 }
168
172 int dims() const { return m_dims; }
173
177 janus::InterpolationMethod method() const { return m_interp.method(); }
178
182 bool valid() const { return m_interp.valid(); }
183};
184
185// ============================================================================
186// ScatteredTable1D - One-dimensional scattered data interpolation
187// ============================================================================
188
209 private:
210 janus::ScatteredInterpolator m_interp;
211
212 public:
222 ScatteredTable1D(const janus::NumericVector &x,
223 const janus::NumericVector &y, int grid_resolution = 50,
224 RBFKernel kernel = RBFKernel::ThinPlateSpline)
225 : m_interp(x, y, grid_resolution, kernel) {}
226
234 template <janus::JanusScalar Scalar>
235 Scalar operator()(const Scalar &x) const {
236 return m_interp(x);
237 }
238
244 double reconstruction_error() const {
245 return m_interp.reconstruction_error();
246 }
247
251 int dims() const { return m_interp.dims(); }
252
256 bool valid() const { return m_interp.valid(); }
257};
258
259// ============================================================================
260// ScatteredTableND - N-dimensional scattered data interpolation
261// ============================================================================
262
286 private:
287 janus::ScatteredInterpolator m_interp;
288
289 public:
302 const janus::NumericMatrix &points, const janus::NumericVector &values,
303 int grid_resolution = 20, RBFKernel kernel = RBFKernel::ThinPlateSpline,
304 double epsilon = 1.0,
305 janus::InterpolationMethod method = janus::InterpolationMethod::Linear)
306 : m_interp(points, values, grid_resolution, kernel, epsilon, method) {}
307
319 const janus::NumericMatrix &points, const janus::NumericVector &values,
320 const std::vector<janus::NumericVector> &grid_points,
321 RBFKernel kernel = RBFKernel::ThinPlateSpline, double epsilon = 1.0,
322 janus::InterpolationMethod method = janus::InterpolationMethod::Linear)
323 : m_interp(points, values, grid_points, kernel, epsilon, method) {}
324
332 template <janus::JanusScalar Scalar>
333 Scalar operator()(const janus::JanusVector<Scalar> &x) const {
334 return m_interp(x);
335 }
336
342 double reconstruction_error() const {
343 return m_interp.reconstruction_error();
344 }
345
349 int dims() const { return m_interp.dims(); }
350
354 bool valid() const { return m_interp.valid(); }
355};
356
357} // namespace vulcan
double reconstruction_error() const
Get RMS reconstruction error at original data points.
Definition TableInterpolator.hpp:244
bool valid() const
Check if table is valid (initialized).
Definition TableInterpolator.hpp:256
ScatteredTable1D(const janus::NumericVector &x, const janus::NumericVector &y, int grid_resolution=50, RBFKernel kernel=RBFKernel::ThinPlateSpline)
Construct 1D scattered interpolation table.
Definition TableInterpolator.hpp:222
int dims() const
Get number of dimensions (always 1).
Definition TableInterpolator.hpp:251
Scalar operator()(const Scalar &x) const
Query table at a single point.
Definition TableInterpolator.hpp:235
bool valid() const
Check if table is valid (initialized).
Definition TableInterpolator.hpp:354
ScatteredTableND(const janus::NumericMatrix &points, const janus::NumericVector &values, int grid_resolution=20, RBFKernel kernel=RBFKernel::ThinPlateSpline, double epsilon=1.0, janus::InterpolationMethod method=janus::InterpolationMethod::Linear)
Construct N-D scattered interpolation table.
Definition TableInterpolator.hpp:301
int dims() const
Get number of input dimensions.
Definition TableInterpolator.hpp:349
ScatteredTableND(const janus::NumericMatrix &points, const janus::NumericVector &values, const std::vector< janus::NumericVector > &grid_points, RBFKernel kernel=RBFKernel::ThinPlateSpline, double epsilon=1.0, janus::InterpolationMethod method=janus::InterpolationMethod::Linear)
Construct with explicit per-dimension grid specification.
Definition TableInterpolator.hpp:318
double reconstruction_error() const
Get RMS reconstruction error at original data points.
Definition TableInterpolator.hpp:342
Scalar operator()(const janus::JanusVector< Scalar > &x) const
Query table at a single N-D point.
Definition TableInterpolator.hpp:333
auto operator()(const Eigen::MatrixBase< Derived > &x) const
Query table at multiple points (batch evaluation).
Definition TableInterpolator.hpp:77
Scalar operator()(const Scalar &x) const
Query table at a single point.
Definition TableInterpolator.hpp:65
bool valid() const
Check if table is valid (initialized).
Definition TableInterpolator.hpp:89
janus::InterpolationMethod method() const
Get the interpolation method.
Definition TableInterpolator.hpp:84
Table1D(const janus::NumericVector &x, const janus::NumericVector &y, janus::InterpolationMethod method=janus::InterpolationMethod::Linear)
Construct 1D interpolation table.
Definition TableInterpolator.hpp:50
TableND(const std::vector< janus::NumericVector > &grid_points, const janus::NumericVector &values, janus::InterpolationMethod method=janus::InterpolationMethod::Linear)
Construct N-dimensional interpolation table.
Definition TableInterpolator.hpp:138
Scalar operator()(const janus::JanusVector< Scalar > &x) const
Query table at a single N-D point.
Definition TableInterpolator.hpp:153
auto operator()(const Eigen::MatrixBase< Derived > &x) const
Query table at multiple N-D points (batch evaluation).
Definition TableInterpolator.hpp:165
bool valid() const
Check if table is valid (initialized).
Definition TableInterpolator.hpp:182
int dims() const
Get number of dimensions.
Definition TableInterpolator.hpp:172
janus::InterpolationMethod method() const
Get the interpolation method.
Definition TableInterpolator.hpp:177
Definition Aerodynamics.hpp:11