Skip to content

Commit

Permalink
pass x-values to function
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Voigt authored and Alexander Voigt committed Jul 11, 2015
1 parent dc2821e commit bff8ef3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/root_solver.cpp
Expand Up @@ -87,13 +87,23 @@ int RGFlow<Root>::func(const gsl_vector* x, void* params, gsl_vector* f)
RGFlow<Root>* root_finder = static_cast<RGFlow<Root>*>(params);
int status = GSL_SUCCESS;

const std::size_t dimx = x->size;
const std::size_t dimy = f->size;

// vector for calculating function
Eigen::ArrayXd xa(dimx);
for (std::size_t i = 0; i < dimx; i++)
xa(i) = gsl_vector_get(x, i);

try {
// @todo set x values in models
const Eigen::ArrayXd func(root_finder->calculate_function());
assert(func.rows() == f->size);
// calculate function
const Eigen::ArrayXd func(root_finder->calculate_function(xa));

for (std::size_t i = 0; i < func.rows(); i++)
assert(func.rows() == dimy);

for (std::size_t i = 0; i < dimy; i++)
gsl_vector_set(f, i, func(i));

} catch (const Error& e) {

#ifdef ENABLE_VERBOSE
Expand Down Expand Up @@ -278,7 +288,7 @@ void RGFlow<Root>::starting_point()
assert(count == get_dimension());
}

Eigen::ArrayXd RGFlow<Root>::calculate_function()
Eigen::ArrayXd RGFlow<Root>::calculate_function(const Eigen::ArrayXd& x)
{
Eigen::ArrayXd f(get_dimension());
std::size_t offset = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/root_solver.hpp
Expand Up @@ -99,7 +99,7 @@ class RGFlow<Root> {
static int func(const gsl_vector*, void*, gsl_vector*);

bool accuracy_goal_reached() const; ///< check if accuracy goal is reached
Eigen::ArrayXd calculate_function(); ///< calculates function
Eigen::ArrayXd calculate_function(const Eigen::ArrayXd&); ///< calculates function
void check_setup() const; ///< check the setup
void clear_problems(); ///< clear model problems
void delete_models(); ///< delete all models
Expand Down

0 comments on commit bff8ef3

Please sign in to comment.