Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit f9882c3

Browse files
vwaurichOpenModelica-Hudson
authored andcommitted
support boolean sub clocks for cpp
1 parent 89d9bc6 commit f9882c3

6 files changed

Lines changed: 80 additions & 7 deletions

File tree

Compiler/SimCode/SimCodeUtil.mo

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ algorithm
756756
off := off + basePartition.nSubClocks;
757757
clockedPartitions := SimCode.CLOCKED_PARTITION(basePartition.clock, simSubPartitions)::clockedPartitions;
758758
end for;
759+
clockedPartitions := listReverse(clockedPartitions); // in order to keep the correct indexes for the correct clkfire-calls
759760
end createClockedSimPartitions;
760761

761762
protected function collectClockedVars "author: rfranke
@@ -13175,5 +13176,26 @@ algorithm
1317513176
end match;
1317613177
end isModelTooBigForCSharpInOneFile;
1317713178

13179+
public function absoluteClockIdxForBaseClock
13180+
input Integer baseClockIdx; // one-based
13181+
input list<SimCode.ClockedPartition> allBaseClockPartitions;
13182+
output Integer absBaseClockIdx;
13183+
protected
13184+
Integer i = 1;
13185+
algorithm
13186+
absBaseClockIdx := 1;
13187+
while i < baseClockIdx loop
13188+
absBaseClockIdx := absBaseClockIdx + listLength(getSubPartition(listGet(allBaseClockPartitions,i)));
13189+
i := i+1;
13190+
end while;
13191+
end absoluteClockIdxForBaseClock;
13192+
13193+
public function getClockedPartitions
13194+
input SimCode.SimCode simcode;
13195+
output list<SimCode.ClockedPartition> clockedPartitions;
13196+
algorithm
13197+
clockedPartitions := simcode.clockedPartitions;
13198+
end getClockedPartitions;
13199+
1317813200
annotation(__OpenModelica_Interface="backend");
1317913201
end SimCodeUtil;

Compiler/Template/CodegenCpp.tpl

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12448,6 +12448,8 @@ end clockedPartFunctions;
1244812448

1244912449
template createEvaluateAll( list<SimEqSystem> allEquationsPlusWhen, SimCode simCode ,Text& extraFuncs,Text& extraFuncsDecl,Text extraFuncsNamespace, Context context, Text stateDerVectorName /*=__zDot*/, Boolean useFlatArrayNotation, Boolean createMeasureTime)
1245012450
::=
12451+
match simCode
12452+
case SIMCODE(modelInfo = MODELINFO(__)) then
1245112453
let className = lastIdentOfPathFromSimCode(simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)
1245212454

1245312455
let equation_all_func_calls = (List.partition(allEquationsPlusWhen, 100) |> eqs hasindex i0 =>
@@ -12458,8 +12460,7 @@ template createEvaluateAll( list<SimEqSystem> allEquationsPlusWhen, SimCode simC
1245812460
bool <%className%>::evaluateAll(const UPDATETYPE command)
1245912461
{
1246012462
<%if createMeasureTime then generateMeasureTimeStartCode("measuredFunctionStartValues", "evaluateAll", "MEASURETIME_MODELFUNCTIONS") else ""%>
12461-
12462-
<%createTimeConditionTreatments(timeEventLength(simCode))%>
12463+
<%createTimeConditionTreatments(timeEventLength(simCode), clockedPartitions)%>
1246312464

1246412465
// Evaluate Equations
1246512466
<%equation_all_func_calls%>
@@ -12471,20 +12472,58 @@ template createEvaluateAll( list<SimEqSystem> allEquationsPlusWhen, SimCode simC
1247112472
>>
1247212473
end createEvaluateAll;
1247312474

12474-
template createTimeConditionTreatments(String numberOfTimeEvents)
12475+
template createTimeConditionTreatments(String numberOfTimeEvents, list<ClockedPartition> clockPartitions)
1247512476
::=
12477+
let booleanSubClocks = (clockPartitions |> baseClock hasindex i0 =>
12478+
booleanSubClockActivation1(absoluteClockIdxForBaseClock(intAdd(i0,1),clockPartitions), baseClock, numberOfTimeEvents)
12479+
;separator="\n")
1247612480
<<
1247712481
// treatment of clocks in model as time events
1247812482
for (int i = <%numberOfTimeEvents%>; i < _dimTimeEvent; i++) {
1247912483
if (_time_conditions[i]) {
1248012484
evaluateClocked(i - <%numberOfTimeEvents%> + 1);
12485+
<%booleanSubClocks%>
1248112486
_time_conditions[i] = false; // reset clock after one evaluation
1248212487
_clockSubactive[i - <%numberOfTimeEvents%>] = false;
1248312488
}
1248412489
}
1248512490
>>
1248612491
end createTimeConditionTreatments;
1248712492

12493+
template booleanSubClockActivation1(Integer absBaseClockIdx, ClockedPartition baseClock, String numberOfTimeEvents)
12494+
::=
12495+
match baseClock
12496+
case CLOCKED_PARTITION(baseClock = BOOLEAN_CLOCK(__)) then
12497+
let subClocks = (subPartitions |> subClock hasindex i0 =>
12498+
booleanSubClockActivation2(absBaseClockIdx, i0, subClock, numberOfTimeEvents)
12499+
;separator="\n")
12500+
<<
12501+
//the subclocks <%absBaseClockIdx%>
12502+
<%subClocks%>
12503+
>>
12504+
else
12505+
<<
12506+
//no subclock <%absBaseClockIdx%>
12507+
>>
12508+
end match
12509+
end booleanSubClockActivation1;
12510+
12511+
template booleanSubClockActivation2(Integer absClockIdx, Integer subClockIdx, SubPartition subPartition, String numberOfTimeEvents)
12512+
::=
12513+
if intNe(subClockIdx,0) then
12514+
let absSubClockIdx = intAdd(absClockIdx,subClockIdx)
12515+
<<
12516+
//activate boolean triggered subclock <%absSubClockIdx%> of the base sub-clock <%absClockIdx%> is triggered
12517+
if (_time_conditions[<%absClockIdx%> -1+<%numberOfTimeEvents%>] && (_simTime >= _clockShift[<%absSubClockIdx%> -1]*_clockInterval[<%absClockIdx%> -1])) {
12518+
_time_conditions[<%absSubClockIdx%> -1+<%numberOfTimeEvents%>] = (_simTime >= _clockShift[<%absSubClockIdx%> -1]*_clockInterval[<%absClockIdx%> -1]);
12519+
}
12520+
>>
12521+
else
12522+
<<
12523+
12524+
>>
12525+
end booleanSubClockActivation2;
12526+
1248812527
template createEvaluateConditions( list<SimEqSystem> allEquationsPlusWhen, SimCode simCode ,Text& extraFuncs,Text& extraFuncsDecl,Text extraFuncsNamespace, Context context, Text stateDerVectorName /*=__zDot*/, Boolean useFlatArrayNotation)
1248912528
::=
1249012529
let className = lastIdentOfPathFromSimCode(simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace)

Compiler/Template/CodegenCppCommon.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@ template daeExpCall(Exp call, Context context, Text &preExp /*BUFP*/, Text &varD
17101710
'<%contextSystem(context)%>_clockInterval[clockIndex - 1]'
17111711

17121712
case CALL(path=IDENT(name="$_clkfire"), expLst={arg as ICONST(__)}) then
1713-
'_time_conditions[<%arg.integer%> - 1 + <%timeEventLength(simCode)%>] = (_simTime > _clockTime[<%arg.integer%> - 1])'
1713+
'_time_conditions[<%absoluteClockIdxForBaseClock(arg.integer, getClockedPartitions(simCode))%> - 1 + <%timeEventLength(simCode)%>] = (_simTime > _clockTime[<%arg.integer%> - 1])'
17141714

17151715
case CALL(path=IDENT(name="$getPart"), expLst={e1}) then
17161716
daeExp(e1, context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)

Compiler/Template/CodegenCppHpcom.tpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,8 @@ template generateParallelEvaluate(list<SimEqSystem> allEquationsPlusWhen, Absyn.
773773
SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace, Option<tuple<Schedule, Schedule, Schedule>> schedulesOpt, Context context, Text stateDerVectorName /*=__zDot*/,
774774
String modelNamePrefixStr, Boolean useFlatArrayNotation)
775775
::=
776+
match simCode
777+
case SIMCODE(modelInfo = MODELINFO(__)) then
776778
let &varDecls = buffer "" /*BUFD*/
777779
let measureTimeEvaluateOdeStart = if boolNot(stringEq(getConfigString(PROFILING_LEVEL),"none")) then generateMeasureTimeStartCode("measuredFunctionStartValues", "evaluateODE", "MEASURETIME_MODELFUNCTIONS") else ""
778780
let measureTimeEvaluateOdeEnd = if boolNot(stringEq(getConfigString(PROFILING_LEVEL),"none")) then generateMeasureTimeEndCode("measuredFunctionStartValues", "measuredFunctionEndValues", "(*measureTimeFunctionsArray)[0]", "evaluateODE", "MEASURETIME_MODELFUNCTIONS") else ""
@@ -801,7 +803,7 @@ template generateParallelEvaluate(list<SimEqSystem> allEquationsPlusWhen, Absyn.
801803
{
802804
<%measureTimeEvaluateAllStart%>
803805

804-
<%createTimeConditionTreatments(timeEventLength(simCode))%>
806+
<%createTimeConditionTreatments(timeEventLength(simCode), clockedPartitions)%>
805807

806808
<%varDecls%>
807809

Compiler/Template/SimCodeTV.mo

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,17 @@ end SimCodeFunction;
811811

812812
package SimCodeUtil
813813

814+
function absoluteClockIdxForBaseClock
815+
input Integer baseClockIdx;
816+
input list<SimCode.ClockedPartition> allBaseClockPartitions;
817+
output Integer absBaseClockIdx;
818+
end absoluteClockIdxForBaseClock;
819+
820+
function getClockedPartitions
821+
input SimCode.SimCode simcode;
822+
output list<SimCode.ClockedPartition> clockedPartitions;
823+
end getClockedPartitions;
824+
814825
function functionInfo
815826
input SimCodeFunction.Function fn;
816827
output builtin.SourceInfo info;

SimulationRuntime/cpp/Include/Core/System/ITime.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ class ITime
1111
virtual ~ITime() {};
1212
virtual int getDimTimeEvent() const = 0;
1313
virtual std::pair<double, double>* getTimeEventData() const = 0;
14-
// gibt die Time events (Startzeit und Frequenz) zurück
15-
virtual void initTimeEventData() = 0;
14+
virtual void initTimeEventData() = 0;// sets the start time and interval length in the timeEventData
1615
virtual void computeTimeEventConditions(double currTime) = 0;
1716
virtual double computeNextTimeEvents(double currTime) = 0;
1817
virtual void resetTimeConditions() = 0;

0 commit comments

Comments
 (0)