Skip to content

Commit

Permalink
- use cref because #define A.B is not allowed because of "." error C2…
Browse files Browse the repository at this point in the history
…008 (Visual Studio)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8101 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Mar 4, 2011
1 parent 88befc8 commit dad6a1d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 41 deletions.
51 changes: 11 additions & 40 deletions Compiler/susan_codegen/SimCode/SimCodeFMU.tpl
Expand Up @@ -338,7 +338,7 @@ case SIMCODE(__) then
#include "fmu_model_interface.h"

void setStartValues(ModelInstance *comp);
void getEventIndicator(ModelInstance* comp, int i);
fmiReal getEventIndicator(ModelInstance* comp, int i);
void eventUpdate(ModelInstance* comp, fmiEventInfo* eventInfo);
fmiReal getReal(ModelInstance* comp, const fmiValueReference vr);
fmiStatus setReal(ModelInstance* comp, const fmiValueReference vr, const fmiReal value);
Expand Down Expand Up @@ -391,7 +391,7 @@ let numberOfBooleans = intAdd(varInfo.numBoolAlgVars,varInfo.numBoolParams)
// define variable data for model
<%System.tmpTickReset(0)%>
<%vars.stateVars |> var => DefineVariables(var) ;separator="\n"%>
<%vars.derivativeVars |> var => DefineDerivativeVariables(var) ;separator="\n"%>
<%vars.derivativeVars |> var => DefineVariables(var) ;separator="\n"%>
<%vars.algVars |> var => DefineVariables(var) ;separator="\n"%>
<%vars.paramVars |> var => DefineVariables(var) ;separator="\n"%>
<%System.tmpTickReset(0)%>
Expand All @@ -405,22 +405,12 @@ let numberOfBooleans = intAdd(varInfo.numBoolAlgVars,varInfo.numBoolParams)
<%vars.stringParamVars |> var => DefineVariables(var) ;separator="\n"%>

// define initial state vector as vector of value references
#define STATES { <%vars.stateVars |> SIMVAR(__) => '<%crefStr(name)%>_' ;separator=", "%> }
#define STATESDERIVATIVES { <%vars.derivativeVars |> SIMVAR(__) => '<%dervativeNameCStyle(name)%>' ;separator=", "%> }
#define STATES { <%vars.stateVars |> SIMVAR(__) => '<%cref(name)%>_' ;separator=", "%> }
#define STATESDERIVATIVES { <%vars.derivativeVars |> SIMVAR(__) => '<%cref(name)%>_' ;separator=", "%> }

>>
end ModelDefineData;

template DefineDerivativeVariables(SimVar simVar)
"Generates code for defining variables in c file for FMU target. "
::=
match simVar
case SIMVAR(__) then
<<
#define <%dervativeNameCStyle(name)%> <%System.tmpTick()%>
>>
end DefineDerivativeVariables;

template dervativeNameCStyle(ComponentRef cr)
"Generates the name of a derivative in c style, replaces ( with _"
::=
Expand All @@ -435,7 +425,7 @@ match simVar
case SIMVAR(__) then
let description = if comment then '// "<%comment%>"'
<<
#define <%crefStr(name)%>_ <%System.tmpTick()%> <%description%>
#define <%cref(name)%>_ <%System.tmpTick()%> <%description%>
>>
end DefineVariables;

