euler integration maybe working
This commit is contained in:
parent
933fbf4503
commit
2864e70d39
|
|
@ -18,22 +18,3 @@ cd build
|
|||
cmake ..
|
||||
make
|
||||
```
|
||||
|
||||
### Building with Linux
|
||||
Makes use of `mdspan` which is not supported by glibc++ at time of writing. See [compiler support](https://en.cppreference.com/w/cpp/compiler_support/23) for `mdspan`. The solution to this is to use Clang and libc++; this is configured in our CMake setup, however the default installation of the `netcdf-cxx` package on at least Arch linux (and suspectedly Debian derivatives as well) specifically builds for the glibc implementation. To get the netcdf C++ bindings functional with the libc++ implementation, one needs to build from source. On Linux, this requires a few changes to the CMake file included with the netcdf-cxx source code, which are detailed below.
|
||||
|
||||
Step-by-step to build the program using clang++ and libc++ on linux:
|
||||
1. Download the source code of netcdf-cxx, found at 'https://github.com/Unidata/netcdf-cxx4/releases/tag/v4.3.1' (make sure to download the release source code, as the master branch contains non-compilable code).
|
||||
2. Edit the CMakeLists.txt file, by appending '-stdlib=libc++' to the `CMAKE_CXX_FLAGS` variable in line 430. This means line 430 should read:
|
||||
```cmake
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wno-unused-variable -Wno-unused-parameter -stdlib=libc++")
|
||||
```
|
||||
2. Build the source code with the following:
|
||||
```sh
|
||||
mkdir build && cd build
|
||||
cmake .. -DCMAKE_CXX_COMPILER=/usr/bin/clang++
|
||||
make
|
||||
ctest
|
||||
sudo make install
|
||||
```
|
||||
3. Now the code should compile through the standard steps described in the Compiling section.
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue