From 8f82fd281e4c96c0de55e7ba209bd8d5c6c5c82b Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <dmitri.naumov@ufz.de>
Date: Thu, 17 Mar 2016 17:10:16 +0100
Subject: [PATCH] [MaL] Move init() into ctor of ode solver classes.

---
 MathLib/ODE/CVodeSolver.cpp    | 20 +++++++-------------
 MathLib/ODE/CVodeSolver.h      |  4 ++--
 MathLib/ODE/OdeSolverFactory.h |  3 +--
 3 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/MathLib/ODE/CVodeSolver.cpp b/MathLib/ODE/CVodeSolver.cpp
index b5a29582cbc..55e0c68a7d2 100644
--- a/MathLib/ODE/CVodeSolver.cpp
+++ b/MathLib/ODE/CVodeSolver.cpp
@@ -83,8 +83,8 @@ class CVodeSolverImpl
 	              "cvode's realtype is not the same as double");
 
 public:
-	CVodeSolverImpl(BaseLib::ConfigTree const& config);
-	void init(const unsigned num_equations);
+	CVodeSolverImpl(BaseLib::ConfigTree const& config,
+	                unsigned const num_equations);
 
 	friend class CVodeSolver;
 	~CVodeSolverImpl();
@@ -119,7 +119,8 @@ private:
 	int _nonlinear_solver_iteration = CV_FUNCTIONAL;
 };
 
-CVodeSolverImpl::CVodeSolverImpl(const BaseLib::ConfigTree& config)
+CVodeSolverImpl::CVodeSolverImpl(const BaseLib::ConfigTree& config,
+                                 const unsigned num_equations)
 {
 	if (auto const param =
 	        config.getConfParamOptional<std::string>("linear_multistep_method"))
@@ -160,10 +161,7 @@ CVodeSolverImpl::CVodeSolverImpl(const BaseLib::ConfigTree& config)
 			std::abort();
 		}
 	}
-}
 
-void CVodeSolverImpl::init(const unsigned num_equations)
-{
 	_y = N_VNew_Serial(num_equations);
 	_abstol = N_VNew_Serial(num_equations);
 	_num_equations = num_equations;
@@ -306,14 +304,10 @@ CVodeSolverImpl::~CVodeSolverImpl()
 	}
 }
 
-CVodeSolverInternal::CVodeSolverInternal(BaseLib::ConfigTree const& config)
-    : _impl{new CVodeSolverImpl{config}}
-{
-}
-
-void CVodeSolverInternal::init(const unsigned num_equations)
+CVodeSolverInternal::CVodeSolverInternal(BaseLib::ConfigTree const& config,
+                                         unsigned const num_equations)
+    : _impl{new CVodeSolverImpl{config, num_equations}}
 {
-	_impl->init(num_equations);
 }
 
 void CVodeSolverInternal::setTolerance(const double* abstol,
diff --git a/MathLib/ODE/CVodeSolver.h b/MathLib/ODE/CVodeSolver.h
index 1b0252d331f..81e9418d047 100644
--- a/MathLib/ODE/CVodeSolver.h
+++ b/MathLib/ODE/CVodeSolver.h
@@ -27,8 +27,8 @@ class CVodeSolverImpl;
 class CVodeSolverInternal
 {
 protected:
-	CVodeSolverInternal(BaseLib::ConfigTree const& config);
-	void init(const unsigned num_equations);
+	CVodeSolverInternal(BaseLib::ConfigTree const& config,
+	                    unsigned const num_equations);
 
 	void setTolerance(double const* const abstol, const double reltol);
 	void setTolerance(const double abstol, const double reltol);
diff --git a/MathLib/ODE/OdeSolverFactory.h b/MathLib/ODE/OdeSolverFactory.h
index eccace28033..de5fba09734 100644
--- a/MathLib/ODE/OdeSolverFactory.h
+++ b/MathLib/ODE/OdeSolverFactory.h
@@ -145,7 +145,6 @@ public:
 	void setFunction(Function f, JacobianFunction df,
 	                 FunctionArguments&... args) override
 	{
-		Implementation::init(NumEquations);
 		Implementation::setFunction(
 		    std::unique_ptr<
 		        detail::Handles<NumEquations, FunctionArguments...>>{
@@ -187,7 +186,7 @@ private:
 	/// instances of this class shall only be constructed by
 	/// the friend function listed below
 	ConcreteOdeSolver(BaseLib::ConfigTree const& config)
-	    : Implementation{config}
+	    : Implementation{config, NumEquations}
 	{
 	}
 
-- 
GitLab