Skip to content
Snippets Groups Projects
Commit 3e687aaa authored by Boris Martin's avatar Boris Martin
Browse files

introduced unique_ptrs

parent c26a1a37
No related branches found
No related tags found
2 merge requests!10Draft: Source estimation,!9Introducing unique_ptrs to simplify memory management
......@@ -12,8 +12,13 @@
#include "../../optimization/linesearch/newLineSearch.h"
#include "../../optimization/localminimumsearch/newLocalMinimumSearch.h"
// STL
#include <memory>
using namespace gmshfem;
using namespace gmshfem::common;
using std::unique_ptr;
using std::make_unique;
namespace sequential
{
......@@ -143,9 +148,8 @@ namespace sequential
ObjectiveInterface<T_Physic>* const objective = newObjective<T_Physic>(d0,_config,_gmshFem,_suffix);
InnerProductInterface* const innerproduct = newInnerProduct(_config,*m,_gmshFem,_suffix);
RegularizationInterface* const regularization = newRegularization(_config,*m,_gmshFem,_suffix);
StateFunctional<T_Physic>* const statefunctional = new StateFunctional<T_Physic>(_config,innerproduct,regularization,d0.frequency(),equation,objective);
FunctionalInterface* const functional = statefunctional;
functional->setModel(*m);
auto statefunctional = make_unique<StateFunctional<T_Physic>>(_config,innerproduct,regularization,d0.frequency(),equation,objective);
statefunctional->setModel(*m);
LocalMinimumSearchInterface* const minimumsearch = newLocalMinimumSearch(_gmshFem);
DescentSearchInterface* const descentsearch = newDescentSearch(_gmshFem);
......@@ -154,7 +158,7 @@ namespace sequential
std::vector<GlobalMinimumSearchHistoryLine2> historyline;
double js_1 =0.;
double js = functional->performance();
double js = statefunctional->performance();
historyline.emplace_back(js,0.,0.,statefunctional->performance_objective(),statefunctional->performance_regularization());
double rel_djs = 0.;
bool success = false;
......@@ -181,8 +185,8 @@ namespace sequential
}
minimumsearch->name(_name+"g"+_suffix+"s"+suffix1);
js_1=js;
(*minimumsearch)(m, functional, descentsearch, linesearch);
js = functional->performance();
(*minimumsearch)(m, statefunctional.get(), descentsearch, linesearch);
js = statefunctional->performance();
m->write(_name+"_mg"+_suffix+"s"+suffix1);
//statefunctional->write_data(Type::FS,_name+"_dg"+_suffix+"s"+suffix1,"pos");
rel_djs = 2. * (js_1-js) / (js_1+js);
......@@ -204,7 +208,6 @@ namespace sequential
delete descentsearch;
delete linesearch;
delete functional;
delete innerproduct;
delete regularization;
delete objective;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment