Skip to content

Commit

Permalink
- Oops! revert r19216 and r19217
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19218 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Feb 20, 2014
1 parent 599bd32 commit e94dab9
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 74 deletions.
29 changes: 13 additions & 16 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -119,7 +119,7 @@ template simulationHeaderFile(SimCode simCode, String guid)
case simCode as SIMCODE(modelInfo=MODELINFO(__)) then
<<
/* Simulation code for <%dotPath(modelInfo.name)%> generated by the OpenModelica Compiler <%getVersionNr()%>. */
<%variableDefinitions(modelInfo, timeEvents)%>
<%variableDefinitions(modelInfo, sampleLookup)%>
<%\n%>
>>
end match
Expand Down Expand Up @@ -260,7 +260,7 @@ template simulationFile_evt(SimCode simCode, String guid)
/* Events: Sample, Zero Crossings, Relations, Discrete Changes */
<%simulationFileHeader(simCode)%>

<%functionInitSample(timeEvents, modelNamePrefix(simCode))%>
<%functionInitSample(sampleLookup, modelNamePrefix(simCode))%>

<%functionZeroCrossing(zeroCrossings, modelNamePrefix(simCode))%>

Expand Down Expand Up @@ -854,7 +854,7 @@ template functionInitializeDataStruc2(ModelInfo modelInfo, list<SimEqSystem> all
end match
end functionInitializeDataStruc2;

template variableDefinitions(ModelInfo modelInfo, list<BackendDAE.TimeEvent> timeEvents)
template variableDefinitions(ModelInfo modelInfo, BackendDAE.SampleLookup sampleLookup)
"Generates global data in simulation file."
::=
let () = System.tmpTickReset(1000)
Expand Down Expand Up @@ -930,11 +930,9 @@ template variableDefinitions(ModelInfo modelInfo, list<BackendDAE.TimeEvent> tim
;separator="\n"%>

/* sample */
<%(timeEvents |> timeEvent =>
match timeEvent
case SAMPLE_TIME_EVENT(__) then '#define $P$sample<%index%> data->simulationInfo.samples[<%intSub(index, 1)%>]'
else ''
;separator="\n")%>
<%match sampleLookup
case BackendDAE.SAMPLE_LOOKUP(__) then
(lookup |> (index, start, interval) =>'#define $P$sample<%index%> data->simulationInfo.samples[<%intSub(index, 1)%>]'; separator="\n")%>

<%functions |> fn hasindex i0 => '#define <%functionName(fn,false)%>_index <%i0%>'; separator="\n"%>
>>
Expand Down Expand Up @@ -1268,7 +1266,7 @@ template functionOutput(ModelInfo modelInfo, String modelNamePrefix)
end match
end functionOutput;

template functionInitSample(list<BackendDAE.TimeEvent> timeEvents, String modelNamePrefix)
template functionInitSample(BackendDAE.SampleLookup sampleLookup, String modelNamePrefix)
"Generates function initSample() in simulation file."
::=
let &varDecls = buffer "" /*BUFD*/
Expand All @@ -1281,12 +1279,12 @@ template functionInitSample(list<BackendDAE.TimeEvent> timeEvents, String modelN
long i=0;
<%varDecls%>
<%(timeEvents |> timeEvent =>
match timeEvent
case SAMPLE_TIME_EVENT(__) then
<%match sampleLookup
case BackendDAE.SAMPLE_LOOKUP(__) then
(lookup |> (index, start, interval) =>
let &preExp = buffer "" /*BUFD*/
let e1 = daeExp(startExp, contextOther, &preExp /*BUFC*/, &varDecls /*BUFD*/)
let e2 = daeExp(intervalExp, contextOther, &preExp /*BUFC*/, &varDecls /*BUFD*/)
let e1 = daeExp(start, contextOther, &preExp /*BUFC*/, &varDecls /*BUFD*/)
let e2 = daeExp(interval, contextOther, &preExp /*BUFC*/, &varDecls /*BUFD*/)
<<
<%preExp%>
/* $P$sample<%index%> */
Expand All @@ -1295,8 +1293,7 @@ template functionInitSample(list<BackendDAE.TimeEvent> timeEvents, String modelN
data->modelData.samplesInfo[i].interval = <%e2%>;
assertStreamPrint(threadData,data->modelData.samplesInfo[i].interval > 0.0, "sample-interval <= 0.0");
i++;
>>
else '')%>
>>)%>
}
>>
end functionInitSample;
Expand Down
18 changes: 8 additions & 10 deletions Compiler/Template/CodegenCSharp.tpl
Expand Up @@ -110,7 +110,7 @@ namespace Bodylight.Models<%modelNameSpace(modelInfo.name)%>
<%functionOutput(modelInfo, simCode)%>
<%functionInitSample(timeEvents, simCode)%>
<%functionInitSample(sampleLookup, simCode)%>
<%functionStoreDelayed(simCode)%>
Expand Down Expand Up @@ -754,7 +754,7 @@ public override void OutputFun()
end functionOutput;


template functionInitSample(list<BackendDAE.TimeEvent> timeEvents, SimCode simCode)
template functionInitSample(BackendDAE.SampleLookup sampleLookup, SimCode simCode)
"Generates function initSample() in simulation file."
::=
/* Initializes the raw time events of the simulation using the now
Expand All @@ -765,19 +765,17 @@ template functionInitSample(list<BackendDAE.TimeEvent> timeEvents, SimCode simCo
<% localRepresentationArrayDefines %>
var SA = SampleHeap.Samples;
<%(timeEvents |> timeEvent =>
match timeEvent
case SAMPLE_TIME_EVENT(__) then
<%match sampleLookup
case BackendDAE.SAMPLE_LOOKUP(__) then
(lookup |> (index, start, interval) =>
let &preExp = buffer "" /*BUFD*/
let startE = daeExp(startExp, contextOther, &preExp, simCode)
let intervalE = daeExp(intervalExp, contextOther, &preExp, simCode)
let startE = daeExp(start, contextOther, &preExp, simCode)
let intervalE = daeExp(interval, contextOther, &preExp, simCode)
<<
<%preExp%>
/* $P$sample<%index%> */
SA[i++] = new OneSample(<%intervalE%>, <%startE%>, <%intSub(index, 1)%>, false);
>>
else ''
)%>
>>)%>
}
>>
end functionInitSample;
Expand Down
73 changes: 39 additions & 34 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -891,9 +891,9 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
<%geConditions(simCode)%>
<%isConsistent(simCode)%>
<%generateStepCompleted(listAppend(allEquations,initialEquations),simCode)%>
<%generatehandleTimeEvent(timeEvents, simCode)%>
<%generatehandleTimeEvent(sampleLookup,simCode)%>
<%generateDimTimeEvent(listAppend(allEquations,initialEquations),simCode)%>
<%generateTimeEvent(timeEvents, simCode)%>
<%generateTimeEvent(sampleLookup,simCode)%>
<%isODE(simCode)%>
Expand Down Expand Up @@ -5097,7 +5097,7 @@ let store_delay_expr = functionStoreDelay(delayedExps,simCode)
end generateStepCompleted;


template generatehandleTimeEvent(list<BackendDAE.TimeEvent> timeEvents, SimCode simCode)
template generatehandleTimeEvent(BackendDAE.SampleLookup sampleLookup,SimCode simCode)
::=

match simCode
Expand All @@ -5106,15 +5106,18 @@ then
<<
void <%lastIdentOfPath(modelInfo.name)%>::handleTimeEvent(int* time_events)
{
for(int i=0; i<_dimTimeEvent; i++)
{
if(time_events[i] != _time_event_counter[i])
_time_conditions[i] = true;
else
_time_conditions[i] = false;
}
memcpy(_time_event_counter, time_events, (int)_dimTimeEvent*sizeof(int));
}
for(int i = 0;i<_dimTimeEvent;i++)
{
if(time_events[i]!=_time_event_counter[i])
_time_conditions[i] = true;
else
_time_conditions[i] = false;
}
memcpy(_time_event_counter,time_events,(int)_dimTimeEvent*sizeof(int));
}
>>

end generatehandleTimeEvent;
Expand All @@ -5134,29 +5137,31 @@ then
end generateDimTimeEvent;


template generateTimeEvent(list<BackendDAE.TimeEvent> timeEvents, SimCode simCode)
::=
template generateTimeEvent(BackendDAE.SampleLookup sampleLookup,SimCode simCode)
::=

match simCode
case SIMCODE(modelInfo = MODELINFO(__))
then
let &varDecls = buffer "" /*BUFD*/
<<
void <%lastIdentOfPath(modelInfo.name)%>::getTimeEvent(time_event_type& time_events)
{
<%(timeEvents |> timeEvent =>
match timeEvent
case SAMPLE_TIME_EVENT(__) then
let &preExp = buffer "" /*BUFD*/
let e1 = daeExp(startExp, contextOther, &preExp /*BUFC*/, &varDecls /*BUFD*/,simCode)
let e2 = daeExp(intervalExp, contextOther, &preExp /*BUFC*/, &varDecls /*BUFD*/,simCode)
<<
<%preExp%>
time_events.push_back(std::make_pair(<%e1%>, <%e2%>));
>>
else ''
;separator="\n\n")%>
}
>>
case SIMCODE(modelInfo = MODELINFO(__))
then
let &varDecls = buffer "" /*BUFD*/
<<
void <%lastIdentOfPath(modelInfo.name)%>::getTimeEvent(time_event_type& time_events)
{
<%match sampleLookup
case BackendDAE.SAMPLE_LOOKUP(__) then
(lookup |> (index, start, interval) =>
let &preExp = buffer "" /*BUFD*/
let e1 = daeExp(start, contextOther, &preExp /*BUFC*/, &varDecls /*BUFD*/,simCode)
let e2 = daeExp(interval, contextOther, &preExp /*BUFC*/, &varDecls /*BUFD*/,simCode)
<<
<%preExp%>
time_events.push_back(std::make_pair(<%e1%>, <%e2%>));
>>)%>
}
>>

end generateTimeEvent;


Expand Down
21 changes: 7 additions & 14 deletions Compiler/Template/SimCodeTV.mo
Expand Up @@ -149,7 +149,7 @@ package SimCode
list<BackendDAE.ZeroCrossing> zeroCrossings;
list<BackendDAE.ZeroCrossing> relations;
list<list<SimVar>> zeroCrossingsNeedSave;
list<BackendDAE.TimeEvent> timeEvents;
BackendDAE.SampleLookup sampleLookup;
list<SimWhenClause> whenClauses;
list<DAE.ComponentRef> discreteModelVars;
ExtObjInfo extObjInfo;
Expand Down Expand Up @@ -754,19 +754,12 @@ package BackendDAE
end ZERO_CROSSING;
end ZeroCrossing;

uniontype TimeEvent
record SIMPLE_TIME_EVENT "e.g. time > 0.5"
end SIMPLE_TIME_EVENT;

record COMPLEX_TIME_EVENT "e.g. sin(time) > 0"
end COMPLEX_TIME_EVENT;

record SAMPLE_TIME_EVENT "e.g. sample(1, 1)"
Integer index "unique sample index" ;
DAE.Exp startExp;
DAE.Exp intervalExp;
end SAMPLE_TIME_EVENT;
end TimeEvent;
uniontype SampleLookup
record SAMPLE_LOOKUP
Integer nSamples "total number of different sample calls" ;
list<tuple<Integer, DAE.Exp, DAE.Exp>> lookup "sample arguments (index, start, interval)" ;
end SAMPLE_LOOKUP;
end SampleLookup;

uniontype WhenOperator "- Reinit Statement"
record REINIT
Expand Down

0 comments on commit e94dab9

Please sign in to comment.