BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ScalarFunctionAdapter.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Fit/RootAdapter/ScalarFunctionAdapter.cpp
6 //! @brief Defines class ScalarFunctionAdapter.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
17 
18 using namespace Fit;
19 
20 ScalarFunctionAdapter::ScalarFunctionAdapter(fcn_scalar_t func, const Parameters& parameters)
21  : m_fcn(func), m_parameters(parameters)
22 {
23 }
24 
25 const RootScalarFunction* ScalarFunctionAdapter::rootObjectiveFunction()
26 {
27  root_scalar_t rootfun = [&](const double* pars) {
28  std::vector<double> vec;
29  vec.resize(m_parameters.size(), 0.0);
30  std::copy(pars, pars + m_parameters.size(), vec.begin());
31  m_parameters.setValues(vec);
32  ++m_number_of_calls;
33  return m_fcn(m_parameters);
34  };
35 
36  m_root_objective =
37  std::make_unique<RootScalarFunction>(rootfun, static_cast<int>(m_parameters.size()));
38  return m_root_objective.get();
39 }
Defines classes RootScalarFunction.
Defines class ScalarFunctionAdapter.
A collection of fit parameters.
Definition: Parameters.h:28
The chi2 function for use in minimizers.
Objective function types.