From 824fb967a21c9e0ec64fcabf16f6272193b25012 Mon Sep 17 00:00:00 2001 From: robin Date: Mon, 29 Apr 2024 17:56:50 +0200 Subject: [PATCH] fix: readme and static const DT --- advection/README.md | 25 +++++++++++++++++++++++++ advection/src/AdvectionKernel.h | 5 +++-- advection/src/main.cpp | 2 +- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/advection/README.md b/advection/README.md index 4774b34..76cebec 100644 --- a/advection/README.md +++ b/advection/README.md @@ -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 +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::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 The data path is hardcoded such that the following tree structure is assumed: ``` diff --git a/advection/src/AdvectionKernel.h b/advection/src/AdvectionKernel.h index 87208bf..bf0f094 100644 --- a/advection/src/AdvectionKernel.h +++ b/advection/src/AdvectionKernel.h @@ -5,22 +5,23 @@ #include "Vel.h" -#define DT 50 /* * Implement this class for every integration method. */ class AdvectionKernel { public: + const static int DT = 50; /** * 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 latitude Latitude of particle * @param longitude Longitude of particle * @return A pair of latitude and longitude of particle. */ virtual std::pair advect(int time, double latitude, double longitude) const = 0; + }; #endif //ADVECTION_ADVECTIONKERNEL_H diff --git a/advection/src/main.cpp b/advection/src/main.cpp index 7331def..4827271 100644 --- a/advection/src/main.cpp +++ b/advection/src/main.cpp @@ -16,7 +16,7 @@ void advectForSomeTime(const UVGrid &uvGrid, const AdvectionKernelImpl &kernel, static_assert(std::is_base_of::value, NotAKernelError); 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; auto [templat, templon] = kernel.advect(time, lat1, lon1); lat1 = templat;