Skip to content

Commit

Permalink
More fixes from PR review.
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-copeland committed Jan 14, 2025
1 parent 305e7f5 commit 4754351
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 31 deletions.
4 changes: 2 additions & 2 deletions lib/algo/AdaptiveDMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ void AdaptiveDMD::interpolateSnapshots()

// Obtain distances from database points to new point
std::vector<double> rbf = obtainRBFToTrainingPoints(
*scalarsToVectors(d_sampled_times),
d_interp_method, d_rbf, epsilon, point);
*sampled_times, d_interp_method,
d_rbf, epsilon, point);

// Obtain the interpolated snapshot.
std::shared_ptr<CAROM::Vector> curr_interpolated_snapshot =
Expand Down
24 changes: 5 additions & 19 deletions lib/algo/DMDc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ DMDc::DMDc(std::string base_file_name)
DMDc::DMDc(std::vector<std::complex<double>> & eigs,
std::shared_ptr<Matrix> & phi_real,
std::shared_ptr<Matrix> & phi_imaginary,
std::shared_ptr<Matrix> B_tilde, int k, double dt, double t_offset,
std::shared_ptr<Matrix> & B_tilde, int k, double dt, double t_offset,
std::shared_ptr<Vector> & state_offset, std::shared_ptr<Matrix> & basis)
{
// Get the rank of this process, and the number of processors.
Expand All @@ -134,19 +134,6 @@ DMDc::DMDc(std::vector<std::complex<double>> & eigs,
setOffset(state_offset);
}

DMDc::~DMDc()
{
for (auto snapshot : d_snapshots)
{
delete snapshot;
}

for (auto control : d_controls)
{
delete control;
}
}

void DMDc::setOffset(std::shared_ptr<Vector> & offset_vector)
{
d_state_offset = offset_vector;
Expand Down Expand Up @@ -174,8 +161,6 @@ void DMDc::takeSample(double* u_in, double t, double* f_in, bool last_step)
{
if (d_rank == 0) std::cout << "Removing existing snapshot at time: " <<
d_t_offset + d_sampled_times.back() << std::endl;
Vector* last_snapshot = d_snapshots.back();
delete last_snapshot;
d_snapshots.pop_back();
d_controls.pop_back();
d_sampled_times.pop_back();
Expand All @@ -190,12 +175,12 @@ void DMDc::takeSample(double* u_in, double t, double* f_in, bool last_step)
{
CAROM_VERIFY(d_sampled_times.back() < t);
}
d_snapshots.push_back(sample);
d_snapshots.push_back(std::shared_ptr<Vector>(sample));

if (!last_step)
{
Vector* control = new Vector(f_in, d_dim_c, false);
d_controls.push_back(control);
d_controls.push_back(std::shared_ptr<Vector>(control));
}

d_sampled_times.push_back(t);
Expand Down Expand Up @@ -803,7 +788,8 @@ DMDc::getSnapshotMatrix()
}

std::unique_ptr<const Matrix>
DMDc::createSnapshotMatrix(std::vector<Vector*> snapshots)
DMDc::createSnapshotMatrix(const std::vector<std::shared_ptr<Vector>> &
snapshots)
{
CAROM_VERIFY(snapshots.size() > 0);
CAROM_VERIFY(snapshots[0]->dim() > 0);
Expand Down
14 changes: 7 additions & 7 deletions lib/algo/DMDc.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class DMDc
/**
* @brief Destroy the DMDc object
*/
virtual ~DMDc();
virtual ~DMDc() {};

/**
* @brief Set the state offset.
Expand Down Expand Up @@ -213,7 +213,7 @@ class DMDc
friend void getParametricDMDc<DMDc>(std::unique_ptr<DMDc>& parametric_dmdc,
const std::vector<Vector>& parameter_points,
std::vector<DMDc*>& dmdcs,
std::vector<std::shared_ptr<Matrix>> controls,
std::vector<std::shared_ptr<Matrix>> & controls,
std::shared_ptr<Matrix> & controls_interpolated,
const Vector & desired_point,
std::string rbf,
Expand Down Expand Up @@ -248,7 +248,7 @@ class DMDc
DMDc(std::vector<std::complex<double>> & eigs,
std::shared_ptr<Matrix> & phi_real,
std::shared_ptr<Matrix> & phi_imaginary,
std::shared_ptr<Matrix> B_tilde,
std::shared_ptr<Matrix> & B_tilde,
int k, double dt, double t_offset,
std::shared_ptr<Vector> & state_offset,
std::shared_ptr<Matrix> & basis);
Expand Down Expand Up @@ -304,8 +304,8 @@ class DMDc
/**
* @brief Get the snapshot matrix contained within d_snapshots.
*/
std::unique_ptr<const Matrix> createSnapshotMatrix(std::vector<Vector*>
snapshots);
std::unique_ptr<const Matrix>
createSnapshotMatrix(const std::vector<std::shared_ptr<Vector>> & snapshots);

/**
* @brief The rank of the process this object belongs to.
Expand Down Expand Up @@ -340,12 +340,12 @@ class DMDc
/**
* @brief std::vector holding the snapshots.
*/
std::vector<Vector*> d_snapshots;
std::vector<std::shared_ptr<Vector>> d_snapshots;

/**
* @brief std::vector holding the controls.
*/
std::vector<Vector*> d_controls;
std::vector<std::shared_ptr<Vector>> d_controls;

/**
* @brief The stored times of each sample.
Expand Down
4 changes: 2 additions & 2 deletions lib/algo/ParametricDMDc.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ template <class T>
void getParametricDMDc(std::unique_ptr<T>& parametric_dmdc,
const std::vector<Vector>& parameter_points,
std::vector<T*>& dmdcs,
std::vector<std::shared_ptr<Matrix>> controls,
std::vector<std::shared_ptr<Matrix>> & controls,
std::shared_ptr<Matrix> & controls_interpolated,
const Vector & desired_point,
std::string rbf = "G",
Expand Down Expand Up @@ -161,7 +161,7 @@ template <class T>
void getParametricDMDc(std::unique_ptr<T>& parametric_dmdc,
const std::vector<Vector>& parameter_points,
std::vector<std::string>& dmdc_paths,
std::vector<std::shared_ptr<Matrix>> controls,
std::vector<std::shared_ptr<Matrix>> & controls,
std::shared_ptr<Matrix> & controls_interpolated,
const Vector & desired_point,
std::string rbf = "G",
Expand Down
2 changes: 1 addition & 1 deletion regression_tests/basisComparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void compareBasis(string &baselineFile, string &targetFile, double errorBound,
std::unique_ptr<const CAROM::Matrix> targetBasis =
targetReader.getSpatialBasis();
CAROM::BasisReader diffReader(baselineFile);
CAROM::Matrix* diffBasis = diffReader.getSpatialBasis().get();
std::unique_ptr<CAROM::Matrix> diffBasis = diffReader.getSpatialBasis();

// Get basis dimensions
int baselineNumRows = baselineBasis->numRows();
Expand Down

0 comments on commit 4754351

Please sign in to comment.