fix: readme and static const DT
This commit is contained in:
parent
78b784cf68
commit
824fb967a2
|
|
@ -1,3 +1,28 @@
|
||||||
|
## What is new?
|
||||||
|
There is one new added component: `AdvectionKernel`s which is an "interface" (i.e an abstract class).
|
||||||
|
There are two implementations simple Euler integration called `EulerIntegrationKernel` and
|
||||||
|
Runge Kutta integration called `RK4AdvectionKernel`.
|
||||||
|
|
||||||
|
Main function gives a good example of how to use the library. Especially the following function which prints the
|
||||||
|
position of the particle at every time step.
|
||||||
|
```Cpp
|
||||||
|
template <typename AdvectionKernelImpl>
|
||||||
|
void advectForSomeTime(const UVGrid &uvGrid, const AdvectionKernelImpl &kernel, double latstart, double lonstart) {
|
||||||
|
|
||||||
|
// Require at compile time that kernel derives from the abstract class AdvectionKernel
|
||||||
|
static_assert(std::is_base_of<AdvectionKernel, AdvectionKernelImpl>::value, NotAKernelError);
|
||||||
|
|
||||||
|
double lat1 = latstart, lon1 = lonstart;
|
||||||
|
for(int time = 100; time <= 10000; time += AdvectionKernel::DT) {
|
||||||
|
cout << "lat = " << lat1 << " lon = " << lon1 << endl;
|
||||||
|
auto [templat, templon] = kernel.advect(time, lat1, lon1);
|
||||||
|
lat1 = templat;
|
||||||
|
lon1 = templon;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Location of data
|
## Location of data
|
||||||
The data path is hardcoded such that the following tree structure is assumed:
|
The data path is hardcoded such that the following tree structure is assumed:
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -5,22 +5,23 @@
|
||||||
|
|
||||||
#include "Vel.h"
|
#include "Vel.h"
|
||||||
|
|
||||||
#define DT 50
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Implement this class for every integration method.
|
* Implement this class for every integration method.
|
||||||
*/
|
*/
|
||||||
class AdvectionKernel {
|
class AdvectionKernel {
|
||||||
public:
|
public:
|
||||||
|
const static int DT = 50;
|
||||||
/**
|
/**
|
||||||
* This function must take a time, latitude and longitude of a particle and must output
|
* This function must take a time, latitude and longitude of a particle and must output
|
||||||
* a new latitude and longitude after being advected once for DT time as defined above.
|
* a new latitude and longitude after being advected once for AdvectionKernel::DT time as defined above.
|
||||||
* @param time Time since the beginning of the data
|
* @param time Time since the beginning of the data
|
||||||
* @param latitude Latitude of particle
|
* @param latitude Latitude of particle
|
||||||
* @param longitude Longitude of particle
|
* @param longitude Longitude of particle
|
||||||
* @return A pair of latitude and longitude of particle.
|
* @return A pair of latitude and longitude of particle.
|
||||||
*/
|
*/
|
||||||
virtual std::pair<double, double> advect(int time, double latitude, double longitude) const = 0;
|
virtual std::pair<double, double> advect(int time, double latitude, double longitude) const = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //ADVECTION_ADVECTIONKERNEL_H
|
#endif //ADVECTION_ADVECTIONKERNEL_H
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ void advectForSomeTime(const UVGrid &uvGrid, const AdvectionKernelImpl &kernel,
|
||||||
static_assert(std::is_base_of<AdvectionKernel, AdvectionKernelImpl>::value, NotAKernelError);
|
static_assert(std::is_base_of<AdvectionKernel, AdvectionKernelImpl>::value, NotAKernelError);
|
||||||
|
|
||||||
double lat1 = latstart, lon1 = lonstart;
|
double lat1 = latstart, lon1 = lonstart;
|
||||||
for(int time = 100; time <= 10000; time += DT) {
|
for(int time = 100; time <= 10000; time += AdvectionKernel::DT) {
|
||||||
cout << "lat = " << lat1 << " lon = " << lon1 << endl;
|
cout << "lat = " << lat1 << " lon = " << lon1 << endl;
|
||||||
auto [templat, templon] = kernel.advect(time, lat1, lon1);
|
auto [templat, templon] = kernel.advect(time, lat1, lon1);
|
||||||
lat1 = templat;
|
lat1 = templat;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue