Skip to content

Commit

Permalink
[OMSICpp/cppRuntime] Extended cpp runtime to OMSI Cpp library
Browse files Browse the repository at this point in the history
Renamed cpp runtime to omsicpp runtime
omsicpp code target is later used to extend omsic codegeneration with additonal
functionality
OMSICpp Simulation runtime for FMU 2.0 ME and OMSUC simulation in C++.
 - Added OMSICpp build
   - Use CMake to build SimultaionRuntime/OMSICpp
 - Added OMSICpp folder in SimulationRuntime
   - The code targets cpp and cpp fmu using this runtime also now
   - Using OMSIBase library for base functionalities shared with OMSIC runtime
   - Wrapper class for FMI 2.0 ModelExchange functions
     - Functions for continuous simulation of FMU/OMSU
     - Functions for event simulation of FMU/OMSU
     - Getter and Setter functions for FMU/OMSU
     - Logging and some debugging functionalities
     - Initialization and deallocation of FMU/OMSU
   - OMSICpp Simulation runtime which supports omsu/fmu 2.0 ME and  the old
     cpp code traget systems
 - Documentation with Doxygen
   - Doxyfile not included

Co-authored-by: AnHeuermann <andreas.heuermann@fh-bielefeld.de>
Co-authored-by: wibraun <wbraun@fh-bielefeld.de>
  • Loading branch information
3 people authored and adrpo committed Mar 12, 2020
1 parent c4985ea commit 573788c
Show file tree
Hide file tree
Showing 1,677 changed files with 180,756 additions and 167,229 deletions.
12 changes: 8 additions & 4 deletions Makefile.omdev.mingw
Expand Up @@ -8,7 +8,10 @@ OMDEVMSYS=$(shell cygpath $$OMDEV)
CMAKE = $(OMDEVMSYS)/bin/cmake/bin/cmake
CMAKE_TARGET = "MSYS Makefiles"

builddir_bin = $(OMBUILDDIR)/bin
builddir_build=$(OMBUILDDIR)
builddir_bin=$(OMBUILDDIR)/bin
builddir_lib=$(OMBUILDDIR)/lib/omc
builddir_inc=$(OMBUILDDIR)/include/omc

PKG_CONFIG_BIN = $(OMDEVMSYS)/lib/gtk+-2.24.10/bin
ifeq (MINGW32,$(findstring MINGW32,$(shell uname)))
Expand Down Expand Up @@ -202,8 +205,10 @@ simulationruntimecmsvc:
runtimeCPPmsvcinstall:
$(MAKE) -C OMCompiler -f $(defaultMakefileTarget) OMBUILDDIR=$(OMBUILDDIR) BUILDTYPE=$(BUILDTYPE) runtimeCPPmsvcinstall

runtimeCPPinstall:
$(MAKE) -C OMCompiler -f $(defaultMakefileTarget) OMBUILDDIR=$(OMBUILDDIR) BUILDTYPE=$(BUILDTYPE) runtimeCPPinstall
runtimeCPPinstall: OMSICPPinstall

OMSICPPinstall:
$(MAKE) -C OMCompiler -f $(defaultMakefileTarget) OMBUILDDIR=$(OMBUILDDIR) BUILDTYPE=$(BUILDTYPE) OMSICPPinstall

nox:
$(MAKE) -C OMCompiler -f $(defaultMakefileTarget) OMBUILDDIR=$(OMBUILDDIR) BUILDTYPE=$(BUILDTYPE) nox
Expand Down Expand Up @@ -291,4 +296,3 @@ gitclean:
git submodule foreach --recursive 'git clean -fdx -e /git -e /svn'
git clean -fdx -e OpenModelicaSetup -e OMSetup -e .project -e *.launch
for d in $(LIBGITDIRS); do git clean -fdx libraries/git/$$d; done

