HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
rom_object_dmd.h
Go to the documentation of this file.
1 #ifdef with_librom
2 
8 #ifndef _ROM_OBJECT_DMD_H_
9 #define _ROM_OBJECT_DMD_H_
10 
12 #define _ROM_TYPE_DMD_ "DMD"
13 
14 #include <climits>
15 #include <vector>
16 #include <utility>
17 #include <linalg/Matrix.h>
18 #include <algo/DMD.h>
19 #include <rom_object.h>
20 
21 #ifndef serial
22 #include <mpi.h>
23 #endif
24 
26 typedef std::pair<double,double> Interval;
27 
37 class DMDROMObject : public ROMObject
38 {
39  public:
40 
42  DMDROMObject( const int,
43  const double,
44  const int,
45  const int,
46  const int,
47  const int,
48  const int a_var_idx = -1);
49 
51  virtual ~DMDROMObject()
52  {
53  for (int i = 0; i < m_dmd.size(); i++) delete m_dmd[i];
54  m_dmd.clear();
55  m_intervals.clear();
56  m_dmd_is_trained.clear();
57  }
58 
60  virtual void projectInitialSolution( CAROM::Vector& a_U )
61  {
62  if (m_dmd.size() == 0) {
63  if (!m_rank) {
64  printf("ERROR in DMDROMObject::projectInitialSolution() - m_dmd is a vector of size 0.\n");
65  }
66  return;
67  }
68 
69  m_dmd[0]->projectInitialCondition( &a_U );
70  for (int i = 1; i < m_dmd.size(); i++) {
71  m_dmd[i]->projectInitialCondition( m_dmd[i-1]->predict(m_intervals[i].first) );
72  }
73  return;
74  }
75 
77  virtual void takeSample( const CAROM::Vector&, const double );
78 
80  virtual void train();
81 
83  virtual
84  const CAROM::Vector* const predict(const double a_t ) const
85  {
86  for (int i = 0; i < m_dmd.size(); i++) {
87  if ( (a_t >= m_intervals[i].first)
88  && ( (a_t < m_intervals[i].second) || (m_intervals[i].second < 0) ) ){
89  return m_dmd[i]->predict(a_t);
90  }
91  }
92  printf("ERROR in DMDROMObject::predict(): m_dmd is of size zero or interval not found!");
93  return nullptr;
94  }
95 
97  virtual void save(const std::string& a_fname_root ) const;
98 
100  virtual void load(const std::string& a_fname_root );
101 
102  protected:
103 
104  std::vector<CAROM::DMD*> m_dmd;
105  std::vector<bool> m_dmd_is_trained;
106  std::vector<Interval> m_intervals;
108  int m_rank;
109  int m_nproc;
112  double m_dt;
113  double m_t_final;
114  int m_rdim;
118  int m_tic;
121  int m_sim_idx;
122  int m_var_idx;
126  std::string m_dirname;
128  private:
129 };
130 
131 #endif
132 
133 #endif
virtual void load(const std::string &a_fname_root)
std::pair< double, double > Interval
std::vector< CAROM::DMD * > m_dmd
Base class defining a ROM object.
Definition: rom_object.h:30
virtual void takeSample(const CAROM::Vector &, const double)
int m_num_window_samples
std::vector< Interval > m_intervals
virtual void train()
Base class for a libROM object.
virtual ~DMDROMObject()
bool m_write_snapshot_mat
std::vector< bool > m_dmd_is_trained
std::string m_dirname
virtual const CAROM::Vector *const predict(const double a_t) const
virtual void projectInitialSolution(CAROM::Vector &a_U)
virtual void save(const std::string &a_fname_root) const
ROM object of type DMD (see libROM)
DMDROMObject(const int, const double, const int, const int, const int, const int, const int a_var_idx=-1)