From a8489a63ddc88ad02c2ae6d6cc123ac7925cb88c Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Thu, 17 Mar 2016 13:22:46 +0000 Subject: [PATCH] [MaL] ODE: Merge init() and setFunction() methods. --- MathLib/ODE/OdeSolver.h | 6 ++---- MathLib/ODE/OdeSolverFactory.h | 12 ++++-------- Tests/MathLib/TestCVode.cpp | 5 ----- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/MathLib/ODE/OdeSolver.h b/MathLib/ODE/OdeSolver.h index 6425eea1bef..7e1b608b678 100644 --- a/MathLib/ODE/OdeSolver.h +++ b/MathLib/ODE/OdeSolver.h @@ -34,14 +34,12 @@ public: using JacobianFunction = MathLib::JacobianFunction<NumEquations, FunctionArguments...>; - virtual void init() = 0; + virtual void setFunction(Function f, JacobianFunction df, + FunctionArguments&... args) = 0; virtual void setTolerance(const Arr& abstol, const double reltol) = 0; virtual void setTolerance(const double abstol, const double reltol) = 0; - virtual void setFunction(Function f, JacobianFunction df, - FunctionArguments&... args) = 0; - virtual void setIC(const double t0, const Arr& y0) = 0; virtual void preSolve() = 0; diff --git a/MathLib/ODE/OdeSolverFactory.h b/MathLib/ODE/OdeSolverFactory.h index b4fc23b4a91..17b411a2e53 100644 --- a/MathLib/ODE/OdeSolverFactory.h +++ b/MathLib/ODE/OdeSolverFactory.h @@ -142,9 +142,12 @@ public: using Function = typename Interface::Function; using JacobianFunction = typename Interface::JacobianFunction; - void init() override + void setFunction(Function f, JacobianFunction df, + FunctionArguments&... args) override { Implementation::init(NumEquations); + _handles.reset(new detail::Handles<NumEquations, FunctionArguments...>{ + f, df, args...}); Implementation::setFunction(_handles.get()); } @@ -158,13 +161,6 @@ public: Implementation::setTolerance(abstol, reltol); } - void setFunction(Function f, JacobianFunction df, - FunctionArguments&... args) override - { - _handles.reset(new detail::Handles<NumEquations, FunctionArguments...>{ - f, df, args...}); - } - void setIC(const double t0, const Arr& y0) override { Implementation::setIC(t0, y0.data()); diff --git a/Tests/MathLib/TestCVode.cpp b/Tests/MathLib/TestCVode.cpp index 17a9beb7b83..73181c776d8 100644 --- a/Tests/MathLib/TestCVode.cpp +++ b/Tests/MathLib/TestCVode.cpp @@ -64,7 +64,6 @@ TEST(MathLibCVodeTest, Exponential) auto ode_solver = MathLib::createOdeSolver<1>(config); ode_solver->setFunction(f, nullptr); - ode_solver->init(); ode_solver->setTolerance(1e-8, 1e-6); ode_solver->setIC(t0, {y0}); @@ -103,8 +102,6 @@ TEST(MathLibCVodeTest, ExponentialExtraData) ExtraData data; ode_solver->setFunction(f_extra, nullptr, data); - - ode_solver->init(); ode_solver->setTolerance(1e-8, 1e-6); ode_solver->setIC(t0, {y0}); @@ -159,7 +156,6 @@ TEST(MathLibCVodeTest, ExponentialWithJacobian) auto ode_solver = MathLib::createOdeSolver<1>(config); ode_solver->setFunction(f, df); - ode_solver->init(); ode_solver->setTolerance(1e-10, 1e-8); ode_solver->setIC(t0, {y0}); @@ -200,7 +196,6 @@ TEST(MathLibCVodeTest, ExponentialWithJacobianNewton) auto ode_solver = MathLib::createOdeSolver<1>(config); ode_solver->setFunction(f, df); - ode_solver->init(); ode_solver->setTolerance(1e-6, 1e-6); ode_solver->setIC(t0, {y0}); -- GitLab