From 06a0a0fad839cf208bc24c4c74f7b62bd9106caa Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <dmitri.naumov@ufz.de>
Date: Fri, 18 Mar 2016 14:56:14 +0100
Subject: [PATCH] [MaL] ODE: Move CVodeInit call to ctor.

---
 MathLib/ODE/CVodeSolver.cpp | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/MathLib/ODE/CVodeSolver.cpp b/MathLib/ODE/CVodeSolver.cpp
index daf38d062ac..4b1ad7f6688 100644
--- a/MathLib/ODE/CVodeSolver.cpp
+++ b/MathLib/ODE/CVodeSolver.cpp
@@ -170,6 +170,17 @@ CVodeSolverImpl::CVodeSolverImpl(const BaseLib::ConfigTree& config,
 	    CVodeCreate(_linear_multistep_method, _nonlinear_solver_iteration);
 
 	assert(_cvode_mem != nullptr && _y != nullptr && _abstol != nullptr);
+
+	auto f_wrapped = [](const realtype t, const N_Vector y, N_Vector ydot,
+	                    void* function_handles) -> int
+	{
+		bool successful = static_cast<FunctionHandles*>(function_handles)
+		                      ->call(t, NV_DATA_S(y), NV_DATA_S(ydot));
+		return successful ? 0 : 1;
+	};
+
+	int flag = CVodeInit(_cvode_mem, f_wrapped, 0.0, _y);
+	(void)flag;
 }
 
 void CVodeSolverImpl::setTolerance(const double* abstol, const double reltol)
@@ -196,18 +207,6 @@ void CVodeSolverImpl::setFunction(std::unique_ptr<FunctionHandles>&& f)
 {
 	_f = std::move(f);
 	assert(_num_equations == _f->getNumEquations());
-
-	auto f_wrapped = [](const realtype t, const N_Vector y, N_Vector ydot,
-	                    void* function_handles) -> int
-	{
-		bool successful = static_cast<FunctionHandles*>(function_handles)
-		                      ->call(t, NV_DATA_S(y), NV_DATA_S(ydot));
-		return successful ? 0 : 1;
-	};
-
-	// TODO: check not run twice! move this call somewhere else
-	int flag = CVodeInit(_cvode_mem, f_wrapped, 0.0, _y);
-	(void)flag;
 }
 
 void CVodeSolverImpl::setIC(const double t0, double const* const y0)
-- 
GitLab