Merge branch 'main' into djairo-wrapping

This commit is contained in:
Djairo 2024-05-16 10:50:37 +00:00 committed by GitHub
commit 95d1724af4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 95 additions and 85 deletions

View File

@ -8,14 +8,14 @@
using namespace std;
UVGrid::UVGrid() {
auto us = readHydrodynamicU();
auto vs = readHydrodynamicV();
UVGrid::UVGrid(string path) {
auto us = readHydrodynamicU(path);
auto vs = readHydrodynamicV(path);
if (us.size() != vs.size()) {
throw domain_error(sizeError2);
}
tie(times, lats, lons) = readGrid();
tie(times, lats, lons) = readGrid(path);
timeSize = times.size();
latSize = lats.size();

View File

@ -11,7 +11,12 @@ private:
*/
std::vector<Vel> uvData;
public:
UVGrid();
/**
* Constructs the UVGrid.
* @param path The data path where the constructor expects to find
* the files hydrodynamic_U.h5, hydrodynamic_V.h5, and grid.h5
*/
UVGrid(std::string path);
/**
* The matrix has shape (timeSize, latSize, lonSize)
@ -76,7 +81,7 @@ public:
* The 3D index into the data. The array is sized by [8761][67][116]
* @return Velocity at that index
*/
const Vel& operator[](size_t timeIndex, size_t latIndex, size_t lonIndex) const;
const Vel &operator[](size_t timeIndex, size_t latIndex, size_t lonIndex) const;
/**
* Streams a slice at timeIndex t of the matrix to the outstream given by os

View File

@ -7,10 +7,10 @@
using namespace std;
using namespace netCDF;
template <typename T>
template<typename T>
vector<T> getVarVector(const NcVar &var) {
int length = 1;
for (NcDim dim : var.getDims()) {
for (NcDim dim: var.getDims()) {
length *= dim.getSize();
}
@ -21,27 +21,31 @@ vector<T> getVarVector(const NcVar &var) {
return vec;
}
vector<double> readHydrodynamicU() {
vector<double> readHydrodynamicU(string path) {
// Vs and Us flipped cause the files are named incorrectly
netCDF::NcFile data("../../../../data/hydrodynamic_V.h5", netCDF::NcFile::read);
string fileName = "hydrodynamic_V.h5";
multimap< string, NcVar > vars = data.getVars();
netCDF::NcFile data(path + '/' + fileName, netCDF::NcFile::read);
multimap<string, NcVar> vars = data.getVars();
return getVarVector<double>(vars.find("vo")->second);
}
vector<double> readHydrodynamicV() {
vector<double> readHydrodynamicV(string path) {
// Vs and Us flipped cause the files are named incorrectly
netCDF::NcFile data("../../../../data/hydrodynamic_U.h5", netCDF::NcFile::read);
string fileName = "hydrodynamic_U.h5";
netCDF::NcFile data(path + '/' + fileName, netCDF::NcFile::read);
multimap< string, NcVar > vars = data.getVars();
multimap<string, NcVar> vars = data.getVars();
return getVarVector<double>(vars.find("uo")->second);
}
tuple<vector<int>, vector<double>, vector<double>> readGrid() {
netCDF::NcFile data("../../../../data/grid.h5", netCDF::NcFile::read);
multimap< string, NcVar > vars = data.getVars();
tuple<vector<int>, vector<double>, vector<double>> readGrid(string path) {
string fileName = "grid.h5";
netCDF::NcFile data(path + '/' + fileName, netCDF::NcFile::read);
multimap<string, NcVar> vars = data.getVars();
vector<int> time = getVarVector<int>(vars.find("times")->second);
vector<double> longitude = getVarVector<double>(vars.find("longitude")->second);
vector<double> latitude = getVarVector<double>(vars.find("latitude")->second);

View File

@ -5,18 +5,18 @@
* reads the file hydrodynamic_U.h5
* @return the data vector of us
*/
std::vector<double> readHydrodynamicU();
std::vector<double> readHydrodynamicU(std::string path);
/**
* reads the file hydrodynamic_V.h5
* @return the data vector of vs
*/
std::vector<double> readHydrodynamicV();
std::vector<double> readHydrodynamicV(std::string path);
/**
* Reads the file grid.h5
* @return a tuple of (times, latitude, longitude)
*/
std::tuple<std::vector<int>, std::vector<double>, std::vector<double>> readGrid();
std::tuple<std::vector<int>, std::vector<double>, std::vector<double>> readGrid(std::string path);
#endif //READDATA_H

View File

@ -23,17 +23,18 @@ using namespace std;
int main() {
cout << "Reading data..." << endl;
shared_ptr<UVGrid> uvGrid = make_shared<UVGrid>();
string dataPath = "../../../../data";
shared_ptr<UVGrid> uvGrid = make_shared<UVGrid>(dataPath);
auto kernelRK4 = make_unique<RK4AdvectionKernel>(uvGrid);
auto kernelRK4BoundaryChecked = make_unique<SnapBoundaryConditionKernel>(std::move(kernelRK4), uvGrid);
cout << "Starting vtk..." << endl;
auto l = new LGlyphLayer(uvGrid, std::move(kernelRK4BoundaryChecked));
l->spoofPoints();
// l->spoofPoints();
l->setDt(DT);
unique_ptr<Program> program = make_unique<Program>(DT);
program->addLayer(new BackgroundImage("../../../../data/map_661-661.png"));
program->addLayer(new BackgroundImage(dataPath + "/map_661-661.png"));
program->addLayer(new EGlyphLayer(uvGrid));
program->addLayer(l);