Skip to content

Commit

Permalink
New Modelica state machine prototype
Browse files Browse the repository at this point in the history
- Added DAE.FLAT_SM and DAE.SM_COMP to capture state machine
  composition
- Most of the code for state machine instantiation is in the new
  package "InstStateMachineUtil.mo"
- Transformation from state machines to data-flow is now triggered
  within the front-end function
  DAEUtil.transformationsBeforeBackend(..)
- The state machine to data-flow transformation code is in the new
  package "StateMachineFlatten.mo"
  (stateMachineFlatten.stateMachineToDataFlow(..))
- The old back-end prototype in package "StateMachineFeatures.mo"
  is now obsolete

Remaining issues:
- Not yet implemented operators "ticksInState()" and "timeInState()"
  and MLS "17.3.6 Merging Connections to Multiple Outputs"
- Equations in states need to confirm to the same requirements as
  when-equations (component ref to be assigned to must be at the LHS)
- State machines are based on the synchronous elements features and
  in order simulate state-machines requires these to be working in OM
- As a current workaround to simulate state machines is is possible
  to uncomment code that wraps all equations in "when-equations" and
  replaces "previous(x)" by "pre(x)", however, this is only intended
  for development purposes
- The functionality provided by "StateMachineFlatten.mo" should be
  better adapted to a back-end implementation, however this will
  require to adapt the data structures used in the back-end
  (future work)
  • Loading branch information
bernhard-thiele authored and OpenModelica-Hudson committed Jul 22, 2015
1 parent e8d65ec commit c30ebad
Show file tree
Hide file tree
Showing 16 changed files with 2,774 additions and 175 deletions.
20 changes: 16 additions & 4 deletions Compiler/BackEnd/StateMachineFeatures.mo
Expand Up @@ -33,8 +33,7 @@ encapsulated package StateMachineFeatures
" file: StateMachineFeatures.mo
package: StateMachineFeatures
description: Provides support for Modelica State Machines.

RCS: $Id$"
"

public import Absyn;
public import BackendDAE;
Expand Down Expand Up @@ -171,6 +170,18 @@ constant String SMS_PRE = "smOf" "prefix for crefs of fresh State Machine Semant
constant Boolean DEBUG_SMDUMP = false "enable verbose stdout debug information during elaboration";

public function stateMachineElab
"Deactived old module, since now implemented in frontend. See function 'stateMachineElabDEACTIVATED' for old code.

Might want to reactivate (and adapt) the module at a later time, particularly when state machine support is to be
extended to support features that cannot be handled in a good way in the front-end.
"
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
algorithm
outDAE := inDAE;
end stateMachineElab;

public function stateMachineElabDEACTIVATED
"Elaborate state machines and transform them in data-flow equations."
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
Expand Down Expand Up @@ -277,7 +288,7 @@ algorithm
//BackendDump.printShared(shared);
end if;

end stateMachineElab;
end stateMachineElabDEACTIVATED;

protected function synthesizeAutomataEqs "
Author: BTH
Expand Down Expand Up @@ -313,7 +324,7 @@ Synthesize Automaton/state machine relevant data-flow equations.
output BackendDAE.EqSystem systOut;
protected
DAE.ComponentRef initRef, resetRef, stateRef, activeResetStateRef, activeStateRef, activeResetRef, activeRef;
BackendDAE.Var initVar, resetVar, activePlotIndicatorVar;
BackendDAE.Var initVar, activePlotIndicatorVar;
DAE.ComponentRef preRef, refiningRef, refiningResetRef, refiningActiveRef;
Composition refiningComp;
list<Composition> stateRefiningComps, refiningComps;
Expand Down Expand Up @@ -2440,6 +2451,7 @@ algorithm
mode1 = MODE(name1, isInitial1, edges1, eqs1, outgoing1,os1,ol1,ps1);
modes = BaseHashTable.add((cstate1, mode1), inA);

