@@ -48,6 +48,7 @@ protected
48
48
import Tearing = NBTearing ;
49
49
50
50
// NF imports
51
+ import ComponentRef = NFComponentRef ;
51
52
import NFFlatten.FunctionTree ;
52
53
import Variable = NFVariable ;
53
54
@@ -121,30 +122,29 @@ public
121
122
bdae := match (systemType, bdae)
122
123
local
123
124
list< System . System > systems;
124
- VariablePointers variables;
125
125
Pointer < Integer > eq_index;
126
126
127
- case (NBSystem . SystemType . ODE , BackendDAE . MAIN (ode = systems, funcTree = funcTree, varData = BVariable . VAR_DATA_SIM (variables = variables), eqData = BEquation . EQ_DATA_SIM (uniqueIndex = eq_index)))
127
+ case (NBSystem . SystemType . ODE , BackendDAE . MAIN (ode = systems, funcTree = funcTree, eqData = BEquation . EQ_DATA_SIM (uniqueIndex = eq_index)))
128
128
algorithm
129
- (systems, funcTree) := tearingTraverser(systems, funcs, funcTree, variables, eq_index, systemType);
129
+ (systems, funcTree) := tearingTraverser(systems, funcs, funcTree, eq_index, systemType);
130
130
bdae. ode := systems;
131
131
bdae. funcTree := funcTree;
132
132
then bdae;
133
133
134
- case (NBSystem . SystemType . INI , BackendDAE . MAIN (init = systems, funcTree = funcTree, varData = BVariable . VAR_DATA_SIM (variables = variables), eqData = BEquation . EQ_DATA_SIM (uniqueIndex = eq_index)))
134
+ case (NBSystem . SystemType . INI , BackendDAE . MAIN (init = systems, funcTree = funcTree, eqData = BEquation . EQ_DATA_SIM (uniqueIndex = eq_index)))
135
135
algorithm
136
- (systems, funcTree) := tearingTraverser(systems, funcs, funcTree, variables, eq_index, systemType);
136
+ (systems, funcTree) := tearingTraverser(systems, funcs, funcTree, eq_index, systemType);
137
137
bdae. init := systems;
138
138
if Util . isSome(bdae. init_0) then
139
- (systems, funcTree) := tearingTraverser(Util . getOption(bdae. init_0), funcs, funcTree, variables, eq_index, systemType);
139
+ (systems, funcTree) := tearingTraverser(Util . getOption(bdae. init_0), funcs, funcTree, eq_index, systemType);
140
140
bdae. init_0 := SOME (systems);
141
141
end if ;
142
142
bdae. funcTree := funcTree;
143
143
then bdae;
144
144
145
- case (NBSystem . SystemType . DAE , BackendDAE . MAIN (dae = SOME (systems), funcTree = funcTree, varData = BVariable . VAR_DATA_SIM (variables = variables), eqData = BEquation . EQ_DATA_SIM (uniqueIndex = eq_index)))
145
+ case (NBSystem . SystemType . DAE , BackendDAE . MAIN (dae = SOME (systems), funcTree = funcTree, eqData = BEquation . EQ_DATA_SIM (uniqueIndex = eq_index)))
146
146
algorithm
147
- (systems, funcTree) := tearingTraverser(systems, funcs, funcTree, variables, eq_index, systemType);
147
+ (systems, funcTree) := tearingTraverser(systems, funcs, funcTree, eq_index, systemType);
148
148
bdae. dae := SOME (systems);
149
149
bdae. funcTree := funcTree;
150
150
then bdae;
@@ -161,26 +161,36 @@ public
161
161
protected
162
162
// dummy adjacency matrix, dont need it for tearingNone()
163
163
Adjacency . Matrix dummy = Adjacency . EMPTY (NBAdjacency . MatrixStrictness . FULL );
164
+ list< Module . tearingInterface> funcs = {tearingNone, tearingFinalize};
165
+ StrongComponent new_comp;
164
166
algorithm
165
167
(comp, dummy, funcTree, index) := match comp
166
168
// create implicit equations
167
- case StrongComponent . SINGLE_COMPONENT ()
168
- then tearingNone(StrongComponent . ALGEBRAIC_LOOP (
169
- idx = index,
170
- strict = singleImplicit(comp. var , comp. eqn),
171
- casual = NONE (),
172
- linear = false ,
173
- mixed = false ,
174
- status = NBSolve . Status . IMPLICIT ), dummy, funcTree, index, VariablePointers . empty(), Pointer . create(0 ), systemType);
175
-
176
- case StrongComponent . MULTI_COMPONENT ()
177
- then tearingNone(StrongComponent . ALGEBRAIC_LOOP (
178
- idx = index,
179
- strict = singleImplicit(List . first(comp. vars), comp. eqn), // this is wrong! need to take all vars
180
- casual = NONE (),
181
- linear = false ,
182
- mixed = false ,
183
- status = NBSolve . Status . IMPLICIT ), dummy, funcTree, index, VariablePointers . empty(), Pointer . create(0 ), systemType);
169
+ case StrongComponent . SINGLE_COMPONENT () algorithm
170
+ new_comp := StrongComponent . ALGEBRAIC_LOOP (
171
+ idx = index,
172
+ strict = singleImplicit(comp. var , comp. eqn),
173
+ casual = NONE (),
174
+ linear = false ,
175
+ mixed = false ,
176
+ status = NBSolve . Status . IMPLICIT );
177
+ for func in funcs loop
178
+ (new_comp, dummy, funcTree, index) := func (new_comp, dummy, funcTree, index, VariablePointers . empty(), EquationPointers . empty(), Pointer . create(0 ), systemType);
179
+ end for ;
180
+ then (new_comp, dummy, funcTree, index);
181
+
182
+ case StrongComponent . MULTI_COMPONENT () algorithm
183
+ new_comp := StrongComponent . ALGEBRAIC_LOOP (
184
+ idx = index,
185
+ strict = singleImplicit(List . first(comp. vars), comp. eqn), // this is wrong! need to take all vars
186
+ casual = NONE (),
187
+ linear = false ,
188
+ mixed = false ,
189
+ status = NBSolve . Status . IMPLICIT );
190
+ for func in funcs loop
191
+ (new_comp, dummy, funcTree, index) := func (new_comp, dummy, funcTree, index, VariablePointers . empty(), EquationPointers . empty(), Pointer . create(0 ), systemType);
192
+ end for ;
193
+ then (new_comp, dummy, funcTree, index);
184
194
185
195
// do nothing otherwise
186
196
else (comp, dummy, funcTree, index);
@@ -234,7 +244,6 @@ protected
234
244
input list< Module . tearingInterface> funcs;
235
245
output list< System . System > new_systems = {};
236
246
input output FunctionTree funcTree;
237
- input VariablePointers variables;
238
247
input Pointer < Integer > eq_index;
239
248
input System . SystemType systemType;
240
249
protected
@@ -251,7 +260,7 @@ protected
251
260
// each module has a list of functions that need to be applied
252
261
tmp := strongComponents[i];
253
262
for func in funcs loop
254
- (tmp, full, funcTree, idx) := func (tmp, full, funcTree, idx, variables , eq_index, systemType);
263
+ (tmp, full, funcTree, idx) := func (tmp, full, funcTree, idx, syst . unknowns, syst . equations , eq_index, systemType);
255
264
end for ;
256
265
// only update if it changed
257
266
if not referenceEq(tmp, strongComponents[i]) then
@@ -288,7 +297,6 @@ protected
288
297
comps = listArray(residual_comps),
289
298
funcTree = funcTree,
290
299
name = System . System . systemTypeString(systemType) + tag + intString(index));
291
-
292
300
strict. jac := jacobian;
293
301
comp. strict := strict;
294
302
if Flags . isSet(Flags . TEARING_DUMP ) then
@@ -346,8 +354,9 @@ protected
346
354
Adjacency . Matrix adj;
347
355
Matching matching;
348
356
list< StrongComponent > inner_comps, residual_comps;
357
+ UnorderedMap < ComponentRef , Integer > v, e;
349
358
algorithm
350
- // print("######## minimal ########\n");
359
+ print("######## minimal ######## \n " );
351
360
(comp, index) := match comp
352
361
case StrongComponent . ALGEBRAIC_LOOP (strict = strict) algorithm
353
362
@@ -356,8 +365,12 @@ protected
356
365
(cont_vars, disc_vars) := List . splitOnTrue(vars_lst, BVariable . isContinuous);
357
366
(cont_eqns, disc_eqns) := List . splitOnTrue(eqns_lst, Equation . isContinuous);
358
367
359
- // print(List.toString(disc_vars, function BVariable.pointerToString()) + "\n");
360
- // print(List.toString(disc_eqns, function Equation.pointerToString(str = "")) + "\n");
368
+ print(List . toString(disc_vars, function BVariable . pointerToString(), "" , "" , " \n " , "" ) + " \n " );
369
+ print(List . toString(disc_eqns, function Equation . pointerToString(str = "" ), "" , "" , " \n " , "" ) + " \n " );
370
+ v := UnorderedMap . subSet(variables. map, list(BVariable . getVarName(var ) for var in disc_vars));
371
+ e := UnorderedMap . subSet(equations. map, list(Equation . getEqnName(eqn) for eqn in disc_eqns));
372
+ (full, funcTree) := Adjacency . Matrix . refine(full, funcTree, v, e, variables, equations);
373
+
361
374
362
375
/*
363
376
0 commit comments