Skip to content

Commit

Permalink
Moving FMU Experimental outside QSS and into SimCodeUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergero committed Oct 9, 2015
1 parent 1759454 commit 7212ce4
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 72 deletions.
63 changes: 0 additions & 63 deletions Compiler/BackEnd/BackendQSS.mo
Expand Up @@ -1017,69 +1017,6 @@ algorithm
end matchcontinue;
end replaceInExpZC;

protected function getSimVarCompRef
input SimCodeVar.SimVar inVar;
output DAE.ComponentRef outComp;
algorithm
outComp := inVar.name;
end getSimVarCompRef;

function computeDependenciesHelper
input list<SimCode.SimEqSystem> eqs;
input list<DAE.ComponentRef> unknowns;
output list<SimCode.SimEqSystem> deps;
algorithm
deps := matchcontinue (eqs,unknowns)
local list<SimCode.SimEqSystem> tail;
SimCode.SimEqSystem head;
list<DAE.ComponentRef> new_unknowns;
DAE.ComponentRef cref;
list<SimCodeVar.SimVar> vars;
list<DAE.ComponentRef> linsys_unk;
DAE.Exp exp;
list<DAE.Exp> beqs;
case ({},_)
then {};
case ( (head as SimCode.SES_SIMPLE_ASSIGN(cref=cref,exp=exp))::tail,_)
equation
true = List.isMemberOnTrue(cref,unknowns,ComponentReference.crefEqual);
// We must include this equation in the ODE
new_unknowns = Expression.getAllCrefs(exp);
// And include all those one defining the RHS
then head::computeDependenciesHelper(tail,listAppend(unknowns,new_unknowns));
case ( (head as SimCode.SES_NONLINEAR())::tail,_)
equation
print("Error in computeDependecies - NONLINEAR not supported yet\n");
then computeDependenciesHelper(tail,unknowns);
case ( (head as SimCode.SES_LINEAR(lSystem = SimCode.LINEARSYSTEM(vars=vars, beqs=beqs)))::tail,_)
equation
// This linear system defines the following crefs
linsys_unk = List.map(vars,getSimVarCompRef);
// If any of those are in our unkowns me must include this equation system
false = listEmpty(List.intersectionOnTrue(linsys_unk,unknowns,ComponentReference.crefEqual));
new_unknowns = List.flatten(List.map(beqs, Expression.getAllCrefs));
then head::computeDependenciesHelper(tail,listAppend(unknowns,new_unknowns));
case (head ::tail,_)
then computeDependenciesHelper(tail,unknowns);
case (_,_)
equation
print("Error in computeDependecies");
then fail();
end matchcontinue;
end computeDependenciesHelper;

public function computeDependencies
input list<SimCode.SimEqSystem> eqs;
input DAE.ComponentRef cref;
output list<SimCode.SimEqSystem> deps;
algorithm
deps := match (eqs,cref)
case (_,_)
then listReverse(computeDependenciesHelper(listReverse(eqs),{cref}));
end match;
end computeDependencies;


////////////////////////////////////////////////////////////////////////////////////////////////////
///// END OF PACKAGE
////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
58 changes: 58 additions & 0 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -11523,5 +11523,63 @@ algorithm
end matchcontinue;
end getHighestDerivation1;

