HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
librom_interface.h
Go to the documentation of this file.
1 #ifdef with_librom
2 
8 #ifndef _LIBROM_INTERFACE_H_
9 #define _LIBROM_INTERFACE_H_
10 
12 #define _ROM_MODE_NONE_ "none"
13 
14 #define _ROM_MODE_TRAIN_ "train"
15 
16 #define _ROM_MODE_PREDICT_ "predict"
17 
19 #define _ROM_MODE_INITIAL_GUESS_ "initial_guess"
20 
22 #define _ROM_COMP_MODE_MONOLITHIC_ "monolithic"
23 
24 #define _ROM_COMP_MODE_COMPONENTWISE_ "component-wise"
25 
26 #include <string>
27 #include <vector>
28 #include <sys/time.h>
29 
30 #include <linalg/Vector.h>
31 #include <rom_object.h>
32 
46 {
47  public:
48 
51  {
52  m_is_defined = false;
53  m_rank = -1;
54  m_nproc = -1;
55  m_nsims = -1;
56  m_vec_size.clear();
57  m_rdim = -1;
58  m_sampling_freq = 1;
60  m_comp_mode = "monolithic";
61  m_ncomps.clear();
62  m_rom.clear();
63  m_U.clear();
64  m_train_wctime = 0;
65  m_predict_wctime = 0;
66  m_save_ROM = true;
67  }
68 
70  libROMInterface( void* a_s,
71  int a_nsims,
72  int a_rank,
73  int a_nproc,
74  double a_dt )
75  {
76  define( a_s, a_nsims, a_rank, a_nproc, a_dt );
77  }
78 
80  void define( void*, int, int, int, double);
81 
84  {
85  for (int i = 0; i < m_rom.size(); i++) delete m_rom[i];
86  m_rom.clear();
87  for (int i = 0; i < m_U.size(); i++) delete m_U[i];
88  m_U.clear();
89  }
90 
92  inline int samplingFrequency() const { return m_sampling_freq; }
94  inline const std::string& mode() const { return m_mode; }
96  inline const std::string& componentMode() const { return m_comp_mode; }
98  inline const std::string& type() const { return m_rom_type; }
100  inline double trainWallclockTime() const { return m_train_wctime; }
102  inline double predictWallclockTime() const { return m_predict_wctime; }
103 
105  void takeSample( void* a_s, const double a_t );
106 
108  void projectInitialSolution( void* a_s );
109 
111  void train();
112 
114  void predict(void* a_s, const double a_t) const;
115 
117  void saveROM(const std::string& a_fname_root="") const;
118 
120  void loadROM(const std::string& a_fname_root="");
121 
123  void copyFromHyPar( std::vector<CAROM::Vector*>&, void* );
124 
126  void copyToHyPar( const CAROM::Vector&, void*, int ) const;
127 
129  void copyToHyPar( const CAROM::Vector&, void*, int, int ) const;
130 
131  protected:
132 
135  int m_rank;
136  int m_nproc;
137  int m_nsims;
139  std::vector<int> m_vec_size;
141  int m_rdim;
144  std::string m_mode;
145  std::string m_comp_mode;
146  std::string m_rom_type;
148  std::vector<int> m_ncomps;
150  std::vector<ROMObject*> m_rom;
151  std::vector<CAROM::Vector*> m_U;
153  mutable struct timeval m_train_start; /*<! Training start time */
154  mutable struct timeval m_train_end; /*<! Training end time */
155  mutable struct timeval m_predict_start; /*<! Prediction start time */
156  mutable struct timeval m_predict_end; /*<! Prediction end time */
157  mutable double m_train_wctime;
158  mutable double m_predict_wctime;
160  bool m_save_ROM;
162  private:
163 
164 };
165 
166 #endif
167 
168 #endif
const std::string & mode() const
struct timeval m_train_start
libROMInterface(void *a_s, int a_nsims, int a_rank, int a_nproc, double a_dt)
void takeSample(void *a_s, const double a_t)
void saveROM(const std::string &a_fname_root="") const
struct timeval m_train_end
std::vector< ROMObject * > m_rom
Base class for a libROM object.
struct timeval m_predict_start
struct timeval m_predict_end
void loadROM(const std::string &a_fname_root="")
std::string m_mode
#define _ROM_MODE_TRAIN_
void copyFromHyPar(std::vector< CAROM::Vector *> &, void *)
std::vector< CAROM::Vector * > m_U
void projectInitialSolution(void *a_s)
double predictWallclockTime() const
Class implementing interface with libROM.
int samplingFrequency() const
std::vector< int > m_ncomps
double trainWallclockTime() const
std::vector< int > m_vec_size
const std::string & componentMode() const
void define(void *, int, int, int, double)
void predict(void *a_s, const double a_t) const
void copyToHyPar(const CAROM::Vector &, void *, int) const
std::string m_comp_mode
std::string m_rom_type
const std::string & type() const