Skip to content

Commit

Permalink
extend FMI export with sub clocks
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke committed Nov 1, 2015
1 parent 693d9cf commit ceca57e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
18 changes: 10 additions & 8 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -385,7 +385,7 @@ algorithm
//BaseHashTable.dumpHashTable(varToArrayIndexMapping);
//print("END MAPPING\n\n");

crefToClockIndexHT := List.fold(inBackendDAE.eqs, collectClockedVars, HashTable.emptyHashTable());
(crefToClockIndexHT, _) := List.fold(inBackendDAE.eqs, collectClockedVars, (HashTable.emptyHashTable(), 1));

simCode := SimCode.SIMCODE(modelInfo,
{}, // Set by the traversal below...
Expand Down Expand Up @@ -620,19 +620,21 @@ algorithm
end for;
end createClockedSimPartitions;

public function collectClockedVars "author: rfranke
protected function collectClockedVars "author: rfranke
This function collects clocked variables along with their clockIndex"
input BackendDAE.EqSystem inEqSystem;
input HashTable.HashTable inHT;
output HashTable.HashTable outHT;
input tuple<HashTable.HashTable, Integer> inTpl;
output tuple<HashTable.HashTable, Integer> outTpl;
protected
HashTable.HashTable inHT, outHT;
Integer clockIndex;
algorithm
outHT := match inEqSystem
case BackendDAE.EQSYSTEM(partitionKind = BackendDAE.CLOCKED_PARTITION(subPartIdx=clockIndex)) equation
(inHT, clockIndex) := inTpl;
outTpl := match inEqSystem
case BackendDAE.EQSYSTEM(partitionKind = BackendDAE.CLOCKED_PARTITION(_)) equation
(outHT, _) = BackendVariable.traverseBackendDAEVars(inEqSystem.orderedVars, collectClockedVars1, (inHT, clockIndex));
then outHT;
else inHT;
then (outHT, clockIndex + 1);
else (inHT, clockIndex);
end match;
end collectClockedVars;

Expand Down
23 changes: 20 additions & 3 deletions Compiler/Template/CodegenFMUCommon.tpl
Expand Up @@ -311,7 +311,23 @@ template ModelStructureClocks(SimCode simCode)
::=
match simCode
case SIMCODE(modelInfo = MODELINFO(__)) then
let clocks = (clockedPartitions |> partition =>
let subClocks = (clockedPartitions |> partition hasindex baseClockIndex fromindex intAdd(listLength(getSubPartitions(clockedPartitions)), 1) =>
match partition
case CLOCKED_PARTITION(__) then
(subPartitions |> subPartition =>
match subPartition
case SUBPARTITION(subClock=SUBCLOCK(factor=RATIONAL(nom=fnom, denom=fres), shift=RATIONAL(nom=snom, denom=sres))) then
<<
<Clock><SubSampled baseClockIndex="<%baseClockIndex%>"
<%if intGt(fnom, 1) then 'subSampleFactor="'+fnom+'"'%>
<%if intGt(fres, 1) then 'subSampleResolution="'+fres+'"'%>
<%if intGt(snom, 0) then 'shiftCounter="'+snom+'"'%>
<%if intGt(sres, 1) then 'shiftResolution="'+sres+'"'%>
/></Clock>
>>
; separator="\n")
;separator="\n")
let baseClocks = (clockedPartitions |> partition =>
match partition
case CLOCKED_PARTITION(__) then
match baseClock
Expand All @@ -336,13 +352,14 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
<Clock/>
>>
;separator="\n")
match clocks
match baseClocks
case "" then
<<>>
else
<<
<Clocks>
<%clocks%>
<%subClocks%>
<%baseClocks%>
</Clocks>
>>
end ModelStructureClocks;
Expand Down

0 comments on commit ceca57e

Please sign in to comment.