13 #include "AdaptiveDMD.h"
14 #include "manifold_interp/VectorInterpolator.h"
16 #include "linalg/Matrix.h"
17 #include "linalg/Vector.h"
22 AdaptiveDMD::AdaptiveDMD(
int dim,
double desired_dt, std::string rbf,
23 std::string interp_method,
24 double closest_rbf_val,
25 bool alt_output_basis,
27 DMD(dim, alt_output_basis, state_offset)
29 CAROM_VERIFY(rbf ==
"G" || rbf ==
"IQ" || rbf ==
"IMQ");
30 CAROM_VERIFY(interp_method ==
"LS" || interp_method ==
"IDW"
31 || interp_method ==
"LP");
32 CAROM_VERIFY(closest_rbf_val >= 0.0 && closest_rbf_val <= 1.0);
34 d_interp_method = interp_method;
36 d_closest_rbf_val = closest_rbf_val;
41 for (
auto interp_snapshot : d_interp_snapshots)
43 delete interp_snapshot;
52 CAROM_VERIFY(energy_fraction > 0 && energy_fraction <= 1);
63 CAROM_VERIFY(k > 0 && k <= f_snapshots->numColumns() - 1);
71 void AdaptiveDMD::interpolateSnapshots()
73 CAROM_VERIFY(d_interp_snapshots.size() == 0);
80 bool automate_dt =
false;
84 std::vector<double> d_sampled_dts;
91 auto m = d_sampled_dts.begin() + d_sampled_dts.size() / 2;
92 std::nth_element(d_sampled_dts.begin(), m, d_sampled_dts.end());
93 if (
d_rank == 0) std::cout <<
94 "Setting desired dt to the median dt between the samples: " <<
95 d_sampled_dts[d_sampled_dts.size() / 2] << std::endl;
96 d_dt = d_sampled_dts[d_sampled_dts.size() / 2];
105 if (
d_rank == 0) std::cout <<
106 "There will be less interpolated snapshots than FOM snapshots. dt will be decreased."
113 if (
d_rank == 0) std::cout <<
"Setting desired dt to " <<
d_dt <<
114 " to ensure a constant dt given the final sampled time." << std::endl;
121 if (d_interp_method ==
"LS")
128 for (
int i = 0; i <= num_time_steps; i++)
130 double curr_time = i *
d_dt;
131 if (
d_rank == 0) std::cout <<
"Creating new interpolated sample at: " <<
137 d_interp_method, d_rbf, epsilon, point);
140 CAROM::Vector* curr_interpolated_snapshot = obtainInterpolatedVector(
142 d_interp_snapshots.push_back(curr_interpolated_snapshot);
147 if (
d_rank == 0) std::cout <<
"Number of interpolated snapshots is: " <<
148 d_interp_snapshots.size() << std::endl;
158 if (d_interp_snapshots.size() == 0) interpolateSnapshots();
~AdaptiveDMD()
Destroy the AdaptiveDMD object.
double getTrueDt() const
Get the true dt between interpolated snapshots.
const Matrix * getInterpolatedSnapshots()
Get the interpolated snapshot matrix contained within d_interp_snapshots.
void train(double energy_fraction, const Matrix *W0=NULL, double linearity_tol=0.0)
double d_energy_fraction
The energy fraction used to obtain the DMD modes.
const Matrix * createSnapshotMatrix(std::vector< Vector * > snapshots)
Get the snapshot matrix contained within d_snapshots.
void constructDMD(const Matrix *f_snapshots, int rank, int num_procs, const Matrix *W0, double linearity_tol)
Construct the DMD object.
double d_dt
The time step size between samples.
std::vector< Vector * > d_sampled_times
The stored times of each sample.
double d_t_offset
The time offset of the first sample.
int d_rank
The rank of the process this object belongs to.
std::vector< Vector * > d_snapshots
std::vector holding the snapshots.
int d_num_procs
The number of processors being run on.
int d_k
The number of columns used after obtaining the SVD decomposition.
int numColumns() const
Returns the number of columns in the Matrix. This method will return the same value from each process...
double convertClosestRBFToEpsilon(std::vector< Vector * > parameter_points, std::string rbf, double closest_rbf_val)
Convert closest RBF value to an epsilon value.
std::vector< double > obtainRBFToTrainingPoints(std::vector< Vector * > parameter_points, std::string interp_method, std::string rbf, double epsilon, Vector *point)
Compute the RBF from the parameter points with the unsampled parameter point.