Skip to content

Commit 92c29ce

Browse files
authored
[NB] Mark algebraic loops using homotopy (#15535)
TODO structural reduction on homotopy system
1 parent d540a4d commit 92c29ce

7 files changed

Lines changed: 205 additions & 171 deletions

File tree

OMCompiler/Compiler/NBackEnd/Classes/NBStrongComponent.mo

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,18 @@ public
10561056
end match;
10571057
end isAlgebraicLoop;
10581058

1059+
function setHomotopy
1060+
input output StrongComponent comp;
1061+
input Boolean homotopy;
1062+
algorithm
1063+
comp := match comp
1064+
case ALGEBRAIC_LOOP() algorithm
1065+
comp.homotopy := homotopy;
1066+
then comp;
1067+
else comp;
1068+
end match;
1069+
end setHomotopy;
1070+
10591071
function createPseudoScalar
10601072
input list<Integer> comp_indices;
10611073
input array<Integer> eqn_to_var;

OMCompiler/Compiler/NBackEnd/Classes/NBackendDAE.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ public
331331
(function Tearing.main(kind = kind), "Tearing"),
332332
(Partitioning.categorize, "Categorize"),
333333
(Solve.main, "Solve"),
334-
(function Jacobian.main(kind = kind), "Jacobian")
334+
(function Jacobian.main(kind = kind), "Jacobian"),
335+
(Initialization.minimizeHomotopySystem, "Minimize Homotopy System")
335336
};
336337

337338
(bdae, preOptClocks) := applyModules(bdae, preOptModules, eq_filter_opt, ClockIndexes.RT_CLOCK_NEW_BACKEND_MODULE);

OMCompiler/Compiler/NBackEnd/Modules/1_Main/NBInitialization.mo

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ protected
7070
import Replacements = NBReplacements;
7171
import BPartition = NBPartition;
7272
import NBPartition.Partition;
73+
import StrongComponent = NBStrongComponent;
7374
import Tearing = NBTearing;
7475

7576
// Util imports
@@ -804,6 +805,22 @@ public
804805
end if;
805806
end containsLambda0;
806807

808+
function minimizeHomotopySystem
809+
extends Module.wrapper;
810+
algorithm
811+
bdae := match bdae
812+
case BackendDAE.MAIN() algorithm
813+
if isSome(bdae.init_0) then
814+
// for now all strong components have homotopy if init_0 exists
815+
// TODO reduced analysis on what needs to be computed for homotopy
816+
bdae.init := list(Partition.mapStrongComponents(par, function StrongComponent.setHomotopy(homotopy = true)) for par in bdae.init);
817+
end if;
818+
then bdae;
819+
820+
else bdae;
821+
end match;
822+
end minimizeHomotopySystem;
823+
807824
function removeWhenEquation
808825
"this function checks if an equation has to be removed before initialization.
809826
true for: when branch without condition initial()"

testsuite/simulation/modelica/NBackend/initialization/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ TEST = ../../../../rtest -v
22

33
TESTFILES = \
44
experimental_initialSimplified.mos \
5+
homotopy_indirect.mos \
56
homotopy_no_loop.mos \
67
init_if_eq.mos \
78
init_if_exp.mos \

0 commit comments

Comments
 (0)