gsl_ode-initval__control.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* ode-initval/control.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. /* Author: G. Jungman */
  20. #include "gsl__config.h"
  21. #include <stdlib.h>
  22. #include "gsl_math.h"
  23. #include "gsl_errno.h"
  24. #include "gsl_odeiv.h"
  25. gsl_odeiv_control *
  26. gsl_odeiv_control_alloc(const gsl_odeiv_control_type * T)
  27. {
  28. gsl_odeiv_control * c =
  29. (gsl_odeiv_control *) malloc(sizeof(gsl_odeiv_control));
  30. if(c == 0)
  31. {
  32. GSL_ERROR_NULL ("failed to allocate space for control struct",
  33. GSL_ENOMEM);
  34. };
  35. c->type = T;
  36. c->state = c->type->alloc();
  37. if (c->state == 0)
  38. {
  39. free (c); /* exception in constructor, avoid memory leak */
  40. GSL_ERROR_NULL ("failed to allocate space for control state",
  41. GSL_ENOMEM);
  42. };
  43. return c;
  44. }
  45. int
  46. gsl_odeiv_control_init(gsl_odeiv_control * c,
  47. double eps_abs, double eps_rel,
  48. double a_y, double a_dydt)
  49. {
  50. return c->type->init (c->state, eps_abs, eps_rel, a_y, a_dydt);
  51. }
  52. void
  53. gsl_odeiv_control_free(gsl_odeiv_control * c)
  54. {
  55. c->type->free(c->state);
  56. free(c);
  57. }
  58. const char *
  59. gsl_odeiv_control_name(const gsl_odeiv_control * c)
  60. {
  61. return c->type->name;
  62. }
  63. int
  64. gsl_odeiv_control_hadjust (gsl_odeiv_control * c, gsl_odeiv_step * s, const double y[], const double yerr[], const double dydt[], double * h)
  65. {
  66. return c->type->hadjust(c->state, s->dimension, s->type->order(s->state),
  67. y, yerr, dydt, h);
  68. }