Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 - added support for event triggering math function
   e.g. ceil,floor,div,mod,rem,integer


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14235 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Willi Braun committed Dec 5, 2012
1 parent 92b794e commit 217ea9c
Show file tree
Hide file tree
Showing 15 changed files with 656 additions and 266 deletions.
1 change: 1 addition & 0 deletions Compiler/BackEnd/BackendDAE.mo
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ uniontype EventInfo "- EventInfo"
// TODO: relationsLst could be removed if cpp runtime is prepared to handle zero-crossing conditions
list<ZeroCrossing> relationsLst "List of zero crossing function as before, used by cpp runtime";
Integer relationsNumber "stores the number of relation in all zero-crossings";
Integer numberMathEvents "stores the number of math function that trigger events e.g. floor, ceil, integer, ...";
end EVENT_INFO;

end EventInfo;
Expand Down
538 changes: 369 additions & 169 deletions Compiler/BackEnd/BackendDAECreate.mo

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2551,12 +2551,12 @@ algorithm
BackendDAE.SymbolicJacobians symjacs;
list<BackendDAE.WhenClause> whenClauseLst,whenClauseLst1;
list<BackendDAE.ZeroCrossing> zeroCrossingLst, relationsLst,sampleLst;
Integer numberOfRealtions;
Integer numberOfRealtions,numMathFunctions;
BackendDAE.BackendDAEType btp;
BackendDAE.EqSystems systs,systs1;
list<BackendDAE.Var> ordvarslst,varlst;
case (false,_,_) then inDAE;
case (true,BackendDAE.DAE(systs,BackendDAE.SHARED(knvars,exobj,aliasVars,inieqns,remeqns,constrs,clsAttrs,cache,env,funcTree,BackendDAE.EVENT_INFO(whenClauseLst,zeroCrossingLst,sampleLst,relationsLst,numberOfRealtions),eoc,btp,symjacs)),_)
case (true,BackendDAE.DAE(systs,BackendDAE.SHARED(knvars,exobj,aliasVars,inieqns,remeqns,constrs,clsAttrs,cache,env,funcTree,BackendDAE.EVENT_INFO(whenClauseLst,zeroCrossingLst,sampleLst,relationsLst,numberOfRealtions,numMathFunctions),eoc,btp,symjacs)),_)
equation
// replace moved vars in knvars,remeqns
(aliasVars,(_,varlst)) = BackendVariable.traverseBackendDAEVarsWithUpdate(aliasVars,replaceAliasVarTraverser,(repl,{}));
Expand All @@ -2569,7 +2569,7 @@ algorithm
// remove asserts with condition=true from removed equations
remeqns1 = BackendDAEUtil.listEquation(List.select(BackendDAEUtil.equationList(remeqns1),assertWithCondTrue));
then
BackendDAE.DAE(systs1,BackendDAE.SHARED(knvars1,exobj,aliasVars,inieqns,remeqns1,constrs,clsAttrs,cache,env,funcTree,BackendDAE.EVENT_INFO(whenClauseLst1,zeroCrossingLst,sampleLst,relationsLst,numberOfRealtions),eoc,btp,symjacs));
BackendDAE.DAE(systs1,BackendDAE.SHARED(knvars1,exobj,aliasVars,inieqns,remeqns1,constrs,clsAttrs,cache,env,funcTree,BackendDAE.EVENT_INFO(whenClauseLst1,zeroCrossingLst,sampleLst,relationsLst,numberOfRealtions,numMathFunctions),eoc,btp,symjacs));
end match;
end removeSimpleEquationsShared;

Expand Down Expand Up @@ -5482,7 +5482,7 @@ algorithm
emptyEqns = BackendDAEUtil.listEquation({});
emptyVars = BackendDAEUtil.emptyVars();
eqSystem = BackendDAE.EQSYSTEM(variables,eqArray,NONE(),NONE(),BackendDAE.NO_MATCHING());
shared = BackendDAE.SHARED(knownVars,externalObjects,aliasVars,emptyEqns,removedEqs,constraints,classAttrs,cache,env,functionTree,BackendDAE.EVENT_INFO({},{},{},{},0),{},BackendDAE.SIMULATION(),{});
shared = BackendDAE.SHARED(knownVars,externalObjects,aliasVars,emptyEqns,removedEqs,constraints,classAttrs,cache,env,functionTree,BackendDAE.EVENT_INFO({},{},{},{},0,0),{},BackendDAE.SIMULATION(),{});
(m_new,mT_new) = BackendDAEUtil.incidenceMatrix(eqSystem,BackendDAE.NORMAL());
match1 = arrayCreate(l,1);
matching = BackendDAE.MATCHING(match1,match1,{});
Expand Down Expand Up @@ -8296,7 +8296,7 @@ algorithm
constrs = listArray({});
clsAttrs = listArray({});
functions = DAEUtil.avlTreeNew();
jacEventInfo = BackendDAE.EVENT_INFO({}, {}, {}, {}, 0);
jacEventInfo = BackendDAE.EVENT_INFO({}, {}, {}, {}, 0, 0);
jacExtObjClasses = {};

