@@ -52,6 +52,7 @@ package SimCodeQSS
5252
5353import interface SimCodeTV;
5454import SimCodeC;
55+ import SimCodeDump;
5556
5657template translateModel(SimCode simCode)
5758 "Generates C code and Makefile for compiling and running a simulation of a
@@ -129,14 +130,14 @@ case SIMCODE(modelInfo=modelInfo as MODELINFO(varInfo=varInfo as VARINFO(__)))
129130 return abs_accuracy;
130131 }
131132
132-
133133 <%functionQssStaticBlocks(odeEquations,zeroCrossings)%>
134134
135135 <%functionQssWhen(BackendQSS.replaceCondWhens(whenClauses,helpVarInfo,zeroCrossings),helpVarInfo,zeroCrossings)%>
136136
137137 <%functionQssSample(zeroCrossings)%>
138138
139- <%functionQssUpdateDiscrete()%>
139+ <%functionQssUpdateDiscrete(allEquations,zeroCrossings)%>
140+
140141 #endif
141142
142143 <%SimCodeC.equationInfo(appendLists(appendAllequation(JacobianMatrixes),allEquations))%>
@@ -441,22 +442,53 @@ template generateZeroCrossingsEq(Integer offset,list<ZeroCrossing> zeroCrossings
441442 ;separator="\n")
442443end generateZeroCrossingsEq;
443444
444- template functionQssUpdateDiscrete()
445+ template functionQssUpdateDiscrete(list< SimEqSystem > allEquationsPlusWhen,list< ZeroCrossing > zeroCrossings )
445446 "Generates function in simulation file."
446447::=
447448 let &varDecls = buffer "" /*BUFD*/
449+ let eqs = (allEquationsPlusWhen |> eq => generateDiscUpdate(BackendQSS.replaceZC(eq,zeroCrossings), zeroCrossings, &varDecls); separator="\n")
448450 <<
449451 void functionQssUpdateDiscrete(double time)
450452 {
451453 state mem_state;
452454 <% varDecls%>
453455 mem_state = get_memory_state();
454- // Code
456+ <% eqs %>
455457 restore_memory_state(mem_state);
456458 }
457459 >>
458460end functionQssUpdateDiscrete;
459461
462+ template generateDiscUpdate(SimEqSystem eq, list<ZeroCrossing > zeroCrossings, Text &varDecls)
463+ "Generate the updates of the disc variavbles
464+ author: fbergero"
465+ ::=
466+ match eq
467+ case SES_MIXED(__) then
468+ let disc = (discEqs |> SES_SIMPLE_ASSIGN(__) =>
469+ let &preDisc = buffer "" /*BUFD*/
470+ let expPart = SimCodeC.daeExp(exp, contextSimulationDiscrete, &preDisc /* BUFC */, &varDecls /* BUFD */)
471+ <<
472+ <%preDisc%>
473+ <%SimCodeC.cref(cref)%> = <%expPart%>;
474+ >>
475+ ;separator="\n")
476+ <<
477+ <%disc%>
478+ >>
479+
480+ /*
481+ case SES_SIMPLE_ASSIGN(__) then
482+ let &preDisc = buffer "" /*BUFD*/
483+ let expPart = SimCodeC.daeExp(exp, contextSimulationDiscrete, &preDisc /* BUFC */, &varDecls /* BUFD */)
484+ <<
485+ <%preDisc%>
486+ <%SimCodeC.cref(cref)%> = <%expPart%>;
487+ >>
488+ */
489+ case _ then ''
490+ end generateDiscUpdate;
491+
460492
461493template generateIntegrators()
462494"Function to generate the integrator atomics for the DEVS structure"
0 commit comments