diff --git a/lib/algo/AdaptiveDMD.cpp b/lib/algo/AdaptiveDMD.cpp index 7286d045a..c3501822c 100644 --- a/lib/algo/AdaptiveDMD.cpp +++ b/lib/algo/AdaptiveDMD.cpp @@ -123,8 +123,8 @@ void AdaptiveDMD::interpolateSnapshots() // Obtain distances from database points to new point std::vector 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 curr_interpolated_snapshot = diff --git a/lib/algo/DMDc.cpp b/lib/algo/DMDc.cpp index fcfdffa33..d001164f9 100644 --- a/lib/algo/DMDc.cpp +++ b/lib/algo/DMDc.cpp @@ -108,7 +108,7 @@ DMDc::DMDc(std::string base_file_name) DMDc::DMDc(std::vector> & eigs, std::shared_ptr & phi_real, std::shared_ptr & phi_imaginary, - std::shared_ptr B_tilde, int k, double dt, double t_offset, + std::shared_ptr & B_tilde, int k, double dt, double t_offset, std::shared_ptr & state_offset, std::shared_ptr & basis) { // Get the rank of this process, and the number of processors. @@ -134,19 +134,6 @@ DMDc::DMDc(std::vector> & 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 & offset_vector) { d_state_offset = offset_vector; @@ -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(); @@ -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(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(control)); } d_sampled_times.push_back(t); @@ -803,7 +788,8 @@ DMDc::getSnapshotMatrix() } std::unique_ptr -DMDc::createSnapshotMatrix(std::vector snapshots) +DMDc::createSnapshotMatrix(const std::vector> & + snapshots) { CAROM_VERIFY(snapshots.size() > 0); CAROM_VERIFY(snapshots[0]->dim() > 0); diff --git a/lib/algo/DMDc.h b/lib/algo/DMDc.h index 738a51aa8..259a0f3fc 100644 --- a/lib/algo/DMDc.h +++ b/lib/algo/DMDc.h @@ -55,7 +55,7 @@ class DMDc /** * @brief Destroy the DMDc object */ - virtual ~DMDc(); + virtual ~DMDc() {}; /** * @brief Set the state offset. @@ -213,7 +213,7 @@ class DMDc friend void getParametricDMDc(std::unique_ptr& parametric_dmdc, const std::vector& parameter_points, std::vector& dmdcs, - std::vector> controls, + std::vector> & controls, std::shared_ptr & controls_interpolated, const Vector & desired_point, std::string rbf, @@ -248,7 +248,7 @@ class DMDc DMDc(std::vector> & eigs, std::shared_ptr & phi_real, std::shared_ptr & phi_imaginary, - std::shared_ptr B_tilde, + std::shared_ptr & B_tilde, int k, double dt, double t_offset, std::shared_ptr & state_offset, std::shared_ptr & basis); @@ -304,8 +304,8 @@ class DMDc /** * @brief Get the snapshot matrix contained within d_snapshots. */ - std::unique_ptr createSnapshotMatrix(std::vector - snapshots); + std::unique_ptr + createSnapshotMatrix(const std::vector> & snapshots); /** * @brief The rank of the process this object belongs to. @@ -340,12 +340,12 @@ class DMDc /** * @brief std::vector holding the snapshots. */ - std::vector d_snapshots; + std::vector> d_snapshots; /** * @brief std::vector holding the controls. */ - std::vector d_controls; + std::vector> d_controls; /** * @brief The stored times of each sample. diff --git a/lib/algo/ParametricDMDc.h b/lib/algo/ParametricDMDc.h index f8c7d2704..a4903076a 100644 --- a/lib/algo/ParametricDMDc.h +++ b/lib/algo/ParametricDMDc.h @@ -56,7 +56,7 @@ template void getParametricDMDc(std::unique_ptr& parametric_dmdc, const std::vector& parameter_points, std::vector& dmdcs, - std::vector> controls, + std::vector> & controls, std::shared_ptr & controls_interpolated, const Vector & desired_point, std::string rbf = "G", @@ -161,7 +161,7 @@ template void getParametricDMDc(std::unique_ptr& parametric_dmdc, const std::vector& parameter_points, std::vector& dmdc_paths, - std::vector> controls, + std::vector> & controls, std::shared_ptr & controls_interpolated, const Vector & desired_point, std::string rbf = "G", diff --git a/regression_tests/basisComparator.cpp b/regression_tests/basisComparator.cpp index 2b79cebad..576a0a690 100644 --- a/regression_tests/basisComparator.cpp +++ b/regression_tests/basisComparator.cpp @@ -44,7 +44,7 @@ void compareBasis(string &baselineFile, string &targetFile, double errorBound, std::unique_ptr targetBasis = targetReader.getSpatialBasis(); CAROM::BasisReader diffReader(baselineFile); - CAROM::Matrix* diffBasis = diffReader.getSpatialBasis().get(); + std::unique_ptr diffBasis = diffReader.getSpatialBasis(); // Get basis dimensions int baselineNumRows = baselineBasis->numRows();