Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 3e4eb94

Browse files
ptaeuberOpenModelica-Hudson
authored andcommitted
Better flag handling for different homotopy approaches
Belonging to [master]: - #2019 - OpenModelica/OpenModelica-testsuite#781
1 parent 0a33707 commit 3e4eb94

File tree

7 files changed

+68
-30
lines changed

7 files changed

+68
-30
lines changed

Compiler/BackEnd/BackendDAEOptimize.mo

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5706,19 +5706,22 @@ protected
57065706
BackendDAE.StrongComponents comps;
57075707
BackendDAE.EqSystems newEqSystems={};
57085708
array<Integer> ass1, ass2;
5709-
Boolean globalHomotopy = stringEq(Flags.getConfigString(Flags.HOMOTOPY_APPROACH), "global");
57105709
algorithm
5711-
for syst in outDAE.eqs loop
5712-
BackendDAE.MATCHING(ass1=ass1, ass2=ass2, comps=comps) := syst.matching;
5713-
if globalHomotopy then
5714-
(comps, syst) := traverseStrongComponentsForHomotopyLoop(comps, syst);
5715-
else
5716-
(comps, syst) := traverseStrongComponentsAddLambda(comps, syst);
5717-
end if;
5718-
syst.matching := BackendDAE.MATCHING(ass1=ass1, ass2=ass2, comps=comps);
5719-
newEqSystems := syst::newEqSystems;
5720-
end for;
5721-
outDAE.eqs := listReverse(newEqSystems);
5710+
if Config.adaptiveHomotopy() then
5711+
for syst in outDAE.eqs loop
5712+
BackendDAE.MATCHING(ass1=ass1, ass2=ass2, comps=comps) := syst.matching;
5713+
if Config.globalHomotopy() then
5714+
(comps, syst) := traverseStrongComponentsForHomotopyLoop(comps, syst);
5715+
else
5716+
(comps, syst) := traverseStrongComponentsAddLambda(comps, syst);
5717+
end if;
5718+
syst.matching := BackendDAE.MATCHING(ass1=ass1, ass2=ass2, comps=comps);
5719+
newEqSystems := syst::newEqSystems;
5720+
end for;
5721+
outDAE.eqs := listReverse(newEqSystems);
5722+
else
5723+
Error.addCompilerWarning("InitOptModule generateHomotopyComponents is activated for an equidistant homotopy method and will therefore be ignored.");
5724+
end if;
57225725
end generateHomotopyComponents;
57235726

57245727
protected function traverseStrongComponentsForHomotopyLoop " traverses all the strong components and finds the smallest homotopy loop

Compiler/BackEnd/Initialization.mo

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected
9595
BackendDAE.Variables vars, fixvars;
9696
Boolean b, b1, b2, useHomotopy;
9797
String msg;
98-
list<String> disabledModules;
98+
list<String> enabledModules, disabledModules;
9999
HashSet.HashSet hs "contains all pre variables";
100100
list<BackendDAE.Equation> removedEqns;
101101
list<BackendDAE.Var> dumpVars, dumpVars2, outAllPrimaryParameters;
@@ -228,15 +228,14 @@ algorithm
228228

229229

230230
if useHomotopy then
231+
enabledModules := if Config.adaptiveHomotopy() then {"inlineHomotopy", "generateHomotopyComponents"} else {};
231232
disabledModules := {};
232233
else
234+
enabledModules := {};
233235
disabledModules := {"inlineHomotopy", "generateHomotopyComponents"};
234236
end if;
235237

236-
initOptModules := BackendDAEUtil.getInitOptModules(NONE(), {}, disabledModules);
237-
if BackendDAEUtil.isInitOptModuleActivated("generateHomotopyComponents", initOptModules) and not BackendDAEUtil.isInitOptModuleActivated("inlineHomotopy", initOptModules) then
238-
initOptModules := (BackendDAEOptimize.inlineHomotopy, "inlineHomotopy")::initOptModules;
239-
end if;
238+
initOptModules := BackendDAEUtil.getInitOptModules(NONE(), enabledModules, disabledModules);
240239
matchingAlgorithm := BackendDAEUtil.getMatchingAlgorithm(NONE());
241240
daeHandler := BackendDAEUtil.getIndexReductionMethod(SOME("none"));
242241
initdae := BackendDAEUtil.postOptimizeDAE(initdae, initOptModules, matchingAlgorithm, daeHandler);
@@ -249,7 +248,7 @@ algorithm
249248
end if;
250249

