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

Commit

Permalink
[FMI] Give default start-values for parameters
Browse files Browse the repository at this point in the history
Previously we would just give an error for parameters with bindings and
no start-value.
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Oct 4, 2017
1 parent c520576 commit 19186f7
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions Compiler/Template/CodegenFMU.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -460,21 +460,7 @@ template initValsDefault(SimVar var, String arrayName) ::=
match var
case SIMVAR(index=index, type_=type_) then
let str = 'comp->fmuData->modelData-><%arrayName%>Data[<%index%>].attribute.start'
match initialValue
case SOME(v as ICONST(__))
case SOME(v as RCONST(__))
case SOME(v as SCONST(__))
case SOME(v as BCONST(__))
case SOME(v as ENUM_LITERAL(__)) then
'<%str%> = <%initVal(v)%>;'
else
match type_
case T_INTEGER(__)
case T_REAL(__)
case T_ENUMERATION(__)
case T_BOOL(__) then '<%str%> = 0;'
case T_STRING(__) then '<%str%> = "";'
else 'UNKOWN_TYPE'
'<%str%> = <%initValDefault(var)%>;'
end initValsDefault;

template initParamsDefault(SimVar var, String arrayName) ::=
Expand All @@ -484,10 +470,29 @@ template initParamsDefault(SimVar var, String arrayName) ::=
match initialValue
case SOME(v as SCONST(__)) then
'<%str%> = mmc_mk_scon(<%initVal(v)%>);'
case SOME(v) then
'<%str%> = <%initVal(v)%>;'
else
'<%str%> = <%initValDefault(var)%>;'
end initParamsDefault;

template initValDefault(SimVar var) ::=
match var
case var as SIMVAR(__) then
match var.initialValue
case SOME(v as ICONST(__))
case SOME(v as RCONST(__))
case SOME(v as SCONST(__))
case SOME(v as BCONST(__))
case SOME(v as ENUM_LITERAL(__)) then initVal(v)
else
match var.type_
case T_INTEGER(__)
case T_REAL(__)
case T_ENUMERATION(__)
case T_BOOL(__) then '0'
case T_STRING(__) then '""'
else error(sourceInfo(), 'Unknown type for initValDefault: <%unparseType(var.type_)%>')
end initValDefault;

template initVal(Exp initialValue)
::=
match initialValue
Expand All @@ -496,7 +501,7 @@ template initVal(Exp initialValue)
case SCONST(__) then '"<%Util.escapeModelicaStringToXmlString(string)%>"'
case BCONST(__) then if bool then "1" else "0"
case ENUM_LITERAL(__) then '<%index%>'
else "*ERROR* initial value of unknown type"
else error(sourceInfo(), 'initial value of unknown type: <%printExpStr(initialValue)%>')
end initVal;

template eventUpdateFunction(SimCode simCode)
Expand Down

0 comments on commit 19186f7

Please sign in to comment.