Merge pull request #26 from MakeNEnjoy/robin-boundary-conditions

feat: boundary conditions
This commit is contained in:
Djairo 2024-05-07 09:10:54 +00:00 committed by GitHub
commit 3cdf3dde2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 73 additions and 16 deletions

View File

@ -54,19 +54,21 @@ add_executable(ParticleTrackTrace MACOSX_BUNDLE main.cpp
commands/CameraMoveCallback.cpp commands/CameraMoveCallback.cpp
commands/CameraMoveCallback.h commands/CameraMoveCallback.h
CartographicTransformation.cpp CartographicTransformation.cpp
advection/AdvectionKernel.h advection/kernel/AdvectionKernel.h
advection/EulerAdvectionKernel.cpp advection/kernel/EulerAdvectionKernel.cpp
advection/EulerAdvectionKernel.h advection/kernel/EulerAdvectionKernel.h
advection/interpolate.cpp advection/interpolate.cpp
advection/interpolate.h advection/interpolate.h
advection/readdata.cpp advection/readdata.cpp
advection/readdata.h advection/readdata.h
advection/RK4AdvectionKernel.cpp advection/kernel/RK4AdvectionKernel.cpp
advection/RK4AdvectionKernel.h advection/kernel/RK4AdvectionKernel.h
advection/UVGrid.cpp advection/UVGrid.cpp
advection/UVGrid.h advection/UVGrid.h
advection/Vel.cpp advection/Vel.cpp
advection/Vel.h advection/Vel.h
advection/kernel/SnapBoundaryConditionKernel.h
advection/kernel/SnapBoundaryConditionKernel.cpp
) )
execute_process( execute_process(

View File

@ -3,7 +3,7 @@
#include <tuple> #include <tuple>
#include "Vel.h" #include "../Vel.h"
/* /*
* Implement this class for every integration method. * Implement this class for every integration method.

View File

@ -1,6 +1,6 @@
#include "EulerAdvectionKernel.h" #include "EulerAdvectionKernel.h"
#include "interpolate.h" #include "../interpolate.h"
using namespace std; using namespace std;

View File

@ -2,7 +2,7 @@
#define EULERADVECTIONKERNEL_H #define EULERADVECTIONKERNEL_H
#include "AdvectionKernel.h" #include "AdvectionKernel.h"
#include "UVGrid.h" #include "../UVGrid.h"
#include <memory> #include <memory>
/** /**

View File

@ -1,5 +1,5 @@
#include "RK4AdvectionKernel.h" #include "RK4AdvectionKernel.h"
#include "interpolate.h" #include "../interpolate.h"
using namespace std; using namespace std;

View File

@ -2,7 +2,7 @@
#define RK4ADVECTIONKERNEL_H #define RK4ADVECTIONKERNEL_H
#include "AdvectionKernel.h" #include "AdvectionKernel.h"
#include "UVGrid.h" #include "../UVGrid.h"
#include <memory> #include <memory>
/** /**

View File

@ -0,0 +1,26 @@
#include "SnapBoundaryConditionKernel.h"
SnapBoundaryConditionKernel::SnapBoundaryConditionKernel(std::unique_ptr<AdvectionKernel> kernel,
std::shared_ptr<UVGrid> uvGrid) :
kernel(std::move(kernel)),
uvGrid(uvGrid) { }
std::pair<double, double> SnapBoundaryConditionKernel::advect(int time, double latitude, double longitude, int dt) const {
auto [newLat, newLon] = kernel->advect(time, latitude, longitude, dt);
double minLat = uvGrid->lats.front();
double maxLat = uvGrid->lats.back();
double minLon = uvGrid->lons.front();
double maxLon = uvGrid->lons.back();
if (newLat < minLat) {
newLat = minLat;
}
if (newLat > maxLat) {
newLat = maxLat;
}
if (newLon < minLon) {
newLon = minLon;
}
if (newLon > maxLon) {
newLon = maxLon;
}
return {newLat, newLon};
}

View File

@ -0,0 +1,27 @@
#ifndef SNAPBOUNDARYCONDITIONKERNEL_H
#define SNAPBOUNDARYCONDITIONKERNEL_H
#include <memory>
#include "AdvectionKernel.h"
#include "../UVGrid.h"
/**
* When a point goes outside of the grid, this Kernel will snap it to the closest edge.
* This kernel wraps around another kernel, and implements only the boundary conditions.
*/
class SnapBoundaryConditionKernel: public AdvectionKernel {
std::unique_ptr<AdvectionKernel> kernel;
std::shared_ptr<UVGrid> uvGrid;
public:
/**
* Construct the kernel.
* @param kernel The kernel to be called first before boundary conditions are applied
* @param uvGrid The grid that is used to check boundary conditions against
*/
SnapBoundaryConditionKernel(std::unique_ptr<AdvectionKernel> kernel, std::shared_ptr<UVGrid> uvGrid);
std::pair<double, double> advect(int time, double latitude, double longitude, int dt) const override;
};
#endif //SNAPBOUNDARYCONDITIONKERNEL_H

View File

@ -2,7 +2,7 @@
#define LGLYPHLAYER_H #define LGLYPHLAYER_H
#include "Layer.h" #include "Layer.h"
#include "../advection/AdvectionKernel.h" #include "../advection/kernel/AdvectionKernel.h"
#include "../commands/SpawnPointCallback.h" #include "../commands/SpawnPointCallback.h"
#include <vtkPolyData.h> #include <vtkPolyData.h>
#include <vtkInteractorStyle.h> #include <vtkInteractorStyle.h>

View File

@ -14,21 +14,23 @@
#include "layers/LGlyphLayer.h" #include "layers/LGlyphLayer.h"
#include "Program.h" #include "Program.h"
#include "advection/UVGrid.h" #include "advection/UVGrid.h"
#include "advection/RK4AdvectionKernel.h" #include "advection/kernel/RK4AdvectionKernel.h"
#include "advection/kernel/SnapBoundaryConditionKernel.h"
using namespace std; using namespace std;
#define DT 60 * 60 // 60 sec/min * 60 mins #define DT 60 * 60 // 60 sec/min * 60 mins
int main() { int main() {
cout << "reading data..." << endl; cout << "Reading data..." << endl;
shared_ptr<UVGrid> uvGrid = std::make_shared<UVGrid>(); shared_ptr<UVGrid> uvGrid = make_shared<UVGrid>();
auto kernelRK4 = make_unique<RK4AdvectionKernel>(uvGrid); auto kernelRK4 = make_unique<RK4AdvectionKernel>(uvGrid);
auto kernelRK4BoundaryChecked = make_unique<SnapBoundaryConditionKernel>(std::move(kernelRK4), uvGrid);
cout << "Starting vtk..." << endl; cout << "Starting vtk..." << endl;
auto l = new LGlyphLayer(uvGrid, std::move(kernelRK4)); auto l = new LGlyphLayer(uvGrid, std::move(kernelRK4BoundaryChecked));
Program *program = new Program(DT); unique_ptr<Program> program = make_unique<Program>(DT);
program->addLayer(new BackgroundImage("../../../../data/map_661-661.png")); program->addLayer(new BackgroundImage("../../../../data/map_661-661.png"));
program->addLayer(new EGlyphLayer(uvGrid)); program->addLayer(new EGlyphLayer(uvGrid));
program->addLayer(l); program->addLayer(l);