251250
// compute system for lambda=0
252-
if useHomotopy and stringEq(Flags.getConfigString(Flags.HOMOTOPY_APPROACH), "global") then
251+
if useHomotopy and Config.globalHomotopy() then
253252
initOptModulesLambda0 := BackendDAEUtil.getInitOptModules(NONE(),{"replaceHomotopyWithSimplified"},{"inlineHomotopy", "generateHomotopyComponents"});
254253
initdae0 := BackendDAEUtil.setFunctionTree(initdae0, BackendDAEUtil.getFunctions(initdae.shared));
255254
initdae0 := BackendDAEUtil.postOptimizeDAE(initdae0, initOptModulesLambda0, matchingAlgorithm, daeHandler);

Compiler/Template/CodegenC.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ template simulationFile(SimCode simCode, String guid, Boolean isModelExchangeFMU
10801080
<%symbolName(modelNamePrefixStr,"function_storeDelayed")%>,
10811081
<%symbolName(modelNamePrefixStr,"updateBoundVariableAttributes")%>,
10821082
<%symbolName(modelNamePrefixStr,"functionInitialEquations")%>,
1083-
<%if listEmpty(initialEquations_lambda0) then (if not BackendDAEUtil.isInitOptModuleActivated("generateHomotopyComponents") then '0' else '3') else if not BackendDAEUtil.isInitOptModuleActivated("generateHomotopyComponents") then '1' else '2'%>, /* useHomotopy - 0: no homotopy or local homotopy (equidistant lambda), 1: global homotopy (equidistant lambda), 2: new global homotopy approach, 3: new local homotopy approach */
1083+
<%if Config.adaptiveHomotopy() then (if Config.globalHomotopy() then '2' else '3') else (if Config.globalHomotopy() then '1' else '0')%>, /* useHomotopy - 0: local homotopy (equidistant lambda), 1: global homotopy (equidistant lambda), 2: new global homotopy approach (adaptive lambda), 3: new local homotopy approach (adaptive lambda)*/
10841084
<%symbolName(modelNamePrefixStr,"functionInitialEquations_lambda0")%>,
10851085
<%symbolName(modelNamePrefixStr,"functionRemovedInitialEquations")%>,
10861086
<%symbolName(modelNamePrefixStr,"updateBoundParameters")%>,

Compiler/Template/SimCodeTV.mo

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3424,6 +3424,14 @@ package Config
34243424
function typeinfo
34253425
output Boolean flag;
34263426
end typeinfo;
3427+
3428+
function globalHomotopy
3429+
output Boolean outBoolean;
3430+
end globalHomotopy;
3431+
3432+
function adaptiveHomotopy
3433+
output Boolean outBoolean;
3434+
end adaptiveHomotopy;
34273435
end Config;
34283436

34293437
package Flags
@@ -3567,13 +3575,6 @@ package DAEUtil
35673575

35683576
end DAEUtil;
35693577

3570-
package BackendDAEUtil
3571-
function isInitOptModuleActivated
3572-
input String initOptModule;
3573-
output Boolean isActivated;
3574-
end isInitOptModuleActivated;
3575-
end BackendDAEUtil;
3576-
35773578
package Types
35783579
function getDimensionSizes
35793580
input DAE.Type inType;

Compiler/Util/Config.mo

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,5 +613,27 @@ algorithm
613613
outBoolean := Flags.getConfigBool(Flags.IGNORE_COMMAND_LINE_OPTIONS_ANNOTATION);
614614
end ignoreCommandLineOptionsAnnotation;
615615

616+
public function globalHomotopy
617+
output Boolean outBoolean;
618+
algorithm
619+
outBoolean := match(Flags.getConfigString(Flags.HOMOTOPY_APPROACH))
620+
case("equidistantLocal") then false;
621+
case("adaptiveLocal") then false;
622+
case("equidistantGlobal") then true;
623+
case("adaptiveGlobal") then true;
624+
end match;
625+
end globalHomotopy;
626+
627+
public function adaptiveHomotopy
628+
output Boolean outBoolean;
629+
algorithm
630+
outBoolean := match(Flags.getConfigString(Flags.HOMOTOPY_APPROACH))
631+
case("equidistantLocal") then false;
632+
case("adaptiveLocal") then true;
633+
case("equidistantGlobal") then false;
634+
case("adaptiveGlobal") then true;
635+
end match;
636+
end adaptiveHomotopy;
637+
616638
annotation(__OpenModelica_Interface="util");
617639
end Config;

Compiler/Util/Flags.mo

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,10 +1390,12 @@ constant ConfigFlag ZEROMQ_FILE_SUFFIX = CONFIG_FLAG(115, "zeroMQFileSuffix",
13901390
SOME("z"), EXTERNAL(), STRING_FLAG(""), NONE(),
13911391
Util.gettext("Sets the file suffix for zeroMQ port file if --interactive=zmq is used."));
13921392
constant ConfigFlag HOMOTOPY_APPROACH = CONFIG_FLAG(116, "homotopyApproach",
1393-
NONE(), EXTERNAL(), STRING_FLAG("global"),
1393+
NONE(), EXTERNAL(), STRING_FLAG("equidistantGlobal"),
13941394
SOME(STRING_DESC_OPTION({
1395-
("local", Util.gettext("Local homotopy approach. The homotopy parameter only effects the local strongly connected component.")),
1396-
("global", Util.gettext("Default, global homotopy approach. The homotopy parameter effects the entire initialization system."))
1395+
("equidistantLocal", Util.gettext("Local homotopy approach with equidistant lambda steps. The homotopy parameter only effects the local strongly connected component.")),
1396+
("adaptiveLocal", Util.gettext("Local homotopy approach with adaptive lambda steps. The homotopy parameter only effects the local strongly connected component.")),
1397+
("equidistantGlobal", Util.gettext("Default, global homotopy approach with equidistant lambda steps. The homotopy parameter effects the entire initialization system.")),
1398+
("adaptiveGlobal", Util.gettext("Global homotopy approach with adaptive lambda steps. The homotopy parameter effects the entire initialization system."))
13971399
})),
13981400
Util.gettext("Sets the homotopy approach."));
13991401

SimulationRuntime/c/simulation/solver/initialization/initialization.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,18 @@ static int symbolic_initialization(DATA *data, threadData_t *threadData)
185185
FILE *pFile = NULL;
186186
long i;
187187
MODEL_DATA *mData = data->modelData;
188-
int solveWithGlobalHomotopy = (data->callback->useHomotopy == 1 && init_lambda_steps > 1) || data->callback->useHomotopy == 2;
188+
int homotopySupport = 0;
189+
int solveWithGlobalHomotopy;
190+
191+
#if !defined(OMC_NUM_NONLINEAR_SYSTEMS) || OMC_NUM_NONLINEAR_SYSTEMS>0
192+
for(i=0; i<mData->nNonLinearSystems; i++) {
193+
if (data->simulationInfo->nonlinearSystemData[i].homotopySupport) {
194+
homotopySupport = 1;
195+
break;
196+
}
197+
}
198+
#endif
199+
solveWithGlobalHomotopy = homotopySupport && ((data->callback->useHomotopy == 1 && init_lambda_steps > 1) || data->callback->useHomotopy == 2);
189200

190201
#if !defined(OMC_NDELAY_EXPRESSIONS) || OMC_NDELAY_EXPRESSIONS>0
191202
/* initial sample and delay before initial the system */

0 commit comments

Comments
 (0)