OMCompiler/SimulationRuntime/c/simulation/solver/nonlinearSystem.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 | /*! \file nonlinearSystem.h | ||
| 29 | */ | ||
| 30 | |||
| 31 | |||
| 32 | #ifndef _NONLINEARSYSTEM_H_ | ||
| 33 | #define _NONLINEARSYSTEM_H_ | ||
| 34 | |||
| 35 | #include "../../simulation_data.h" | ||
| 36 | #include "../../util/omc_error.h" | ||
| 37 | #include "../../util/simulation_options.h" | ||
| 38 | |||
| 39 | #ifdef __cplusplus | ||
| 40 | extern "C" { | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #ifdef VOID | ||
| 44 | #undef VOID | ||
| 45 | #endif | ||
| 46 | |||
| 47 | typedef void* NLS_SOLVER_DATA; | ||
| 48 | |||
| 49 | typedef struct NLS_USERDATA { | ||
| 50 | DATA *data; | ||
| 51 | threadData_t *threadData; | ||
| 52 | |||
| 53 | int sysNumber; /* System index, for print messages only */ | ||
| 54 | NONLINEAR_SYSTEM_DATA* nlsData; /* Pointer to nonlinear system data */ | ||
| 55 | JACOBIAN* analyticJacobian; /* Pointer to analytic Jacobian */ | ||
| 56 | |||
| 57 | void* solverData; /* Optional pointer to ODE solver data. | ||
| 58 | * Used in NLS solving of ODE integrator step. */ | ||
| 59 | } NLS_USERDATA; | ||
| 60 | |||
| 61 | /** | ||
| 62 | * @brief Store primary and secondary solvers in single NLS_USERDATA->solverData | ||
| 63 | */ | ||
| 64 | struct dataSolver | ||
| 65 | { | ||
| 66 | void* ordinaryData; | ||
| 67 | void* initHomotopyData; | ||
| 68 | }; | ||
| 69 | |||
| 70 | void cleanUpOldValueListAfterEvent(DATA *data, double time); | ||
| 71 | int initializeNonlinearSystems(DATA *data, threadData_t *threadData); | ||
| 72 | int updateStaticDataOfNonlinearSystems(DATA *data, threadData_t *threadData); | ||
| 73 | void freeNonlinearSystems(DATA *data, threadData_t *threadData); | ||
| 74 | void printNonLinearSystemSolvingStatistics(NONLINEAR_SYSTEM_DATA* nonlinsys, enum OMC_LOG_STREAM stream); | ||
| 75 | NLS_SOLVER_STATUS solveNLS(DATA *data, threadData_t *threadData, NONLINEAR_SYSTEM_DATA* nonlinsys); | ||
| 76 | int solve_nonlinear_system(DATA *data, threadData_t *threadData, int sysNumber); | ||
| 77 | int check_nonlinear_solutions(DATA *data, int printFailingSystems); | ||
| 78 | int print_csvLineIterStats(void* csvData, int size, int num, | ||
| 79 | int iteration, double* x, double* f, double error_f, | ||
| 80 | double error_fs, double delta_x, double delta_xs, | ||
| 81 | double lambda); | ||
| 82 | void initializeNonlinearSystemData(DATA *data, threadData_t *threadData, NONLINEAR_SYSTEM_DATA *nonlinsys, int sysNum); | ||
| 83 | |||
| 84 | NLS_USERDATA* initNlsUserData(DATA* data, threadData_t* threadData, int sysNumber, NONLINEAR_SYSTEM_DATA* nlsData, JACOBIAN* analyticJacobian); | ||
| 85 | void freeNlsUserData(NLS_USERDATA* userData); | ||
| 86 | |||
| 87 | extern void debugMatrixPermutedDouble(int logName, char* matrixName, double* matrix, int n, int m, int* indRow, int* indCol); | ||
| 88 | extern void debugMatrixDouble(int logName, char* matrixName, double* matrix, int n, int m); | ||
| 89 | extern void debugVectorDouble(int logName, char* vectorName, double* vector, int n); | ||
| 90 | extern void debugVectorBool(int logName, char* vectorName, modelica_boolean* vector, int n); | ||
| 91 | extern void debugVectorInt(int logName, char* vectorName, int* vector, int n); | ||
| 92 | |||
| 93 | static inline void debugString(int logName, char* message) | ||
| 94 | { | ||
| 95 | ✗ | infoStreamPrint(logName, 0, "%s", message); | |
| 96 | ✗ | } | |
| 97 | |||
| 98 | static inline void debugInt(int logName, char* message, int value) | ||
| 99 | { | ||
| 100 | ✗ | infoStreamPrint(logName, 0, "%s %d", message, value); | |
| 101 | ✗ | } | |
| 102 | |||
| 103 | static inline void debugDouble(int logName, char* message, double value) | ||
| 104 | { | ||
| 105 | ✗ | infoStreamPrint(logName, 0, "%s %18.10e", message, value); | |
| 106 | ✗ | } | |
| 107 | |||
| 108 | #ifdef __cplusplus | ||
| 109 | } | ||
| 110 | #endif | ||
| 111 | |||
| 112 | #endif | ||
| 113 |