jacobian = BackendDAE.DAE({BackendDAE.EQSYSTEM(jacOrderedVars, jacOrderedEqs, NONE(), NONE(), BackendDAE.NO_MATCHING())}, BackendDAE.SHARED(jacKnownVars, jacExternalObjects, jacAliasVars, jacInitialEqs, jacRemovedEqs, constrs, clsAttrs, cache, env, functions, jacEventInfo, jacExtObjClasses,BackendDAE.JACOBIAN(),{}));
Expand Down Expand Up @@ -8337,7 +8337,7 @@ algorithm
constrs = listArray({});
clsAttrs = listArray({});
functions = DAEUtil.avlTreeNew();
jacEventInfo = BackendDAE.EVENT_INFO({}, {}, {}, {}, 0);
jacEventInfo = BackendDAE.EVENT_INFO({}, {}, {}, {}, 0, 0);
jacExtObjClasses = {};

jacobian = BackendDAE.DAE(BackendDAE.EQSYSTEM(jacOrderedVars, jacOrderedEqs, NONE(), NONE(), BackendDAE.NO_MATCHING())::{}, BackendDAE.SHARED(jacKnownVars, jacExternalObjects, jacAliasVars, jacInitialEqs, jacRemovedEqs, constrs, clsAttrs, cache, env, functions, jacEventInfo, jacExtObjClasses, BackendDAE.JACOBIAN(),{}));
Expand Down
71 changes: 38 additions & 33 deletions Compiler/BackEnd/BackendDAEUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ algorithm
cache,
{},
funcTree,
BackendDAE.EVENT_INFO({},{},{},{},0),
BackendDAE.EVENT_INFO({},{},{},{},0, 0),
{},
inBDAEType,
{}
Expand Down Expand Up @@ -946,16 +946,19 @@ algorithm
osysts := syst::isysts;
end addDummyState;

