Skip to content

Commit

Permalink
More elimination of raw pointers in Vector class.
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-copeland committed Jul 19, 2024
1 parent 7e221da commit 1f6df17
Show file tree
Hide file tree
Showing 34 changed files with 176 additions and 843 deletions.
23 changes: 4 additions & 19 deletions examples/dmd/de_dg_advection_greedy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,9 @@ double simulation()
}

dmd_prediction_timer.Start();
CAROM::Vector* result_U = dmd_U->predict(t_final);
std::shared_ptr<CAROM::Vector> result_U = dmd_U->predict(t_final);
dmd_prediction_timer.Stop();


// 21. Calculate the relative error between the DMD final solution and the true solution.
Vector dmd_solution_U(result_U->getData(),
result_U->dim());
Expand All @@ -668,8 +667,6 @@ double simulation()
dmd_prediction_timer.RealTime());
}

delete result_U;

return rel_diff;
}

Expand Down Expand Up @@ -740,17 +737,14 @@ double simulation()
// THIS IS LIKE COMPUTING A RESIDUAL.
t = t_final - 10.*dt;

CAROM::Vector* carom_tf_u_minus_some = dmd_U->predict(t);

std::shared_ptr<CAROM::Vector> carom_tf_u_minus_some = dmd_U->predict(t);

for(int i = 0; i < carom_tf_u_minus_some->dim(); i++)
{
(*U)[i] = (*carom_tf_u_minus_some)(i);
}

u_gf->SetFromTrueDofs(*U);

delete carom_tf_u_minus_some;
}

ts.push_back(t);
Expand Down Expand Up @@ -925,8 +919,7 @@ double simulation()

}

CAROM::Vector* result_U = dmd_U->predict(t_final);

std::shared_ptr<CAROM::Vector> result_U = dmd_U->predict(t_final);

Vector dmd_solution_U(result_U->getData(),
result_U->dim());
Expand All @@ -945,8 +938,6 @@ double simulation()
<< rel_diff << std::endl;
}

delete result_U;

if (myid == 0)
{
printf("Elapsed time for training DMD: %e second\n",
Expand All @@ -956,7 +947,7 @@ double simulation()
else if (online)
{
dmd_prediction_timer.Start();
CAROM::Vector* result_U = dmd_U->predict(ts[0]);
std::shared_ptr<CAROM::Vector> result_U = dmd_U->predict(ts[0]);
Vector initial_dmd_solution_U(result_U->getData(),
result_U->dim());
u_gf->SetFromTrueDofs(initial_dmd_solution_U);
Expand All @@ -972,8 +963,6 @@ double simulation()
dmd_visit_dc.Save();
}

delete result_U;

if (visit)
{
for (int i = 1; i < ts.size(); i++)
Expand All @@ -993,8 +982,6 @@ double simulation()
dmd_visit_dc.SetCycle(i);
dmd_visit_dc.SetTime(ts[i]);
dmd_visit_dc.Save();

delete result_U;
}
}
}
Expand Down Expand Up @@ -1039,8 +1026,6 @@ double simulation()
tot_true_solution_u_norm << std::endl;
fout.close();
}

delete result_U;
}
// 22. Calculate the relative error as commanded by the greedy algorithm.
if (offline)
Expand Down
17 changes: 4 additions & 13 deletions examples/dmd/de_parametric_heat_conduction_greedy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,13 @@ double simulation()
// compare the final FOM solution to the DMD predicted solution.
t = t_final - 10.0 * dt;

CAROM::Vector* carom_tf_u_minus_some = dmd_u->predict(t);
std::shared_ptr<CAROM::Vector> carom_tf_u_minus_some = dmd_u->predict(t);

Vector tf_u_minus_some(carom_tf_u_minus_some->getData(),
carom_tf_u_minus_some->dim());

u = tf_u_minus_some;
u_gf.SetFromTrueDofs(u);

delete carom_tf_u_minus_some;
}

ts.push_back(t);
Expand Down Expand Up @@ -683,7 +681,8 @@ double simulation()
*true_solution_u, *true_solution_u));
}
}
CAROM::Vector* result_u = dmd_u->predict(t_final);

std::shared_ptr<CAROM::Vector> result_u = dmd_u->predict(t_final);

Vector dmd_solution_u(result_u->getData(), result_u->dim());
Vector diff_u(true_solution_u->Size());
Expand All @@ -699,8 +698,6 @@ double simulation()
<< rel_diff << std::endl;
}

delete result_u;

