fix: manual implementation of ranges::to as this is not supported by gcc 13
This commit is contained in:
parent
d06f287a91
commit
855ac4d654
|
|
@ -6,6 +6,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS 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)
|
find_package(netCDF REQUIRED)
|
||||||
|
|
||||||
add_executable(LinearInterpolate main.cpp
|
add_executable(LinearInterpolate main.cpp
|
||||||
|
|
@ -16,6 +20,7 @@ add_executable(LinearInterpolate main.cpp
|
||||||
UVGrid.cpp
|
UVGrid.cpp
|
||||||
UVGrid.h
|
UVGrid.h
|
||||||
Vel.h
|
Vel.h
|
||||||
|
to_vector.h
|
||||||
Vel.cpp)
|
Vel.cpp)
|
||||||
|
|
||||||
execute_process(
|
execute_process(
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include <print>
|
|
||||||
|
|
||||||
#include "UVGrid.h"
|
#include "UVGrid.h"
|
||||||
#include "readdata.h"
|
#include "readdata.h"
|
||||||
|
#include "to_vector.h"
|
||||||
|
|
||||||
#define sizeError2 "The sizes of the hydrodynamic data files are different"
|
#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"
|
#define sizeError "The sizes of the hydrodynamicU or -V files does not correspond with the sizes of the grid file"
|
||||||
|
|
@ -27,11 +27,12 @@ UVGrid::UVGrid() {
|
||||||
throw domain_error(sizeError);
|
throw domain_error(sizeError);
|
||||||
}
|
}
|
||||||
|
|
||||||
uvData = views::zip(us, vs)
|
uvData = to_vector(views::transform(views::zip(us, vs), [](auto pair){return Vel(pair);}));
|
||||||
| views::transform([](auto pair) {
|
// uvData = views::zip(us, vs)
|
||||||
return Vel(pair);
|
// | views::transform([](auto pair) {
|
||||||
})
|
// return Vel(pair);
|
||||||
| ranges::to<vector>();
|
// })
|
||||||
|
// | ranges::to<vector>();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vel &UVGrid::operator[](size_t timeIndex, size_t latIndex, size_t lonIndex) const {
|
const Vel &UVGrid::operator[](size_t timeIndex, size_t latIndex, size_t lonIndex) const {
|
||||||
|
|
@ -55,8 +56,8 @@ void UVGrid::printSlice(size_t t) {
|
||||||
for (int x = 0; x < latSize; x++) {
|
for (int x = 0; x < latSize; x++) {
|
||||||
for (int y = 0; y < lonSize; y++) {
|
for (int y = 0; y < lonSize; y++) {
|
||||||
auto [u,v] = (*this)[t,x,y];
|
auto [u,v] = (*this)[t,x,y];
|
||||||
print("({:>7.4f}, {:>7.4f}) ", u, v);
|
printf("%7.4f, %7.4f", u, v);
|
||||||
}
|
}
|
||||||
println("");
|
cout << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include <print>
|
|
||||||
|
|
||||||
#include "interpolate.h"
|
#include "interpolate.h"
|
||||||
|
#include "to_vector.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
@ -41,11 +41,9 @@ Vel bilinearInterpolate(const UVGrid &uvGrid, int time, double lat, double lon)
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<Vel> bilinearInterpolate(const UVGrid &uvGrid, vector<tuple<int, double, double>> points) {
|
vector<Vel> bilinearInterpolate(const UVGrid &uvGrid, vector<tuple<int, double, double>> points) {
|
||||||
auto results = points
|
auto results = points | std::views::transform([&uvGrid](const auto &point) {
|
||||||
| std::views::transform([&uvGrid](const auto &point) {
|
|
||||||
auto [time, lat, lon] = point;
|
auto [time, lat, lon] = point;
|
||||||
return bilinearInterpolate(uvGrid, time, lat, lon);
|
return bilinearInterpolate(uvGrid, time, lat, lon);
|
||||||
})
|
});
|
||||||
| std::ranges::to<std::vector<Vel>>();
|
return to_vector(results);
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#include "interpolate.h"
|
#include "interpolate.h"
|
||||||
#include "Vel.h"
|
#include "Vel.h"
|
||||||
#include <print>
|
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
@ -39,14 +39,14 @@ int main() {
|
||||||
|
|
||||||
auto duration = std::chrono::duration_cast<std::chrono::milliseconds >(stop - start);
|
auto duration = std::chrono::duration_cast<std::chrono::milliseconds >(stop - start);
|
||||||
|
|
||||||
println("Time taken for {} points was {} seconds", N, duration.count()/1000.);
|
printf("Time taken for %d points was %lf seconds\n", N, duration.count()/1000.);
|
||||||
|
|
||||||
// Do something with result in case of optimisation
|
// Do something with result in case of optimisation
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
for (auto [u,v]: x) {
|
for (auto [u,v]: x) {
|
||||||
sum += u + v;
|
sum += u + v;
|
||||||
}
|
}
|
||||||
println("Sum = {}", sum);
|
printf("Sum = %lf\n", sum);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
#include <print>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <netcdf>
|
#include <netcdf>
|
||||||
|
|
@ -46,4 +45,4 @@ tuple<vector<int>, vector<double>, vector<double>> readGrid() {
|
||||||
vector<double> latitude = getVarVector<double>(vars.find("latitude")->second);
|
vector<double> latitude = getVarVector<double>(vars.find("latitude")->second);
|
||||||
|
|
||||||
return {time, latitude, longitude};
|
return {time, latitude, longitude};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue