Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more smart pointers #294

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ed895f4
Introduced smart pointers in some functions, removed some unnecessary…
dylan-copeland Jul 11, 2024
601372e
Update unit tests.
dylan-copeland Jul 11, 2024
7e221da
Bug fix.
dylan-copeland Jul 11, 2024
1f6df17
More elimination of raw pointers in Vector class.
dylan-copeland Jul 19, 2024
1eb6344
Elimination of raw pointers in Matrix class.
dylan-copeland Jul 31, 2024
9b90860
Fixed DMDc.
dylan-copeland Aug 1, 2024
ffa9e5a
Elimination of raw pointers in BasisReader, BasisGenerator, and SVD c…
dylan-copeland Aug 1, 2024
93e53c1
Eliminated more raw pointers in DMD classes. Added more const correct…
dylan-copeland Aug 21, 2024
38c3edf
Merge branch 'master' of github.com:LLNL/libROM into smart-ptr
dylan-copeland Aug 21, 2024
b149873
Fix merge.
dylan-copeland Aug 21, 2024
49dd7bd
Minor fix
dylan-copeland Aug 21, 2024
04bc30b
Fixed a test.
dylan-copeland Aug 21, 2024
b9816f9
Eliminated raw pointers in hyperreduction interface. Changed offsets …
dylan-copeland Aug 26, 2024
23f1b69
More removal of raw pointers.
dylan-copeland Aug 26, 2024
84ad448
Removal of pointers in svd.
dylan-copeland Aug 27, 2024
2841465
Fixed memory issues in mixed nonlinear diffusion example.
dylan-copeland Oct 30, 2024
d471a7f
Merge branch 'master' of github.com:LLNL/libROM into smart-ptr
dylan-copeland Oct 30, 2024
5032943
Fixed memory leaks in DMD examples.
dylan-copeland Nov 7, 2024
0bc402d
Minor fix.
dylan-copeland Nov 7, 2024
3ac1579
Various small fixes.
dylan-copeland Nov 20, 2024
80126cd
Minor change.
dylan-copeland Nov 20, 2024
305e7f5
Merge branch 'master' of github.com:LLNL/libROM into smart-ptr
dylan-copeland Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
219 changes: 93 additions & 126 deletions examples/dmd/de_dg_advection_greedy.cpp

Large diffs are not rendered by default.

83 changes: 33 additions & 50 deletions examples/dmd/de_parametric_heat_conduction_greedy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,15 @@ double simulation()

fom_timer.Stop();

CAROM::DMD* dmd_u = NULL;
std::unique_ptr<CAROM::DMD> dmd_u;

// 14. If in offline mode, create DMD object and take initial sample.
if (offline)
{
dmd_training_timer.Start();

u_gf.SetFromTrueDofs(u);
dmd_u = new CAROM::DMD(u.Size(), dt);
dmd_u.reset(new CAROM::DMD(u.Size(), dt));
dmd_u->takeSample(u.GetData(), t);

if (myid == 0)
Expand Down Expand Up @@ -414,7 +414,7 @@ double simulation()
std::fstream fin("parameters.txt", std::ios_base::in);
double curr_param;
std::vector<std::string> dmd_paths;
std::vector<CAROM::Vector*> param_vectors;
std::vector<CAROM::Vector> param_vectors;

while (fin >> curr_param)
{
Expand All @@ -429,36 +429,34 @@ double simulation()
dmd_paths.push_back(to_string(curr_radius) + "_" +
to_string(curr_alpha) + "_" + to_string(curr_cx) + "_" +
to_string(curr_cy));
CAROM::Vector* param_vector = new CAROM::Vector(4, false);
param_vector->item(0) = curr_radius;
param_vector->item(1) = curr_alpha;
param_vector->item(2) = curr_cx;
param_vector->item(3) = curr_cy;
CAROM::Vector param_vector(4, false);
param_vector(0) = curr_radius;
param_vector(1) = curr_alpha;
param_vector(2) = curr_cx;
param_vector(3) = curr_cy;
param_vectors.push_back(param_vector);
}
fin.close();

if (dmd_paths.size() > 1)
{
CAROM::Vector* desired_param = new CAROM::Vector(4, false);
desired_param->item(0) = radius;
desired_param->item(1) = alpha;
desired_param->item(2) = cx;
desired_param->item(3) = cy;
CAROM::Vector desired_param(4, false);
desired_param(0) = radius;
desired_param(1) = alpha;
desired_param(2) = cx;
desired_param(3) = cy;

dmd_training_timer.Start();

CAROM::getParametricDMD(dmd_u, param_vectors, dmd_paths, desired_param,
"G", "LS", closest_rbf_val);

delete desired_param;
}
else
{
dmd_u = new CAROM::DMD(dmd_paths[0]);
dmd_u.reset(new CAROM::DMD(dmd_paths[0]));
}

dmd_u->projectInitialCondition(init);
dmd_u->projectInitialCondition(*init);

dmd_training_timer.Stop();

Expand All @@ -467,15 +465,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 @@ -583,7 +579,7 @@ double simulation()
std::fstream fin("parameters.txt", std::ios_base::in);
double curr_param;
std::vector<std::string> dmd_paths;
std::vector<CAROM::Vector*> param_vectors;
std::vector<CAROM::Vector> param_vectors;

while (fin >> curr_param)
{
Expand All @@ -598,30 +594,29 @@ double simulation()
dmd_paths.push_back(to_string(curr_radius) + "_" +
to_string(curr_alpha) + "_" + to_string(curr_cx) + "_" +
to_string(curr_cy));
CAROM::Vector* param_vector = new CAROM::Vector(4, false);
param_vector->item(0) = curr_radius;
param_vector->item(1) = curr_alpha;
param_vector->item(2) = curr_cx;
param_vector->item(3) = curr_cy;
CAROM::Vector param_vector(4, false);
param_vector(0) = curr_radius;
param_vector(1) = curr_alpha;
param_vector(2) = curr_cx;
param_vector(3) = curr_cy;
param_vectors.push_back(param_vector);
}
fin.close();

CAROM::Vector* desired_param = new CAROM::Vector(4, false);
desired_param->item(0) = radius;
desired_param->item(1) = alpha;
desired_param->item(2) = cx;
desired_param->item(3) = cy;
CAROM::Vector desired_param(4, false);
desired_param(0) = radius;
desired_param(1) = alpha;
desired_param(2) = cx;
desired_param(3) = cy;

dmd_training_timer.Start();

CAROM::getParametricDMD(dmd_u, param_vectors, dmd_paths, desired_param,
"G", "LS", closest_rbf_val);

dmd_u->projectInitialCondition(init);
dmd_u->projectInitialCondition(*init);

dmd_training_timer.Stop();
delete desired_param;
}

if (offline || de || calc_err_indicator)
Expand Down Expand Up @@ -683,7 +678,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 +695,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,12 +724,11 @@ 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);

VisItDataCollection dmd_visit_dc("DMD_DE_Parametric_Heat_Conduction_Greedy_"
+
VisItDataCollection dmd_visit_dc("DMD_DE_Parametric_Heat_Conduction_Greedy_" +
to_string(radius) + "_" + to_string(alpha) + "_" +
to_string(cx) + "_" + to_string(cy), pmesh);
dmd_visit_dc.RegisterField("temperature", &u_gf);
Expand All @@ -746,8 +739,6 @@ double simulation()
dmd_visit_dc.Save();
}

delete result_u;

if (visit)
{
for (int i = 1; i < ts.size(); i++)
Expand All @@ -766,8 +757,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 +781,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 All @@ -818,10 +805,6 @@ double simulation()
// 21. Free the used memory.
delete ode_solver;
delete pmesh;
if (dmd_u != NULL)
{
delete dmd_u;
}

return rel_diff;
}
Expand All @@ -834,7 +817,7 @@ class RelativeDifferenceCostFunction : public CAROM::IOptimizable
{

}
double EvaluateCost(std::vector<double> inputs) const override
double EvaluateCost(std::vector<double> & inputs) const override
{
radius = inputs[0];
alpha = inputs[1];
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
7 changes: 1 addition & 6 deletions examples/dmd/heat_conduction_dmdc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ int main(int argc, char *argv[])
std::cout << "Predicting temperature using DMDc" << std::endl;
}

CAROM::Vector* result_u = dmd_u->predict(ts[0]);
std::unique_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 @@ -553,8 +553,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 @@ -568,8 +566,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 @@ -602,7 +598,6 @@ int main(int argc, char *argv[])
// 16. Free the used memory.
delete ode_solver;
delete pmesh;
delete result_u;

MPI_Finalize();

Expand Down
Loading
Loading