Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 0.0% 0 / 0 / 56
Functions: 0.0% 0 / 0 / 2
Branches: 0.0% 0 / 0 / 30

OMCompiler/SimulationRuntime/c/optimization/eval_all/EvalF.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 /*! EvalF.c
29 */
30
31 #include "../OptimizerData.h"
32 #include "../OptimizerLocalFunction.h"
33
34
35 /* eval object function
36 */
37 ✗ Bool evalfF(ipindex n, ipnumber * vopt, Bool new_x, ipnumber *objValue, void * useData){
38
39 OptData *optData = (OptData*)useData;
40
41 ✗ const modelica_boolean la = optData->s.lagrange;
42 ✗ const modelica_boolean ma = optData->s.mayer;
43
44 long double mayer = 0.0;
45 long double lagrange = 0.0;
46
47 ✗ if(new_x)
48 ✗ optData2ModelData(optData, vopt, 1);
49
50 ✗ if(la){
51 ✗ const int nsi = optData->dim.nsi;
52 ✗ const int np = optData->dim.np;
53 ✗ const int il = optData->dim.index_lagrange;
54
55 ✗ const long double * const b = optData->rk.b;
56 ✗ const long double * const dt = optData->time.dt;
57
58 ✗ modelica_real *** v = optData->v;
59 ✗ long double *erg = (long double*)malloc(np * sizeof(long double));
60 int i,j;
61
62 ✗ for(j = 0; j< np; ++j){
63 ✗ erg[j] = dt[0]*v[0][j][il];
64 }
65
66 ✗ for(i = 1; i < nsi; ++i){
67 ✗ for(j = 0; j< np; ++j){
68 ✗ erg[j] += dt[i]*v[i][j][il];
69 }
70 }
71
72 ✗ for(j = 0; j< np; ++j)
73 ✗ lagrange += b[j]*erg[j];
74 ✗ free(erg);
75 }
76
77 ✗ if(ma){
78 ✗ modelica_real *** v = optData->v;
79 ✗ const int nsi = optData->dim.nsi;
80 ✗ const int np = optData->dim.np;
81 ✗ const int im = optData->dim.index_mayer;
82 ✗ mayer = v[nsi-1][np-1][im];
83 }
84
85 ✗ *objValue = (ipnumber)(lagrange + mayer);
86
87 ✗ return TRUE;
88 }
89
90
91 /*!
92 * eval derivation (object func)
93 * author: Vitalij Ruge
94 **/
95 ✗ Bool evalfDiffF(ipindex n, double * vopt, Bool new_x, ipnumber *gradF, void * useData){
96 OptData *optData = (OptData*)useData;
97
98 ✗ const int nv = optData->dim.nv;
99 ✗ const int nsi = optData->dim.nsi;
100 ✗ const int np = optData->dim.np;
101 ✗ const int nJ = optData->dim.nJ;
102 ✗ const int nJ1 = optData->dim.nJ + 1;
103
104 ✗ const modelica_boolean la = optData->s.lagrange;
105 ✗ const modelica_boolean ma = optData->s.mayer;
106
107 ✗ if(new_x)
108 ✗ optData2ModelData(optData, vopt, 1);
109
110 ✗ if(la){
111
112 int i, j, ii;
113 modelica_real * gradL;
114
115 ✗ for(i = 0, ii = 0; i < nsi - 1; ++i){
116 ✗ for(j = 0; j < np; ++j, ii += nv){
117 ✗ gradL = optData->J[i][j][nJ];
118 ✗ memcpy(gradF + ii, gradL, nv*sizeof(modelica_real));
119 }
120 }
121
122 ✗ for(j = 0; j < np; ++j, ii += nv){
123 ✗ gradL = optData->J[i][j][nJ];;
124 ✗ memcpy(gradF + ii, gradL, nv*sizeof(modelica_real));
125 }
126
127 }else{
128 ✗ memset(gradF,0.0,n*sizeof(ipnumber));
129 }
130
131 ✗ if(ma){
132 ✗ modelica_real * gradM = optData->J[nsi - 1][np -1][nJ1];
133 ✗ if(la){
134 int i;
135 ✗ const int nnv = n - nv;
136 ✗ for(i = 0; i < nv; ++i)
137 ✗ gradF[nnv + i] += gradM[i];
138 }else{
139 ✗ memcpy(gradF + n - nv, gradM, nv*sizeof(modelica_real));
140 }
141
142 }
143
144 ✗ return TRUE;
145 }
146