feat: made uvgrid take a path as argument

This commit is contained in:
robin 2024-05-09 08:34:45 +02:00
parent 61b307ee49
commit c50a27948f
5 changed files with 41 additions and 36 deletions

View File

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

View File

@ -11,7 +11,7 @@ private:
*/ */
std::vector<Vel> uvData; std::vector<Vel> uvData;
public: public:
UVGrid(); UVGrid(std::string path);
/** /**
* The matrix has shape (timeSize, latSize, lonSize) * The matrix has shape (timeSize, latSize, lonSize)

View File

@ -21,26 +21,30 @@ vector<T> getVarVector(const NcVar &var) {
return vec; return vec;
} }
vector<double> readHydrodynamicU() { vector<double> readHydrodynamicU(string path) {
// Vs and Us flipped cause the files are named incorrectly // 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";
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("vo")->second); 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 // 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); return getVarVector<double>(vars.find("uo")->second);
} }
tuple<vector<int>, vector<double>, vector<double>> readGrid() { tuple<vector<int>, vector<double>, vector<double>> readGrid(string path) {
netCDF::NcFile data("../../../../data/grid.h5", netCDF::NcFile::read); string fileName = "grid.h5";
netCDF::NcFile data(path + '/' + fileName, netCDF::NcFile::read);
multimap<string, NcVar> vars = data.getVars(); multimap<string, NcVar> vars = data.getVars();
vector<int> time = getVarVector<int>(vars.find("times")->second); vector<int> time = getVarVector<int>(vars.find("times")->second);
vector<double> longitude = getVarVector<double>(vars.find("longitude")->second); vector<double> longitude = getVarVector<double>(vars.find("longitude")->second);

View File

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

View File

@ -23,16 +23,17 @@ using namespace std;
int main() { int main() {
cout << "Reading data..." << endl; 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 kernelRK4 = make_unique<RK4AdvectionKernel>(uvGrid);
auto kernelRK4BoundaryChecked = make_unique<SnapBoundaryConditionKernel>(std::move(kernelRK4), 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(kernelRK4BoundaryChecked)); auto l = new LGlyphLayer(uvGrid, std::move(kernelRK4BoundaryChecked));
l->spoofPoints(); // l->spoofPoints();
unique_ptr<Program> program = make_unique<Program>(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(new EGlyphLayer(uvGrid));
program->addLayer(l); program->addLayer(l);