OMCompiler/SimulationRuntime/c/simulation/solver/omc_math.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 | #ifndef OMCMATH_H_ | ||
| 29 | #define OMCMATH_H_ | ||
| 30 | |||
| 31 | #include "../simulation_info_json.h" | ||
| 32 | |||
| 33 | typedef double _omc_scalar; | ||
| 34 | |||
| 35 | #if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__) | ||
| 36 | typedef int _omc_integer; | ||
| 37 | typedef unsigned int _omc_size; | ||
| 38 | #else | ||
| 39 | typedef long int _omc_integer; | ||
| 40 | typedef unsigned long int _omc_size; | ||
| 41 | #endif | ||
| 42 | |||
| 43 | typedef struct | ||
| 44 | { | ||
| 45 | _omc_size size; | ||
| 46 | _omc_scalar *data; | ||
| 47 | } _omc_vector; | ||
| 48 | |||
| 49 | typedef struct | ||
| 50 | { | ||
| 51 | _omc_size rows; | ||
| 52 | _omc_size cols; | ||
| 53 | _omc_scalar *data; | ||
| 54 | } _omc_matrix; | ||
| 55 | |||
| 56 | /* memory management vector */ | ||
| 57 | _omc_vector* _omc_allocateVectorData(const _omc_size size); | ||
| 58 | void _omc_deallocateVectorData(_omc_vector* vec); | ||
| 59 | _omc_vector* _omc_createVector(const _omc_size size, _omc_scalar* data); | ||
| 60 | static inline void _omc_initVector(_omc_vector* vec, const _omc_size size, _omc_scalar* data) { | ||
| 61 | ✗ | vec->size = size; | |
| 62 | ✗ | vec->data = data; | |
| 63 | } | ||
| 64 | void _omc_destroyVector(_omc_vector* vec); | ||
| 65 | void _omc_copyVector(_omc_vector* dest, const _omc_vector* src); | ||
| 66 | |||
| 67 | /* memory management matrix */ | ||
| 68 | _omc_matrix* _omc_allocateMatrixData(const _omc_size rows, const _omc_size cols); | ||
| 69 | void _omc_deallocateMatrixData(_omc_matrix* mat); | ||
| 70 | _omc_matrix* _omc_createMatrix(const _omc_size rows, const _omc_size cols, _omc_scalar* data); | ||
| 71 | void _omc_destroyMatrix(_omc_matrix* mat); | ||
| 72 | _omc_matrix* _omc_copyMatrix(_omc_matrix* mat); | ||
| 73 | |||
| 74 | /* get and set vector */ | ||
| 75 | _omc_scalar* _omc_getVectorData(_omc_vector* vec); | ||
| 76 | _omc_size _omc_getVectorSize(_omc_vector* vec); | ||
| 77 | _omc_scalar _omc_getVectorElement(_omc_vector* vec, const _omc_size i); | ||
| 78 | void _omc_setVectorElement(_omc_vector* vec, const _omc_size i, _omc_scalar s); | ||
| 79 | _omc_scalar* _omc_setVectorData(_omc_vector* vec, _omc_scalar* data); | ||
| 80 | |||
| 81 | /* get and set matrix */ | ||
| 82 | _omc_scalar* _omc_getMatrixData(_omc_matrix* mat); | ||
| 83 | _omc_size _omc_getMatrixRows(_omc_matrix* mat); | ||
| 84 | _omc_size _omc_getMatrixCols(_omc_matrix* mat); | ||
| 85 | _omc_size _omc_getMatrixSize(_omc_matrix* mat); | ||
| 86 | _omc_scalar _omc_getMatrixElement(_omc_matrix* mat, const _omc_size i, const _omc_size j); | ||
| 87 | void _omc_setMatrixElement(_omc_matrix* mat, const _omc_size i, const _omc_size j, _omc_scalar s); | ||
| 88 | _omc_scalar* _omc_setMatrixData(_omc_matrix* mat, _omc_scalar* data); | ||
| 89 | |||
| 90 | /* vector operations */ | ||
| 91 | _omc_vector* _omc_fillVector(_omc_vector* vec, _omc_scalar s); | ||
| 92 | _omc_vector* _omc_negateVector(_omc_vector* vec); | ||
| 93 | |||
| 94 | _omc_vector* _omc_multiplyScalarVector(_omc_vector* vec, _omc_scalar s); | ||
| 95 | _omc_vector* _omc_addVector(_omc_vector* vec1, const _omc_vector* vec2); | ||
| 96 | _omc_vector* _omc_subVector(_omc_vector* vec1, const _omc_vector* vec2); | ||
| 97 | _omc_vector* _omc_addVectorVector(_omc_vector* dest, const _omc_vector* vec1, const _omc_vector* vec2); | ||
| 98 | _omc_vector* _omc_subVectorVector(_omc_vector* dest, const _omc_vector* vec1, const _omc_vector* vec2); | ||
| 99 | _omc_scalar _omc_scalarProduct(const _omc_vector* vec1, const _omc_vector* vec2); | ||
| 100 | _omc_scalar _omc_sumVector(const _omc_vector* vec); | ||
| 101 | |||
| 102 | /* matrix operations */ | ||
| 103 | _omc_matrix* _omc_fillMatrix(_omc_matrix* mat, _omc_scalar s); | ||
| 104 | _omc_matrix* _omc_fillIndentityMatrix(_omc_matrix* mat); | ||
| 105 | _omc_matrix* _omc_negateMatrix(_omc_matrix* mat); | ||
| 106 | |||
| 107 | _omc_matrix* _omc_multiplyScalarMatrix(_omc_matrix* mat, _omc_scalar s); | ||
| 108 | _omc_matrix* _omc_addMatrixMatrix(_omc_matrix* mat1, _omc_matrix* mat2); | ||
| 109 | _omc_matrix* _omc_subtractMatrixMatrix(_omc_matrix* mat1, _omc_matrix* mat2); | ||
| 110 | _omc_matrix* _omc_multiplyMatrixMatrix(_omc_matrix* mat1, _omc_matrix* mat2); | ||
| 111 | |||
| 112 | /* print functions */ | ||
| 113 | void _omc_printVectorWithEquationInfo(_omc_vector* vec, const char* name, const enum OMC_LOG_STREAM stream, EQUATION_INFO eqnInfo); | ||
| 114 | void _omc_printVector(_omc_vector* vec, const char* name, const enum OMC_LOG_STREAM stream); | ||
| 115 | void _omc_printMatrix(_omc_matrix* mat, const char* name, const enum OMC_LOG_STREAM stream); | ||
| 116 | |||
| 117 | /* norm functions */ | ||
| 118 | _omc_scalar _omc_euclideanVectorNorm(const _omc_vector* vec); | ||
| 119 | _omc_scalar _omc_gen_euclideanVectorNorm(const _omc_scalar* vec_data, const _omc_size vec_size); | ||
| 120 | _omc_scalar _omc_maximumVectorNorm(const _omc_vector* vec); | ||
| 121 | _omc_scalar _omc_gen_maximumVectorNorm(const _omc_scalar* vec_data, const _omc_size vec_size); | ||
| 122 | |||
| 123 | #endif | ||
| 124 |