removed some functional stuff
This commit is contained in:
parent
6288a43da7
commit
ea23ed9d68
|
|
@ -6,10 +6,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
# Make flags for release compilation
|
||||
# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall -DNDEBUG")
|
||||
|
||||
|
||||
find_package(netCDF REQUIRED)
|
||||
|
||||
add_executable(LinearInterpolate main.cpp
|
||||
|
|
@ -20,7 +16,6 @@ add_executable(LinearInterpolate main.cpp
|
|||
UVGrid.cpp
|
||||
UVGrid.h
|
||||
Vel.h
|
||||
to_vector.h
|
||||
Vel.cpp)
|
||||
|
||||
execute_process(
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "UVGrid.h"
|
||||
#include "readdata.h"
|
||||
#include "to_vector.h"
|
||||
|
||||
#define sizeError2 "The sizes of the hydrodynamic data files are different"
|
||||
#define sizeError "The sizes of the hydrodynamicU or -V files does not correspond with the sizes of the grid file"
|
||||
|
|
@ -27,12 +26,11 @@ UVGrid::UVGrid() {
|
|||
throw domain_error(sizeError);
|
||||
}
|
||||
|
||||
uvData = to_vector(views::transform(views::zip(us, vs), [](auto pair){return Vel(pair);}));
|
||||
// uvData = views::zip(us, vs)
|
||||
// | views::transform([](auto pair) {
|
||||
// return Vel(pair);
|
||||
// })
|
||||
// | ranges::to<vector>();
|
||||
uvData.reserve(gridSize);
|
||||
|
||||
for (auto vel: views::zip(us, vs)) {
|
||||
uvData.push_back(Vel(vel));
|
||||
}
|
||||
}
|
||||
|
||||
const Vel &UVGrid::operator[](size_t timeIndex, size_t latIndex, size_t lonIndex) const {
|
||||
|
|
@ -52,12 +50,12 @@ int UVGrid::timeStep() const {
|
|||
return times[1] - times[0];
|
||||
}
|
||||
|
||||
void UVGrid::printSlice(size_t t) {
|
||||
void UVGrid::streamSlice(ostream &os, size_t t) {
|
||||
for (int x = 0; x < latSize; x++) {
|
||||
for (int y = 0; y < lonSize; y++) {
|
||||
auto [u,v] = (*this)[t,x,y];
|
||||
printf("%7.4f, %7.4f", u, v);
|
||||
auto vel = (*this)[t,x,y];
|
||||
os << vel << " ";
|
||||
}
|
||||
cout << endl;
|
||||
os << endl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,11 +45,7 @@ public:
|
|||
*/
|
||||
const Vel& operator[](size_t timeIndex, size_t latIndex, size_t lonIndex) const;
|
||||
|
||||
// Friend declaration for the stream insertion operator
|
||||
friend std::ostream& operator<<(std::ostream& os, const UVGrid& vel);
|
||||
|
||||
void printSlice(size_t t);
|
||||
void streamSlice(std::ostream &os, size_t t);
|
||||
};
|
||||
|
||||
|
||||
#endif //LINEARINTERPOLATE_UVGRID_H
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
#include "Vel.h"
|
||||
#include <stdexcept>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace std;
|
||||
|
||||
Vel::Vel(double u, double v) : u(u), v(v) {}
|
||||
|
||||
|
|
@ -27,7 +30,11 @@ Vel Vel::operator/(Scalar scalar) const {
|
|||
return Vel(u / scalar, v / scalar);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Vel& vel) {
|
||||
os << "(" << vel.u << ", " << vel.v << ")";
|
||||
std::ostream& operator<<(ostream& os, const Vel& vel) {
|
||||
os << "(";
|
||||
os << fixed << setprecision(2) << setw(5) << vel.u;
|
||||
os << ", ";
|
||||
os << fixed << setprecision(2) << setw(5) << vel.v;
|
||||
os << ")";
|
||||
return os;
|
||||
}
|
||||
|
|
@ -1,8 +1,4 @@
|
|||
#include <cmath>
|
||||
#include <ranges>
|
||||
|
||||
#include "interpolate.h"
|
||||
#include "to_vector.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
@ -41,9 +37,11 @@ Vel bilinearInterpolate(const UVGrid &uvGrid, int time, double lat, double lon)
|
|||
}
|
||||
|
||||
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);
|
||||
});
|
||||
return to_vector(results);
|
||||
vector<Vel> result;
|
||||
result.reserve(points.size());
|
||||
for (auto [time, lat, lon]: points) {
|
||||
result.push_back(bilinearInterpolate(uvGrid, time, lat, lon));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using namespace std;
|
|||
|
||||
int main() {
|
||||
UVGrid uvGrid;
|
||||
uvGrid.printSlice(100);
|
||||
uvGrid.streamSlice(cout, 100);
|
||||
|
||||
int N = 10000000; // Number of points
|
||||
|
||||
|
|
@ -20,7 +20,6 @@ int main() {
|
|||
double lon_start = -15.875;
|
||||
double lon_end = 12.875;
|
||||
|
||||
// Calculate increments
|
||||
double lat_step = (lat_end - lat_start) / (N - 1);
|
||||
double lon_step = (lon_end - lon_start) / (N - 1);
|
||||
int time_step = (time_end - time_start) / (N - 1);
|
||||
|
|
@ -31,22 +30,22 @@ int main() {
|
|||
points.push_back({time_start+time_step*i, lat_start+lat_step*i, lon_start+lon_step*i});
|
||||
}
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
auto start = chrono::high_resolution_clock::now();
|
||||
|
||||
auto x = bilinearInterpolate(uvGrid, points);
|
||||
|
||||
auto stop = std::chrono::high_resolution_clock::now();
|
||||
auto stop = chrono::high_resolution_clock::now();
|
||||
|
||||
auto duration = std::chrono::duration_cast<std::chrono::milliseconds >(stop - start);
|
||||
auto duration = chrono::duration_cast<std::chrono::milliseconds >(stop - start);
|
||||
|
||||
printf("Time taken for %d points was %lf seconds\n", N, duration.count()/1000.);
|
||||
cout << "Time taken for " << N << " points was " << duration.count()/1000. << " seconds\n";
|
||||
|
||||
// Do something with result in case of optimisation
|
||||
double sum = 0;
|
||||
for (auto [u,v]: x) {
|
||||
sum += u + v;
|
||||
}
|
||||
printf("Sum = %lf\n", sum);
|
||||
cout << "Sum = " << sum << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
#ifndef TO_VECTOR_H
|
||||
#define TO_VECTOR_H
|
||||
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
|
||||
template <std::ranges::range R>
|
||||
auto to_vector(R&& r) {
|
||||
std::vector<std::ranges::range_value_t<R>> v;
|
||||
|
||||
// if we can get a size, reserve that much
|
||||
if constexpr (requires { std::ranges::size(r); }) {
|
||||
v.reserve(std::ranges::size(r));
|
||||
}
|
||||
|
||||
// push all the elements
|
||||
for (auto&& e : r) {
|
||||
v.push_back(static_cast<decltype(e)&&>(e));
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue