Skip to content

Commit 131bf48

Browse files
committed
FMI2 Cpp: fix naming to consistent use of short model identifiers (#3241)
This way the FMI export is compatible with the overall Cpp runtime. It might be changed to consistent use long model identifiers later on. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25207 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 5d4eb06 commit 131bf48

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

Compiler/Template/CodegenFMUCpp.tpl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,16 @@ match simCode
6060
case SIMCODE(modelInfo=modelInfo as MODELINFO(__)) then
6161
let guid = getUUIDStr()
6262
let target = simulationCodeTarget()
63-
let name = lastIdentOfPath(modelInfo.name)
6463
let stateDerVectorName = "__zDot"
6564
let &extraFuncs = buffer "" /*BUFD*/
6665
let &extraFuncsDecl = buffer "" /*BUFD*/
6766
let cpp = CodegenCpp.translateModel(simCode)
68-
let()= textFile(fmuModelWrapperFile(simCode, extraFuncs, extraFuncsDecl, "",guid, name, FMUVersion), 'OMCpp<%name%>FMU.cpp')
67+
let()= textFile(fmuModelWrapperFile(simCode, extraFuncs, extraFuncsDecl, "",guid, FMUVersion), 'OMCpp<%fileNamePrefix%>FMU.cpp')
6968
let()= textFile(fmuModelDescriptionFileCpp(simCode, extraFuncs, extraFuncsDecl, "", guid, FMUVersion, FMUType), 'modelDescription.xml')
70-
let()= textFile(simulationHeaderFile(simCode,contextFMI, extraFuncs, extraFuncsDecl,"","","","",MemberVariable(modelInfo, false),false), 'OMCpp<%name%>.h')
71-
let()= textFile(simulationCppFile(simCode, contextFMI, extraFuncs, extraFuncsDecl, "", stateDerVectorName, false), 'OMCpp<%name%>.cpp')
72-
let()= textFile(fmudeffile(simCode, FMUVersion), '<%name%>.def')
73-
let()= textFile(fmuMakefile(target,simCode, extraFuncs, extraFuncsDecl, ""), '<%fileNamePrefix%>_FMU.makefile')
69+
let()= textFile(simulationHeaderFile(simCode,contextFMI, extraFuncs, extraFuncsDecl,"","","","",MemberVariable(modelInfo, false),false), 'OMCpp<%fileNamePrefix%>.h')
70+
let()= textFile(simulationCppFile(simCode, contextFMI, extraFuncs, extraFuncsDecl, "", stateDerVectorName, false), 'OMCpp<%fileNamePrefix%>.cpp')
71+
let()= textFile(fmudeffile(simCode, FMUVersion), '<%fileNamePrefix%>.def')
72+
let()= textFile(fmuMakefile(target,simCode, extraFuncs, extraFuncsDecl, "", FMUVersion), '<%fileNamePrefix%>_FMU.makefile')
7473
""
7574
// Return empty result since result written to files directly
7675
end translateModel;
@@ -138,15 +137,17 @@ case SIMCODE(modelInfo = MODELINFO(varInfo = vi as VARINFO(__), vars = SIMVARS(s
138137
>>
139138
end fmiModelDescriptionAttributesCpp;
140139

141-
template fmuModelWrapperFile(SimCode simCode,Text& extraFuncs,Text& extraFuncsDecl,Text extraFuncsNamespace, String guid, String name, String FMUVersion)
140+
template fmuModelWrapperFile(SimCode simCode,Text& extraFuncs,Text& extraFuncsDecl,Text extraFuncsNamespace, String guid, String FMUVersion)
142141
"Generates code for ModelDescription file for FMU target."
143142
::=
144143
match simCode
145144
case SIMCODE(modelInfo=MODELINFO(__)) then
146-
let modelName = lastIdentOfPath(modelInfo.name)
145+
let modelName = dotPath(modelInfo.name)
146+
let modelShortName = lastIdentOfPath(modelInfo.name)
147+
let modelIdentifier = System.stringReplace(modelName, ".", "_")
147148
<<
148149
// define class name and unique id
149-
#define MODEL_IDENTIFIER <%System.stringReplace(fileNamePrefix,".", "_")%>Extension
150+
#define MODEL_IDENTIFIER <%modelShortName%>Extension
150151
#define MODEL_GUID "{<%guid%>}"
151152

152153
#include <Core/Modelica.h>
@@ -159,7 +160,7 @@ case SIMCODE(modelInfo=MODELINFO(__)) then
159160
#include <Solver/IAlgLoopSolver.h>
160161
#include <System/IAlgLoopSolverFactory.h>
161162
#include <SimController/ISimData.h>
162-
#include "OMCpp<%lastIdentOfPath(modelInfo.name)%>Extension.h"
163+
#include "OMCpp<%fileNamePrefix%>Extension.h"
163164

164165
<%ModelDefineData(modelInfo)%>
165166
#define NUMBER_OF_EVENT_INDICATORS <%zerocrosslength(simCode, extraFuncs ,extraFuncsDecl, extraFuncsNamespace)%>
@@ -435,7 +436,7 @@ match platform
435436
>>
436437
end getPlatformString2;
437438

438-
template fmuMakefile(String target,SimCode simCode,Text& extraFuncs,Text& extraFuncsDecl,Text extraFuncsNamespace)
439+
template fmuMakefile(String target, SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace, String FMUVersion)
439440
"Generates the contents of the makefile for the simulation case. Copy libexpat & correct linux fmu"
440441
::=
441442
match target
@@ -505,7 +506,8 @@ case "gcc" then
505506
match simCode
506507
case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simulationSettingsOpt = sopt) then
507508
let extraCflags = match sopt case SOME(s as SIMULATION_SETTINGS(__)) then ""
508-
let modelName = '<%lastIdentOfPath(modelInfo.name)%>'
509+
// Note: FMI 1.0 did not distinguish modelIdentifier from fileNamePrefix
510+
let modelName = if isFMIVersion20(FMUVersion) then dotPath(modelInfo.name) else fileNamePrefix
509511
let platformstr = match makefileParams.platform case "i386-pc-linux" then 'linux32' case "x86_64-linux" then 'linux64' else '<%makefileParams.platform%>'
510512
let mkdir = match makefileParams.platform case "win32" then '"mkdir.exe"' else 'mkdir'
511513
<<
@@ -523,8 +525,8 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
523525
CFLAGS=$(CFLAGS_BASED_ON_INIT_FILE) -Winvalid-pch $(SYSTEM_CFLAGS) -I"<%makefileParams.omhome%>/include/omc/cpp" -I"$(SUITESPARSE_INCLUDE)" -I"<%makefileParams.omhome%>/include/omc/cpp/Core" -I"<%makefileParams.omhome%>/include/omc/cpp/SimCoreFactory" -I"$(BOOST_INCLUDE)" <%makefileParams.includes ; separator=" "%>
524526
LDFLAGS=-L"<%makefileParams.omhome%>/lib/omc/cpp" -L$(BOOST_LIBS) -L"$(BOOST_LIBS)"
525527
PLATFORM="<%platformstr%>"
526-
SRC=OMCpp<%modelName%>.cpp
527-
SRC+= OMCpp<%modelName%>FMU.cpp
528+
SRC=OMCpp<%fileNamePrefix%>.cpp
529+
SRC+= OMCpp<%fileNamePrefix%>FMU.cpp
528530
SRC+= OMCpp<%fileNamePrefix%>CalcHelperMain.cpp
529531
SRC+= OMCpp<%fileNamePrefix%>CalcHelperMain2.cpp
530532
SRC+= OMCpp<%fileNamePrefix%>CalcHelperMain3.cpp

0 commit comments

Comments
 (0)