interpolation1d
done single-threded 1d interpolations; linear, rational, cubic spline, polynomial and barycentric. Still not done test functions yet. Still missing multi-core options.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "utils/vector.h"
|
||||
|
||||
|
||||
namespace fvm {
|
||||
|
||||
template <typename T>
|
||||
|
||||
struct Grid1D{
|
||||
uint64_t center_idx; // max cell index
|
||||
uint64_t vertices_idx; // max vertice index
|
||||
utils::Vector<T> centers; // size N (unknowns at cell centers)
|
||||
utils::Vector<T> vertices; // size N+1 (face positions)
|
||||
|
||||
Grid1D() = default;
|
||||
|
||||
explicit Grid1D(const utils::Vector<T>& midpoints){
|
||||
centers = midpoints;
|
||||
center_idx = centers.size()-1;
|
||||
vertices_idx = centers.size();
|
||||
}
|
||||
|
||||
void generate_vertices(T left, T right){
|
||||
vertices.resize(vertices_idx+1);
|
||||
vertices[0] = left;
|
||||
vertices[vertices_idx] = right;
|
||||
for (uint64_t i = 1; i < center_idx+1; ++i){
|
||||
vertices[i] = (centers[i-1] + centers[i])*0.5;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
T dx(uint64_t i) const { check(i); return vertices[i+1] - vertices[i]; }
|
||||
T center(uint64_t i) const { check(i); return centers[i]; }
|
||||
|
||||
void check(uint64_t i) const {
|
||||
if (i > center_idx) throw std::runtime_error("Grid1D: cell index out of range");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user