function computeDependenciesHelper
input list<SimCode.SimEqSystem> eqs;
input list<DAE.ComponentRef> unknowns;
output list<SimCode.SimEqSystem> deps;
algorithm
deps := matchcontinue (eqs,unknowns)
local list<SimCode.SimEqSystem> tail;
SimCode.SimEqSystem head;
list<DAE.ComponentRef> new_unknowns;
DAE.ComponentRef cref;
list<SimCodeVar.SimVar> vars;
list<DAE.ComponentRef> linsys_unk;
DAE.Exp exp;
list<DAE.Exp> beqs;
case ({},_)
then {};
case ( (head as SimCode.SES_SIMPLE_ASSIGN(cref=cref,exp=exp))::tail,_)
equation
true = List.isMemberOnTrue(cref,unknowns,ComponentReference.crefEqual);
// We must include this equation in the ODE
new_unknowns = Expression.getAllCrefs(exp);
// And include all those one defining the RHS
then head::computeDependenciesHelper(tail,listAppend(unknowns,new_unknowns));
case ( (head as SimCode.SES_NONLINEAR())::tail,_)
equation
print("Error in computeDependecies - NONLINEAR not supported yet\n");
then computeDependenciesHelper(tail,unknowns);
case ( (head as SimCode.SES_LINEAR(lSystem = SimCode.LINEARSYSTEM(vars=vars, beqs=beqs)))::tail,_)
equation
// This linear system defines the following crefs
linsys_unk = List.map(vars,getSimVarCompRef);
// If any of those are in our unkowns me must include this equation system
false = listEmpty(List.intersectionOnTrue(linsys_unk,unknowns,ComponentReference.crefEqual));
new_unknowns = List.flatten(List.map(beqs, Expression.getAllCrefs));
then head::computeDependenciesHelper(tail,listAppend(unknowns,new_unknowns));
case (head ::tail,_)
then computeDependenciesHelper(tail,unknowns);
case (_,_)
equation
print("Error in computeDependecies");
then fail();
end matchcontinue;
end computeDependenciesHelper;

public function computeDependencies
input list<SimCode.SimEqSystem> eqs;
input DAE.ComponentRef cref;
output list<SimCode.SimEqSystem> deps;
algorithm
deps := match (eqs,cref)
case (_,_)
then listReverse(computeDependenciesHelper(listReverse(eqs),{cref}));
end match;
end computeDependencies;




annotation(__OpenModelica_Interface="backend");
end SimCodeUtil;
2 changes: 1 addition & 1 deletion Compiler/Template/CodegenC.tpl
Expand Up @@ -5565,7 +5565,7 @@ template functionXXX_systemPartial(list<SimEqSystem> derivativEquations, String
::=
let code = match modelInfo
case MODELINFO(vars=SIMVARS(derivativeVars=ders)) then
(ders |> SIMVAR(__) hasindex i0 => equationNames_Partial(BackendQSS.computeDependencies(derivativEquations,name),modelNamePrefixStr,i0,crefStr(name)) ; separator="\n")
(ders |> SIMVAR(__) hasindex i0 => equationNames_Partial(SimCodeUtil.computeDependencies(derivativEquations,name),modelNamePrefixStr,i0,crefStr(name)) ; separator="\n")
<<
static void <%modelNamePrefixStr%>_function<%name%><%n%>(DATA *data, threadData_t *threadData, int i)
{
Expand Down
8 changes: 0 additions & 8 deletions Compiler/Template/SimCodeBackendTV.mo
Expand Up @@ -281,12 +281,4 @@ package FMI
end getEnumerationTypeFromTypes;
end FMI;


package BackendQSS
function computeDependencies
input list<SimCode.SimEqSystem> eqs;
input DAE.ComponentRef cref;
output list<SimCode.SimEqSystem> deps;
end computeDependencies;
end BackendQSS;
end SimCodeBackendTV;
6 changes: 6 additions & 0 deletions Compiler/Template/SimCodeTV.mo
Expand Up @@ -831,6 +831,12 @@ package SimCodeUtil
input list<SimCode.ClockedPartition> inPartitions;
output list<SimCode.SubPartition> outSubPartitions;
end getSubPartitions;

function computeDependencies
input list<SimCode.SimEqSystem> eqs;
input DAE.ComponentRef cref;
output list<SimCode.SimEqSystem> deps;
end computeDependencies;
end SimCodeUtil;

package SimCodeFunctionUtil
Expand Down

0 comments on commit 7212ce4

Please sign in to comment.