OMCompiler/SimulationRuntime/cpp/Solver/DASSL/DASSL.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file belongs to the OpenModelica Run-Time System | ||
| 3 | * | ||
| 4 | * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), c/o Linköpings | ||
| 5 | * universitet, Department of Computer and Information Science, SE-58183 Linköping, Sweden. All rights | ||
| 6 | * reserved. | ||
| 7 | * | ||
| 8 | * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE | ||
| 9 | * AGPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. ANY | ||
| 10 | * USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S | ||
| 11 | * ACCEPTANCE OF THE BSD NEW LICENSE OR THE OSMC PUBLIC LICENSE OR THE AGPL | ||
| 12 | * VERSION 3, ACCORDING TO RECIPIENTS CHOICE. | ||
| 13 | * | ||
| 14 | * The OpenModelica software and the OSMC (Open Source Modelica Consortium) Public License | ||
| 15 | * (OSMC-PL) are obtained from OSMC, either from the above address, from the URLs: | ||
| 16 | * http://www.openmodelica.org or https://github.com/OpenModelica/ or | ||
| 17 | * http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica distribution. GNU | ||
| 18 | * AGPL version 3 is obtained from: https://www.gnu.org/licenses/licenses.html#GPL. The BSD NEW | ||
| 19 | * License is obtained from: http://www.opensource.org/licenses/BSD-3-Clause. | ||
| 20 | * | ||
| 21 | * This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY | ||
| 23 | * SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF | ||
| 24 | * OSMC-PL. | ||
| 25 | * | ||
| 26 | */ | ||
| 27 | |||
| 28 | /** @defgroup solverDASSL Solver.DASSL | ||
| 29 | * DASSL wrapper accessing Cdaskr from OMCompiler/3rdParty | ||
| 30 | * @{ | ||
| 31 | */ | ||
| 32 | |||
| 33 | |||
| 34 | |||
| 35 | #pragma once | ||
| 36 | |||
| 37 | #include "FactoryExport.h" | ||
| 38 | |||
| 39 | #include <Core/Solver/SolverDefaultImplementation.h> | ||
| 40 | |||
| 41 | #ifdef RUNTIME_PROFILING | ||
| 42 | #include <Core/Utils/extension/measure_time.hpp> | ||
| 43 | #endif | ||
| 44 | |||
| 45 | class DASSL | ||
| 46 | : public ISolver, public SolverDefaultImplementation | ||
| 47 | { | ||
| 48 | public: | ||
| 49 | |||
| 50 | DASSL(IMixedSystem* system, ISolverSettings* settings); | ||
| 51 | |||
| 52 | virtual ~DASSL(); | ||
| 53 | |||
| 54 | /// initialize solver (and settings through base class SolverDefaultImplementation) | ||
| 55 | virtual void initialize(); | ||
| 56 | |||
| 57 | |||
| 58 | 3799 | virtual void setStartTime(const double& time) | |
| 59 | { | ||
| 60 | 3799 | SolverDefaultImplementation::setStartTime(time); | |
| 61 | 3799 | } | |
| 62 | |||
| 63 | 1930 | virtual void setEndTime(const double& time) | |
| 64 | { | ||
| 65 | 1930 | SolverDefaultImplementation::setEndTime(time); | |
| 66 | 1930 | } | |
| 67 | |||
| 68 | 1852 | virtual void setInitStepSize(const double& stepSize) | |
| 69 | { | ||
| 70 | 1852 | SolverDefaultImplementation::setInitStepSize(stepSize); | |
| 71 | 1852 | } | |
| 72 | |||
| 73 | /// call solver | ||
| 74 | virtual void solve(const SOLVERCALL command = UNDEF_CALL); | ||
| 75 | |||
| 76 | 1869 | virtual ISolver::SOLVERSTATUS getSolverStatus() | |
| 77 | { | ||
| 78 | 1869 | return (SolverDefaultImplementation::getSolverStatus()); | |
| 79 | } | ||
| 80 | |||
| 81 | virtual void writeSimulationInfo(); | ||
| 82 | |||
| 83 | virtual void setTimeOut(unsigned int time_out); | ||
| 84 | |||
| 85 | virtual void stop(); | ||
| 86 | |||
| 87 | virtual bool stateSelection(); | ||
| 88 | |||
| 89 | private: | ||
| 90 | |||
| 91 | // solver call | ||
| 92 | void DASSLCore(); | ||
| 93 | |||
| 94 | /// evaluate right hand side of ODE | ||
| 95 | int calcFunction(const double& time, const double* y, const double* yp, double *f); | ||
| 96 | |||
| 97 | // callback for right hand side | ||
| 98 | static int _res(double *t, double *y, double *yp, double *cj, | ||
| 99 | double *delta, int *ires, double *rpar, int *ipar); | ||
| 100 | |||
| 101 | // roots | ||
| 102 | int calcRoots(double t, const double *y, double *zeroValue); | ||
| 103 | |||
| 104 | // callback for roots | ||
| 105 | static int _rt(int *neq, double *t, double *y, double *yp, | ||
| 106 | int *nrt, double *rval, double *rpar, int *ipar); | ||
| 107 | |||
| 108 | bool isInterrupted(); | ||
| 109 | |||
| 110 | // Jacobian | ||
| 111 | static int _jac(double *t, double *y, double *yp, double *delta, | ||
| 112 | double *pd, double *cj, double *h, double *wt, double *rpar, int *ipar); | ||
| 113 | int calcJacobian(double t, double *y, double *yp, double *delta, | ||
| 114 | double *pd, double cj, double h, double *wt); | ||
| 115 | |||
| 116 | int | ||
| 117 | _idid, | ||
| 118 | *_zeroSign, ///< vector of signs of zero crossings | ||
| 119 | *_info, ///< solver configuration | ||
| 120 | *_iwork, ///< integer work array | ||
| 121 | *_iworkAcc, ///< accumulated statistics from iwork | ||
| 122 | _liw, ///< length of iwork | ||
| 123 | _lrw; ///< length of rwork | ||
| 124 | |||
| 125 | double | ||
| 126 | *_rwork, ///< real work array | ||
| 127 | *_y, ///< state vector | ||
| 128 | *_yPrime, ///< state derivatives | ||
| 129 | *_rtol, ///< vector of relative tolerances | ||
| 130 | *_atol, ///< vector of absolute tolerances | ||
| 131 | *_yJac, ///< states for Jacobian evaluation | ||
| 132 | *_dyJac, ///< deltas for Jacobian evaluation | ||
| 133 | *_fJac, ///< function results for Jacobian evaluation | ||
| 134 | _tLastEvent; ///< last event time point | ||
| 135 | |||
| 136 | unsigned int | ||
| 137 | _event_n; ///< event counter | ||
| 138 | |||
| 139 | bool | ||
| 140 | _zeroFound; ///< event detection | ||
| 141 | |||
| 142 | // Variables for Coloured Jacobians | ||
| 143 | int _maxColors; | ||
| 144 | |||
| 145 | // DAE support | ||
| 146 | int _dimStates; | ||
| 147 | int _dimAE; | ||
| 148 | |||
| 149 | ISystemProperties* _properties; | ||
| 150 | IContinuous* _continuous_system; | ||
| 151 | IEvent* _event_system; | ||
| 152 | IMixedSystem* _mixed_system; | ||
| 153 | ITime* _time_system; | ||
| 154 | |||
| 155 | #ifdef RUNTIME_PROFILING | ||
| 156 | std::vector<MeasureTimeData*> *measureTimeFunctionsArray; | ||
| 157 | MeasureTimeValues *measuredFunctionStartValues, *measuredFunctionEndValues, *solveFunctionStartValues, *solveFunctionEndValues; | ||
| 158 | MeasureTimeValuesSolver *solverValues; | ||
| 159 | #endif | ||
| 160 | }; | ||
| 161 | /** @} */ // end of solverDASSL | ||
| 162 |