// FIXME: I should just update the mode1 and not create a mode2???
mode2 = if BaseHashTable.hasKey(cstate2, modes)
then BaseHashTable.get(cstate2, modes)
else MODE(ComponentReference.crefLastIdent(cstate1), false, HashSet.emptyHashSet(),
Expand Down
12 changes: 11 additions & 1 deletion Compiler/FrontEnd/DAE.mo
Expand Up @@ -337,6 +337,17 @@ public uniontype Element
ClassAttributes classAttrs;
end CLASS_ATTRIBUTES;

record FLAT_SM "Flat state machine section"
Ident ident;
list<Element> dAElist "The states/modes transitions and variable
merging equations within the the flat state machine";
end FLAT_SM;

record SM_COMP "A state/mode component in a state machine"
ComponentRef componentRef;
list<Element> dAElist "a component with subelements";
end SM_COMP;


end Element;

Expand Down Expand Up @@ -1031,7 +1042,6 @@ end EvaluateSingletonTypeFunction;
public constant FunctionAttributes FUNCTION_ATTRIBUTES_BUILTIN = FUNCTION_ATTRIBUTES(NO_INLINE(),true,false,false,FUNCTION_BUILTIN(NONE()),FP_NON_PARALLEL());
public constant FunctionAttributes FUNCTION_ATTRIBUTES_DEFAULT = FUNCTION_ATTRIBUTES(NO_INLINE(),true,false,false,FUNCTION_NOT_BUILTIN(),FP_NON_PARALLEL());
public constant FunctionAttributes FUNCTION_ATTRIBUTES_IMPURE = FUNCTION_ATTRIBUTES(NO_INLINE(),false,true,false,FUNCTION_NOT_BUILTIN(),FP_NON_PARALLEL());
//BTH
public constant FunctionAttributes FUNCTION_ATTRIBUTES_BUILTIN_IMPURE = FUNCTION_ATTRIBUTES(NO_INLINE(),false,true,false,FUNCTION_BUILTIN(NONE()),FP_NON_PARALLEL());

public
Expand Down
28 changes: 22 additions & 6 deletions Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -77,6 +77,7 @@ public uniontype splitElements
list<DAE.Element> co;
list<DAE.Element> o;
list<DAE.Element> ca;
list<compWithSplitElements> sm;
end SPLIT_ELEMENTS;
end splitElements;

Expand Down Expand Up @@ -2170,6 +2171,24 @@ algorithm
Print.printBuf("NORETCALL()");
then
();
case DAE.SM_COMP(componentRef = cr,dAElist = l)
equation
Print.printBuf("SM_COMP(");
ComponentReference.printComponentRef(cr);
Print.printBuf(",");
dumpDebugElist(l);
Print.printBuf(")");
then
();
case DAE.FLAT_SM(ident = n,dAElist = l)
equation
Print.printBuf("FLAT_SM(");
Print.printBuf(n);
Print.printBuf(",");
dumpDebugElist(l);
Print.printBuf(")");
then
();
case _
equation
Print.printBuf("UNKNOWN ");
Expand Down Expand Up @@ -2620,20 +2639,17 @@ algorithm
list<DAE.Element> co;
list<DAE.Element> o;
list<DAE.Element> ca;
list<compWithSplitElements> sm;
splitElements loc_splelem;

compWithSplitElements compWSplElem;


case (DAE.COMP(ident = n,dAElist = l,comment = c))
equation

(v,ie,ia,e,a,ca,co,o) = DAEUtil.splitElements(l);

loc_splelem = SPLIT_ELEMENTS(v,ie,ia,e,a,ca,co,o);

(v,ie,ia,e,a,ca,co,o,sm) = DAEUtil.splitElements(l);
loc_splelem = SPLIT_ELEMENTS(v,ie,ia,e,a,ca,co,o,sm);
compWSplElem = COMP_WITH_SPLIT(n, loc_splelem, c);

then
(compWSplElem);

Expand Down

0 comments on commit c30ebad

Please sign in to comment.