Skip to content

Commit

Permalink
Move providesDirectionalDerivative from susan to simcode (#738)
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel committed Feb 20, 2020
1 parent 05f528f commit 13e7251
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 24 deletions.
11 changes: 11 additions & 0 deletions OMCompiler/Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -11598,6 +11598,17 @@ algorithm
((_,oConcreteVarIndex)) := getVarIndexInfosByMapping(iVarToArrayIndexMapping, iVarName, iColumnMajor, iIndexForUndefinedReferences);
end getVarIndexByMapping;

public function providesDirectionalDerivative
input SimCode.SimCode inSimCode;
output Boolean b;
algorithm
b := match inSimCode
case SimCode.SIMCODE(modelStructure=SOME(SimCode.FMIMODELSTRUCTURE(continuousPartialDerivatives=SOME(_))))
then true;
else false;
end match;
end providesDirectionalDerivative;

protected function getVarIndexInfosByMapping "author: marcusw
Return the variable indices stored for the given variable in the mapping-table. This function is used by susan."
input HashTableCrIListArray.HashTable iVarToArrayIndexMapping;
Expand Down
19 changes: 2 additions & 17 deletions OMCompiler/Compiler/Template/CodegenFMUCommon.tpl
Expand Up @@ -58,11 +58,10 @@ template ModelExchange(SimCode simCode, list<String> sourceFiles)
match simCode
case SIMCODE(__) then
let modelIdentifier = modelNamePrefix(simCode)
let pdd = providesDirectionalDerivative(simCode)
let pdd = if providesDirectionalDerivative(simCode) then ' providesDirectionalDerivative="true"' else ''
<<
<ModelExchange
modelIdentifier="<%modelIdentifier%>"<% if not pdd then '>' %>
<% if pdd then 'providesDirectionalDerivative="' + pdd + '">' %>
modelIdentifier="<%modelIdentifier%>"<%pdd%>>
<%SourceFiles(sourceFiles)%>
</ModelExchange>
>>
Expand All @@ -78,20 +77,6 @@ template SourceFiles(list<String> sourceFiles)
>>
end SourceFiles;

template providesDirectionalDerivative(SimCode simCode)
"Returns true if Jacobian is present, returns nothing otherwise"
::=
match simCode
case SIMCODE(__) then
let result = if isSome(modelStructure) then
match modelStructure
case SOME(FMIMODELSTRUCTURE(continuousPartialDerivatives=SOME(__)))
then "true"
else ""
else ""
'<%result%>'
end providesDirectionalDerivative;

template fmiModelVariables(SimCode simCode, String FMUVersion)
"Generates code for ModelVariables file for FMU target."
::=
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/Template/CodegenFMUCpp.tpl
Expand Up @@ -621,7 +621,7 @@ case SIMCODE(modelInfo=MODELINFO(), modelStructure=fmiModelStructure) then
const unsigned int vrKnown[], size_t nKnown,
const double dvKnown[], double dvUnknown[])
{
<% if CodegenFMUCommon.providesDirectionalDerivative(simCode) then
<% if providesDirectionalDerivative(simCode) then
<<
unsigned int idx, *ref_p, ref_1;
int dimStates = _dimContinuousStates + <%dimDiscreteStates%>;
Expand Down
6 changes: 6 additions & 0 deletions OMCompiler/Compiler/Template/SimCodeTV.mo
Expand Up @@ -1114,6 +1114,11 @@ package SimCodeUtil
output String oVarIndex;
end getVarIndexByMapping;

function providesDirectionalDerivative
input SimCode.SimCode inSimCode;
output Boolean b;
end providesDirectionalDerivative;

function isVarIndexListConsecutive
input HashTableCrIListArray.HashTable iVarToArrayIndexMapping;
input DAE.ComponentRef iVarName;
Expand Down Expand Up @@ -1237,6 +1242,7 @@ package SimCodeUtil
input Integer numStates;
output Integer n;
end getNumContinuousEquations;

function lookupVR
input DAE.ComponentRef cr;
input SimCode.SimCode simCode;
Expand Down
Expand Up @@ -64,8 +64,7 @@ getErrorString();
// variableNamingConvention=\"structured\"
// numberOfEventIndicators=\"0\">
// <ModelExchange
// modelIdentifier=\"CSTRModel\"
// providesDirectionalDerivative=\"true\">
// modelIdentifier=\"CSTRModel\" providesDirectionalDerivative=\"true\">
// </ModelExchange>
// <TypeDefinitions>
// <Clocks>
Expand Down
Expand Up @@ -64,8 +64,7 @@ val(evaporator_qm_S, 100);
// variableNamingConvention=\"structured\"
// numberOfEventIndicators=\"3\">
// <ModelExchange
// modelIdentifier=\"DrumBoilerModel\"
// providesDirectionalDerivative=\"true\">
// modelIdentifier=\"DrumBoilerModel\" providesDirectionalDerivative=\"true\">
// </ModelExchange>
// <TypeDefinitions>
// <SimpleType name=\"Modelica.Blocks.Types.Init\">
Expand Down
Expand Up @@ -46,8 +46,7 @@ readFile("modelDescription.tmp.xml");
// variableNamingConvention=\"structured\"
// numberOfEventIndicators=\"0\">
// <ModelExchange
// modelIdentifier=\"testDID\"
// providesDirectionalDerivative=\"true\">
// modelIdentifier=\"testDID\" providesDirectionalDerivative=\"true\">
// <SourceFiles>
// <File name=\"testDID.c\" />
// <File name=\"testDID_functions.c\" />
Expand Down

0 comments on commit 13e7251

Please sign in to comment.