Skip to content

Commit

Permalink
Added code for eventupdate function.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8241 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Azam Zia committed Mar 16, 2011
1 parent 954dff9 commit e70ec3f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 19 deletions.
24 changes: 8 additions & 16 deletions Compiler/susan_codegen/SimCode/SimCodeFMU.tpl
Expand Up @@ -351,7 +351,7 @@ case SIMCODE(__) then
#include "<%fileNamePrefix%>_functions.h"

void setStartValues(ModelInstance *comp);
fmiReal getEventIndicator(ModelInstance* comp, int i);
fmiReal getEventIndicator(ModelInstance* comp, fmiReal eventIndicators[]);
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 @@ -563,12 +563,8 @@ case SIMCODE(__) then
let zeroCrossingsCode = zeroCrossingsTpl2_fmu(zeroCrossings, &varDecls /*BUFD*/)
<<
// Used to get event indicators
fmiReal getEventIndicator(ModelInstance* comp, int i) {
switch(i)
{
default:
return 0.0;
}
fmiReal getEventIndicator(ModelInstance* comp, fmiReal eventIndicators[]) {
<%zeroCrossingsCode%>
}

>>
Expand All @@ -595,9 +591,7 @@ template zeroCrossingTpl2_fmu(Integer index1, Exp relation, Text &varDecls /*BUF
let e2 = daeExp(exp2, contextOther, &preExp /*BUFC*/, &varDecls /*BUFD*/)
<<
<%preExp%>
//globalData->states[<%e1%>_] <%op%> <%e2%>;
case <%e1%>_:
return <%e2%>;
FMIZEROCROSSING(<%index1%>, <%op%>(<%e1%>_, <%e2%>));
>>
case CALL(path=IDENT(name="sample"), expLst={start, interval}) then
<< >>
Expand All @@ -611,12 +605,10 @@ template zeroCrossingOpFunc_fmu(Operator op)
"Generates zero crossing function name for operator."
::=
match op
case LESS(__) then "<"
case GREATER(__) then ">"
case LESSEQ(__) then "<="
case GREATEREQ(__) then ">="
case EQUAL(__) then "="
case NEQUAL(__) then "!="
case LESS(__) then "FmiLess"
case GREATER(__) then "FmiGreater"
case LESSEQ(__) then "FmiLessEq"
case GREATEREQ(__) then "FmiGreaterEq"

end zeroCrossingOpFunc_fmu;

Expand Down
38 changes: 35 additions & 3 deletions c_runtime/fmu_model_interface.c
Expand Up @@ -539,10 +539,15 @@ fmiStatus fmiGetEventIndicators(fmiComponent c, fmiReal eventIndicators[], size_
if (invalidNumber(comp, "fmiGetEventIndicators", "ni", ni, NUMBER_OF_EVENT_INDICATORS))
return fmiError;
#if NUMBER_OF_EVENT_INDICATORS>0
for (i=0; i<ni; i++) {
eventIndicators[i] = getEventIndicator(comp, i); // to be implemented by the includer of this file
if (comp->loggingOn) comp->functions.logger(c, comp->instanceName, fmiOK, "log",
// for (i=0; i<ni; i++) {
//eventIndicators[i] = getEventIndicator(comp, i); // to be implemented by the includer of this file
getEventIndicator(comp, eventIndicators); // to be implemented by the includer of this file
if (comp->loggingOn)
{
for (i=0; i<ni; i++) {
comp->functions.logger(c, comp->instanceName, fmiOK, "log",
"fmiGetEventIndicators: z%d = %.16g", i, eventIndicators[i]);
}
}
#endif
return fmiOK;
Expand Down Expand Up @@ -707,4 +712,31 @@ fmiStatus fmiSetExternalFunction(fmiComponent c, fmiValueReference vr[], size_t

}


// relation functions used in zero crossing detection
fmiReal
FmiLess(fmiReal a, fmiReal b)
{
return a - b;
}

fmiReal
FmiLessEq(fmiReal a, fmiReal b)
{
return a - b;
}

fmiReal
FmiGreater(fmiReal a, fmiReal b)
{
return b - a;
}

fmiReal
FmiGreaterEq(fmiReal a, fmiReal b)
{
return b - a;
}


#endif
12 changes: 12 additions & 0 deletions c_runtime/fmu_model_interface.h
Expand Up @@ -47,5 +47,17 @@ fmiStatus setString(fmiComponent comp, fmiValueReference vr, fmiString value){
return fmiSetString(comp, &vr, 1, &value);
}

// relation functions used in zero crossing detection
fmiReal
FmiLess(fmiReal a, fmiReal b);
fmiReal
FmiLessEq(fmiReal a, fmiReal b);
fmiReal
FmiGreater(fmiReal a, fmiReal b);
fmiReal
FmiGreaterEq(fmiReal a, fmiReal b);
#define FMIZEROCROSSING(ind,exp) { \
eventIndicators[ind] = exp; \
}

#endif

0 comments on commit e70ec3f

Please sign in to comment.