ida_solver.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * This file is part of OpenModelica.
  3. *
  4. * Copyright (c) 1998-2016, Open Source Modelica Consortium (OSMC),
  5. * c/o Linköpings universitet, Department of Computer and Information Science,
  6. * SE-58183 Linköping, Sweden.
  7. *
  8. * All rights reserved.
  9. *
  10. * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE
  11. * GPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
  12. * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
  13. * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
  14. * ACCORDING TO RECIPIENTS CHOICE.
  15. *
  16. * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
  17. * Public License (OSMC-PL) are obtained from OSMC, either from the above
  18. * address, from the URLs: http://www.openmodelica.org or
  19. * http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica
  20. * distribution. GNU version 3 is obtained from:
  21. * http://www.gnu.org/copyleft/gpl.html. The New BSD License is obtained from:
  22. * http://www.opensource.org/licenses/BSD-3-Clause.
  23. *
  24. * This program is distributed WITHOUT ANY WARRANTY; without even the implied
  25. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS
  26. * EXPRESSLY SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE
  27. * CONDITIONS OF OSMC-PL.
  28. *
  29. */
  30. /*! \file ida_solver.h
  31. */
  32. #ifndef OMC_IDA_SOLVER_H
  33. #define OMC_IDA_SOLVER_H
  34. #include "openmodelica.h"
  35. #include "simulation_data.h"
  36. #include "util/simulation_options.h"
  37. #include "simulation/solver/solver_main.h"
  38. #ifdef WITH_SUNDIALS
  39. #include <sundials/sundials_nvector.h>
  40. #include <nvector/nvector_serial.h>
  41. #include <idas/idas.h>
  42. #include <idas/idas_dense.h>
  43. #include <idas/idas_sparse.h>
  44. typedef struct IDA_USERDATA
  45. {
  46. DATA* data;
  47. threadData_t* threadData;
  48. }IDA_USERDATA;
  49. typedef struct IDA_SOLVER
  50. {
  51. /* ### configuration ### */
  52. int setInitialSolution;
  53. int jacobianMethod; /* specifices the method to calculate the jacobian matrix */
  54. int linearSolverMethod; /* specifices the method to solve the linear problem */
  55. int internalSteps; /* if = 1 internal step of the integrator are used */
  56. unsigned int stepsFreq; /* value specifies the output frequency regarding to time steps. Used in internal steps mode. */
  57. double stepsTime; /* value specifies the time increment when output happens. Used in internal steps mode. */
  58. /* ### work arrays ### */
  59. N_Vector y;
  60. N_Vector yp;
  61. /* ### work array used in jacobian calculation */
  62. double sqrteps;
  63. double *ysave;
  64. double *ypsave;
  65. double *delta_hh;
  66. N_Vector errwgt;
  67. N_Vector newdelta;
  68. /* ### ida internal data */
  69. void* ida_mem;
  70. IDA_USERDATA* simData;
  71. SlsMat tmpJac;
  72. DlsMat denseJac;
  73. /* ### daeMode ### */
  74. int daeMode; /* if TRUE then solve dae more with a reals residual function */
  75. long int N;
  76. long int NNZ;
  77. double *states;
  78. double *statesDer;
  79. int (*residualFunction)(double time, N_Vector yy, N_Vector yp, N_Vector res, void* userData);
  80. /* ### ida sensitivities ### */
  81. int idaSmode;
  82. int Np;
  83. N_Vector* yS;
  84. N_Vector* ySp;
  85. N_Vector* ySResult;
  86. }IDA_SOLVER;
  87. /* initial main ida Data */
  88. int
  89. ida_solver_initial(DATA* simData, threadData_t *threadData, SOLVER_INFO* solverInfo, IDA_SOLVER *idaData);
  90. /* deinitial main ida Data */
  91. int
  92. ida_solver_deinitial(IDA_SOLVER *idaData);
  93. /* main ida function to make a step */
  94. int
  95. ida_solver_step(DATA* simData, threadData_t *threadData, SOLVER_INFO* solverInfo);
  96. #endif
  97. #endif