Here is a simple example: https://wandbox.org/permlink/fbcldo9PIiHl6tfI In your case, try something like
auto my_lambda = [&polar](Vector<double> a, Vector<double>b) {return polar.Callback(a,b);}; opt.solve ( my_lambda, X ); Bruno Le lun. 28 oct. 2019 à 06:30, Juan Carlos Araujo Cabarcas <ju4...@gmail.com> a écrit : > > Thanks Bruno for your prompt reply, > > I got the important part of the code compiling, however since I am new to > this lambda (functional) functions, I do not know how to pass the new > definitions to SolverBFGS. > > Looking at your suggestion I do the following: > > class Shape_compute { > public: > Parameters par; > > Shape_compute (Parameters epar):par(epar) { > Register([=]( Vector<double> ex, Vector<double> dx ){ return > objective_fun (ex,dx); }); > } > > void Register(std::function<double(Vector<double>, Vector<double>)> > Callback) {} //fun = objective_fun; > > double objective_fun ( Vector<double> ex, Vector<double> dx) { > > vector<double> x (par.design_N), grad (par.design_N); > for (unsigned int i=0; i < x.size (); i++) { > x [i] = ex(i); > } > Adaptive::DtN_Helmholtz<2> fem (par, x, true); > fem.run (); > double objective_function = fem.objective_function; > > for (unsigned int i=0; i < par.design_N; i++) { > if (i < par.design_N) { > vector<double> aux = x; aux [i] += h; > Adaptive::DtN_Helmholtz<2> fem (par, aux, false); > fem.run (); > grad [i] = (fem.objective_function - objective_function > )/h; > } > dx(i) = grad [i]; > } > iteration++; > return objective_function; > } > }; > > > Then, when calling the optimization routine: > > Vector<double> X (N); > > SolverControl residual_control (N, 1e-7); > //SolverBFGS::AdditionalData data (10, true); > > SolverBFGS<Vector<double> > opt (residual_control);//, data); > > Shape_compute polar(par); > opt.solve ( polar.Callback, X ); // If this line is commented, it > compiles fine! > > > I would appreciate guidance on how to achieve this, > > Thanks in advance, > Juan Carlos Araújo -- The deal.II project is located at http://www.dealii.org/ For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en --- You received this message because you are subscribed to the Google Groups "deal.II User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to dealii+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/CAGVt9eOUZVF-swxCJOHXyqG_zg_Jg4qht1BEonEV_HZJHgRqTg%40mail.gmail.com.