Skip to content

Commit

Permalink
- optimized fmi-export calculations
Browse files Browse the repository at this point in the history
 - added support input and output vars for fmi-import and a test-case
 - added a better flow control for fmi-import models

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11641 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Willi Braun committed Apr 2, 2012
1 parent 42954a3 commit d27a356
Show file tree
Hide file tree
Showing 6 changed files with 811 additions and 549 deletions.
10 changes: 2 additions & 8 deletions SimulationRuntime/fmi/export/fmu_model_interface.c
Expand Up @@ -308,10 +308,6 @@ fmiStatus fmiSetContinuousStates(fmiComponent c, const fmiReal x[], size_t nx){
return fmiError;
}
#endif
functionODE(comp->fmuData);
functionAlgebraics(comp->fmuData);
output_function(comp->fmuData);
function_storeDelayed(comp->fmuData);
return fmiOK;
}

Expand Down Expand Up @@ -476,6 +472,7 @@ fmiStatus fmiGetDerivatives(fmiComponent c, fmiReal derivatives[], size_t nx) {
return fmiError;
if (nullPointer(comp, "fmiGetDerivatives", "derivatives[]", derivatives))
return fmiError;
functionODE(comp->fmuData);
#if (NUMBER_OF_STATES>0)
for (i=0; i<nx; i++) {
fmiValueReference vr = vrStatesDerivatives[i];
Expand All @@ -495,8 +492,6 @@ 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
functionODE(comp->fmuData);
functionAlgebraics(comp->fmuData);
function_onlyZeroCrossings(comp->fmuData,NULL,&(comp->fmuData->localData[0]->timeValue));
for (i=0; i<ni; i++) {
/* retVal = getEventIndicator(comp, i, eventIndicators[i]); // to be implemented by the includer of this file
Expand Down Expand Up @@ -549,6 +544,7 @@ fmiStatus fmiInitialize(fmiComponent c, fmiBoolean toleranceControlled, fmiReal
}
/* due to an event overwrite old values */
overwriteOldSimulationData(comp->fmuData);
resetAllHelpVars(comp->fmuData);

return fmiOK;
}
Expand Down Expand Up @@ -633,9 +629,7 @@ fmiStatus fmiCompletedIntegratorStep(fmiComponent c, fmiBoolean* callEventUpdate
return fmiError;
if (comp->loggingOn) comp->functions.logger(c, comp->instanceName, fmiOK, "log",
"fmiCompletedIntegratorStep");
functionODE(comp->fmuData);
functionAlgebraics(comp->fmuData);
output_function(comp->fmuData);
function_storeDelayed(comp->fmuData);
return fmiOK;
}
Expand Down
87 changes: 53 additions & 34 deletions SimulationRuntime/fmi/import/fmuModelica.in
Expand Up @@ -7,11 +7,11 @@ class fmuModelInst
input fmuCallbackFuns functions;
input Boolean logFlag;
output fmuModelInst inst;
external "C" inst = fmiInstantiate(in_fmufun,in_instName,guid,functions,logFlag) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" inst = fmiInstantiate(in_fmufun,in_instName,guid,functions,logFlag) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end constructor;
function destructor
input fmuModelInst in_inst;
external "C" fmiFreeDummy(in_inst) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" fmiFreeDummy(in_inst) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end destructor;
end fmuModelInst;

Expand All @@ -21,10 +21,10 @@ class fmuModelInst
input fmuFunctions in_fmufun;
input String in_dllPath;
output fmuLoadDll dummy;
external "C" dummy = loadFMUDll(in_fmufun,in_dllPath) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" dummy = loadFMUDll(in_fmufun,in_dllPath) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end constructor;
function destructor
external "C" freeFMUDll() annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" freeFMUDll() annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end destructor;
end fmuLoadDll;

Expand All @@ -34,39 +34,43 @@ class fmuModelInst
input String mid;
input String dllPath;
output fmuFunctions fmufun;
external "C" fmufun = instantiateFMIFun(mid,dllPath) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" fmufun = instantiateFMIFun(mid,dllPath) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end constructor;
function destructor
input fmuFunctions fmufun;
external "C" fmiFreeDummy(fmufun) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" fmiFreeDummy(fmufun) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end destructor;
end fmuFunctions;

class fmuCallbackFuns "Construct for callbacks defined in FMU"
extends ExternalObject;
function constructor
output fmuCallbackFuns functions;
external "C" functions = fmiCallbackFuns() annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" functions = fmiCallbackFuns() annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end constructor;
function destructor
input fmuCallbackFuns functions;
external "C" fmiFreeDummy(functions) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" fmiFreeDummy(functions) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end destructor;
end fmuCallbackFuns;

function fmuSetTime
input fmuFunctions fmufun;
input fmuModelInst inst;
input Real in_time;
external "C" fmiSetT(fmufun,inst,in_time) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
input Real inFlowControl;
output Real outFlowControl;
external "C" outFlowControl = fmiSetT(fmufun, inst, in_time, inFlowControl) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuSetTime;

function fmuSetContStates "set values of continuous states"
input fmuFunctions fmufun;
input fmuModelInst in_inst;
input Integer nx;
input Real x[nx];
external "C" fmiSetContStates(fmufun,in_inst,x,nx) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
input Real inFlowControl;
output Real outFlowControl;
external "C" outFlowControl = fmiSetContStates(fmufun, in_inst, x, nx, inFlowControl) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuSetContStates;

function fmuSetRealVR "set values of real variables via value references"
Expand All @@ -75,7 +79,9 @@ class fmuModelInst
input Integer nr;
input Integer in_vr[nr];
input Real in_rv[nr];
external "C" fmiSetRealVR(fmufun,in_inst,in_vr,in_rv,nr) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
input Real inFlowControl;
output Real outFlowControl;
external "C" outFlowControl = fmiSetRealVR(fmufun, in_inst, in_vr, in_rv, nr, inFlowControl) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuSetRealVR;

function fmuSetIntegerVR "set values of integer variables via value references"
Expand All @@ -84,7 +90,9 @@ class fmuModelInst
input Integer ni;
input Integer in_vr[ni];
input Integer in_iv[ni];
external "C" fmiSetIntegerVR(fmufun,in_inst,in_vr,in_iv,ni) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
input Real inFlowControl;
output Real outFlowControl;
external "C" outFlowControl = fmiSetIntegerVR(fmufun, in_inst, in_vr, in_iv, ni, inFlowControl) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuSetIntegerVR;

function fmuSetStringVR "set values of string variables via value references"
Expand All @@ -93,7 +101,9 @@ class fmuModelInst
input Integer ns;
input Integer in_vr[ns];
input String in_sv[ns];
external "C" fmiSetStringVR(fmufun,in_inst,in_vr,in_sv,ns) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
input Real inFlowControl;
output Real outFlowControl;
external "C" outFlowControl = fmiSetStringVR(fmufun, in_inst, in_vr, in_sv, ns, inFlowControl) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuSetStringVR;

function fmuSetBooleanVR "set values of boolean variables via value references"
Expand All @@ -102,71 +112,78 @@ class fmuModelInst
input Integer nb;
input Integer in_vr[nb];
input Boolean in_bv[nb];
external "C" fmiSetBooleanVR(fmufun,in_inst,in_vr,in_bv,nb) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
input Real inFlowControl;
output Real outFlowControl;
external "C" outFlowControl = fmiSetBooleanVR(fmufun, in_inst, in_vr, in_bv, nb, inFlowControl) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuSetBooleanVR;

function fmuGetContStates "get values of continuous states"
input fmuFunctions fmufun;
input fmuModelInst in_inst;
input Integer nx;
output Real in_x[nx];
external "C" fmiGetContStates(fmufun,in_inst,in_x,nx) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" fmiGetContStates(fmufun,in_inst,in_x,nx) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuGetContStates;

function fmuGetRealVR "get values of real variables via value references"
input fmuFunctions fmufun;
input fmuModelInst in_inst;
input Integer nr;
input Integer in_vr[nr];
input Real inFlowControl;
output Real rv[nr];
external "C" fmiGetRealVR(fmufun,in_inst,in_vr,rv,nr) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" fmiGetRealVR(fmufun, in_inst, in_vr, rv, nr, inFlowControl) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuGetRealVR;

function fmuGetIntegerVR "get values of integer variables via value references"
input fmuFunctions fmufun;
input fmuModelInst in_inst;
input Integer ni;
input Integer in_vr[ni];
input Real inFlowControl;
output Integer iv[ni];
external "C" fmiGetIntegerVR(fmufun,in_inst,in_vr,iv,ni) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" fmiGetIntegerVR(fmufun,in_inst,in_vr,iv,ni,inFlowControl) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuGetIntegerVR;

function fmuGetStringVR "get values of string variables via value references"
input fmuFunctions fmufun;
input fmuModelInst in_inst;
input Integer ns;
input Integer in_vr[ns];
input Real inFlowControl;
output String sv[ns];
external "C" fmiGetStringVR(fmufun,in_inst,in_vr,sv,ns) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" fmiGetStringVR(fmufun, in_inst, in_vr, sv, ns, inFlowControl) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuGetStringVR;

function fmuGetBooleanVR "get values of boolean variables via value references"
input fmuFunctions fmufun;
input fmuModelInst in_inst;
input Integer nb;
input Integer in_vr[nb];
input Real inFlowControl;
output Boolean bv[nb];
external "C" fmiGetBooleanVR(fmufun,in_inst,in_vr,bv,nb) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" fmiGetBooleanVR(fmufun, in_inst, in_vr, bv, nb, inFlowControl) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuGetBooleanVR;

function fmuGetDer "function to calculate the derivatives"
input fmuFunctions fmufun;
input fmuModelInst inst;
input Integer nx;
input Real x[nx];
input Real inFlowControl;
output Real der_x_out[nx];
external "C" fmiGetDer(fmufun,inst,der_x_out,nx,x) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" fmiGetDer(fmufun, inst, der_x_out, nx, x, inFlowControl) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuGetDer;

class fmuEventInfo
extends ExternalObject;
function constructor
output fmuEventInfo evtInfo;
external "C" evtInfo = fmiEvtInfo() annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" evtInfo = fmiEvtInfo() annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end constructor;
function destructor
input fmuEventInfo evtInfo;
external "C" freefmiEvtInfo(evtInfo) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" freefmiEvtInfo(evtInfo) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end destructor;
end fmuEventInfo;

Expand All @@ -175,11 +192,11 @@ class fmuModelInst
function constructor
input Integer default;
output fmuBoolean fmuBool;
external "C" fmuBool = fmuBooleanInst(default) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" fmuBool = fmuBooleanInst(default) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end constructor;
function destructor
input fmuBoolean in_bool;
external "C" freefmuBooleanInst(in_bool) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" freefmuBooleanInst(in_bool) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end destructor;
end fmuBoolean;

Expand All @@ -189,14 +206,16 @@ class fmuModelInst
input Boolean tolControl;
input Real relTol;
input fmuEventInfo evtInfo;
external "C" fmiInit(fmufun,inst,tolControl,relTol,evtInfo) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" fmiInit(fmufun,inst,tolControl,relTol,evtInfo) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuInit;

function fmuCompIntStep
input fmuFunctions fmufun;
input fmuModelInst inst;
input fmuBoolean stepEvt;
external "C" fmiCompIntStep(fmufun,inst,stepEvt) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
input Real inFlowControl;
output Real outFlowControl;
external "C" outFlowControl = fmiCompIntStep(fmufun, inst, stepEvt, inFlowControl) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuCompIntStep;

function fmuGetTimeEvt
Expand All @@ -205,23 +224,23 @@ class fmuModelInst
input Real in_pretime;
input fmuBoolean in_timeEvt;
output Real out_nextTime;
external "C" fmiGetTimeEvent(in_evtInfo,in_time,in_pretime,in_timeEvt,out_nextTime) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" fmiGetTimeEvent(in_evtInfo,in_time,in_pretime,in_timeEvt,out_nextTime) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuGetTimeEvt;

function fmuGetEventInd
input fmuFunctions fmufun;
input fmuModelInst inst;
input Integer nz;
output Real z[nz];
external "C" fmiGetEventInd(fmufun,inst,z,nz) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" fmiGetEventInd(fmufun,inst,z,nz) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuGetEventInd;

function fmuStateEvtCheck
input fmuBoolean stateEvt;
input Integer nz;
input Real z[nz];
input Real prez[nz];
external "C" fmuStateEventCheck(stateEvt,nz,z,prez) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" fmuStateEventCheck(stateEvt,nz,z,prez) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuStateEvtCheck;

function fmuEvtUpdate
Expand All @@ -232,35 +251,35 @@ class fmuModelInst
input fmuBoolean stepEvt;
input fmuBoolean stateEvt;
input fmuBoolean interMediateRes;
external "C" fmuEventUpdate(in_fmufun,in_inst,in_evtInfo,timeEvt,stepEvt,stateEvt,interMediateRes) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" fmuEventUpdate(in_fmufun,in_inst,in_evtInfo,timeEvt,stepEvt,stateEvt,interMediateRes) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end fmuEvtUpdate;

function fmuFreeAll
input fmuFunctions in_fmufun;
input fmuModelInst in_inst;
input fmuCallbackFuns functions;
output fmuBoolean dummy;
external "C" fmuFreeAll(in_fmufun,in_inst,functions,dummy) annotation(Include = "#include <fmuWrapper.h>", Library = "fmuWrapper");
external "C" fmuFreeAll(in_fmufun,in_inst,functions,dummy) annotation(Include = "#include <fmuWrapper.h>", Library = {"fmuWrapper"});
end fmuFreeAll;

function PrintState
input fmuModelInst in_fmu;
input Real in_time;
external "C" PrintModelStates(in_fmu,in_time) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" PrintModelStates(in_fmu,in_time) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end PrintState;

function printVariable
input Real var[:];
input Integer n;
input String varName;
external "C" printVariables(var,n,varName) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" printVariables(var,n,varName) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end printVariable;

function printIntVariable
input Integer var[:];
input Integer n;
input String varName;
external "C" printIntVariables(var,n,varName) annotation(Include="#include <fmuWrapper.h>",Library = "fmuWrapper");
external "C" printIntVariables(var,n,varName) annotation(Include="#include <fmuWrapper.h>",Library = {"fmuWrapper"});
end printIntVariable;

function Bool2Int
Expand Down

0 comments on commit d27a356

Please sign in to comment.