Skip to content

Commit

Permalink
parametric_tw_csv example.
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer2368 committed Aug 31, 2023
1 parent f34b3ed commit 684b031
Show file tree
Hide file tree
Showing 4 changed files with 914 additions and 22 deletions.
4 changes: 3 additions & 1 deletion bindings/pylibROM/python_utils/cpp_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ get1DArrayBufferHandle(T *ptr, const bool free_when_done=false)

template<typename T>
py::array_t<T>
get1DArrayFromPtr(T *ptr, const int nelem, const bool free_when_done=false)
get1DArrayFromPtr(T *ptr, const int nelem, bool free_when_done=false)
{
// if empty array, no need to free when done.
free_when_done = free_when_done && (nelem > 0);
return py::array(get1DArrayBufferInfo(ptr, nelem),
get1DArrayBufferHandle(ptr, free_when_done));
}
Expand Down
18 changes: 18 additions & 0 deletions bindings/pylibROM/utils/pyCSVDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ void init_CSVDatabase(pybind11::module_ &m) {
return get1DArrayFromPtr(dataptr, nelements, true);
});

csvdb.def("getIntegerVector", [](
CSVDatabase &self, const std::string& key, bool append)
{
std::vector<int> *datavec = new std::vector<int>;
self.getIntegerVector(key, *datavec, append);
return get1DArrayFromPtr(datavec->data(), datavec->size(), true);
},
py::arg("key"), py::arg("append") = false);

csvdb.def("getDoubleArray", [](
CSVDatabase &self, const std::string& key, int nelements)
{
Expand All @@ -132,6 +141,15 @@ void init_CSVDatabase(pybind11::module_ &m) {
return get1DArrayFromPtr(dataptr, nelements, true);
});

csvdb.def("getDoubleVector", [](
CSVDatabase &self, const std::string& key, bool append)
{
std::vector<double> *datavec = new std::vector<double>();
self.getDoubleVector(key, *datavec, append);
return get1DArrayFromPtr(datavec->data(), datavec->size(), true);
},
py::arg("key"), py::arg("append") = false);

csvdb.def("getDoubleArraySize", &CSVDatabase::getDoubleArraySize);

csvdb.def("getStringVector", [](
Expand Down
23 changes: 2 additions & 21 deletions examples/dmd/local_tw_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,6 @@
# // 8. DATA_DIR/SPATIAL_IDX.csv -- (optional) each row specifies one spatial index of VAR_NAME
# // 9. run/OUT_DIR/indicator_val.csv -- (optional) each row specifies one indicator endpoint value

#include "mfem.hpp"
#include "algo/DMD.h"
#include "algo/AdaptiveDMD.h"
#include "algo/NonuniformDMD.h"
#include "linalg/Vector.h"
#include "linalg/Matrix.h"
#include "utils/HDFDatabase.h"
#include "utils/CSVDatabase.h"
#include <cmath>
#include <iostream>
#include <limits>

#ifndef _WIN32
#include <sys/stat.h> // mkdir
#else
#include <direct.h> // _mkdir
#define mkdir(dir, mode) _mkdir(dir)
#endif

import os
import io
import pathlib
Expand Down Expand Up @@ -130,7 +111,7 @@
action='store_true', default=True,
help='Enable GLVis visualization')
parser.add_argument("-train", "--train",
action='store_true', dest='train',
action='store_true', dest='train', default=True,
help="Enable DMD training.")
parser.add_argument("-no-train", "--no-train",
action='store_false', dest='train',
Expand Down Expand Up @@ -247,7 +228,7 @@
assert(not ((dtc > 0.0) and (ddt > 0.0)))

if (t_final > 0.0):
save_csv = true
save_csv = True

outputPath = "run"
if (basename != ""):
Expand Down
Loading

0 comments on commit 684b031

Please sign in to comment.