euler integration maybe working
This commit is contained in:
15
advection/src/AdvectionKernel.h
Normal file
15
advection/src/AdvectionKernel.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef ADVECTION_ADVECTIONKERNEL_H
|
||||
#define ADVECTION_ADVECTIONKERNEL_H
|
||||
|
||||
#include <tuple>
|
||||
|
||||
#include "Vel.h"
|
||||
|
||||
#define DT 4000
|
||||
|
||||
class AdvectionKernel {
|
||||
public:
|
||||
virtual std::pair<double, double> advect(int time, double latitude, double longitude) const = 0;
|
||||
};
|
||||
|
||||
#endif //ADVECTION_ADVECTIONKERNEL_H
|
||||
@@ -17,6 +17,9 @@ add_executable(Advection main.cpp
|
||||
UVGrid.h
|
||||
Vel.h
|
||||
Vel.cpp
|
||||
AdvectionKernel.h
|
||||
EulerAdvectionKernel.cpp
|
||||
EulerAdvectionKernel.h
|
||||
)
|
||||
|
||||
execute_process(
|
||||
|
||||
11
advection/src/EulerAdvectionKernel.cpp
Normal file
11
advection/src/EulerAdvectionKernel.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
#include "EulerAdvectionKernel.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
EulerAdvectionKernel::EulerAdvectionKernel(std::shared_ptr<UVGrid> grid) { }
|
||||
|
||||
std::pair<double, double> EulerAdvectionKernel::advect(int time, double latitude, double longitude) const {
|
||||
auto [u,v] = (*grid)[time, latitude, longitude];
|
||||
return {latitude+u*DT, longitude+v*DT};
|
||||
}
|
||||
17
advection/src/EulerAdvectionKernel.h
Normal file
17
advection/src/EulerAdvectionKernel.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef ADVECTION_EULERADVECTIONKERNEL_H
|
||||
#define ADVECTION_EULERADVECTIONKERNEL_H
|
||||
|
||||
#include "AdvectionKernel.h"
|
||||
#include "UVGrid.h"
|
||||
|
||||
class EulerAdvectionKernel: public AdvectionKernel {
|
||||
private:
|
||||
std::shared_ptr<UVGrid> grid;
|
||||
public:
|
||||
explicit EulerAdvectionKernel(std::shared_ptr<UVGrid> grid);
|
||||
std::pair<double, double> advect(int time, double latitude, double longitude) const override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //ADVECTION_EULERADVECTIONKERNEL_H
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
Vel biadvection(const UVGrid &uvGrid, int time, double lat, double lon) {
|
||||
Vel bilinearinterpolation(const UVGrid &uvGrid, int time, double lat, double lon) {
|
||||
double latStep = uvGrid.latStep();
|
||||
double lonStep = uvGrid.lonStep();
|
||||
int timeStep = uvGrid.timeStep();
|
||||
@@ -36,11 +36,11 @@ Vel biadvection(const UVGrid &uvGrid, int time, double lat, double lon) {
|
||||
return point;
|
||||
}
|
||||
|
||||
vector<Vel> biadvection(const UVGrid &uvGrid, vector<tuple<int, double, double>> points) {
|
||||
vector<Vel> bilinearinterpolation(const UVGrid &uvGrid, vector<tuple<int, double, double>> points) {
|
||||
vector<Vel> result;
|
||||
result.reserve(points.size());
|
||||
for (auto [time, lat, lon]: points) {
|
||||
result.push_back(biadvection(uvGrid, time, lat, lon));
|
||||
result.push_back(bilinearinterpolation(uvGrid, time, lat, lon));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* @param lon longitude of point
|
||||
* @return interpolated velocity
|
||||
*/
|
||||
Vel biadvection(const UVGrid &uvGrid, int time, double lat, double lon);
|
||||
Vel bilinearinterpolation(const UVGrid &uvGrid, int time, double lat, double lon);
|
||||
|
||||
/**
|
||||
* Helper function for bilnearly interpolating a vector of points
|
||||
@@ -23,6 +23,6 @@ Vel biadvection(const UVGrid &uvGrid, int time, double lat, double lon);
|
||||
* @param points vector of points
|
||||
* @return interpolated velocities
|
||||
*/
|
||||
std::vector<Vel> biadvection(const UVGrid &uvGrid, std::vector<std::tuple<int, double, double>> points);
|
||||
std::vector<Vel> bilinearinterpolation(const UVGrid &uvGrid, std::vector<std::tuple<int, double, double>> points);
|
||||
|
||||
#endif //ADVECTION_INTERPOLATE_H
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
UVGrid uvGrid;
|
||||
uvGrid.streamSlice(cout, 100);
|
||||
// UVGrid uvGrid;
|
||||
std::shared_ptr<UVGrid> uvGrid = std::make_shared<UVGrid>();
|
||||
uvGrid->streamSlice(cout, 100);
|
||||
|
||||
int N = 10000000; // Number of points
|
||||
|
||||
@@ -32,7 +33,7 @@ int main() {
|
||||
|
||||
auto start = chrono::high_resolution_clock::now();
|
||||
|
||||
auto x = biadvection(uvGrid, points);
|
||||
auto x = bilinearinterpolation(*uvGrid, points);
|
||||
|
||||
auto stop = chrono::high_resolution_clock::now();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user