libROM  v1.0
Data-driven physical simulation library
SnapshotDMD.cpp
1 
11 // Description: Implementation of the SnapshotDMD class.
12 
13 #include "manifold_interp/PCHIPInterpolator.h"
14 #include "SnapshotDMD.h"
15 #include "linalg/Matrix.h"
16 #include "linalg/Vector.h"
17 #include "utils/CSVDatabase.h"
18 #include <algorithm>
19 
20 namespace CAROM {
21 
23 {
24 }
25 
26 void SnapshotDMD::train(int k, const Matrix* W0, double linearity_tol)
27 {
28  CAROM_VERIFY(d_snapshots.size() > 0);
29 
30  if(k >= d_snapshots.size())
31  {
33  }
34 
35  std::unique_ptr<const Matrix> f_snapshots = getSnapshotMatrix();
36  CAROM_VERIFY(f_snapshots->numColumns() > 1);
37  CAROM_VERIFY(k > 0 && k <= f_snapshots->numColumns() - 1);
38  d_energy_fraction = -1.0;
39  d_k = k;
40  constructDMD(*f_snapshots, d_rank, d_num_procs, W0, linearity_tol);
41 }
42 
43 void SnapshotDMD::train(double energy_fraction, const Matrix* W0,
44  double linearity_tol)
45 {
46  DMD::train(energy_fraction,W0,linearity_tol);
47 }
48 
50 {
51  PCHIPInterpolator* interp = new PCHIPInterpolator();
52  std::vector<std::shared_ptr<Vector>> new_snapshots;
53  std::vector<Vector> new_times;
54 
55  std::unique_ptr<std::vector<Vector>> times = scalarsToVectors(d_sampled_times);
56  interp->interpolate(*times.get(), d_snapshots, n,
57  new_times, new_snapshots);
58  d_snapshots = new_snapshots;
59  d_sampled_times.resize(new_times.size());
60  for (int i=0; i<new_times.size(); ++i) d_sampled_times[i] = new_times[i](0);
62 }
63 
64 }
void constructDMD(const Matrix &f_snapshots, int rank, int num_procs, const Matrix *W0, double linearity_tol)
Construct the DMD object.
Definition: DMD.cpp:256
double d_energy_fraction
The energy fraction used to obtain the DMD modes.
Definition: DMD.h:397
virtual void train(double energy_fraction, const Matrix *W0=NULL, double linearity_tol=0.0)
Train the DMD model with energy fraction criterion.
Definition: DMD.cpp:180
std::unique_ptr< const Matrix > getSnapshotMatrix()
Get the snapshot matrix contained within d_snapshots.
Definition: DMD.cpp:693
double d_dt
The time step size between samples.
Definition: DMD.h:352
std::vector< double > d_sampled_times
The stored times of each sample.
Definition: DMD.h:367
std::vector< std::shared_ptr< Vector > > d_snapshots
std::vector holding the snapshots.
Definition: DMD.h:362
int d_rank
The rank of the process this object belongs to.
Definition: DMD.h:337
int d_num_procs
The number of processors being run on.
Definition: DMD.h:342
int d_k
The number of columns used after obtaining the SVD decomposition.
Definition: DMD.h:402
void interpolate(std::vector< Vector > &snapshot_ts, std::vector< std::shared_ptr< Vector >> &snapshots, std::vector< Vector > &output_ts, std::vector< std::shared_ptr< Vector >> &output_snapshots)
Compute new snapshots interpolated from snapshot_ts to output_ts.
void interpolateToNSnapshots(int n)
Interpolate the current snapshots to n, new snapshots distributed uniformly over the currently sample...
Definition: SnapshotDMD.cpp:49
~SnapshotDMD()
Destroy the SnapshotDMD object.
Definition: SnapshotDMD.cpp:22
void train(int k, const Matrix *W0=NULL, double linearity_tol=0.0)
Train the DMD model with specified reduced dimension. If k is too large then new snapshots are comput...
Definition: SnapshotDMD.cpp:26