Expand Down Expand Up @@ -555,7 +545,8 @@ match simCode
case SIMCODE(__) then
<<
// Used to get event indicators
void getEventIndicator(ModelInstance* comp, int i) {
fmiReal getEventIndicator(ModelInstance* comp, int i) {
return 0.0;
}

>>
Expand All @@ -570,7 +561,7 @@ case MODELINFO(vars=SIMVARS(__)) then
fmiReal getReal(ModelInstance* comp, const fmiValueReference vr) {
switch (vr) {
<%vars.stateVars |> var => SwitchVars(var,"states") ;separator="\n"%>
<%vars.derivativeVars |> var => SwitchDerivativeVariables(var) ;separator="\n"%>
<%vars.derivativeVars |> var => SwitchVars(var,"statesDerivatives") ;separator="\n"%>
<%vars.algVars |> var => SwitchVars(var,"algebraics") ;separator="\n"%>
<%vars.paramVars |> var => SwitchVars(var,"parameters") ;separator="\n"%>
default:
Expand All @@ -590,7 +581,7 @@ case MODELINFO(vars=SIMVARS(__)) then
fmiStatus setReal(ModelInstance* comp, const fmiValueReference vr, const fmiReal value) {
switch (vr) {
<%vars.stateVars |> var => SwitchVarsSet(var,"states") ;separator="\n"%>
<%vars.derivativeVars |> var => SwitchDerivativeVariablesSet(var) ;separator="\n"%>
<%vars.derivativeVars |> var => SwitchVarsSet(var,"statesDerivatives") ;separator="\n"%>
<%vars.algVars |> var => SwitchVarsSet(var,"algebraics") ;separator="\n"%>
<%vars.paramVars |> var => SwitchVarsSet(var,"parameters") ;separator="\n"%>
default:
Expand Down Expand Up @@ -720,7 +711,7 @@ match simVar
case SIMVAR(__) then
let description = if comment then '// "<%comment%>"'
<<
case <%crefStr(name)%>_ : return globalData-><%arrayName%>[<%index%>]; break;
case <%cref(name)%>_ : return globalData-><%arrayName%>[<%index%>]; break;
>>
end SwitchVars;

Expand All @@ -731,30 +722,10 @@ match simVar
case SIMVAR(__) then
let description = if comment then '// "<%comment%>"'
<<
case <%crefStr(name)%>_ : globalData-><%arrayName%>[<%index%>]=value; break;
case <%cref(name)%>_ : globalData-><%arrayName%>[<%index%>]=value; break;
>>
end SwitchVarsSet;

template SwitchDerivativeVariables(SimVar simVar)
"Generates code for defining variables in c file for FMU target. "
::=
match simVar
case SIMVAR(__) then
<<
case <%dervativeNameCStyle(name)%> : return globalData->statesDerivatives[<%index%>]; break;
>>
end SwitchDerivativeVariables;

template SwitchDerivativeVariablesSet(SimVar simVar)
"Generates code for defining variables in c file for FMU target. "
::=
match simVar
case SIMVAR(__) then
<<
case <%dervativeNameCStyle(name)%> : globalData->statesDerivatives[<%index%>]=value; break;
>>
end SwitchDerivativeVariablesSet;

template fmuMakefile(SimCode simCode)
"Generates the contents of the makefile for the simulation case."
::=
Expand Down
2 changes: 2 additions & 0 deletions c_runtime/fmiModelFunctions.h
Expand Up @@ -124,6 +124,7 @@
#define fmiGetNominalContinuousStates fmiFullName(_fmiGetNominalContinuousStates)
#define fmiGetStateValueReferences fmiFullName(_fmiGetStateValueReferences)
#define fmiTerminate fmiFullName(_fmiTerminate)
#define fmiSetExternalFunction fmiFullName(_fmiSetExternalFunction)


/* Version number */
Expand Down Expand Up @@ -208,5 +209,6 @@ extern "C" {
DllExport fmiStatus fmiGetNominalContinuousStates(fmiComponent c, fmiReal x_nominal[], size_t nx);
DllExport fmiStatus fmiGetStateValueReferences (fmiComponent c, fmiValueReference vrx[], size_t nx);
DllExport fmiStatus fmiTerminate (fmiComponent c);
DllExport fmiStatus fmiSetExternalFunction (fmiComponent c, fmiValueReference vr[], size_t nvr, const void* value[]);
}
#endif // fmiModelFunctions_h
15 changes: 14 additions & 1 deletion c_runtime/fmu_model_interface.c
Expand Up @@ -122,7 +122,6 @@ fmiComponent fmiInstantiateModel(fmiString instanceName, fmiString GUID,
sim_noemit = 0;
jac_flag = 0;
num_jac_flag = 0;
measure_time_flag = 0;

setStartValues(comp); // to be implemented by the includer of this file

Expand Down Expand Up @@ -583,6 +582,20 @@ fmiStatus fmiTerminate(fmiComponent c){
return fmiOK;
}

// ---------------------------------------------------------------------------
// FMI functions: set external functions
// ---------------------------------------------------------------------------

fmiStatus fmiSetExternalFunction(fmiComponent c, fmiValueReference vr[], size_t nvr, const void* value[])
{
ModelInstance* comp = (ModelInstance *)c;
if (invalidState(comp, "fmiTerminate", modelInitialized))
return fmiError;
if (comp->loggingOn) comp->functions.logger(c, comp->instanceName, fmiOK, "log",
"fmiSetExternalFunction");
return fmiOK;
};

}

#endif

0 comments on commit dad6a1d

Please sign in to comment.