diff --git a/specific/optimization/globalminimumsearch/sequential.cpp b/specific/optimization/globalminimumsearch/sequential.cpp index d93ba5d6193ef3b3b08359893230f9c9c9977f2d..c7c153246afe27973a2e0496f960ecc2f5494543 100644 --- a/specific/optimization/globalminimumsearch/sequential.cpp +++ b/specific/optimization/globalminimumsearch/sequential.cpp @@ -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;