This commit is contained in:
robin 2024-04-24 12:07:51 +02:00
parent db811ba902
commit 933fbf4503
7 changed files with 24 additions and 23 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required (VERSION 3.28) cmake_minimum_required (VERSION 3.28)
project (LinearInterpolate) project (Advection)
set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
@ -8,7 +8,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(netCDF REQUIRED) find_package(netCDF REQUIRED)
add_executable(LinearInterpolate main.cpp add_executable(Advection main.cpp
readdata.cpp readdata.cpp
readdata.h readdata.h
interpolate.cpp interpolate.cpp
@ -16,7 +16,8 @@ add_executable(LinearInterpolate main.cpp
UVGrid.cpp UVGrid.cpp
UVGrid.h UVGrid.h
Vel.h Vel.h
Vel.cpp) Vel.cpp
)
execute_process( execute_process(
COMMAND nc-config --includedir COMMAND nc-config --includedir
@ -30,7 +31,7 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_STRIP_TRAILING_WHITESPACE
) )
target_include_directories(LinearInterpolate PUBLIC ${netCDF_INCLUDE_DIR}) target_include_directories(Advection PUBLIC ${netCDF_INCLUDE_DIR})
find_library(NETCDF_LIB NAMES netcdf-cxx4 netcdf_c++4 PATHS ${NETCDFCXX_LIB_DIR} NO_DEFAULT_PATH) find_library(NETCDF_LIB NAMES netcdf-cxx4 netcdf_c++4 PATHS ${NETCDFCXX_LIB_DIR} NO_DEFAULT_PATH)
target_link_libraries(LinearInterpolate ${NETCDF_LIB}) target_link_libraries(Advection ${NETCDF_LIB})

View File

@ -1,5 +1,5 @@
#ifndef LINEARINTERPOLATE_UVGRID_H #ifndef ADVECTION_UVGRID_H
#define LINEARINTERPOLATE_UVGRID_H #define ADVECTION_UVGRID_H
#include <vector> #include <vector>
#include "Vel.h" #include "Vel.h"
@ -48,4 +48,4 @@ public:
void streamSlice(std::ostream &os, size_t t); void streamSlice(std::ostream &os, size_t t);
}; };
#endif //LINEARINTERPOLATE_UVGRID_H #endif //ADVECTION_UVGRID_H

View File

@ -1,5 +1,5 @@
#ifndef LINEARINTERPOLATE_VEL_H #ifndef ADVECTION_VEL_H
#define LINEARINTERPOLATE_VEL_H #define ADVECTION_VEL_H
#include <utility> #include <utility>
#include <stdexcept> #include <stdexcept>
@ -41,4 +41,4 @@ Vel operator*(Scalar scalar, const Vel& p) {
return Vel(p.u * scalar, p.v * scalar); return Vel(p.u * scalar, p.v * scalar);
} }
#endif //LINEARINTERPOLATE_VEL_H #endif //ADVECTION_VEL_H

View File

@ -2,7 +2,7 @@
using namespace std; using namespace std;
Vel bilinearInterpolate(const UVGrid &uvGrid, int time, double lat, double lon) { Vel biadvection(const UVGrid &uvGrid, int time, double lat, double lon) {
double latStep = uvGrid.latStep(); double latStep = uvGrid.latStep();
double lonStep = uvGrid.lonStep(); double lonStep = uvGrid.lonStep();
int timeStep = uvGrid.timeStep(); int timeStep = uvGrid.timeStep();
@ -36,11 +36,11 @@ Vel bilinearInterpolate(const UVGrid &uvGrid, int time, double lat, double lon)
return point; return point;
} }
vector<Vel> bilinearInterpolate(const UVGrid &uvGrid, vector<tuple<int, double, double>> points) { vector<Vel> biadvection(const UVGrid &uvGrid, vector<tuple<int, double, double>> points) {
vector<Vel> result; vector<Vel> result;
result.reserve(points.size()); result.reserve(points.size());
for (auto [time, lat, lon]: points) { for (auto [time, lat, lon]: points) {
result.push_back(bilinearInterpolate(uvGrid, time, lat, lon)); result.push_back(biadvection(uvGrid, time, lat, lon));
} }
return result; return result;

View File

@ -1,5 +1,5 @@
#ifndef LINEARINTERPOLATE_INTERPOLATE_H #ifndef ADVECTION_INTERPOLATE_H
#define LINEARINTERPOLATE_INTERPOLATE_H #define ADVECTION_INTERPOLATE_H
#include <vector> #include <vector>
@ -15,7 +15,7 @@
* @param lon longitude of point * @param lon longitude of point
* @return interpolated velocity * @return interpolated velocity
*/ */
Vel bilinearInterpolate(const UVGrid &uvGrid, int time, double lat, double lon); Vel biadvection(const UVGrid &uvGrid, int time, double lat, double lon);
/** /**
* Helper function for bilnearly interpolating a vector of points * Helper function for bilnearly interpolating a vector of points
@ -23,6 +23,6 @@ Vel bilinearInterpolate(const UVGrid &uvGrid, int time, double lat, double lon);
* @param points vector of points * @param points vector of points
* @return interpolated velocities * @return interpolated velocities
*/ */
std::vector<Vel> bilinearInterpolate(const UVGrid &uvGrid, std::vector<std::tuple<int, double, double>> points); std::vector<Vel> biadvection(const UVGrid &uvGrid, std::vector<std::tuple<int, double, double>> points);
#endif //LINEARINTERPOLATE_INTERPOLATE_H #endif //ADVECTION_INTERPOLATE_H

View File

@ -32,7 +32,7 @@ int main() {
auto start = chrono::high_resolution_clock::now(); auto start = chrono::high_resolution_clock::now();
auto x = bilinearInterpolate(uvGrid, points); auto x = biadvection(uvGrid, points);
auto stop = chrono::high_resolution_clock::now(); auto stop = chrono::high_resolution_clock::now();

View File

@ -1,5 +1,5 @@
#ifndef LINEARINTERPOLATE_READDATA_H #ifndef ADVECTION_READDATA_H
#define LINEARINTERPOLATE_READDATA_H #define ADVECTION_READDATA_H
/** /**
* reads the file hydrodynamic_U.h5 * reads the file hydrodynamic_U.h5
@ -19,4 +19,4 @@ std::vector<double> readHydrodynamicV();
*/ */
std::tuple<std::vector<int>, std::vector<double>, std::vector<double>> readGrid(); std::tuple<std::vector<int>, std::vector<double>, std::vector<double>> readGrid();
#endif //LINEARINTERPOLATE_READDATA_H #endif //ADVECTION_READDATA_H