Skip to content

Commit

Permalink
keep starting point vector local
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 cc564b0 commit 12a9616
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
25 changes: 9 additions & 16 deletions src/root_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,14 @@ RGFlow<Root>::RGFlow()
, convergence_tester(NULL)
, initial_guesser(NULL)
, precision_goal(1e-4)
, root(NULL)
{
}

RGFlow<Root>::~RGFlow()
{
delete_models();

if (root)
gsl_vector_free(root);
}


/**
* @brief Solves the boundary value problem.
*
Expand Down Expand Up @@ -134,9 +129,13 @@ int RGFlow<Root>::find_root()
gsl_set_error_handler_off();
#endif

starting_point();
gsl_vector* x_init = gsl_vector_alloc(get_dimension());
if (!x_init)
throw OutOfMemoryError("GSL vector allocation failed in RGFlow<Root>()");

starting_point(x_init);

gsl_multiroot_fsolver_set(solver, &f, root);
gsl_multiroot_fsolver_set(solver, &f, x_init);

#ifdef ENABLE_VERBOSE
print_state(solver, iter); // @todo implement
Expand All @@ -160,7 +159,7 @@ int RGFlow<Root>::find_root()
printf("\tRoot_finder status = %s\n", gsl_strerror(status));
#endif

gsl_vector_memcpy(root, solver->x);
gsl_vector_free(x_init);
gsl_multiroot_fsolver_free(solver);

return status;
Expand Down Expand Up @@ -263,21 +262,15 @@ std::size_t RGFlow<Root>::get_dimension() const
return dimension;
}

void RGFlow<Root>::starting_point()
void RGFlow<Root>::starting_point(gsl_vector* x_init)
{
if (!root) {
root = gsl_vector_alloc(get_dimension());
if (!root)
throw OutOfMemoryError("GSL vector allocation failed in RGFlow<Root>()");
}

std::size_t count = 0;

for (std::size_t m = 0; m < models.size(); m++) {
const Eigen::ArrayXd parameters(models[m]->model->get_parameters());

for (std::size_t p = 0; p < parameters.rows(); p++, count++)
gsl_vector_set(root, count, parameters(p));
gsl_vector_set(x_init, count, parameters(p));
}

assert(count == get_dimension());
Expand Down
3 changes: 1 addition & 2 deletions src/root_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class RGFlow<Root> {
Convergence_tester<Root>* convergence_tester; ///< the convergence tester
Initial_guesser<Root>* initial_guesser; ///< does initial guess
double precision_goal; ///< precision goal
gsl_vector* root; ///< GSL vector of root

static int func(const gsl_vector*, void*, gsl_vector*);
static Eigen::ArrayXd to_eigen_array(const gsl_vector*);
Expand All @@ -110,7 +109,7 @@ class RGFlow<Root> {
std::size_t get_dimension() const; ///< calculate dimension
unsigned int get_max_iterations() const; ///< returns max. number of iterations
void initial_guess(); ///< initial guess
void starting_point(); ///< find starting point
void starting_point(gsl_vector*); ///< find starting point
};

} // namespace flexiblesusy
Expand Down

0 comments on commit 12a9616

Please sign in to comment.