-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implemented snapshot interpolation, and initial pass at integrating with DMD. Pivoting the DMD changes to derived class SnapshotDMD in future commits. Turned off "window overlap" in parametric_dw_csv. * Reduced scope to only the interpolator and a unit test. Will construct SnapshotDMD as a separat PR. * Fixed unit test compilation. * Stylize * Improved description of snapshot interpolator to include references * Stylize * Stylize * Implemented SnapshotDMD a derived class of DMD. Fixed SnapshotInterpolator and its unit test. * Addressed Dylan's Comments from PR#283. * Stylized. * Added energy fraction training function to SnapshotDMD * Added energy fraction training function to the snapshot DMD header. * Added new examples to CMakeLists * Added snapshot interpolator unit test to CMakeLists * Added snapshot_interpolation unit test * Removed old snapshot interpolator test * Added improvements for floating point comparison * Stylize * removed old snapshotinterpolator unit test from CMakeLists * Matching updates on snapshot_interpolator branch. * Finalized version of snapshot DMD. Added snapshot DMD as an option to the wave equation example. Improved wave equation example to include projected initial conditions in later windows, as well as print output to a specified directory to keep the running directory clean. * merged with snapshot_interpolator, and added example command for the wave equation example. * Renamed SnapshotInterpolator to PCHIPInterpolator. Addressed relevant PR Comments. * Removed redundant else statement. * Updated SnapshotDMD to use new names for PCHIPInterpolator, modified example run for wave equation. * Addressed Dylan's and Cole's comments. Added several CAROM_VERIFY statements to guarantee strictly increasing input / output ts, that there are >2 input ts, and that there are >1 output ts. * Removed some empty space. Improved wave_equation examples. * Addressed Dylans comments. * Removed duplicate sampling in wave_equation example.
- Loading branch information
Showing
4 changed files
with
279 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/****************************************************************************** | ||
* | ||
* Copyright (c) 2013-2024, Lawrence Livermore National Security, LLC | ||
* and other libROM project developers. See the top-level COPYRIGHT | ||
* file for details. | ||
* | ||
* SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
* | ||
*****************************************************************************/ | ||
|
||
// Description: Implementation of the AdaptiveDMD algorithm. | ||
|
||
#include "manifold_interp/PCHIPInterpolator.h" | ||
#include "SnapshotDMD.h" | ||
#include "linalg/Matrix.h" | ||
#include "linalg/Vector.h" | ||
#include "utils/CSVDatabase.h" | ||
#include <algorithm> | ||
|
||
namespace CAROM { | ||
|
||
SnapshotDMD::~SnapshotDMD() | ||
{ | ||
} | ||
|
||
void SnapshotDMD::train(int k, const Matrix* W0, double linearity_tol) | ||
{ | ||
CAROM_VERIFY(d_snapshots.size() > 0); | ||
|
||
if(k >= d_snapshots.size()) | ||
{ | ||
interpolateToNSnapshots(k + 1); | ||
} | ||
|
||
const Matrix* f_snapshots = getSnapshotMatrix(); | ||
CAROM_VERIFY(f_snapshots->numColumns() > 1); | ||
CAROM_VERIFY(k > 0 && k <= f_snapshots->numColumns() - 1); | ||
d_energy_fraction = -1.0; | ||
d_k = k; | ||
constructDMD(f_snapshots, d_rank, d_num_procs, W0, linearity_tol); | ||
|
||
delete f_snapshots; | ||
} | ||
|
||
void SnapshotDMD::train(double energy_fraction, const Matrix* W0, | ||
double linearity_tol) | ||
{ | ||
DMD::train(energy_fraction,W0,linearity_tol); | ||
} | ||
|
||
void SnapshotDMD::interpolateToNSnapshots(int n) | ||
{ | ||
PCHIPInterpolator* interp = new PCHIPInterpolator(); | ||
std::vector<Vector*> new_snapshots; | ||
std::vector<Vector*> new_times; | ||
|
||
interp->interpolate(d_sampled_times,d_snapshots,n,new_times,new_snapshots); | ||
d_snapshots = new_snapshots; | ||
d_sampled_times = new_times; | ||
d_dt = d_sampled_times[2]->getData()[0]-d_sampled_times[1]->getData()[0]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#ifndef included_SnapshotDMD_h | ||
#define included_SnapshotDMD_h | ||
|
||
#include "DMD.h" | ||
#include <vector> | ||
|
||
namespace CAROM { | ||
|
||
class Vector; | ||
class SnapshotDMD : public DMD | ||
{ | ||
public: | ||
|
||
/** | ||
* @brief Constructor. Basic DMD with uniform time step size. | ||
* Inherited directly from base DMD class. | ||
* | ||
* @param[in] dim The full-order state dimension. | ||
* @param[in] dt The dt between samples. | ||
* @param[in] alt_output_basis Whether to use the alternative basis for | ||
* output, i.e. phi = U^(+)*V*Omega^(-1)*X. | ||
* @param[in] state_offset The state offset. | ||
*/ | ||
SnapshotDMD(int dim, double dt, bool alt_output_basis = false, | ||
Vector* state_offset = NULL) : DMD(dim,dt,alt_output_basis,state_offset) {} | ||
|
||
/** | ||
* @brief Constructor. DMD from saved models. Inherited directly | ||
* from base DMD class. | ||
* | ||
* @param[in] base_file_name The base part of the filename of the | ||
* database to load when restarting from a save. | ||
*/ | ||
SnapshotDMD(std::string base_file_name) : DMD(base_file_name) {} | ||
|
||
/** | ||
* @brief Destroy the SnapshotDMD object | ||
*/ | ||
~SnapshotDMD(); | ||
|
||
/** | ||
* @brief Interpolate the current snapshots to n, new snapshots | ||
* distributed uniformly over the currently sampled time | ||
* domain. | ||
* @param[in] n The number of desired snapshots. | ||
*/ | ||
void interpolateToNSnapshots(int n); | ||
|
||
/** | ||
* @brief Train the DMD model with specified reduced dimension. If k is | ||
* too large then new snapshots are computed using | ||
* interpolateToNSnapshots(k+1). | ||
* | ||
* @param[in] k The number of modes to keep after doing SVD. | ||
* @param[in] W0 The initial basis to prepend to W. | ||
* @param[in] linearity_tol The tolerance for determining whether a column | ||
* of W is linearly independent with W0. | ||
*/ | ||
void train(int k, const Matrix* W0 = NULL, double linearity_tol = 0.0); | ||
|
||
/** | ||
* @brief Train the DMD model with energy fraction criterion. | ||
* | ||
* @param[in] energy_fraction The energy fraction to keep after doing SVD. | ||
* @param[in] W0 The initial basis to prepend to W. | ||
* @param[in] linearity_tol The tolerance for determining whether a column | ||
* of W is linearly independent with W0. | ||
*/ | ||
void train(double energy_fraction, const Matrix* W0 = NULL, | ||
double linearity_tol = 0.0); | ||
|
||
/** | ||
* @brief Returns a copy of the current snapshot vector "d_snapshots" | ||
*/ | ||
std::vector<Vector*> getSnapshotVectors() | ||
{ | ||
std::vector<Vector*> return_snapshots(d_snapshots); | ||
return return_snapshots; | ||
} | ||
protected: | ||
/** | ||
* @brief Obtain DMD model interpolant at desired parameter point by | ||
* interpolation of DMD models from training parameter points. | ||
* | ||
* @param[in] parametric_dmd The interpolant DMD model at the desired point. | ||
* @param[in] parameter_points The training parameter points. | ||
* @param[in] dmds The DMD objects associated with | ||
* each training parameter point. | ||
* @param[in] desired_point The desired point at which to create a parametric DMD. | ||
* @param[in] rbf The RBF type ("G" == gaussian, | ||
* "IQ" == inverse quadratic, | ||
* "IMQ" == inverse multiquadric) | ||
* @param[in] interp_method The interpolation method type | ||
* ("LS" == linear solve, | ||
* "IDW" == inverse distance weighting, | ||
* "LP" == lagrangian polynomials) | ||
* @param[in] closest_rbf_val The RBF parameter determines the width of influence. | ||
* Set the RBF value of the nearest two parameter points to a value between 0.0 to 1.0 | ||
* @param[in] reorthogonalize_W Whether to reorthogonalize the interpolated W (basis) matrix. | ||
*/ | ||
friend void getParametricDMD<SnapshotDMD>(SnapshotDMD*& parametric_dmd, | ||
std::vector<Vector*>& parameter_points, | ||
std::vector<SnapshotDMD*>& dmds, | ||
Vector* desired_point, | ||
std::string rbf, | ||
std::string interp_method, | ||
double closest_rbf_val, | ||
bool reorthogonalize_W); | ||
|
||
/** | ||
* @brief Constructor. | ||
* | ||
* @param[in] eigs d_eigs | ||
* @param[in] phi_real d_phi_real | ||
* @param[in] phi_imaginary d_phi_imaginary | ||
* @param[in] k d_k | ||
* @param[in] dt d_dt | ||
* @param[in] t_offset d_t_offset | ||
* @param[in] state_offset d_state_offset | ||
* @param[in] derivative_offset d_derivative_offset | ||
*/ | ||
SnapshotDMD(std::vector<std::complex<double>> eigs, Matrix* phi_real, | ||
Matrix* phi_imaginary, int k, | ||
double dt, double t_offset, | ||
Vector* state_offset) : | ||
DMD(eigs, phi_real, phi_imaginary, k, dt, t_offset, state_offset) {} | ||
|
||
private: | ||
}; | ||
} | ||
#endif |