OMCompiler/SimulationRuntime/c/simulation/solver/mixedSystem.c
| 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 mixedSystem.c | ||
| 29 | */ | ||
| 30 | |||
| 31 | #include <math.h> | ||
| 32 | |||
| 33 | #include "../../util/omc_error.h" | ||
| 34 | #include "mixedSystem.h" | ||
| 35 | #include "mixedSearchSolver.h" | ||
| 36 | #include "../simulation_info_json.h" | ||
| 37 | |||
| 38 | /*! \fn int initializeMixedSystems(DATA *data) | ||
| 39 | * | ||
| 40 | * This function allocates memory for all mixed systems. | ||
| 41 | * | ||
| 42 | * \param [ref] [data] | ||
| 43 | */ | ||
| 44 | 1 | int initializeMixedSystems(DATA *data, threadData_t *threadData) | |
| 45 | { | ||
| 46 | int i; | ||
| 47 | int size; | ||
| 48 | 1 | MIXED_SYSTEM_DATA *system = data->simulationInfo->mixedSystemData; | |
| 49 | |||
| 50 | 1 | infoStreamPrint(OMC_LOG_MIXED, 1, "initialize mixed system solvers"); | |
| 51 | 1 | infoStreamPrint(OMC_LOG_MIXED, 0, "%ld mixed systems", data->modelData->nMixedSystems); | |
| 52 | |||
| 53 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1 | for(i=0; i<data->modelData->nMixedSystems; ++i) |
| 54 | { | ||
| 55 | ✗ | size = system[i].size; | |
| 56 | |||
| 57 | ✗ | system[i].iterationVarsPtr = (modelica_boolean**) malloc(size*sizeof(modelica_boolean*)); | |
| 58 | ✗ | system[i].iterationPreVarsPtr = (modelica_boolean**) malloc(size*sizeof(modelica_boolean*)); | |
| 59 | |||
| 60 | /* allocate solver data */ | ||
| 61 | ✗ | switch(data->simulationInfo->mixedMethod) | |
| 62 | { | ||
| 63 | ✗ | case MIXED_SEARCH: | |
| 64 | ✗ | allocateMixedSearchData(size, &system[i].solverData); | |
| 65 | break; | ||
| 66 | ✗ | default: | |
| 67 | ✗ | throwStreamPrint(threadData, "unrecognized mixed solver"); | |
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | 1 | messageClose(OMC_LOG_MIXED); | |
| 72 | 1 | return 0; | |
| 73 | } | ||
| 74 | |||
| 75 | /*! \fn freeMixedSystems | ||
| 76 | * | ||
| 77 | * Thi function frees memory of mixed systems. | ||
| 78 | * | ||
| 79 | * \param [ref] [data] | ||
| 80 | */ | ||
| 81 | 1 | int freeMixedSystems(DATA *data, threadData_t *threadData) | |
| 82 | { | ||
| 83 | int i; | ||
| 84 | 1 | MIXED_SYSTEM_DATA* system = data->simulationInfo->mixedSystemData; | |
| 85 | |||
| 86 | 1 | infoStreamPrint(OMC_LOG_MIXED, 1, "free mixed system solvers"); | |
| 87 | |||
| 88 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1 | for(i=0;i<data->modelData->nMixedSystems;++i) |
| 89 | { | ||
| 90 | |||
| 91 | ✗ | free(system[i].iterationVarsPtr); | |
| 92 | ✗ | free(system[i].iterationPreVarsPtr); | |
| 93 | |||
| 94 | /* allocate solver data */ | ||
| 95 | ✗ | switch(data->simulationInfo->mixedMethod) | |
| 96 | { | ||
| 97 | ✗ | case MIXED_SEARCH: | |
| 98 | ✗ | freeMixedSearchData(&system[i].solverData); | |
| 99 | break; | ||
| 100 | ✗ | default: | |
| 101 | ✗ | throwStreamPrint(threadData, "unrecognized mixed solver"); | |
| 102 | } | ||
| 103 | |||
| 104 | ✗ | free(system[i].solverData); | |
| 105 | } | ||
| 106 | |||
| 107 | 1 | messageClose(OMC_LOG_MIXED); | |
| 108 | 1 | return 0; | |
| 109 | } | ||
| 110 | |||
| 111 | /*! \fn solve mixed systems | ||
| 112 | * | ||
| 113 | * \param [in] [data] | ||
| 114 | * [sysNumber] index of corresponding mixed System | ||
| 115 | * | ||
| 116 | * \author wbraun | ||
| 117 | */ | ||
| 118 | ✗ | int solve_mixed_system(DATA *data, threadData_t *threadData, int sysNumber) | |
| 119 | { | ||
| 120 | int success; | ||
| 121 | ✗ | MIXED_SYSTEM_DATA* system = data->simulationInfo->mixedSystemData; | |
| 122 | |||
| 123 | ✗ | if (!system->logActive) { | |
| 124 | ✗ | deactivateLogging(); | |
| 125 | } | ||
| 126 | |||
| 127 | /* for now just use lapack solver as before */ | ||
| 128 | ✗ | switch(data->simulationInfo->mixedMethod) | |
| 129 | { | ||
| 130 | ✗ | case MIXED_SEARCH: | |
| 131 | ✗ | success = solveMixedSearch(data, sysNumber); | |
| 132 | break; | ||
| 133 | ✗ | default: | |
| 134 | ✗ | throwStreamPrint(threadData, "unrecognized mixed solver"); | |
| 135 | } | ||
| 136 | ✗ | system[sysNumber].solved = success; | |
| 137 | |||
| 138 | ✗ | if (!system->logActive) { | |
| 139 | ✗ | reactivateLogging(); | |
| 140 | } | ||
| 141 | |||
| 142 | ✗ | return 0; | |
| 143 | } | ||
| 144 | |||
| 145 | /*! \fn check_mixed_solutions | ||
| 146 | * This function checks whether some of the mixed systems | ||
| 147 | * are failed to solve. If one is failed it returns 1 otherwise 0. | ||
| 148 | * | ||
| 149 | * \param [in] [data] | ||
| 150 | * \param [in] [printFailingSystems] | ||
| 151 | * | ||
| 152 | * \author wbraun | ||
| 153 | */ | ||
| 154 | 2 | int check_mixed_solutions(DATA *data, int printFailingSystems) | |
| 155 | { | ||
| 156 | 2 | MIXED_SYSTEM_DATA* system = data->simulationInfo->mixedSystemData; | |
| 157 | int i, j, retVal=0; | ||
| 158 | |||
| 159 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | for(i=0; i<data->modelData->nMixedSystems; ++i) |
| 160 | ✗ | if(system[i].solved == 0) | |
| 161 | { | ||
| 162 | retVal = 1; | ||
| 163 | ✗ | if(printFailingSystems && OMC_ACTIVE_WARNING_STREAM(OMC_LOG_MIXED)) | |
| 164 | { | ||
| 165 | ✗ | warningStreamPrint(OMC_LOG_MIXED, 0, "mixed system fails: %d at t=%g", modelInfoGetEquation(&data->modelData->modelDataXml, system->equationIndex).id, data->localData[0]->timeValue); | |
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 | 2 | return retVal; | |
| 170 | } | ||
| 171 |