29 changes: 18 additions & 11 deletions OMCompiler/.gitignore
Expand Up @@ -85,12 +85,12 @@ build/
.vscode/
revision.h
SimulationRuntime/c/Makefile
SimulationRuntime/cpp/Makefile
SimulationRuntime/cpp/Makefile.env
SimulationRuntime/cpp/Build_*/
SimulationRuntime/cpp/Debug/
SimulationRuntime/cpp/.cproject
SimulationRuntime/cpp/confdefs.h
SimulationRuntime/OMSICpp/Makefile
SimulationRuntime/OMSICpp/Makefile.env
SimulationRuntime/OMSICpp/Build_*/
SimulationRuntime/OMSICpp/Debug/
SimulationRuntime/OMSICpp/.cproject
SimulationRuntime/OMSICpp/confdefs.h
SimulationRuntime/ParModelica/Makefile
SimulationRuntime/ParModelica/auto/Makefile
SimulationRuntime/ParModelica/explicit/Makefile
Expand All @@ -101,9 +101,13 @@ SimulationRuntime/opc/ua/open62541.c
SimulationRuntime/opc/ua/libomopcua.dll
SimulationRuntime/OMSI/Build_dynamic/
SimulationRuntime/OMSI/Build_static/
SimulationRuntime/OMSI/Build_MSVC/
SimulationRuntime/OMSI/Build_MSVC_static/
SimulationRuntime/OMSIC/Build_dynamic/
SimulationRuntime/OMSIC/Build_static/



# OpenModelicaSetup
Compiler/OpenModelicaSetup
# Compiler files
Expand Down Expand Up @@ -163,12 +167,15 @@ Parser/ParModelica_Lexer_BaseModelica_Lexer.h

SimulationRuntime/c/RuntimeSources.mo
SimulationRuntime/**/test_files/*.jar
SimulationRuntime/cpp/build_msvc/
SimulationRuntime/OMSICpp/build_msvc/
# Visual Studio 2015/2017 cache/options directory
SimulationRuntime/cpp/.vs/
SimulationRuntime/cpp/CMakeSettings.json
SimulationRuntime/cpp/omcWrapper/.vs
SimulationRuntime/cpp/omcWrapper/CMakeSettings.json

SimulationRuntime/OMSICpp/.vs/
SimulationRuntime/OMSICpp/CMakeSettings.json
SimulationRuntime/OMSICpp/omcWrapper/.vs
SimulationRuntime/OMSICpp/omcWrapper/CMakeSettings.json
SimulationRuntime/OMSI/.vs/
SimulationRuntime/OMSI/CMakeSettings.json
tags

*.plist
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -3487,7 +3487,7 @@ algorithm
DAE.FunctionTree funcs;
case(_)
equation
true = stringEq(Flags.getConfigString(Flags.SIMCODE_TARGET),"Cpp");
true = (stringEq(Flags.getConfigString(Flags.SIMCODE_TARGET),"Cpp"));
funcLst = DAE.AvlTreePathFunction.toList(fTreeIn);
funcLst = List.map(funcLst,renameFunctionParameter1);
funcs = DAE.AvlTreePathFunction.addList(DAE.AvlTreePathFunction.new(), funcLst);
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/ExpressionSolve.mo
Expand Up @@ -505,7 +505,7 @@ preprocessing for solve1,
(x, y, new_x) := preprocessingSolve4(x,y, inExp3);
con := new_x or con;
// TODO: use new defined function, which missing in the cpp runtime
if not stringEqual(Config.simCodeTarget(), "Cpp") then
if not (stringEqual(Config.simCodeTarget(), "Cpp") )then
(x, y, new_x, eqnForNewVars, newVarsCrefs, depth) := preprocessingSolveTmpVars(x, y, inExp3, uniqueEqIndex, eqnForNewVars, newVarsCrefs, depth);
con := new_x or con;
end if;
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/HpcOmMemory.mo
Expand Up @@ -1469,7 +1469,7 @@ import Util;
list<CacheLineMap> cacheLineFloatMaps;
array<tuple<Integer,Integer>> tmpScVarCLMapping;
algorithm
if(stringEqual(Config.simCodeTarget(), "Cpp")) then
if((stringEqual(Config.simCodeTarget(), "Cpp") )) then
(oCacheMap, oScVarCLMapping, oNumCL) := createCacheMapDefaultCppRuntime(iAllSCVars, iCacheLineSize, iSimCodeVars, iScVarTaskMapping, iSchedulerInfo, iSimCodeVarTypes);
else
oCacheMap := UNIFORM_CACHEMAP(iCacheLineSize,{},{});
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/Initialization.mo
Expand Up @@ -135,7 +135,7 @@ algorithm
// If Cpp runtime is used set fixvars to emptyVars because otherwise Cpp testcases fail
// This is wrong and leads to bigger initialization tearing sets than necessary!!!
// To-Do: Fix the problems with the Cpp runtime
if stringEq(Config.simCodeTarget(), "Cpp") then
if (stringEq(Config.simCodeTarget(), "Cpp"))then
fixvars := BackendVariable.emptyVars();
else
fixvars := BackendVariable.listVar(outAllPrimaryParameters);
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/FrontEnd/ComponentReference.mo
Expand Up @@ -1352,7 +1352,7 @@ algorithm
DAE.ComponentRef cr;
case (cr)
equation
if stringEqual(Config.simCodeTarget(), "Cpp") then
if (stringEqual(Config.simCodeTarget(), "Cpp"))then
((subs as (_ :: _))) = crefLastSubs(cr);
else
((subs as (_ :: _))) = crefSubs(cr);
Expand Down Expand Up @@ -2013,7 +2013,7 @@ algorithm

case (_) equation
true = crefIsFirstArrayElt(name);
if stringEqual(Config.simCodeTarget(), "Cpp") then
if (stringEqual(Config.simCodeTarget(), "Cpp")) then
arrayCrefInner = crefStripLastSubs(name);
else
arrayCrefInner = crefStripSubs(name);
Expand Down
84 changes: 57 additions & 27 deletions OMCompiler/Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -1520,44 +1520,68 @@ algorithm
case (cache,env,"simulate",vals as Values.CODE(Absyn.C_TYPENAME(className))::_,_)
algorithm
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMULATE_TOTAL);
if not Config.simCodeTarget() == "omsic" then

if Config.simCodeTarget() == "omsicpp" then

filenameprefix := AbsynUtil.pathString(className);
try
(cache, Values.STRING(str)) := buildModelFMU(cache, env, className, "2.0", "me", "<default>", true, {"static"});
if stringEmpty(str) then
fail();
end if;
b := true;
else
b := false;
end try;

compileDir := System.pwd() + Autoconf.pathDelimiter;
executable := filenameprefix;
initfilename := filenameprefix + "_init_xml";
simflags:="";
resultValues:={};
elseif not Config.simCodeTarget() == "omsic" then
(b,cache,compileDir,executable,_,outputFormat_str,_,simflags,resultValues,vals) := buildModel(cache,env,vals,msg);
else
Error.addMessage(Error.SIMULATOR_BUILD_ERROR, {"Can't simulate for SimCodeTarget=omsic!\n"});
fail();
end if;

if b then
exeDir := compileDir;
(cache,simSettings) := calculateSimulationSettings(cache,env,vals,msg);
SimCode.SIMULATION_SETTINGS(outputFormat = outputFormat_str) := simSettings;
result_file := stringAppendList(List.consOnTrue(not Testsuite.isRunning(),compileDir,{executable,"_res.",outputFormat_str}));
// result file might have been set by simflags (-r ...)
result_file := selectResultFile(result_file, simflags);
executableSuffixedExe := stringAppend(executable, getSimulationExtension(Config.simCodeTarget(),Autoconf.platform));
logFile := stringAppend(executable,".log");
// adrpo: log file is deleted by buildModel! do NOT DELETE IT AGAIN!
// we should really have different log files for simulation/compilation!
// as the buildModel log file will be deleted here and that gives less information to the user!
if System.regularFileExists(logFile) then
0 := System.removeFile(logFile);
end if;
sim_call := stringAppendList({"\"",exeDir,executableSuffixedExe,"\""," ",simflags});
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMULATE_SIMULATION);
SimulationResults.close() "Windows cannot handle reading and writing to the same file from different processes like any real OS :(";
resI := System.systemCall(sim_call,logFile);
timeSimulation := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMULATE_SIMULATION);
else
result_file := "";
resI := 1;
timeSimulation := 0.0;
end if;
exeDir := compileDir;
(cache,simSettings) := calculateSimulationSettings(cache,env,vals,msg);
SimCode.SIMULATION_SETTINGS(outputFormat = outputFormat_str) := simSettings;
result_file := stringAppendList(List.consOnTrue(not Testsuite.isRunning(),compileDir,{executable,"_res.",outputFormat_str}));
// result file might have been set by simflags (-r ...)

result_file := selectResultFile(result_file, simflags);

executableSuffixedExe := stringAppend(executable, getSimulationExtension(Config.simCodeTarget(),Autoconf.platform));
logFile := stringAppend(executable,".log");
// adrpo: log file is deleted by buildModel! do NOT DELETE IT AGAIN!
// we should really have different log files for simulation/compilation!
// as the buildModel log file will be deleted here and that gives less information to the user!
if System.regularFileExists(logFile) then
0 := System.removeFile(logFile);
end if;
sim_call := stringAppendList({"\"",exeDir,executableSuffixedExe,"\""," ",simflags});
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMULATE_SIMULATION);
SimulationResults.close() "Windows cannot handle reading and writing to the same file from different processes like any real OS :(";

resI := System.systemCall(sim_call,logFile);

timeSimulation := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMULATE_SIMULATION);

else
result_file := "";
resI := 1;
timeSimulation := 0.0;
end if;

timeTotal := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMULATE_TOTAL);

(cache,simValue) := createSimulationResultFromcallModelExecutable(b,resI,timeTotal,timeSimulation,resultValues,cache,className,vals,result_file,logFile);
then
(cache,simValue);

case (cache,_,"simulate",vals as Values.CODE(Absyn.C_TYPENAME(className))::_,_)
equation
Settings.getInstallationDirectoryPath() "simulation fail for some other reason than OPENMODELICAHOME not being set." ;
Expand Down Expand Up @@ -3145,6 +3169,12 @@ algorithm
then ".bat";
case ("Cpp","WIN64")
then ".bat";
case ("omsicpp","WIN64")
then ".bat";
case ("omsicpp","WIN32")
then ".bat";
case ("omsicpp","Unix")
then ".sh";
else Autoconf.exeExt;
end match;
end getSimulationExtension;
Expand Down Expand Up @@ -3789,7 +3819,7 @@ algorithm
return;
end if;

if not Config.simCodeTarget() == "omsic" then
if not ((Config.simCodeTarget() == "omsic") or (Config.simCodeTarget() == "omsicpp")) then
CevalScript.compileModel(filenameprefix+"_FMU" , libs);
ExecStat.execStat("buildModelFMU: Generate the FMI files");
else
Expand Down
7 changes: 6 additions & 1 deletion OMCompiler/Compiler/SimCode/SerializeInitXML.mo
Expand Up @@ -77,7 +77,12 @@ protected
algorithm
try
_ := match Config.simCodeTarget()
case "omsic" algorithm
case "omsic"
algorithm
File.open(file, simCode.fullPathPrefix+"/"+simCode.fileNamePrefix + "_init.xml", File.Mode.Write);
then();
case "omsicpp"
algorithm
File.open(file, simCode.fullPathPrefix+"/"+simCode.fileNamePrefix + "_init.xml", File.Mode.Write);
then();
else algorithm
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/SimCode/SerializeModelInfo.mo
Expand Up @@ -77,7 +77,7 @@ algorithm
list<SimCode.SimEqSystem> eqs;
case SimCode.SIMCODE(modelInfo=mi as SimCode.MODELINFO(vars=vars))
equation
if Config.simCodeTarget() == "omsic" then
if (Config.simCodeTarget() == "omsic") or (Config.simCodeTarget() == "omsicpp") then
fileName = code.fullPathPrefix + Autoconf.pathDelimiter + code.fileNamePrefix + "_info.json";
else
fileName = code.fileNamePrefix + "_info.json";
Expand Down

0 comments on commit 573788c

Please sign in to comment.