Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 90.6% 29 / 0 / 32
Functions: -% 0 / 1 / 1
Branches: 94.4% 34 / 0 / 36

OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBBindings.mo
Line Branch Exec Source
1 /*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36 encapsulated package NBBindings
37 " file: NBBindings.mo
38 package: NBBindings
39 description: Creates binding equation for all bound continous variables.
40 "
41
42 protected
43 import Module = NBModule;
44
45 import BackendDAE = NBackendDAE;
46 import NBEquation.{Equation, EquationPointers, EqData};
47 import Variable = NFVariable;
48 import BVariable = NBVariable;
49 import NBVariable.{VariablePointers, VariablePointer, VarData};
50
51 // Util
52 import StringUtil;
53
54 public
55 function main extends Module.wrapper;
56 algorithm
57 bdae := match bdae
58 local
59 Pointer<Equation> bind_eqn "binding equation";
60 VarData varData "Data containing variable pointers";
61 EqData eqData "Data containing equation pointers";
62 list<Pointer<Variable>> bound_vars "list of bound unknown variables";
63 list<Pointer<Variable>> bound_clocks "list of bound clock variables";
64 list<Pointer<Equation>> binding_cont = {} "list of created continuous binding equations";
65 list<Pointer<Equation>> binding_clck = {} "list of created clocked binding equations";
66 list<Pointer<Equation>> binding_disc = {} "list of created discrete binding equations";
67 list<Pointer<Equation>> binding_rec = {} "list of created record binding equations";
68 Pointer<Variable> parent "optional record parent";
69 Boolean skip_record_element "true if this variable is part of an array and the array variable is bound";
70 UnorderedSet<VariablePointer> new_iters = UnorderedSet.new(BVariable.hash, BVariable.equalName);
71
72 case BackendDAE.MAIN(varData = varData as VarData.VAR_DATA_SIM(), eqData = eqData as EqData.EQ_DATA_SIM())
73 algorithm
74 // create continuous and discrete binding equations
75
6/6
✓ Branch 2 taken 3585 times.
✓ Branch 3 taken 376 times.
✓ Branch 4 taken 3961 times.
✓ Branch 5 taken 193 times.
✓ Branch 6 taken 376 times.
✓ Branch 7 taken 193 times.
4154 bound_vars := list(var for var guard(BVariable.isBound(var)) in VariablePointers.toList(varData.unknowns));
76
2/2
✓ Branch 1 taken 376 times.
✓ Branch 2 taken 193 times.
569 for var in bound_vars loop
77 // do not create bindings for record children with bound parents! they are bound off their record variables
78 // if the parent is not fully unkown also create individual bindings
79 skip_record_element := match BVariable.getParent(var)
80
3/4
✓ Branch 1 taken 34 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 34 times.
✗ Branch 5 not taken.
36 case SOME(parent) then BVariable.isBound(parent) and BVariable.isUnknownRecord(parent);
81 else false;
82 end match;
83
84 if not skip_record_element then
85 342 bind_eqn := Equation.generateBindingEquation(var, eqData.uniqueIndex, false, new_iters);
86
2/2
✓ Branch 1 taken 309 times.
✓ Branch 2 taken 33 times.
342 if BVariable.isContinuous(var, false) then
87 binding_cont := bind_eqn :: binding_cont;
88 else
89 binding_disc := bind_eqn :: binding_disc;
90 end if;
91 end if;
92 end for;
93
94 // create record binding equations, but only for unknown records
95 // known record binding equations will be created for initialization
96
8/8
✓ Branch 2 taken 68 times.
✓ Branch 3 taken 84 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 36 times.
✓ Branch 7 taken 152 times.
✓ Branch 8 taken 193 times.
✓ Branch 9 taken 36 times.
✓ Branch 10 taken 193 times.
345 bound_vars := list(var for var guard(BVariable.isBound(var) and BVariable.isUnknownRecord(var)) in VariablePointers.toList(varData.records));
97
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 193 times.
229 for var in bound_vars loop
98 36 binding_rec := Equation.generateBindingEquation(var, eqData.uniqueIndex, false, new_iters) :: binding_rec;
99 end for;
100
101 // create clock bindings
102
6/6
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 193 times.
✓ Branch 6 taken 12 times.
✓ Branch 7 taken 193 times.
207 bound_clocks := list(var for var guard(BVariable.isBound(var)) in VariablePointers.toList(varData.clocks));
103
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 193 times.
205 for var in bound_clocks loop
104 12 binding_clck := Equation.generateBindingEquation(var, eqData.uniqueIndex, false, new_iters) :: binding_clck;
105 end for;
106
107 // adding all continuous equations
108 193 eqData.equations := EquationPointers.addList(binding_cont, eqData.equations);
109 193 eqData.simulation := EquationPointers.addList(binding_cont, eqData.simulation);
110 193 eqData.continuous := EquationPointers.addList(binding_cont, eqData.continuous);
111
112 // adding all discrete equations
113 193 eqData.equations := EquationPointers.addList(binding_disc, eqData.equations);
114 193 eqData.simulation := EquationPointers.addList(binding_disc, eqData.simulation);
115 193 eqData.discretes := EquationPointers.addList(binding_disc, eqData.discretes);
116
117 // adding all record equations
118 193 eqData.equations := EquationPointers.addList(binding_rec, eqData.equations);
119 193 eqData.simulation := EquationPointers.addList(binding_rec, eqData.simulation);
120 193 eqData.continuous := EquationPointers.addList(binding_rec, eqData.continuous);
121
122 // adding all clocked equations
123 193 eqData.clocked := EquationPointers.addList(binding_clck, eqData.clocked);
124
125 193 bdae.eqData := eqData;
126
127 193 bdae.varData := VarData.addTypedList(bdae.varData, UnorderedSet.toList(new_iters), NBVariable.VarData.VarType.ITERATOR);
128
129
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 193 times.
193 if Flags.isSet(Flags.DUMP_BACKENDDAE_INFO) then
130 ✗ Error.addSourceMessage(Error.BACKENDDAEINFO_LOWER,{
131 intString(EqData.scalarSize(eqData)) + " (" + intString(EqData.size(eqData)) + ")",
132 intString(VarData.scalarSize(varData)) + " (" + intString(VarData.size(varData)) + ")"},
133 Absyn.dummyInfo);
134 end if;
135
136
2/2
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 183 times.
193 if Flags.isSet(Flags.DUMP_BINDINGS) then
137 10 print(List.toStringCustom(binding_cont, function Equation.pointerToString(str = "\t"),
138 StringUtil.headline_4("Created Continuous Binding Equations (" + intString(listLength(binding_cont)) + "):"), "", "\n", "", false) + "\n\n");
139 10 print(List.toStringCustom(binding_clck, function Equation.pointerToString(str = "\t"),
140 StringUtil.headline_4("Created Clocked Binding Equations (" + intString(listLength(binding_clck)) + "):"), "", "\n", "", false) + "\n\n");
141 10 print(List.toStringCustom(binding_disc, function Equation.pointerToString(str = "\t"),
142 StringUtil.headline_4("Created Discrete Binding Equations (" + intString(listLength(binding_disc)) + "):"), "", "\n", "", false) + "\n\n");
143 10 print(List.toStringCustom(binding_rec, function Equation.pointerToString(str = "\t"),
144 StringUtil.headline_4("Created Record Binding Equations (" + intString(listLength(binding_rec)) + "):"), "", "\n", "", false) + "\n\n");
145 end if;
146
147 then bdae;
148
149 else algorithm
150 ✗ Error.addMessage(Error.INTERNAL_ERROR, {getInstanceName() + " failed."});
151 ✗ then fail();
152 end match;
153 end main;
154
155 annotation(__OpenModelica_Interface="nbackend");
156 end NBBindings;
157
158
159