if (!de && myid == 0)
{
printf("Elapsed time for training DMD: %e second\n",
Expand Down Expand Up @@ -730,7 +727,7 @@ double simulation()
std::cout << "Predicting temperature using DMD at: " << ts[0] << std::endl;
}

CAROM::Vector* result_u = dmd_u->predict(ts[0]);
std::shared_ptr<CAROM::Vector> result_u = dmd_u->predict(ts[0]);
Vector initial_dmd_solution_u(result_u->getData(), result_u->dim());
u_gf.SetFromTrueDofs(initial_dmd_solution_u);

Expand All @@ -746,8 +743,6 @@ double simulation()
dmd_visit_dc.Save();
}

delete result_u;

if (visit)
{
for (int i = 1; i < ts.size(); i++)
Expand All @@ -766,8 +761,6 @@ double simulation()
dmd_visit_dc.SetCycle(i);
dmd_visit_dc.SetTime(ts[i]);
dmd_visit_dc.Save();

delete result_u;
}
}
}
Expand All @@ -792,8 +785,6 @@ double simulation()
printf("Elapsed time for predicting DMD: %e second\n",
dmd_prediction_timer.RealTime());
}

delete result_u;
}

// 19. Calculate the relative error as commanded by the greedy algorithm.
Expand Down
6 changes: 1 addition & 5 deletions examples/dmd/dg_advection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ int main(int argc, char *argv[])
std::cout << "Predicting solution using DMD" << std::endl;
}

CAROM::Vector* result_u = dmd_U.predict(ts[0]);
std::shared_ptr<CAROM::Vector> result_u = dmd_U.predict(ts[0]);
Vector initial_dmd_solution_u(result_u->getData(), result_u->dim());
u->SetFromTrueDofs(initial_dmd_solution_u);

Expand All @@ -733,8 +733,6 @@ int main(int argc, char *argv[])
dmd_dc->Save();
}

delete result_u;

if (visit)
{
for (int i = 1; i < ts.size(); i++)
Expand All @@ -748,7 +746,6 @@ int main(int argc, char *argv[])
dmd_dc->SetCycle(i);
dmd_dc->SetTime(ts[i]);
dmd_dc->Save();
delete result_u;
}
}
}
Expand Down Expand Up @@ -788,7 +785,6 @@ int main(int argc, char *argv[])
delete pmesh;
delete ode_solver;
delete pd;
delete result_u;
#ifdef MFEM_USE_ADIOS2
if (adios2)
{
Expand Down
21 changes: 4 additions & 17 deletions examples/dmd/dg_euler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,10 @@ int main(int argc, char *argv[])
std::cout << "Predicting density, momentum, and energy using DMD" << std::endl;
}

CAROM::Vector* result_dens = dmd_dens->predict(ts[0]);
CAROM::Vector* result_x_mom = dmd_x_mom->predict(ts[0]);
CAROM::Vector* result_y_mom = dmd_y_mom->predict(ts[0]);
CAROM::Vector* result_e = dmd_e->predict(ts[0]);
std::shared_ptr<CAROM::Vector> result_dens = dmd_dens->predict(ts[0]);
std::shared_ptr<CAROM::Vector> result_x_mom = dmd_x_mom->predict(ts[0]);
std::shared_ptr<CAROM::Vector> result_y_mom = dmd_y_mom->predict(ts[0]);
std::shared_ptr<CAROM::Vector> result_e = dmd_e->predict(ts[0]);
Vector initial_dmd_solution_dens(result_dens->getData(), result_dens->dim());
Vector initial_dmd_solution_x_mom(result_x_mom->getData(), result_x_mom->dim());
Vector initial_dmd_solution_y_mom(result_y_mom->getData(), result_y_mom->dim());
Expand All @@ -604,10 +604,6 @@ int main(int argc, char *argv[])
dmd_visit_dc.Save();
}

delete result_dens;
delete result_x_mom;
delete result_y_mom;
delete result_e;
if (visit)
{
for (int i = 1; i < ts.size(); i++)
Expand All @@ -630,11 +626,6 @@ int main(int argc, char *argv[])
dmd_visit_dc.SetCycle(i);
dmd_visit_dc.SetTime(ts[i]);
dmd_visit_dc.Save();

delete result_dens;
delete result_x_mom;
delete result_y_mom;
delete result_e;
}
}
}
Expand Down Expand Up @@ -701,10 +692,6 @@ int main(int argc, char *argv[])

// Free the used memory.
delete ode_solver;
delete result_dens;
delete result_x_mom;
delete result_y_mom;
delete result_e;
delete dmd_dens;
delete dmd_x_mom;
delete dmd_y_mom;
Expand Down
7 changes: 1 addition & 6 deletions examples/dmd/heat_conduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ int main(int argc, char *argv[])
std::cout << "Predicting temperature using DMD" << std::endl;
}

CAROM::Vector* result_u = dmd_u->predict(ts[0]);
std::shared_ptr<CAROM::Vector> result_u = dmd_u->predict(ts[0]);
Vector initial_dmd_solution_u(result_u->getData(), result_u->dim());
u_gf.SetFromTrueDofs(initial_dmd_solution_u);

Expand All @@ -517,8 +517,6 @@ int main(int argc, char *argv[])
dmd_visit_dc.Save();
}

delete result_u;

if (visit)
{
for (int i = 1; i < ts.size(); i++)
Expand All @@ -532,8 +530,6 @@ int main(int argc, char *argv[])
dmd_visit_dc.SetCycle(i);
dmd_visit_dc.SetTime(ts[i]);
dmd_visit_dc.Save();

delete result_u;
}
}
}
Expand Down Expand Up @@ -566,7 +562,6 @@ int main(int argc, char *argv[])
// 16. Free the used memory.
delete ode_solver;
delete pmesh;
delete result_u;

MPI_Finalize();

Expand Down
18 changes: 6 additions & 12 deletions examples/dmd/local_dw_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ int main(int argc, char *argv[])
for (int k = 0; k < f_snapshots->numColumns(); ++k)
{
f_snapshots->getColumn(k, interp_snap);
CAROM::Vector* result = admd->predict(t_init+k*dtc);
std::shared_ptr<CAROM::Vector> result = admd->predict(t_init+k*dtc);

Vector dmd_solution(result->getData(), dim);
Vector true_solution(interp_snap.getData(), dim);
Expand All @@ -600,7 +600,6 @@ int main(int argc, char *argv[])
cout << "Relative error of DMD prediction for interpolated snapshot #" << k <<
" is " << rel_error << endl;
}
delete result;
}
if (myid == 0)
{
Expand Down Expand Up @@ -677,7 +676,7 @@ int main(int argc, char *argv[])
<< " is read." << endl;
}

CAROM::Vector* init_cond = nullptr;
std::shared_ptr<CAROM::Vector> init_cond;
if (min_idx_snap == -1)
{
double curr_indicator_val = (indicator_idx.size() == 0) ? tval :
Expand All @@ -697,13 +696,12 @@ int main(int argc, char *argv[])
cout << "Projecting initial condition at t = " << tval <<
" for DMD model #0." << endl;
}
init_cond = new CAROM::Vector(dim, true);
init_cond.reset(new CAROM::Vector(dim, true));
for (int i = 0; i < dim; ++i)
{
init_cond->item(i) = sample[i];
}
dmd[curr_window]->projectInitialCondition(init_cond, tval);
delete init_cond;
dmd[curr_window]->projectInitialCondition(init_cond.get(), tval);
dmd_preprocess_timer.Stop();
}
else
Expand All @@ -723,7 +721,7 @@ int main(int argc, char *argv[])
" using DMD model #" << curr_window << endl;
}
dmd_prediction_timer.Start();
CAROM::Vector* result = dmd[curr_window]->predict(tval);
std::shared_ptr<CAROM::Vector> result = dmd[curr_window]->predict(tval);
dmd_prediction_timer.Stop();

double curr_indicator_val = (indicator_idx.size() == 0) ? tval : result->item(
Expand Down Expand Up @@ -764,7 +762,6 @@ int main(int argc, char *argv[])
{
t_left = t_offset;
}
delete init_cond;
}
t_offset = (t_left + t_right) / 2.0;
}
Expand Down Expand Up @@ -794,10 +791,8 @@ int main(int argc, char *argv[])
}

init_cond = dmd[curr_window]->predict(t_offset);
dmd[curr_window+1]->projectInitialCondition(init_cond, t_offset);
delete init_cond;
dmd[curr_window+1]->projectInitialCondition(init_cond.get(), t_offset);

delete result;
curr_window += 1;
result = dmd[curr_window]->predict(tval);
curr_indicator_val = (indicator_idx.size() == 0) ? tval : result->item(
Expand Down Expand Up @@ -837,7 +832,6 @@ int main(int argc, char *argv[])
}
}
}
delete result;

if (curr_window == numWindows-1
&& curr_indicator_val >= indicator_val[numWindows])
Expand Down
Loading

0 comments on commit 1f6df17

Please sign in to comment.