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,
double closest_rbf_val,
24 bool alt_output_basis, std::shared_ptr<Vector> state_offset) :
25 DMD(dim, alt_output_basis, state_offset)
27 CAROM_VERIFY(rbf ==
"G" || rbf ==
"IQ" || rbf ==
"IMQ");
28 CAROM_VERIFY(interp_method ==
"LS" || interp_method ==
"IDW"
29 || interp_method ==
"LP");
30 CAROM_VERIFY(closest_rbf_val >= 0.0 && closest_rbf_val <= 1.0);
32 d_interp_method = interp_method;
34 d_closest_rbf_val = closest_rbf_val;
41 CAROM_VERIFY(f_snapshots->numColumns() > 1);
42 CAROM_VERIFY(energy_fraction > 0 && energy_fraction <= 1);
50 CAROM_VERIFY(f_snapshots->numColumns() > 1);
51 CAROM_VERIFY(k > 0 && k <= f_snapshots->numColumns() - 1);
57 void AdaptiveDMD::interpolateSnapshots()
59 CAROM_VERIFY(d_interp_snapshots.size() == 0);
66 bool automate_dt =
false;
70 std::vector<double> d_sampled_dts;
76 auto m = d_sampled_dts.begin() + d_sampled_dts.size() / 2;
77 std::nth_element(d_sampled_dts.begin(), m, d_sampled_dts.end());
79 std::cout <<
"Setting desired dt to the median dt between the samples: "
80 << d_sampled_dts[d_sampled_dts.size() / 2] << std::endl;
82 d_dt = d_sampled_dts[d_sampled_dts.size() / 2];
91 if (
d_rank == 0) std::cout <<
92 "There will be less interpolated snapshots than FOM snapshots. dt will be decreased."
99 if (
d_rank == 0) std::cout <<
"Setting desired dt to " <<
d_dt <<
100 " to ensure a constant dt given the final sampled time." << std::endl;
104 std::unique_ptr<Matrix> f_T;
105 std::unique_ptr<std::vector<Vector>> sampled_times = scalarsToVectors(
110 if (d_interp_method ==
"LS")
112 f_T = solveLinearSystem(*sampled_times,
d_snapshots, d_interp_method,
117 for (
int i = 0; i <= num_time_steps; i++)
119 double curr_time = i *
d_dt;
120 if (
d_rank == 0) std::cout <<
"Creating new interpolated sample at: " <<
122 Vector point(&curr_time, 1,
false);
126 *sampled_times, d_interp_method,
127 d_rbf, epsilon, point);
130 std::shared_ptr<CAROM::Vector> curr_interpolated_snapshot =
131 obtainInterpolatedVector(
133 d_interp_snapshots.push_back(curr_interpolated_snapshot);
136 if (
d_rank == 0) std::cout <<
"Number of interpolated snapshots is: " <<
137 d_interp_snapshots.size() << std::endl;
147 if (d_interp_snapshots.size() == 0) interpolateSnapshots();
double getTrueDt() const
Get the true dt between interpolated snapshots.
std::unique_ptr< 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)
void constructDMD(const Matrix &f_snapshots, int rank, int num_procs, const Matrix *W0, double linearity_tol)
Construct the DMD object.
double d_energy_fraction
The energy fraction used to obtain the DMD modes.
double d_dt
The time step size between samples.
std::unique_ptr< const Matrix > createSnapshotMatrix(const std::vector< std::shared_ptr< Vector >> &snapshots)
Get the snapshot matrix contained within d_snapshots.
std::vector< double > d_sampled_times
The stored times of each sample.
double d_t_offset
The time offset of the first sample.
std::vector< std::shared_ptr< Vector > > d_snapshots
std::vector holding the snapshots.
int d_rank
The rank of the process this object belongs to.
int d_num_procs
The number of processors being run on.
int d_k
The number of columns used after obtaining the SVD decomposition.
std::vector< double > obtainRBFToTrainingPoints(const std::vector< Vector > ¶meter_points, const std::string &interp_method, const std::string &rbf, double epsilon, const Vector &point)
Compute the RBF from the parameter points with the unsampled parameter point.
double convertClosestRBFToEpsilon(const std::vector< Vector > ¶meter_points, const std::string &rbf, double closest_rbf_val)
Convert closest RBF value to an epsilon value.