Skip to content

Commit

Permalink
- update OMDev.
Browse files Browse the repository at this point in the history
FMI Import
- Separated the FMI Interface and the FMI external interface.
- Use more records for code generation.
FMI Export
- Don't print log if user sets fmiSetDebugLogging off.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13045 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Sep 25, 2012
1 parent 7d3cce6 commit f94658d
Show file tree
Hide file tree
Showing 15 changed files with 1,133 additions and 286 deletions.
1 change: 1 addition & 0 deletions Compiler/GenerateOMCHeader.mos
Expand Up @@ -4,6 +4,7 @@ loadFile("FrontEnd/Values.mo");
loadFile("Util/Error.mo");
loadFile("Util/Config.mo");
loadFile("Util/Util.mo");
loadFile("Util/FMI.mo");
err:=getErrorString();
if err == "" then loadOK := true; end if;
a:=loadOK; // Will cause exit(1) if loadOK is undefined
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Makefile.common
Expand Up @@ -183,6 +183,7 @@ Config.mo \
Debug.mo \
Error.mo \
Flags.mo \
FMI.mo \
Graph.mo \
HashSet.mo \
HashTable.mo \
Expand Down Expand Up @@ -233,8 +234,7 @@ Socket.mo \
System.mo \
TaskGraphExt.mo \
BackendDAEEXT.mo \
FMI.mo \

FMIExt.mo \


# all modules
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Makefile.in
Expand Up @@ -147,7 +147,7 @@ else
simcode: OpenModelicaBootstrappingHeader.h
$(MAKE) -C susan_codegen/
$(MAKE) -C Template/
OpenModelicaBootstrappingHeader.h: FrontEnd/Absyn.mo Script/Interactive.mo FrontEnd/Values.mo Util/Error.mo GenerateOMCHeader.mos Template/Unparsing.mo
OpenModelicaBootstrappingHeader.h: FrontEnd/Absyn.mo Script/Interactive.mo FrontEnd/Values.mo Util/Error.mo Util/Util.mo Util/FMI.mo GenerateOMCHeader.mos Template/Unparsing.mo
../build/bin/omc +g=MetaModelica GenerateOMCHeader.mos > $@.log || (cat $@.log && false)
@mv $@.new $@
endif
Expand Down
120 changes: 120 additions & 0 deletions Compiler/OpenModelicaBootstrappingHeader.h
Expand Up @@ -3,6 +3,126 @@
extern "C" {
#endif
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef FMI_Info_INFO__desc_added
#define FMI_Info_INFO__desc_added
ADD_METARECORD_DEFINTIONS const char* FMI_Info_INFO__desc__fields[10] = {"fmiVersion","fmiModelName","fmiModelIdentifier","fmiGuid","fmiDescription","fmiGenerationTool","fmiGenerationDateAndTime","fmiVariableNamingConvention","fmiNumberOfContinuousStates","fmiNumberOfEventIndicators"};
ADD_METARECORD_DEFINTIONS struct record_description FMI_Info_INFO__desc = {
"FMI_Info_INFO",
"FMI.Info.INFO",
FMI_Info_INFO__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description FMI_Info_INFO__desc;
#endif
#define FMI__INFO_3dBOX10 3
#define FMI__INFO(fmiVersion,fmiModelName,fmiModelIdentifier,fmiGuid,fmiDescription,fmiGenerationTool,fmiGenerationDateAndTime,fmiVariableNamingConvention,fmiNumberOfContinuousStates,fmiNumberOfEventIndicators) (mmc_mk_box(11, 3,&FMI_Info_INFO__desc,fmiVersion,fmiModelName,fmiModelIdentifier,fmiGuid,fmiDescription,fmiGenerationTool,fmiGenerationDateAndTime,fmiVariableNamingConvention,fmiNumberOfContinuousStates,fmiNumberOfEventIndicators))
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef FMI_ExperimentAnnotation_EXPERIMENTANNOTATION__desc_added
#define FMI_ExperimentAnnotation_EXPERIMENTANNOTATION__desc_added
ADD_METARECORD_DEFINTIONS const char* FMI_ExperimentAnnotation_EXPERIMENTANNOTATION__desc__fields[3] = {"fmiExperimentStartTime","fmiExperimentStopTime","fmiExperimentTolerance"};
ADD_METARECORD_DEFINTIONS struct record_description FMI_ExperimentAnnotation_EXPERIMENTANNOTATION__desc = {
"FMI_ExperimentAnnotation_EXPERIMENTANNOTATION",
"FMI.ExperimentAnnotation.EXPERIMENTANNOTATION",
FMI_ExperimentAnnotation_EXPERIMENTANNOTATION__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description FMI_ExperimentAnnotation_EXPERIMENTANNOTATION__desc;
#endif
#define FMI__EXPERIMENTANNOTATION_3dBOX3 3
#define FMI__EXPERIMENTANNOTATION(fmiExperimentStartTime,fmiExperimentStopTime,fmiExperimentTolerance) (mmc_mk_box4(3,&FMI_ExperimentAnnotation_EXPERIMENTANNOTATION__desc,fmiExperimentStartTime,fmiExperimentStopTime,fmiExperimentTolerance))
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef FMI_ModelVariables_REALVARIABLE__desc_added
#define FMI_ModelVariables_REALVARIABLE__desc_added
ADD_METARECORD_DEFINTIONS const char* FMI_ModelVariables_REALVARIABLE__desc__fields[10] = {"instance","name","description","baseType","variability","causality","hasStartValue","startValue","isFixed","valueReference"};
ADD_METARECORD_DEFINTIONS struct record_description FMI_ModelVariables_REALVARIABLE__desc = {
"FMI_ModelVariables_REALVARIABLE",
"FMI.ModelVariables.REALVARIABLE",
FMI_ModelVariables_REALVARIABLE__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description FMI_ModelVariables_REALVARIABLE__desc;
#endif
#define FMI__REALVARIABLE_3dBOX10 3
#define FMI__REALVARIABLE(instance,name,description,baseType,variability,causality,hasStartValue,startValue,isFixed,valueReference) (mmc_mk_box(11, 3,&FMI_ModelVariables_REALVARIABLE__desc,instance,name,description,baseType,variability,causality,hasStartValue,startValue,isFixed,valueReference))
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef FMI_ModelVariables_INTEGERVARIABLE__desc_added
#define FMI_ModelVariables_INTEGERVARIABLE__desc_added
ADD_METARECORD_DEFINTIONS const char* FMI_ModelVariables_INTEGERVARIABLE__desc__fields[10] = {"instance","name","description","baseType","variability","causality","hasStartValue","startValue","isFixed","valueReference"};
ADD_METARECORD_DEFINTIONS struct record_description FMI_ModelVariables_INTEGERVARIABLE__desc = {
"FMI_ModelVariables_INTEGERVARIABLE",
"FMI.ModelVariables.INTEGERVARIABLE",
FMI_ModelVariables_INTEGERVARIABLE__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description FMI_ModelVariables_INTEGERVARIABLE__desc;
#endif
#define FMI__INTEGERVARIABLE_3dBOX10 4
#define FMI__INTEGERVARIABLE(instance,name,description,baseType,variability,causality,hasStartValue,startValue,isFixed,valueReference) (mmc_mk_box(11, 4,&FMI_ModelVariables_INTEGERVARIABLE__desc,instance,name,description,baseType,variability,causality,hasStartValue,startValue,isFixed,valueReference))
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef FMI_ModelVariables_BOOLEANVARIABLE__desc_added
#define FMI_ModelVariables_BOOLEANVARIABLE__desc_added
ADD_METARECORD_DEFINTIONS const char* FMI_ModelVariables_BOOLEANVARIABLE__desc__fields[10] = {"instance","name","description","baseType","variability","causality","hasStartValue","startValue","isFixed","valueReference"};
ADD_METARECORD_DEFINTIONS struct record_description FMI_ModelVariables_BOOLEANVARIABLE__desc = {
"FMI_ModelVariables_BOOLEANVARIABLE",
"FMI.ModelVariables.BOOLEANVARIABLE",
FMI_ModelVariables_BOOLEANVARIABLE__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description FMI_ModelVariables_BOOLEANVARIABLE__desc;
#endif
#define FMI__BOOLEANVARIABLE_3dBOX10 5
#define FMI__BOOLEANVARIABLE(instance,name,description,baseType,variability,causality,hasStartValue,startValue,isFixed,valueReference) (mmc_mk_box(11, 5,&FMI_ModelVariables_BOOLEANVARIABLE__desc,instance,name,description,baseType,variability,causality,hasStartValue,startValue,isFixed,valueReference))
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef FMI_ModelVariables_STRINGVARIABLE__desc_added
#define FMI_ModelVariables_STRINGVARIABLE__desc_added
ADD_METARECORD_DEFINTIONS const char* FMI_ModelVariables_STRINGVARIABLE__desc__fields[10] = {"instance","name","description","baseType","variability","causality","hasStartValue","startValue","isFixed","valueReference"};
ADD_METARECORD_DEFINTIONS struct record_description FMI_ModelVariables_STRINGVARIABLE__desc = {
"FMI_ModelVariables_STRINGVARIABLE",
"FMI.ModelVariables.STRINGVARIABLE",
FMI_ModelVariables_STRINGVARIABLE__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description FMI_ModelVariables_STRINGVARIABLE__desc;
#endif
#define FMI__STRINGVARIABLE_3dBOX10 6
#define FMI__STRINGVARIABLE(instance,name,description,baseType,variability,causality,hasStartValue,startValue,isFixed,valueReference) (mmc_mk_box(11, 6,&FMI_ModelVariables_STRINGVARIABLE__desc,instance,name,description,baseType,variability,causality,hasStartValue,startValue,isFixed,valueReference))
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef FMI_ModelVariables_ENUMERATIONVARIABLE__desc_added
#define FMI_ModelVariables_ENUMERATIONVARIABLE__desc_added
ADD_METARECORD_DEFINTIONS const char* FMI_ModelVariables_ENUMERATIONVARIABLE__desc__fields[10] = {"instance","name","description","baseType","variability","causality","hasStartValue","startValue","isFixed","valueReference"};
ADD_METARECORD_DEFINTIONS struct record_description FMI_ModelVariables_ENUMERATIONVARIABLE__desc = {
"FMI_ModelVariables_ENUMERATIONVARIABLE",
"FMI.ModelVariables.ENUMERATIONVARIABLE",
FMI_ModelVariables_ENUMERATIONVARIABLE__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description FMI_ModelVariables_ENUMERATIONVARIABLE__desc;
#endif
#define FMI__ENUMERATIONVARIABLE_3dBOX10 7
#define FMI__ENUMERATIONVARIABLE(instance,name,description,baseType,variability,causality,hasStartValue,startValue,isFixed,valueReference) (mmc_mk_box(11, 7,&FMI_ModelVariables_ENUMERATIONVARIABLE__desc,instance,name,description,baseType,variability,causality,hasStartValue,startValue,isFixed,valueReference))
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef FMI_FmiImport_FMIIMPORT__desc_added
#define FMI_FmiImport_FMIIMPORT__desc_added
ADD_METARECORD_DEFINTIONS const char* FMI_FmiImport_FMIIMPORT__desc__fields[9] = {"fmuFileName","fmuWorkingDirectory","fmiLogLevel","fmiContext","fmiInstance","fmiInfo","fmiExperimentAnnotation","fmiModelVariablesInstance","fmiModelVariablesList"};
ADD_METARECORD_DEFINTIONS struct record_description FMI_FmiImport_FMIIMPORT__desc = {
"FMI_FmiImport_FMIIMPORT",
"FMI.FmiImport.FMIIMPORT",
FMI_FmiImport_FMIIMPORT__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description FMI_FmiImport_FMIIMPORT__desc;
#endif
#define FMI__FMIIMPORT_3dBOX9 3
#define FMI__FMIIMPORT(fmuFileName,fmuWorkingDirectory,fmiLogLevel,fmiContext,fmiInstance,fmiInfo,fmiExperimentAnnotation,fmiModelVariablesInstance,fmiModelVariablesList) (mmc_mk_box(10, 3,&FMI_FmiImport_FMIIMPORT__desc,fmuFileName,fmuWorkingDirectory,fmiLogLevel,fmiContext,fmiInstance,fmiInfo,fmiExperimentAnnotation,fmiModelVariablesInstance,fmiModelVariablesList))
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef Util_ReplacePattern_REPLACEPATTERN__desc_added
#define Util_ReplacePattern_REPLACEPATTERN__desc_added
ADD_METARECORD_DEFINTIONS const char* Util_ReplacePattern_REPLACEPATTERN__desc__fields[2] = {"from","to"};
Expand Down
24 changes: 13 additions & 11 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -117,6 +117,7 @@ protected import ComponentReference;
protected import Uncertainties;
protected import OpenTURNS;
protected import FMI;
protected import FMIExt;

public constant Integer RT_CLOCK_SIMULATE_TOTAL = 8;
public constant Integer RT_CLOCK_SIMULATE_SIMULATION = 9;
Expand Down Expand Up @@ -830,10 +831,10 @@ algorithm
Values.Value ret_val,simValue,value,v,cvar,cvar2,v1,v2;
Absyn.ComponentRef cr_1;
Integer size,resI,i,n;
Integer fmiContext, fmiInstance, fmiModelVariablesInstance, fmiLogLevel;
list<Integer> fmiModelVariablesList, fmiModelVariablesList1;
Real fmiExperimentStartTime, fmiExperimentStopTime, fmiExperimentTolerance;
String fmiModelIdentifier, fmiDescription;
Integer fmiContext, fmiInstance, fmiModelVariablesInstance, fmiLogLevel, fmiNumberOfRealModelVariables, fmiNumberOfIntegerModelVariables, fmiNumberOfBooleanModelVariables, fmiNumberOfStringModelVariables, fmiNumberOfEnumerationModelVariables;
list<FMI.ModelVariables> fmiModelVariablesList, fmiModelVariablesList1;
FMI.ExperimentAnnotation fmiExperimentAnnotation;
FMI.Info fmiInfo;
list<String> vars_1,args,strings,strs,strs1,strs2,visvars;
Real timeTotal,timeSimulation,timeStamp,val,x1,x2,y1,y2,r;
Interactive.Statements istmts;
Expand Down Expand Up @@ -1448,27 +1449,29 @@ algorithm

case (cache,env,"importFMUNew",{Values.STRING(filename),Values.STRING(workdir),Values.INTEGER(fmiLogLevel)},st,_)
equation
Error.clearMessages() "Clear messages";
true = System.regularFileExists(filename);
workdir = Util.if_(System.directoryExists(workdir), workdir, System.pwd());
/* Initialize FMI objects */
(b, fmiContext, fmiInstance, fmiModelIdentifier, fmiDescription, fmiExperimentStartTime, fmiExperimentStopTime, fmiExperimentTolerance,
fmiModelVariablesInstance, fmiModelVariablesList) = FMI.initializeFMIImport(filename, workdir, fmiLogLevel);
(b, fmiContext, fmiInstance, fmiInfo, fmiExperimentAnnotation, fmiModelVariablesInstance, fmiModelVariablesList) = FMIExt.initializeFMIImport(filename, workdir, fmiLogLevel);
true = b; /* if something goes wrong while initializing */
fmiModelVariablesList1 = listReverse(fmiModelVariablesList);
str = Tpl.tplString(CodegenFMU.importFMUModelica, FMI.FMIIMPORT(filename, workdir, fmiLogLevel, fmiContext, fmiInstance, fmiModelIdentifier, fmiDescription,
fmiExperimentStartTime, fmiExperimentStopTime, fmiExperimentTolerance,
str = Tpl.tplString(CodegenFMU.importFMUModelica, FMI.FMIIMPORT(filename, workdir, fmiLogLevel, fmiContext, fmiInstance, fmiInfo, fmiExperimentAnnotation,
fmiModelVariablesInstance, fmiModelVariablesList1));
pd = System.pathDelimiter();
filename_1 = stringAppendList({workdir,pd,fmiModelIdentifier,"FMUImportNew.mo"});
filename_1 = FMI.getFMIModelIdentifier(fmiInfo);
filename_1 = stringAppendList({workdir,pd,filename_1,"FMUImportNew.mo"});
System.writeFile(filename_1, str);
//b = FMI.printVariables(fmiModelVariablesList1);
/* Release FMI objects */
FMI.releaseFMIImport(fmiModelVariablesInstance, fmiInstance, fmiContext);
FMIExt.releaseFMIImport(fmiModelVariablesInstance, fmiInstance, fmiContext);
then
(cache,Values.STRING(filename_1),st);

case (cache,env,"importFMUNew",{Values.STRING(filename),Values.STRING(workdir),Values.INTEGER(fmiLogLevel)},st,_)
equation
false = System.regularFileExists(filename);
Error.clearMessages() "Clear messages";
Error.addMessage(Error.FILE_NOT_FOUND_ERROR, {filename});
then
(cache,Values.STRING(""),st);
Expand Down Expand Up @@ -6776,5 +6779,4 @@ algorithm
end match;
end cevalWholedimRetCall;


end CevalScript;

0 comments on commit f94658d

Please sign in to comment.