/* Actually obsolete code, should be removed
but is used in modpar in Main.mo
*/
public function calculateSizes "function: calculateSizes
author: PA
Calculates the number of state variables, nx,
the number of algebraic variables, ny
and the number of parameters/constants, np.
inputs: BackendDAE
outputs: (int, /* nx */
int, /* ny */
int, /* np */
int /* ng */
outputs: (int, // nx
int, // ny
int, // np
int // ng
int) next"
input BackendDAE.BackendDAE inBackendDAE;
output Integer outnx "number of states";
Expand Down Expand Up @@ -998,27 +1001,6 @@ algorithm
end match;
end calculateSizes;

public function numberOfZeroCrossings "function: numberOfZeroCrossings
author: Frenkel TUD"
input BackendDAE.BackendDAE inBackendDAE;
output Integer outng "number of zerocrossings";
output Integer outng_sample "number of zerocrossings that are samples";
output Integer outng_rel "number of relation in zerocrossings";
algorithm
(outng,outng_sample,outng_rel):=
match (inBackendDAE)
local
Integer ng,nsam, ngrel;
list<ZeroCrossing> zc, samples;
case (BackendDAE.DAE(shared=BackendDAE.SHARED(eventInfo = BackendDAE.EVENT_INFO(zeroCrossingLst = zc, sampleLst =samples, relationsNumber=ngrel))))
equation
ng = listLength(zc);
nsam = listLength(samples);
then
(ng,nsam,ngrel);
end match;
end numberOfZeroCrossings;

protected function calculateNumberZeroCrossings
input list<ZeroCrossing> zcLst;
input Integer inZc_index;
Expand Down Expand Up @@ -1151,19 +1133,19 @@ algorithm
then
((var,(nx+1,ny,ny_string, ny_int,ny_bool)));

case ((var as BackendDAE.VAR(varKind = BackendDAE.DUMMY_STATE(),varType=DAE.T_STRING(source = _)),(nx,ny,ny_string, ny_int, ny_bool))) /* A dummy state is an algebraic variable */
case ((var as BackendDAE.VAR(varKind = BackendDAE.DUMMY_STATE(),varType=DAE.T_STRING(source = _)),(nx,ny,ny_string, ny_int, ny_bool))) // A dummy state is an algebraic variable
then
((var,(nx,ny,ny_string+1, ny_int,ny_bool)));

case ((var as BackendDAE.VAR(varKind = BackendDAE.DUMMY_STATE(),varType=DAE.T_INTEGER(source = _)),(nx,ny,ny_string, ny_int, ny_bool))) /* A dummy state is an algebraic variable */
case ((var as BackendDAE.VAR(varKind = BackendDAE.DUMMY_STATE(),varType=DAE.T_INTEGER(source = _)),(nx,ny,ny_string, ny_int, ny_bool))) // A dummy state is an algebraic variable
then
((var,(nx,ny,ny_string, ny_int+1,ny_bool)));

case ((var as BackendDAE.VAR(varKind = BackendDAE.DUMMY_STATE(),varType=DAE.T_BOOL(source = _)),(nx,ny,ny_string, ny_int, ny_bool)))
then
((var,(nx,ny,ny_string, ny_int,ny_bool+1)));

case ((var as BackendDAE.VAR(varKind = BackendDAE.DUMMY_STATE()),(nx,ny,ny_string, ny_int, ny_bool))) /* A dummy state is an algebraic variable */
case ((var as BackendDAE.VAR(varKind = BackendDAE.DUMMY_STATE()),(nx,ny,ny_string, ny_int, ny_bool))) // A dummy state is an algebraic variable
then
((var,(nx,ny+1,ny_string, ny_int,ny_bool)));

Expand All @@ -1187,6 +1169,29 @@ algorithm
end matchcontinue;
end calculateVarSizes;


public function numberOfZeroCrossings "function: numberOfZeroCrossings
author: Frenkel TUD"
input BackendDAE.BackendDAE inBackendDAE;
output Integer outng "number of zerocrossings";
output Integer outng_sample "number of zerocrossings that are samples";
output Integer outng_rel "number of relation in zerocrossings";
output Integer outng_math "number of relation in zerocrossings";
algorithm
(outng,outng_sample,outng_rel,outng_math):=
match (inBackendDAE)
local
Integer ng,nsam, ngrel, ngmath;
list<ZeroCrossing> zc, samples;
case (BackendDAE.DAE(shared=BackendDAE.SHARED(eventInfo = BackendDAE.EVENT_INFO(zeroCrossingLst = zc, sampleLst =samples, relationsNumber=ngrel, numberMathEvents = ngmath))))
equation
ng = listLength(zc);
nsam = listLength(samples);
then
(ng,nsam,ngrel,ngmath);
end match;
end numberOfZeroCrossings;

protected function calculateValues "function: calculateValues
author: PA
This function calculates the values from the parameter binding expressions.
Expand Down Expand Up @@ -2782,14 +2787,14 @@ algorithm
DAE.FunctionTree funcs;
list<WhenClause> wclst,wclst1;
list<ZeroCrossing> zc, rellst, smplLst;
Integer numberOfRelations;
Integer numberOfRelations, numberOfMathEventFunctions;
ExternalObjectClasses eoc;
BackendDAE.SymbolicJacobians symjacs;
BackendDAEType btp;
case (_,BackendDAE.SHARED(knvars,exobj,aliasVars,inieqns,remeqns,constrs,clsAttrs,cache,env,funcs,BackendDAE.EVENT_INFO(wclst,zc,smplLst,rellst,numberOfRelations),eoc,btp,symjacs))
case (_,BackendDAE.SHARED(knvars,exobj,aliasVars,inieqns,remeqns,constrs,clsAttrs,cache,env,funcs,BackendDAE.EVENT_INFO(wclst,zc,smplLst,rellst,numberOfRelations,numberOfMathEventFunctions),eoc,btp,symjacs))
equation
wclst1 = listAppend(wclst,inWcLst);
then BackendDAE.SHARED(knvars,exobj,aliasVars,inieqns,remeqns,constrs,clsAttrs,cache,env,funcs,BackendDAE.EVENT_INFO(wclst1,zc,smplLst,rellst,numberOfRelations),eoc,btp,symjacs);
then BackendDAE.SHARED(knvars,exobj,aliasVars,inieqns,remeqns,constrs,clsAttrs,cache,env,funcs,BackendDAE.EVENT_INFO(wclst1,zc,smplLst,rellst,numberOfRelations,numberOfMathEventFunctions),eoc,btp,symjacs);
end match;
end whenClauseAddDAE;

Expand Down Expand Up @@ -9170,7 +9175,7 @@ algorithm
cache,
env,
functionTree,
BackendDAE.EVENT_INFO({},{},{},{},0),
BackendDAE.EVENT_INFO({},{},{},{},0,0),
{},
BackendDAE.INITIALSYSTEM(),
{}));
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/BackendDump.mo
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ algorithm
str2 = stringAppendList({str," in equations [",eq_s,"] and when conditions [",wc_s,"]"});
then
str2;
case BackendDAE.ZERO_CROSSING(relation_ = e as DAE.CALL(path = Absyn.IDENT(name = "sample")),occurEquLst = eq,occurWhenLst = wc)
case BackendDAE.ZERO_CROSSING(relation_ = e as DAE.CALL(path = Absyn.IDENT(name = _)),occurEquLst = eq,occurWhenLst = wc)
equation
eq_s_list = List.map(eq, intString);
eq_s = stringDelimitList(eq_s_list, ",");
Expand All @@ -513,7 +513,7 @@ algorithm
str = ExpressionDump.printExpStr(e);
str2 = stringAppendList({str," in equations [",eq_s,"] and when conditions [",wc_s,"]"});
then
str2;
str2;
else then "";
end match;
end dumpZcStr;
Expand Down
6 changes: 3 additions & 3 deletions Compiler/BackEnd/IndexReduction.mo
Original file line number Diff line number Diff line change
Expand Up @@ -4552,9 +4552,9 @@ algorithm
BackendDAE.SymbolicJacobians symjacs;
list<BackendDAE.WhenClause> whenClauseLst,whenClauseLst1;
list<BackendDAE.ZeroCrossing> zeroCrossingLst, relationsLst, sampleLst;
Integer numberOfRelations;
Integer numberOfRelations, numberOfMathEventFunctions;
BackendDAE.BackendDAEType btp;
case (BackendDAE.SHARED(knvars,exobj,aliasVars,inieqns,remeqns,constrs,clsAttrs,cache,env,funcTree,BackendDAE.EVENT_INFO(whenClauseLst,zeroCrossingLst,sampleLst,relationsLst,numberOfRelations),eoc,btp,symjacs),_)
case (BackendDAE.SHARED(knvars,exobj,aliasVars,inieqns,remeqns,constrs,clsAttrs,cache,env,funcTree,BackendDAE.EVENT_INFO(whenClauseLst,zeroCrossingLst,sampleLst,relationsLst,numberOfRelations,numberOfMathEventFunctions),eoc,btp,symjacs),_)
equation
// replace dummy_derivatives in knvars,aliases,ineqns,remeqns
(aliasVars,_) = BackendVariable.traverseBackendDAEVarsWithUpdate(aliasVars,replaceDummyDerivativesVar,ht);
Expand All @@ -4563,7 +4563,7 @@ algorithm
_ = BackendDAEUtil.traverseBackendDAEExpsEqnsWithUpdate(remeqns,replaceDummyDerivatives,ht);
(whenClauseLst1,_) = BackendDAETransform.traverseBackendDAEExpsWhenClauseLst(whenClauseLst,replaceDummyDerivatives,ht);
then
BackendDAE.SHARED(knvars1,exobj,aliasVars,inieqns,remeqns,constrs,clsAttrs,cache,env,funcTree,BackendDAE.EVENT_INFO(whenClauseLst1,zeroCrossingLst,sampleLst,relationsLst,numberOfRelations),eoc,btp,symjacs);
BackendDAE.SHARED(knvars1,exobj,aliasVars,inieqns,remeqns,constrs,clsAttrs,cache,env,funcTree,BackendDAE.EVENT_INFO(whenClauseLst1,zeroCrossingLst,sampleLst,relationsLst,numberOfRelations,numberOfMathEventFunctions),eoc,btp,symjacs);
end match;
end replaceDummyDerivativesShared;

Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/ResidualCmp.mo
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ algorithm
(daevars,_,allEquations,allInitEquations) = generateEquationscollectVars(elementLst,{},1,{},{});
// generate variable definitions
simvars = SimCode.SIMVARS({},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{});
varinfo = SimCode.VARINFO(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,NONE(),NONE());
varinfo = SimCode.VARINFO(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,NONE(),NONE());

modelInfo = SimCode.MODELINFO(inClassName,fileDir,varinfo,simvars,functions,{});
extObjInfo = SimCode.EXTOBJINFO({},{});
Expand Down
1 change: 1 addition & 0 deletions Compiler/BackEnd/SimCode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ uniontype VarInfo
Integer numZeroCrossings;
Integer numTimeEvents;
Integer numRelations;
Integer numMathEventFunctions;
Integer numStateVars;
Integer numAlgVars;
Integer numIntAlgVars;
Expand Down

0 comments on commit 217ea9c

Please sign in to comment.