removed mdspan requirement

This commit is contained in:
robin committed 2024-04-23 12:21:08 +02:00
1 parent 51fe302920
commit b2415d8c4d
16 files changed
+255 -197

No files matched your search

+30 -22
View File
@@ -1,39 +1,37 @@
#include <cmath>
#include <ranges>
#include <print>
#include "interpolate.h"
using namespace std;
// Inspired by https://numerical.recipes/book.html Chapter 3.6
point bilinearInterpolate(const UVGrid &uvGrid, std::tuple<int, double, double> timeLatLon) {
auto [time, lat, lon] = timeLatLon;
Vel bilinearInterpolate(const UVGrid &uvGrid, int time, double lat, double lon) {
double latStep = uvGrid.latStep();
double lonStep = uvGrid.lonStep();
int timeStep = uvGrid.timeStep();
int latIndex = (lat-uvGrid.lats[0])/latStep;
int lonIndex = (lon-uvGrid.lons[0])/lonStep;
int timeIndex = (time-uvGrid.times[0])/timeStep;
int latIndex = (lat - uvGrid.lats[0]) / latStep;
int lonIndex = (lon - uvGrid.lons[0]) / lonStep;
int timeIndex = (time - uvGrid.times[0]) / timeStep;
double timeRatio = (static_cast<double>(time)-uvGrid.times[timeIndex])/timeStep;
double latRatio = (lat-uvGrid.lats[latIndex]) / latStep;
double lonRatio = (lon-uvGrid.lons[lonIndex]) / lonStep;
double timeRatio = (static_cast<double>(time) - uvGrid.times[timeIndex]) / timeStep;
double latRatio = (lat - uvGrid.lats[latIndex]) / latStep;
double lonRatio = (lon - uvGrid.lons[lonIndex]) / lonStep;
point point = {0, 0};
for(int time = 0; time <= 1; time++) {
for(int lat = 0; lat <= 1; lat++) {
for(int lon = 0; lon <= 1; lon++) {
auto vertex = uvGrid.uvMatrix[
timeIndex + time < uvGrid.uvMatrix.extent(0) ? timeIndex + 1 : timeIndex,
latIndex + lat < uvGrid.uvMatrix.extent(1) ? latIndex + 1 : latIndex,
lonIndex + lon < uvGrid.uvMatrix.extent(2) ? lonIndex + 1 : lonIndex
Vel point = {0, 0};
for (int timeOffset = 0; timeOffset <= 1; timeOffset++) {
for (int latOffset = 0; latOffset <= 1; latOffset++) {
for (int lonOffset = 0; lonOffset <= 1; lonOffset++) {
auto vertex = uvGrid[
timeIndex + 1 < uvGrid.timeSize ? timeIndex + timeOffset : timeIndex,
latIndex + 1 < uvGrid.latSize ? latIndex + latOffset : latIndex,
lonIndex + 1 < uvGrid.lonSize ? lonIndex + lonOffset : lonIndex
];
double timeRation = (1 - time)*(1-timeRatio) + time*timeRatio;
double latRation = (1 - lat)*(1-latRatio) + lat*latRatio;
double lonRation = (1 - lon)*(1-lonRatio) + lon*lonRatio;
double timeRation = (1 - timeOffset) * (1 - timeRatio) + timeOffset * timeRatio;
double latRation = (1 - latOffset) * (1 - latRatio) + latOffset * latRatio;
double lonRation = (1 - lonOffset) * (1 - lonRatio) + lonOffset * lonRatio;
point += timeRation * latRation * lonRation * vertex;
}
}
@@ -41,3 +39,13 @@ point bilinearInterpolate(const UVGrid &uvGrid, std::tuple<int, double, double>
return point;
}
vector<Vel> bilinearInterpolate(const UVGrid &uvGrid, vector<tuple<int, double, double>> points) {
auto results = points
| std::views::transform([&uvGrid](const auto &point) {
auto [time, lat, lon] = point;
return bilinearInterpolate(uvGrid, time, lat, lon);
})
| std::ranges::to<std::vector<Vel>>();
return results;
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.