71 ferr = fscanf(in,
"%s", word);
if (ferr != 1)
return;
73 if (std::string(word) ==
"begin") {
74 while (std::string(word) !=
"end") {
75 ferr = fscanf(in,
"%s",word);
if (ferr != 1)
return;
76 if (std::string(word) ==
"dmd_num_win_samples") {
78 }
else if (std::string(word) ==
"dmd_dirname") {
79 ferr = fscanf(in,
"%s", dirname_c_str);
if (ferr != 1)
return;
80 }
else if (std::string(word) ==
"dmd_write_snapshot_mat") {
81 ferr = fscanf(in,
"%s", write_snapshot_mat);
if (ferr != 1)
return;
83 if (ferr != 1)
return;
86 fprintf( stderr,
"Error: Illegal format in file \"%s\". Word read is: %s\n",
96 printf(
"DMDROMObject details:\n");
98 printf(
" directory name for DMD onjects: %s\n", dirname_c_str);
99 printf(
" write snapshot matrix to file: %s\n", write_snapshot_mat);
101 printf(
" simulation domain: %d\n",
m_sim_idx);
104 printf(
" Vector component: %d\n",
m_var_idx);
114 m_dirname = std::string( dirname_c_str );
118 printf(
"ERROR:DMDROMObject::DMDROMObject() - m_num_window_samples <= m_rdim!!");
127 const double a_time )
136 printf(
"DMDROMObject::takeSample() - creating new DMD object for sim. domain %d, var %d, t=%f (total: %d).\n",
150 printf(
"DMDROMObject::train() - training DMD object %d for sim. domain %d, var %d with %d samples.\n",
157 std::string fname_root(
m_dirname +
"/snapshot_mat_"+std::string(idx_string));
170 printf(
"DMDROMObject::takeSample() - creating new DMD object for sim. domain %d, var %d, t=%f (total: %d).\n",
186 int last_win =
m_dmd.size() - 1;
187 int num_columns(
m_dmd[last_win]->getSnapshotMatrix()->numColumns() );
188 if (num_columns <=
m_rdim) {
193 printf(
"DMDROMObject::train() - last window DMD for sim. domain %d, var %d has %d sample(s) only; deleted it ",
197 printf(
"(total: %d).\n",
m_dmd.size());
202 if (
m_dmd.size() > 0) {
203 for (
int i = 0; i <
m_dmd.size(); i++) {
205 int ncol =
m_dmd[i]->getSnapshotMatrix()->numColumns();
207 printf(
"DMDROMObject::train() - training DMD object %d for sim. domain %d, var %d with %d samples.\n",
212 sprintf(idx_string,
"%04d", i);
213 std::string fname_root(
m_dirname +
"/snapshot_mat_"+std::string(idx_string));
214 m_dmd[i]->getSnapshotMatrix()->write(fname_root);
220 printf(
"ERROR in DMDROMObject::train(): m_dmd is of size zero!");
237 std::string fname_root =
m_dirname +
"/";
238 std::string summary_fname_root =
m_dirname +
"/";
239 std::string header_fname =
m_dirname +
"/";
240 if (a_fname_root ==
"") {
241 fname_root +=
"dmdobj_";
242 summary_fname_root +=
"dmd_summary_";
243 header_fname +=
"dmd_header.dat";
245 fname_root += (a_fname_root+
"_dmdobj_");
246 summary_fname_root += (a_fname_root+
"_dmd_summary_");
247 header_fname += (a_fname_root+
"_dmd_header.dat");
252 out = fopen(header_fname.c_str(),
"w");
253 fprintf(out,
"%d\n",
m_dmd.size());
254 for (
int i = 0; i <
m_dmd.size(); i++) {
260 for (
int i = 0; i <
m_dmd.size(); i++) {
262 sprintf(idx_string,
"%04d", i);
263 std::string fname = fname_root + std::string(idx_string);
264 std::string summary_fname = summary_fname_root + std::string(idx_string);
266 printf(
" Saving DMD object and summary (%s, %s).\n",
267 fname.c_str(), summary_fname.c_str() );
269 m_dmd[i]->save(fname);
283 std::string fname_root =
m_dirname +
"/";
284 std::string header_fname =
m_dirname +
"/";
285 if (a_fname_root ==
"") {
286 fname_root +=
"dmdobj_";
287 header_fname +=
"dmd_header.dat";
289 fname_root += (a_fname_root+
"_dmdobj_");
290 header_fname += (a_fname_root+
"_dmd_header.dat");
294 std::vector<double> intervals_start(0), intervals_end(0);
297 in = fopen(header_fname.c_str(),
"r");
298 fscanf(in,
"%d\n", &num_dmds);
299 intervals_start.resize(num_dmds);
300 intervals_end.resize(num_dmds);
301 for (
int i = 0; i < num_dmds; i++) {
302 fscanf(in,
"%lf", &intervals_start[i]);
303 fscanf(in,
"%lf", &intervals_end[i]);
308 MPI_Bcast(&num_dmds,1,MPI_INT,0,MPI_COMM_WORLD);
310 intervals_start.resize(num_dmds);
311 intervals_end.resize(num_dmds);
313 MPI_Bcast(intervals_start.data(),num_dmds,MPI_DOUBLE,0,MPI_COMM_WORLD);
314 MPI_Bcast(intervals_end.data(),num_dmds,MPI_DOUBLE,0,MPI_COMM_WORLD);
317 for (
int i = 0; i < num_dmds; i++) {
322 sprintf(idx_string,
"%04d", i);
323 std::string fname = fname_root + std::string(idx_string);
325 printf(
" Loading DMD object (%s), time window=[%1.2e,%1.2e].\n",
329 m_dmd.push_back(
new CAROM::DMD(fname) );
std::vector< bool > m_dmd_is_trained
virtual void save(const std::string &a_fname_root) const
Dynamic Mode Decomposition ROM object.
#define _LIBROM_INP_FNAME_
virtual void load(const std::string &a_fname_root)
#define _MAX_STRING_SIZE_
bool m_write_snapshot_mat
virtual void takeSample(const CAROM::Vector &, const double)
std::pair< double, double > Interval
std::vector< Interval > m_intervals
Some basic definitions and macros.
std::vector< CAROM::DMD * > m_dmd
DMDROMObject(const int, const double, const int, const int, const int, const int, const int a_var_idx=-1)