Skip to content

Commit

Permalink
- splitt the initial system in independend subsystems to see easier w…
Browse files Browse the repository at this point in the history
…hat the problem is

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14529 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Dec 23, 2012
1 parent 42000e5 commit 7d5e346
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
18 changes: 10 additions & 8 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -7568,20 +7568,21 @@ algorithm
BackendDAE.Shared shared;
case (BackendDAE.DAE({syst},shared))
equation
(systs,shared) = partitionIndependentBlocksHelper(syst,shared,Error.getNumErrorMessages());
(systs,shared) = partitionIndependentBlocksHelper(syst,shared,Error.getNumErrorMessages(),false);
then BackendDAE.DAE(systs,shared); // TODO: Add support for partitioned systems of equations
end match;
end partitionIndependentBlocks;

protected function partitionIndependentBlocksHelper
public function partitionIndependentBlocksHelper
"Finds independent partitions of the equation system by "
input BackendDAE.EqSystem isyst;
input BackendDAE.Shared ishared;
input Integer numErrorMessages;
input Boolean throwNoError;
output list<BackendDAE.EqSystem> systs;
output BackendDAE.Shared oshared;
algorithm
(systs,oshared) := matchcontinue (isyst,ishared,numErrorMessages)
(systs,oshared) := matchcontinue (isyst,ishared,numErrorMessages,throwNoError)
local
BackendDAE.IncidenceMatrix m,mT;
array<Integer> ixs;
Expand All @@ -7590,7 +7591,7 @@ algorithm
BackendDAE.Shared shared;
BackendDAE.EqSystem syst;

case (syst,shared,_)
case (syst,shared,_,_)
equation
// print("partitionIndependentBlocks: TODO: Implement me\n");
(syst,m,mT) = BackendDAEUtil.getIncidenceMatrixfromOption(syst,BackendDAE.NORMAL());
Expand All @@ -7601,7 +7602,7 @@ algorithm
b = i > 1;
// Debug.bcall(b,BackendDump.dump,BackendDAE.DAE({syst},shared));
// printPartition(b,ixs);
systs = Debug.bcallret4(b,partitionIndependentBlocksSplitBlocks,i,syst,ixs,mT,{syst});
systs = Debug.bcallret5(b,partitionIndependentBlocksSplitBlocks,i,syst,ixs,mT,throwNoError,{syst});
then (systs,shared);
else
equation
Expand All @@ -7616,9 +7617,10 @@ protected function partitionIndependentBlocksSplitBlocks
input BackendDAE.EqSystem syst;
input array<Integer> ixs;
input BackendDAE.IncidenceMatrix mT;
input Boolean throwNoError;
output list<BackendDAE.EqSystem> systs;
algorithm
systs := match (n,syst,ixs,mT)
systs := match (n,syst,ixs,mT,throwNoError)
local
BackendDAE.Variables vars;
BackendDAE.EquationArray arr;
Expand All @@ -7628,15 +7630,15 @@ algorithm
list<list<BackendDAE.Var>> vl;
Integer i1,i2;
String s1,s2;
case (_,BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=arr),_,_)
case (_,BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=arr),_,_,_)
equation
ea = arrayCreate(n,{});
va = arrayCreate(n,{});
i1 = BackendDAEUtil.equationSize(arr);
i2 = BackendVariable.numVariables(vars);
s1 = intString(i1);
s2 = intString(i2);
Error.assertionOrAddSourceMessage(i1 == i2,
Error.assertionOrAddSourceMessage((i1 == i2) or throwNoError,
Util.if_(i1 > i2, Error.OVERDET_EQN_SYSTEM, Error.UNDERDET_EQN_SYSTEM),
{s1,s2}, Absyn.dummyInfo);

Expand Down
10 changes: 5 additions & 5 deletions Compiler/BackEnd/Initialization.mo
Expand Up @@ -414,8 +414,7 @@ algorithm
evars = BackendVariable.emptyVars();
eavars = BackendVariable.emptyVars();
emptyeqns = BackendEquation.emptyEqns();
initdae = BackendDAE.DAE({initsyst},
BackendDAE.SHARED(fixvars,
shared = BackendDAE.SHARED(fixvars,
evars,
eavars,
emptyeqns,
Expand All @@ -428,12 +427,13 @@ algorithm
BackendDAE.EVENT_INFO({},{},{},{},0,0),
{},
BackendDAE.INITIALSYSTEM(),
{}));
{});

// split it in independend subsystems
//initdae = BackendDAEOptimize.partitionIndependentBlocks(initdae);
(systs,shared) = BackendDAEOptimize.partitionIndependentBlocksHelper(initsyst,shared,Error.getNumErrorMessages(),true);
initdae = BackendDAE.DAE(systs,shared);
// analzye initial system
initdae = analyzeInitialSystem(initdae, inDAE, inInitVars);
initdae = analyzeInitialSystem(initdae, inDAE, inInitVars);

// some debug prints
Debug.fcall2(Flags.DUMP_INITIAL_SYSTEM, BackendDump.dumpBackendDAE, initdae, "initial system");
Expand Down
38 changes: 38 additions & 0 deletions Compiler/Util/Debug.mo
Expand Up @@ -493,6 +493,44 @@ algorithm
end match;
end bcallret4;

public function bcallret5
"Boolean controlled calling of given function (2nd arg).
The passed function gets 5 arguments.
The last parameter is returned if the given flag is not set."
input Boolean flag;
input FuncAB_C func;
input Type_a arg1;
input Type_b arg2;
input Type_c arg3;
input Type_d arg4;
input Type_e arg5;
input Type_g default;
output Type_g res;
partial function FuncAB_C
input Type_a inTypeA;
input Type_b inTypeB;
input Type_c inTypeC;
input Type_d inTypeD;
input Type_e inTypeE;
output Type_g g;
end FuncAB_C;
replaceable type Type_a subtypeof Any;
replaceable type Type_b subtypeof Any;
replaceable type Type_c subtypeof Any;
replaceable type Type_d subtypeof Any;
replaceable type Type_e subtypeof Any;
replaceable type Type_f subtypeof Any;
annotation(__OpenModelica_EarlyInline = true);
algorithm
res := match (flag,func,arg1,arg2,arg3,arg4,arg5,default)
case (true,_,_,_,_,_,_,_)
equation
res = func(arg1,arg2,arg3,arg4,arg5);
then res;
else default;
end match;
end bcallret5;

public function bcallret6
"Boolean controlled calling of given function (2nd arg).
The passed function gets 6 arguments.
Expand Down

0 comments on commit 7d5e346

Please sign in to comment.