OMCompiler/SimulationRuntime/c/moo/evaluations.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 MOO_OM_EVALUATIONS_H | ||
| 29 | #define MOO_OM_EVALUATIONS_H | ||
| 30 | |||
| 31 | #include "simulation_data.h" | ||
| 32 | #include "../simulation/jacobian_util.h" | ||
| 33 | |||
| 34 | #include <nlp/instances/gdop/problem.h> | ||
| 35 | |||
| 36 | #include "info.h" | ||
| 37 | |||
| 38 | namespace OpenModelica { | ||
| 39 | |||
| 40 | // TODO: try to not call functionDAE that often. Maybe create a workspace buffer where we memcpy the realVars after evaluation | ||
| 41 | // main advantage: no need to solve NLS several times!! | ||
| 42 | // => maybe allocate an additional buffer for the realVars + parameters and memcpy them inside the evaluation again | ||
| 43 | |||
| 44 | /* init evaluations */ | ||
| 45 | void init_eval(InfoGDOP& info, GDOP::FullSweepLayout& layout_lfg, GDOP::BoundarySweepLayout& layout_mr); | ||
| 46 | void init_eval_lfg(InfoGDOP& info, GDOP::FullSweepLayout& layout_lfg); | ||
| 47 | void init_eval_mr(InfoGDOP& info, GDOP::BoundarySweepLayout& layout_mr); | ||
| 48 | |||
| 49 | /* init Jacobians */ | ||
| 50 | void init_jac(InfoGDOP& info, GDOP::FullSweepLayout& layout_lfg, GDOP::BoundarySweepLayout& layout_mr); | ||
| 51 | void init_jac_lfg(InfoGDOP& info, GDOP::FullSweepLayout& layout_lfg); | ||
| 52 | void init_jac_mr(InfoGDOP& info, GDOP::BoundarySweepLayout& layout_mr); | ||
| 53 | |||
| 54 | /* init Hessians */ | ||
| 55 | void init_hes(InfoGDOP& info, GDOP::FullSweepLayout& layout_lfg, GDOP::BoundarySweepLayout& layout_mr); | ||
| 56 | void init_hes_lfg(InfoGDOP& info, GDOP::FullSweepLayout& layout_lfg); | ||
| 57 | void init_hes_mr(InfoGDOP& info, GDOP::BoundarySweepLayout& layout_mr); | ||
| 58 | |||
| 59 | /* set values in OM realVars array / time value */ | ||
| 60 | void set_parameters(InfoGDOP& info, const f64* p); | ||
| 61 | void set_states(InfoGDOP& info, const f64* x_ij); | ||
| 62 | void set_inputs(InfoGDOP& info, const f64* u_ij); | ||
| 63 | void set_states_inputs(InfoGDOP& info, const f64* xu_ij); | ||
| 64 | void set_time(InfoGDOP& info, const f64 t_ij); | ||
| 65 | |||
| 66 | // === Simulation Utils (e.g. MOO internal RADAU routine) === | ||
| 67 | inline void eval_current_point_ode(InfoGDOP& info) { | ||
| 68 | ✗ | info.data->callback->functionODE(info.data, info.threadData); | |
| 69 | } | ||
| 70 | |||
| 71 | void eval_ode_write(InfoGDOP& info, f64* eval_ode_buffer); | ||
| 72 | ✗ | inline void eval_write_ode_jacobian(InfoGDOP& info, f64* eval_ode_jac_buffer) { | |
| 73 | ✗ | assert(info.exc_jac->A.jacobian && info.exc_jac->A.jacobian->sparsePattern); | |
| 74 | ✗ | evalJacobian(info.data, info.threadData, info.exc_jac->A.jacobian, NULL, eval_ode_jac_buffer, FALSE); | |
| 75 | ✗ | } | |
| 76 | |||
| 77 | // === Optimization Utils === | ||
| 78 | inline void eval_current_point_dae(InfoGDOP& info) { | ||
| 79 | ✗ | info.data->callback->functionDAE(info.data, info.threadData); | |
| 80 | ✗ | } | |
| 81 | |||
| 82 | /* write previous evaluation to buffer */ | ||
| 83 | void eval_lfg_write(InfoGDOP& info, f64* eval_lfg_buffer); | ||
| 84 | void eval_mr_write(InfoGDOP& info, f64* eval_mr_buffer); | ||
| 85 | |||
| 86 | /* call evalJacobian and write to buffer in *CSC* form; just passes the current buffer with offset to OM Jacobian */ | ||
| 87 | ✗ | inline void jac_eval_write_as_csc(InfoGDOP& info, JACOBIAN* jacobian, f64* eval_jac_buffer) { | |
| 88 | ✗ | assert(jacobian != NULL && jacobian->sparsePattern != NULL); | |
| 89 | ✗ | evalJacobian(info.data, info.threadData, jacobian, NULL, eval_jac_buffer, FALSE); | |
| 90 | ✗ | } | |
| 91 | |||
| 92 | /* eval full jacobian (full_buffer) but only fill eval_jac_buffer with elements of first, *moved* row in Exchange's COO structure | ||
| 93 | * (see construction of CscToCoo structures for further info) | ||
| 94 | * clearly order doesnt matter for one row; CSC == COO order for this row, but the entries in original CSC are | ||
| 95 | * stored in CscToCoo.coo_to_csc(nz). */ | ||
| 96 | void jac_eval_write_first_row_as_csc(InfoGDOP& info, JACOBIAN* jacobian, f64* full_buffer, | ||
| 97 | f64* eval_jac_buffer, CscToCoo& exc); | ||
| 98 | |||
| 99 | } // namespace OpenModelica | ||
| 100 | |||
| 101 | #endif // MOO_OM_EVALUATIONS_H | ||
| 102 |