Skip to content

Commit

Permalink
- Use Real value for fmiValueReference instead of Integer.
Browse files Browse the repository at this point in the history
- some other minor fixes.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13637 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Oct 26, 2012
1 parent 917a55a commit 8a78a62
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 63 deletions.
5 changes: 2 additions & 3 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,7 @@ end reopenStandardStream;

function importFMUOld "Imports the Functional Mockup Unit
Example command:
importFMU(\"A.fmu\");"
importFMUOld(\"A.fmu\");"
input String filename "the fmu file name";
input String workdir := "<default>" "The output directory for imported FMU files. <default> will put the files to current working directory.";
output Boolean success "Returns true on success";
Expand All @@ -1906,15 +1906,14 @@ function importFMU "Imports the Functional Mockup Unit
importFMU(\"A.fmu\");"
input String filename "the fmu file name";
input String workdir := "<default>" "The output directory for imported FMU files. <default> will put the files to current working directory.";
input Integer loglevel := 2 "loglevel_nothing=0;loglevel_fatal=1;loglevel_error=2;loglevel_warning=3;loglevel_info=4;loglevel_verbose=5;loglevel_debug=6";
input Integer loglevel := 3 "loglevel_nothing=0;loglevel_fatal=1;loglevel_error=2;loglevel_warning=3;loglevel_info=4;loglevel_verbose=5;loglevel_debug=6";
input Boolean fullPath := false "When true the full output path is returned otherwise only the file name.";
output String generatedFileName "Returns the full path of the generated file.";
external "builtin";
annotation(preferredView="text");
end importFMU;
/* Under Development */


function simulate "simulates a modelica model by generating c code, build it and run the simulation executable.
The only required argument is the className, while all others have some efault values.
simulate(className, [startTime], [stopTime], [numberOfIntervals], [stepSize], [tolerance], [method], [fileNamePrefix],
Expand Down
52 changes: 20 additions & 32 deletions Compiler/Template/CodegenFMU.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -1121,34 +1121,26 @@ case FMIIMPORT(fmiInfo=INFO(__),fmiExperimentAnnotation=EXPERIMENTANNOTATION(__)
let stringVariables = countStringVariables(fmiModelVariablesList)
let stringStartVariables = countStringStartVariables(fmiModelVariablesList)
<<
model <%fmiInfo.fmiModelIdentifier%>_<%getFMIType(fmiInfo)%>_FMU<%if stringEq(fmiInfo.fmiDescription, "") then "" else " \"fmiInfo.fmiDescription\""%>
model <%fmiInfo.fmiModelIdentifier%>_<%getFMIType(fmiInfo)%>_FMU<%if stringEq(fmiInfo.fmiDescription, "") then "" else " \""+fmiInfo.fmiDescription+"\""%>
public
constant String fmuFile = "<%fmuFileName%>";
constant String fmuWorkingDir = "<%fmuWorkingDirectory%>";
constant Integer fmiLogLevel = <%fmiLogLevel%>;
<%dumpFMIModelVariablesList(fmiModelVariablesList)%>
<%if intGt(listLength(fmiInfo.fmiNumberOfContinuousStates), 0) then
<<
constant Integer numberOfContinuousStates = <%listLength(fmiInfo.fmiNumberOfContinuousStates)%>;
Real fmi_x[numberOfContinuousStates] "States";
Real fmi_x_new[numberOfContinuousStates] "New States";
>>
%>
<%if intGt(listLength(fmiInfo.fmiNumberOfEventIndicators), 0) then
<<
constant Integer numberOfEventIndicators = <%listLength(fmiInfo.fmiNumberOfEventIndicators)%>;
Real fmi_z[numberOfEventIndicators] "Events Indicators";
Boolean fmi_z_positive[numberOfEventIndicators];
>>
%>
Real flowControlEvent;
constant Boolean debugLogging = false;
Integer fmi_status;
fmiImportInstance fmi = fmiImportInstance(context, fmuWorkingDir);
fmiImportContext context = fmiImportContext(fmiLogLevel);
fmiEventInfo eventInfo;
Boolean callEventUpdate = false;
Real flowControlTime;
Real flowControlEvent;
Real flowControlStatesInputs;
Boolean initializationDone(start=false);
protected
Expand Down Expand Up @@ -1264,36 +1256,32 @@ case FMIIMPORT(fmiInfo=INFO(__),fmiExperimentAnnotation=EXPERIMENTANNOTATION(__)
eventInfo := fmiFunctions.fmiInitialize(fmi);
initializationDone := true;
end if;
<%if intGt(listLength(fmiInfo.fmiNumberOfContinuousStates), 0) then "fmi_x := fmiFunctions.fmiGetContinuousStates(fmi, numberOfContinuousStates, 1);"%>
fmi_x := fmiFunctions.fmiGetContinuousStates(fmi, numberOfContinuousStates, 1);
algorithm
initializationDone := true;
equation
<%if intGt(listLength(fmiInfo.fmiNumberOfContinuousStates), 0) then "der(fmi_x) = fmiFunctions.fmiGetDerivatives(fmi, numberOfContinuousStates, flowControlStatesInputs);"%>
der(fmi_x) = fmiFunctions.fmiGetDerivatives(fmi, numberOfContinuousStates, flowControlStatesInputs);
flowControlTime = fmiFunctions.fmiSetTime(fmi, time, 1);
<%if intGt(listLength(fmiInfo.fmiNumberOfContinuousStates), 0) then "flowControlStatesInputs = fmiFunctions.fmiSetContinuousStates(fmi, fmi_x, flowControlTime);"%>
<%if intGt(listLength(fmiInfo.fmiNumberOfEventIndicators), 0) then
<<
flowControlStatesInputs = fmiFunctions.fmiSetContinuousStates(fmi, fmi_x, flowControlTime);
fmi_z = fmiFunctions.fmiGetEventIndicators(fmi, numberOfEventIndicators, flowControlEvent);
for i in 1:size(fmi_z,1) loop
fmi_z_positive[i] = if not terminal() then fmi_z[i] > 0 else pre(fmi_z_positive[i]);
end for;
>>
%>
algorithm
<%if intGt(listLength(fmiInfo.fmiNumberOfEventIndicators), 0) then
<<
when (<%fmiInfo.fmiNumberOfEventIndicators |> eventIndicator => "change(fmi_z_positive["+eventIndicator+"])" ;separator=" or "%>) and not initial() then
>>
else
<<
when not initial() then
>>
%>
//eventInfo := fmiFunctions.fmiEventUpdate(fmi, callEventUpdate, eventInfo);
fmiFunctions.fmiEventUpdate(fmi, callEventUpdate, eventInfo);
fmi_x_new := fmiFunctions.fmiGetContinuousStates(fmi, numberOfContinuousStates, flowControlEvent);
<%fmiInfo.fmiNumberOfContinuousStates |> continuousStates => "reinit(fmi_x["+continuousStates+"], fmi_x_new["+continuousStates+"]);" ;separator="\n"%>
end when;
>>
else if intGt(listLength(fmiInfo.fmiNumberOfContinuousStates), 0) then
<<
fmi_x_new := fmiFunctions.fmiGetContinuousStates(fmi, numberOfContinuousStates, flowControlEvent);
>>
%>
when terminal() then
fmi_status := fmiFunctions.fmiTerminate(fmi);
end when;
Expand Down Expand Up @@ -1322,7 +1310,7 @@ case FMIIMPORT(fmiInfo=INFO(__),fmiExperimentAnnotation=EXPERIMENTANNOTATION(__)
let stringVariables = countStringVariables(fmiModelVariablesList)
let stringStartVariables = countStringStartVariables(fmiModelVariablesList)
<<
model <%fmiInfo.fmiModelIdentifier%>_<%getFMIType(fmiInfo)%>_FMU<%if stringEq(fmiInfo.fmiDescription, "") then "" else " \"fmiInfo.fmiDescription\""%>
model <%fmiInfo.fmiModelIdentifier%>_<%getFMIType(fmiInfo)%>_FMU<%if stringEq(fmiInfo.fmiDescription, "") then "" else " \""+fmiInfo.fmiDescription+"\""%>
public
constant String fmuFile = "<%fmuFileName%>";
constant String fmuWorkingDir = "<%fmuWorkingDirectory%>";
Expand Down Expand Up @@ -1460,63 +1448,63 @@ template dumpFMICommonFunctions(String platform)

function fmiGetReal
input fmiImportInstance fmi;
input Integer realValuesReferences[:];
input Real realValuesReferences[:];
input Real in_Flow;
output Real realValues[size(realValuesReferences, 1)];
external "C" fmiGetReal_OMC(fmi, size(realValuesReferences, 1), realValuesReferences, realValues, in_Flow) annotation(Library = {"omcruntime", "fmilib"<%if stringEq(platform, "win32") then ", \"shlwapi\""%>});
end fmiGetReal;

function fmiSetReal
input fmiImportInstance fmi;
input Integer realValuesReferences[:];
input Real realValuesReferences[:];
input Real realValues[size(realValuesReferences, 1)];
output Integer status;
external "C" status = fmiSetReal_OMC(fmi, size(realValuesReferences, 1), realValuesReferences, realValues) annotation(Library = {"omcruntime", "fmilib"<%if stringEq(platform, "win32") then ", \"shlwapi\""%>});
end fmiSetReal;

function fmiGetInteger
input fmiImportInstance fmi;
input Integer integerValuesReferences[:];
input Real integerValuesReferences[:];
input Real in_Flow;
output Integer integerValues[size(integerValuesReferences, 1)];
external "C" fmiGetInteger_OMC(fmi, size(integerValuesReferences, 1), integerValuesReferences, integerValues, in_Flow) annotation(Library = {"omcruntime", "fmilib"<%if stringEq(platform, "win32") then ", \"shlwapi\""%>});
end fmiGetInteger;

function fmiSetInteger
input fmiImportInstance fmi;
input Integer integerValuesReferences[:];
input Real integerValuesReferences[:];
input Integer integerValues[size(integerValuesReferences, 1)];
output Integer status;
external "C" status = fmiSetInteger_OMC(fmi, size(integerValuesReferences, 1), integerValuesReferences, integerValues) annotation(Library = {"omcruntime", "fmilib"<%if stringEq(platform, "win32") then ", \"shlwapi\""%>});
end fmiSetInteger;

function fmiGetBoolean
input fmiImportInstance fmi;
input Integer booleanValuesReferences[:];
input Real booleanValuesReferences[:];
input Real in_Flow;
output Boolean booleanValues[size(booleanValuesReferences, 1)];
external "C" fmiGetBoolean_OMC(fmi, size(booleanValuesReferences, 1), booleanValuesReferences, booleanValues, in_Flow) annotation(Library = {"omcruntime", "fmilib"<%if stringEq(platform, "win32") then ", \"shlwapi\""%>});
end fmiGetBoolean;

function fmiSetBoolean
input fmiImportInstance fmi;
input Integer booleanValuesReferences[:];
input Real booleanValuesReferences[:];
input Boolean booleanValues[size(booleanValuesReferences, 1)];
output Integer status;
external "C" status = fmiSetBoolean_OMC(fmi, size(booleanValuesReferences, 1), booleanValuesReferences, booleanValues) annotation(Library = {"omcruntime", "fmilib"<%if stringEq(platform, "win32") then ", \"shlwapi\""%>});
end fmiSetBoolean;

function fmiGetString
input fmiImportInstance fmi;
input Integer stringValuesReferences[:];
input Real stringValuesReferences[:];
input Real in_Flow;
output String stringValues[size(stringValuesReferences, 1)];
external "C" fmiGetString_OMC(fmi, size(stringValuesReferences, 1), stringValuesReferences, stringValues, in_Flow) annotation(Library = {"omcruntime", "fmilib"<%if stringEq(platform, "win32") then ", \"shlwapi\""%>});
end fmiGetString;

function fmiSetString
input fmiImportInstance fmi;
input Integer stringValuesReferences[:];
input Real stringValuesReferences[:];
input String stringValues[size(stringValuesReferences, 1)];
output Integer status;
external "C" status = fmiSetString_OMC(fmi, size(stringValuesReferences, 1), stringValuesReferences, stringValues) annotation(Library = {"omcruntime", "fmilib"<%if stringEq(platform, "win32") then ", \"shlwapi\""%>});
Expand Down
17 changes: 11 additions & 6 deletions Compiler/Template/SimCodeTV.mo
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ package builtin
output Boolean b;
end intGt;

function realInt
input Real r;
output Integer i;
end realInt;

function arrayList
replaceable type TypeVar subtypeof Any;
input TypeVar[:] arr;
Expand All @@ -85,7 +90,7 @@ package builtin
input String s1;
input String s2;
output Boolean b;
end stringEq;
end stringEq;

end builtin;

Expand Down Expand Up @@ -2620,7 +2625,7 @@ package FMI
Boolean hasStartValue;
Real startValue;
Boolean isFixed;
Integer valueReference;
Real valueReference;
end REALVARIABLE;

record INTEGERVARIABLE
Expand All @@ -2633,7 +2638,7 @@ package FMI
Boolean hasStartValue;
Integer startValue;
Boolean isFixed;
Integer valueReference;
Real valueReference;
end INTEGERVARIABLE;

record BOOLEANVARIABLE
Expand All @@ -2646,7 +2651,7 @@ package FMI
Boolean hasStartValue;
Boolean startValue;
Boolean isFixed;
Integer valueReference;
Real valueReference;
end BOOLEANVARIABLE;

record STRINGVARIABLE
Expand All @@ -2659,7 +2664,7 @@ package FMI
Boolean hasStartValue;
String startValue;
Boolean isFixed;
Integer valueReference;
Real valueReference;
end STRINGVARIABLE;

record ENUMERATIONVARIABLE
Expand All @@ -2672,7 +2677,7 @@ package FMI
Boolean hasStartValue;
Integer startValue;
Boolean isFixed;
Integer valueReference;
Real valueReference;
end ENUMERATIONVARIABLE;
end ModelVariables;

Expand Down
10 changes: 5 additions & 5 deletions Compiler/Util/FMI.mo
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public uniontype ModelVariables
Boolean hasStartValue;
Real startValue;
Boolean isFixed;
Integer valueReference;
Real valueReference;
end REALVARIABLE;

record INTEGERVARIABLE
Expand All @@ -81,7 +81,7 @@ public uniontype ModelVariables
Boolean hasStartValue;
Integer startValue;
Boolean isFixed;
Integer valueReference;
Real valueReference;
end INTEGERVARIABLE;

record BOOLEANVARIABLE
Expand All @@ -94,7 +94,7 @@ public uniontype ModelVariables
Boolean hasStartValue;
Boolean startValue;
Boolean isFixed;
Integer valueReference;
Real valueReference;
end BOOLEANVARIABLE;

record STRINGVARIABLE
Expand All @@ -107,7 +107,7 @@ public uniontype ModelVariables
Boolean hasStartValue;
String startValue;
Boolean isFixed;
Integer valueReference;
Real valueReference;
end STRINGVARIABLE;

record ENUMERATIONVARIABLE
Expand All @@ -120,7 +120,7 @@ public uniontype ModelVariables
Boolean hasStartValue;
Integer startValue;
Boolean isFixed;
Integer valueReference;
Real valueReference;
end ENUMERATIONVARIABLE;
end ModelVariables;

Expand Down
3 changes: 2 additions & 1 deletion Compiler/runtime/FMIImpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ int FMIImpl__initializeFMIImport(const char* file_name, const char* working_dire
void* variable_has_start_value = mk_bcon(hasStartValue);
void* variable_start_value = getModelVariableStartValue(model_variable, hasStartValue);
void* variable_is_fixed = mk_bcon(fmi1_import_get_variable_is_fixed(model_variable));
void* variable_value_reference = mk_icon(model_variables_value_reference_list[i]);
void* variable_value_reference = mk_rcon((double)model_variables_value_reference_list[i]);
//fprintf(stderr, "%s Variable name = %s, valueReference = %d\n", getModelVariableBaseType(model_variable), getModelVariableName(model_variable), model_variables_value_reference_list[i]);fflush(NULL);
void* variable;
fmi1_base_type_enu_t type = fmi1_import_get_variable_base_type(model_variable);
switch (type) {
Expand Down

0 comments on commit 8a78a62

Please sign in to comment.