## Copyright (C) 2010, 2016, 2023  Shinji Tamura  <stamura@ecs.shimane-u.ac.jp>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {Function File} {@var{x} =} ode_solver_wrapper(@var{ode_solver}, @var{dxdt}, @var{t}, @var{x0})
##
## Wrapper for Ordinary Differential Equation Solver.
## Several ODE solvers are called by identical approach.
##
## Return value is the matrix, with each row and column corresponding to the elements of vector @var{t} and state vector, respectively.
##
## Arguments:
## @itemize
##   @item @var{ode_solver} : solver of ode
##   @item @var{dxdt} : function representing the differential equation,
##       1st argument is time(scalar) and 2nd argument is state vector
##   @item @var{t} : time vector
##   @item @var{x0} : initial value vector for @var{x}
## @end itemize
##
## @end deftypefn

function x = ode_solver_wrapper(ode_solver, dxdt, t, x0);
  switch (ode_solver)
    case "crk"
      x = crk(dxdt, t, x0);
    case "rkf"
      x = rkf(dxdt, t, x0);
    case "lsode"
      x = lsode(@(x, t) dxdt(t, x), x0, t);
    case "ode23"
      [~, x] = ode23(dxdt, t, x0);
    case "ode45"
      [~, x] = ode45(dxdt, t, x0);
    otherwise
      printf("ode_solver_wrapper: specified solver '%s' is not implemented.\n", ode_solver);
      exit;
  endswitch
endfunction

##
## Local Variables:
## mode: octave
## End:
