Skip to content

Commit

Permalink
- Make sure empty partitioned independent systems do not count as sys…
Browse files Browse the repository at this point in the history
…tems (filter them out)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14812 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jan 17, 2013
1 parent ced7072 commit 50df299
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
10 changes: 8 additions & 2 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -7579,7 +7579,12 @@ algorithm
case (BackendDAE.DAE({syst},shared))
equation
(systs,shared) = partitionIndependentBlocksHelper(syst,shared,Error.getNumErrorMessages(),false);
then BackendDAE.DAE(systs,shared); // TODO: Add support for partitioned systems of equations
then BackendDAE.DAE(systs,shared);
else // TODO: Improve support for partitioned systems of equations
equation
BackendDAE.DAE({syst},shared) = collapseIndependentBlocks(dlow);
(systs,shared) = partitionIndependentBlocksHelper(syst,shared,Error.getNumErrorMessages(),false);
then BackendDAE.DAE(systs,shared);
end match;
end partitionIndependentBlocks;

Expand Down Expand Up @@ -7611,9 +7616,10 @@ algorithm
i = partitionIndependentBlocks0(arrayLength(m),0,mT,m,ixs);
// i2 = partitionIndependentBlocks0(arrayLength(mT),0,mT,m,ixsT);
b = i > 1;
// Debug.bcall(b,BackendDump.dump,BackendDAE.DAE({syst},shared));
// Debug.bcall2(b,BackendDump.dumpBackendDAE,BackendDAE.DAE({syst},shared), "partitionIndependentBlocksHelper");
// printPartition(b,ixs);
systs = Debug.bcallret5(b,partitionIndependentBlocksSplitBlocks,i,syst,ixs,mT,throwNoError,{syst});
// print("Number of partitioned systems: " +& intString(listLength(systs)) +& "\n");
then (systs,shared);
else
equation
Expand Down
15 changes: 12 additions & 3 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -7990,14 +7990,18 @@ algorithm
list<tuple<preoptimiseDAEModule,String,Boolean>> rest;
String str,moduleStr;
Boolean b;
BackendDAE.EqSystems systs;
BackendDAE.Shared shared;
case (_,{})
equation
Debug.fcall(Flags.OPT_DAE_DUMP, print, "Pre optimisation done.\n");
then
(inDAE,Util.SUCCESS());
case (_,(optModule,moduleStr,_)::rest)
equation
dae = optModule(inDAE);
BackendDAE.DAE(systs,shared) = optModule(inDAE);
systs = filterEmptySystems(systs);
dae = BackendDAE.DAE(systs,shared);
Debug.execStat("preOpt " +& moduleStr,CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.fcall(Flags.OPT_DAE_DUMP, print, stringAppendList({"\nOptimisation Module ",moduleStr,":\n\n"}));
Debug.fcall(Flags.OPT_DAE_DUMP, BackendDump.printBackendDAE, dae);
Expand Down Expand Up @@ -8220,14 +8224,18 @@ algorithm
list<tuple<pastoptimiseDAEModule,String,Boolean>> rest;
String str,moduleStr;
Boolean b;
BackendDAE.EqSystems systs;
BackendDAE.Shared shared;
case (_,{},_,_)
equation
Debug.fcall(Flags.OPT_DAE_DUMP, print, "Post optimisation done.\n");
then
(inDAE,Util.SUCCESS());
case (_,(optModule,moduleStr,_)::rest,_,_)
equation
dae = optModule(inDAE);
BackendDAE.DAE(systs,shared) = optModule(inDAE);
systs = filterEmptySystems(systs);
dae = BackendDAE.DAE(systs,shared);
Debug.execStat("pastOpt " +& moduleStr,CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.fcall(Flags.OPT_DAE_DUMP, print, stringAppendList({"\nOptimisation Module ",moduleStr,":\n\n"}));
Debug.fcall(Flags.OPT_DAE_DUMP, BackendDump.printBackendDAE, dae);
Expand Down Expand Up @@ -8577,7 +8585,8 @@ algorithm
(BackendDAEOptimize.simplifysemiLinear,"simplifysemiLinear",false),
(BackendDAEOptimize.removeConstants,"removeConstants",false),
(BackendDAEOptimize.optimizeInitialSystem,"optimizeInitialSystem",false),
(BackendDAEOptimize.detectSparsePatternODE,"detectJacobianSparsePattern",false)
(BackendDAEOptimize.detectSparsePatternODE,"detectJacobianSparsePattern",false),
(BackendDAEOptimize.partitionIndependentBlocks, "partitionIndependentBlocks", true)
};
strPastOptModules := getPastOptModulesString();
strPastOptModules := Util.getOptionOrDefault(ostrPastOptModules,strPastOptModules);
Expand Down
10 changes: 5 additions & 5 deletions Compiler/BackEnd/SimCodeUtil.mo
Expand Up @@ -1475,7 +1475,7 @@ algorithm

// generate initalsystem before replacing pre(alias)!
(initDAE, varlst) = Initialization.solveInitialSystem(dlow, {});
BackendDAE.DAE(shared=BackendDAE.SHARED(knownVars=knownVars)) = dlow;
BackendDAE.DAE(eqs=systs,shared=BackendDAE.SHARED(knownVars=knownVars)) = dlow;
tempvars = List.map2(varlst, dlowvarToSimvar, NONE(), knownVars);
// replace pre(alias) in time-equations
dlow = BackendDAEOptimize.simplifyTimeIndepFuncCalls(dlow);
Expand Down Expand Up @@ -1521,7 +1521,7 @@ algorithm
constraints=constrsarr,
classAttrs=clsattrsarra,
functionTree=functionTree,
symjacs=symJacs)) = dlow2;
symjacs=symJacs)) = dlow2;

// Add model info
modelInfo = createModelInfo(class_, dlow2, functions, {}, n_h, numberOfInitialEquations, numberOfInitialAlgorithms, numStateSets, fileDir, ifcpp);
Expand All @@ -1530,8 +1530,6 @@ algorithm
(uniqueEqIndex, odeEquations, algebraicEquations, allEquations, tempvars) = createEquationsForSystems(systs, shared, helpVarInfo, uniqueEqIndex, {}, {}, {}, tempvars);
modelInfo = addTempVars(tempvars, modelInfo);

odeEquations = makeEqualLengthLists(odeEquations, Config.noProc());

// Assertions and crap
// create parameter equations
((uniqueEqIndex, startValueEquations)) = BackendDAEUtil.foldEqSystem(dlow2, createStartValueEquations, (uniqueEqIndex, {}));
Expand Down Expand Up @@ -1569,6 +1567,8 @@ algorithm
removedEquations = List.map(removedEquations, addDivExpErrorMsgtoSimEqSystem);
initialEquations = List.map(initialEquations, addDivExpErrorMsgtoSimEqSystem);

odeEquations = makeEqualLengthLists(odeEquations, Config.noProc());

// generate jacobian or linear model matrices
LinearMatrices = createJacobianLinearCode(symJacs, modelInfo, uniqueEqIndex);
LinearMatrices = jacG::LinearMatrices;
Expand Down Expand Up @@ -1947,7 +1947,7 @@ algorithm
stateeqnsmark = arrayCreate(BackendDAEUtil.equationArraySizeDAE(syst), 0);
stateeqnsmark = BackendDAEUtil.markStateEquations(syst, stateeqnsmark, ass1);
(odeEquations1, algebraicEquations1, allEquations1, uniqueEqIndex, tempvars) = createEquationsForSystem1(stateeqnsmark, syst, shared, comps, helpVarInfo, iuniqueEqIndex, itempvars);
odeEquations = odeEquations1::odeEquations;
odeEquations = List.consOnTrue(not List.isEmpty(odeEquations1),odeEquations1,odeEquations);
algebraicEquations = listAppend(algebraicEquations, algebraicEquations1);
allEquations = listAppend(allEquations, allEquations1);
(uniqueEqIndex, odeEquations, algebraicEquations, allEquations, tempvars) = createEquationsForSystems(systs, shared, helpVarInfo, uniqueEqIndex, odeEquations, algebraicEquations, allEquations, tempvars);
Expand Down
4 changes: 0 additions & 4 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -1332,14 +1332,10 @@ end functionWhenReinitStatementElse;

template functionODE_system(list<SimEqSystem> derivativEquations, Integer n)
::=
let &varDecls = buffer ""
let &tmp = buffer ""
let odeEqs = derivativEquations |> eq => equationNames_(eq,contextSimulationNonDiscrete); separator="\n"
<<
<%&tmp%>
static void functionODE_system<%n%>(DATA *data,int omc_thread_number)
{
<%varDecls%>
<%odeEqs%>
}
>>
Expand Down
6 changes: 4 additions & 2 deletions Compiler/Util/Flags.mo
Expand Up @@ -642,8 +642,9 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
"inputDerivativesUsed",
"detectJacobianSparsePattern",
// "generateSymbolicJacobian",
"removeConstants"
"removeConstants"
// "optimizeInitialSystem"
// "partitionIndependentBlocks"
}),
SOME(STRING_DESC_OPTION({
("lateInlineFunction", Util.gettext("perform function inlining for function with annotation LateInline=true")),
Expand All @@ -668,7 +669,8 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
("simplifysemiLinear", Util.gettext("simplifies calls to semiLinear")),
("removeConstants", Util.gettext("remove all constants in the system")),
("optimizeInitialSystem", Util.gettext("simplifies time initial system")),
("detectJacobianSparsePattern", Util.gettext("detects the sparse pattern for Jacobian A"))
("detectJacobianSparsePattern", Util.gettext("detects the sparse pattern for Jacobian A")),
("partitionIndependentBlocks", Util.gettext("Partitions the equation system into independent equation systems (which can then be simulated in parallel or used to speed up subsequent optimizations)"))
})),
Util.gettext("Sets the post optimization modules to use in the back end. See +help=optmodules for more info."));
constant ConfigFlag SIMCODE_TARGET = CONFIG_FLAG(17, "simCodeTarget",
Expand Down

0 comments on commit 50df299

Please sign in to comment.