Skip to content

Commit

Permalink
temporary use fmu generation for omsicpp simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
niklwors authored and adrpo committed Aug 19, 2020
1 parent 5e180d3 commit 109bf99
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 29 deletions.
13 changes: 9 additions & 4 deletions OMCompiler/Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -1493,7 +1493,7 @@ algorithm
if Config.simCodeTarget() == "omsicpp" then

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

compileDir := System.pwd() + Autoconf.pathDelimiter;
executable := filenameprefix;
initfilename := filenameprefix + "_init_xml";
Expand Down Expand Up @@ -3532,6 +3532,7 @@ algorithm

CC := System.getCCompiler();
CFLAGS := "-Os "+System.stringReplace(System.getCFlags(),"${MODELICAUSERCFLAGS}","");

LDFLAGS := ("-L"+dquote+Settings.getInstallationDirectoryPath()+"/lib/"+Autoconf.triple+"/omc"+dquote+" "+
"-Wl,-rpath,"+dquote+Settings.getInstallationDirectoryPath()+"/lib/"+Autoconf.triple+"/omc"+dquote+" "+
System.getLDFlags()+" ");
Expand Down Expand Up @@ -3724,7 +3725,9 @@ protected
Boolean needs3rdPartyLibs;
String FMUType = inFMUType;
Boolean debug = false;

algorithm

cache := inCache;
if not FMI.checkFMIVersion(FMUVersion) then
outValue := Values.STRING("");
Expand Down Expand Up @@ -3790,8 +3793,8 @@ algorithm
end if;
return;
end if;

if not ((Config.simCodeTarget() == "omsic") or (Config.simCodeTarget() == "omsicpp")) then
/*Temporary disabled omsicpp*/
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 Expand Up @@ -5296,6 +5299,8 @@ algorithm
(_,vals) := getListFirstShowError(vals, "while retreaving the tolerance (5 arg) from the buildModel arguments");
(_,vals) := getListFirstShowError(vals, "while retreaving the method (6 arg) from the buildModel arguments");
(Values.STRING(filenameprefix),vals) := getListFirstShowError(vals, "while retreaving the fileNamePrefix (7 arg) from the buildModel arguments");


(_,vals) := getListFirstShowError(vals, "while retreaving the options (8 arg) from the buildModel arguments");
(_,vals) := getListFirstShowError(vals, "while retreaving the outputFormat (9 arg) from the buildModel arguments");
(_,vals) := getListFirstShowError(vals, "while retreaving the variableFilter (10 arg) from the buildModel arguments");
Expand Down
5 changes: 3 additions & 2 deletions OMCompiler/Compiler/SimCode/SerializeInitXML.mo
Expand Up @@ -81,10 +81,11 @@ algorithm
algorithm
File.open(file, simCode.fullPathPrefix+"/"+simCode.fileNamePrefix + "_init.xml", File.Mode.Write);
then();
case "omsicpp"
/*Temporary disabled omsicpp
case "omsicpp"
algorithm
File.open(file, simCode.fullPathPrefix+"/"+simCode.fileNamePrefix + "_init.xml", File.Mode.Write);
then();
then();*/
else algorithm
File.open(file, simCode.fileNamePrefix + "_init.xml", File.Mode.Write);
then();
Expand Down
3 changes: 2 additions & 1 deletion OMCompiler/Compiler/SimCode/SerializeModelInfo.mo
Expand Up @@ -77,7 +77,8 @@ algorithm
list<SimCode.SimEqSystem> eqs;
case SimCode.SIMCODE(modelInfo=mi as SimCode.MODELINFO(vars=vars))
equation
if (Config.simCodeTarget() == "omsic") or (Config.simCodeTarget() == "omsicpp") then
/*Temporary disabled omsicpp*/
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
27 changes: 21 additions & 6 deletions OMCompiler/Compiler/SimCode/SimCodeMain.mo
Expand Up @@ -175,7 +175,8 @@ protected
algorithm
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMCODE);
a_cref := AbsynUtil.pathToCref(className);
if ((Config.simCodeTarget() == "omsic") or (Config.simCodeTarget() == "omsicpp")) then
/*Temporary disabled omsicpp*/
if ((Config.simCodeTarget() == "omsic") /*or (Config.simCodeTarget() == "omsicpp")*/) then
fileDir := listHead(AbsynUtil.pathToStringList(className))+".tmp";
else
fileDir := CevalScriptBackend.getFileDir(a_cref, p);
Expand All @@ -191,7 +192,12 @@ algorithm
ExecStat.execStat("SimCode");

System.realtimeTick(ClockIndexes.RT_CLOCK_TEMPLATES);
callTargetTemplatesFMU(simCode, Config.simCodeTarget(), FMUVersion, FMUType);
/*Temporary disabled omsi fmu and generate C-fmu for omsicpp simcodetarget*/
if Config.simCodeTarget() == "omsicpp" then
callTargetTemplatesFMU(simCode, "C", FMUVersion, FMUType);
else
callTargetTemplatesFMU(simCode, Config.simCodeTarget(), FMUVersion, FMUType);
end if;
timeTemplates := System.realtimeTock(ClockIndexes.RT_CLOCK_TEMPLATES);
end generateModelCodeFMU;

Expand Down Expand Up @@ -280,13 +286,14 @@ algorithm
fileDir := CevalScriptBackend.getFileDir(a_cref, p);

(libs, libPaths, includes, includeDirs, recordDecls, functions, literals) := SimCodeUtil.createFunctions(p, inBackendDAE.shared.functionTree);
/*Temporary disabled omsicpp
if Config.simCodeTarget() == "omsicpp" then
fmuVersion:="2.0";
simCode := createSimCode(inBackendDAE, inInitDAE, inInitDAE_lambda0, inInlineData, inRemovedInitialEquationLst, className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths, p, simSettingsOpt, recordDecls, literals, args,isFMU=true, FMUVersion=fmuVersion,
fmuTargetName=listHead(AbsynUtil.pathToStringList(className)), inFMIDer=inFMIDer);
else
else*/
simCode := createSimCode(inBackendDAE, inInitDAE, inInitDAE_lambda0, inInlineData, inRemovedInitialEquationLst, className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths, p, simSettingsOpt, recordDecls, literals, args,inFMIDer=inFMIDer);
end if;
/*end if;*/
timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE);
ExecStat.execStat("SimCode");

Expand Down Expand Up @@ -686,7 +693,7 @@ algorithm
fmuVersion:="2.0";
fmuType:="me";
Tpl.tplNoret3(CodegenOMSICpp.translateModel, iSimCode, fmuVersion, fmuType);
callTargetTemplatesFMU(iSimCode,"omsic",fmuVersion,fmuType);
callTargetTemplatesFMU(iSimCode,"C",fmuVersion,fmuType);
end callTargetTemplatesOMSICpp;

protected function callTargetTemplatesFMU
Expand All @@ -696,6 +703,7 @@ protected function callTargetTemplatesFMU
input String FMUVersion;
input String FMUType;
algorithm

setGlobalRoot(Global.optionSimCode, SOME(simCode));
_ := match (simCode,target)
local
Expand Down Expand Up @@ -810,6 +818,10 @@ algorithm
txt=Tpl.redirectToFile(Tpl.emptyTxt, simCode.fileNamePrefix+".fmutmp/sources/Makefile.in")));
Tpl.closeFile(Tpl.tplCallWithFailError(CodegenFMU.settingsfile, simCode,
txt=Tpl.redirectToFile(Tpl.emptyTxt, simCode.fileNamePrefix+".fmutmp/sources/omc_simulation_settings.h")));
/*Temporary generate extra files for omsicpp simcodetarget, additionaly to C-fmu code*/
if Config.simCodeTarget() == "omsicpp" then
runTpl(func = function CodegenOMSICpp.translateModel(a_simCode=simCode, a_FMUVersion=FMUVersion, a_FMUType=FMUType));
end if;
then ();
case (_,"omsic")
algorithm
Expand Down Expand Up @@ -840,6 +852,7 @@ algorithm

runTpl(func = function CodegenOMSI_common.generateEquationsCode(a_simCode=simCode, a_FileNamePrefix=fileprefix));
then ();
/*Temporarily disabled
case (_,"omsicpp")
algorithm
guid := System.getUUIDStr();
Expand Down Expand Up @@ -871,7 +884,7 @@ algorithm
runTpl(func = function CodegenOMSICpp.translateModel(a_simCode=simCode, a_FMUVersion=FMUVersion, a_FMUType=FMUType));
then ();

*/
case (_,"Cpp")
equation
if(Flags.isSet(Flags.HPCOM)) then
Expand Down Expand Up @@ -943,6 +956,7 @@ algorithm
list<Option<Integer>> allRoots;

case (graph, _, filenameprefix, _, _, _) algorithm

// calculate stuff that we need to create SimCode data structure
System.realtimeTick(ClockIndexes.RT_CLOCK_FRONTEND);
ExecStat.execStatReset();
Expand Down Expand Up @@ -1037,6 +1051,7 @@ algorithm
then (libs, file_dir, timeSimCode, timeTemplates);
case TranslateModelKind.FMU()
algorithm

(libs,file_dir,timeSimCode,timeTemplates) := generateModelCodeFMU(dlow, initDAE, initDAE_lambda0, fmiDer, removedInitialEquationLst, SymbolTable.getAbsyn(), className, FMI.getFMIVersionString(), kind.kind, filenameprefix, kind.targetName, inSimSettingsOpt);
then (libs, file_dir, timeSimCode, timeTemplates);
case TranslateModelKind.XML()
Expand Down
15 changes: 8 additions & 7 deletions OMCompiler/Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -305,11 +305,10 @@ algorithm
if Flags.isSet(Flags.ITERATION_VARS) then
BackendDAEOptimize.listAllIterationVariables(dlow);
end if;

// initialization stuff
// ********************

if not ((Config.simCodeTarget() == "omsic") or (Config.simCodeTarget() == "omsicpp"))
if not ((Config.simCodeTarget() == "omsic") /*or (Config.simCodeTarget() == "omsicpp")*/)
then
// generate equations for initDAE
(initialEquations, uniqueEqIndex, tempvars) := createInitialEquations(inInitDAE, uniqueEqIndex, {});
Expand Down Expand Up @@ -365,9 +364,9 @@ algorithm
end if;


if not ((Config.simCodeTarget() == "omsic")or (Config.simCodeTarget() == "omsicpp"))
if not ((Config.simCodeTarget() == "omsic")/*or (Config.simCodeTarget() == "omsicpp")*/)
then
(uniqueEqIndex, odeEquations, algebraicEquations, localKnownVars, allEquations, equationsForZeroCrossings, tempvars,
(uniqueEqIndex, odeEquations, algebraicEquations, localKnownVars, allEquations, equationsForZeroCrossings, tempvars,
equationSccMapping, eqBackendSimCodeMapping, backendMapping, sccOffset) :=
createEquationsForSystems(contSysts, shared, uniqueEqIndex, zeroCrossings, tempvars, 1, backendMapping, true);
omsiOptData := NONE();
Expand Down Expand Up @@ -672,7 +671,7 @@ algorithm

// Set fullPathPrefix for FMUs
if isFMU then
if (Config.simCodeTarget()=="omsic") or (Config.simCodeTarget() == "omsicpp")then
if (Config.simCodeTarget()=="omsic") /* or (Config.simCodeTarget() == "omsicpp")*/ then
fullPathPrefix := filenamePrefix+".fmutmp";
else
fullPathPrefix := filenamePrefix+".fmutmp/sources/";
Expand Down Expand Up @@ -3885,7 +3884,6 @@ protected
algorithm
// Add empty hash table to omsiAllEquations
omsiAllEquations.context := SimCodeFunction.OMSI_CONTEXT(SOME(HashTableCrefSimVar.emptyHashTableSized(1013)));

for constSyst in constSysts loop
try
BackendDAE.MATCHING(comps=components) := constSyst.matching;
Expand Down Expand Up @@ -3925,6 +3923,7 @@ protected
Boolean debug=false;
Option<Integer> clockIndex;
algorithm

clockIndex := partitionKindToClockIndex(constSyst.partitionKind);
for component in components loop
tmpEqns := {};
Expand Down Expand Up @@ -4318,6 +4317,7 @@ protected function appendOMSIFunction
input output SimCode.OMSIFunction omsiFunction_1;
input SimCode.OMSIFunction omsiFunction_2;
algorithm

omsiFunction_1.equations := listAppend(omsiFunction_1.equations, omsiFunction_2.equations);

omsiFunction_1.inputVars := listAppend(omsiFunction_1.inputVars, omsiFunction_2.inputVars);
Expand Down Expand Up @@ -14008,7 +14008,8 @@ algorithm
getDefaultValueReference(inSimVar, inSimCode.modelInfo.varInfo);
case (_, _, _) guard(stringEqual(Config.simCodeTarget(), "Cpp")
or stringEqual(Config.simCodeTarget(), "omsic")
or stringEqual(Config.simCodeTarget(), "omsicpp"))
/*Temporary disabled omsicpp*/
/*or stringEqual(Config.simCodeTarget(), "omsicpp")*/)
algorithm
// resolve aliases to get multi-dimensional arrays right
// (this should possibly be done in getVarIndexByMapping?)
Expand Down
14 changes: 7 additions & 7 deletions OMCompiler/Compiler/Template/CodegenCFunctions.tpl
Expand Up @@ -4497,7 +4497,7 @@ template contextCref(ComponentRef cr, Context context, Text &preExp, Text &varDe
case JACOBIAN_CONTEXT(jacHT=SOME(_))
then (match Config.simCodeTarget()
case "omsic" then crefOMSI(cr, context)
case "omsicpp" then crefOMSI(cr, context)
/*deactivated case "omsicpp" then crefOMSI(cr, context)*/
else jacCrefs(cr, context, 0))

case OMSI_CONTEXT(__) then crefOMSI(cr, context)
Expand Down Expand Up @@ -4963,7 +4963,7 @@ end daeExp;
case e as ICONST(__) then
let int_type = match Config.simCodeTarget()
case "omsic" then "omsi_int"
case "omsicpp" then "omsi_int"
/*deactivated case "omsicpp" then "omsi_int"*/
else "modelica_integer"
end match
'((<%int_type%>) <%integer%>)' /* Yes, we need to cast int to long on 64-bit arch... */
Expand Down Expand Up @@ -5870,8 +5870,8 @@ case rel as RELATION(__) then
match Config.simCodeTarget()
case "omsic" then
'omsi_function_zero_crossings(this_function, <%res%>, <%rel.index%>, omsic_get_model_state())'
case "omsicpp" then
'omsi_function_zero_crossings(this_function, <%res%>, <%rel.index%>, omsic_get_model_state())'
/*deactivated case "omsicpp" then
'omsi_function_zero_crossings(this_function, <%res%>, <%rel.index%>, omsic_get_model_state())'*/
end match
case JACOBIAN_CONTEXT(__)
case DAE_MODE_CONTEXT(__)
Expand Down Expand Up @@ -6574,8 +6574,8 @@ template daeExpCall(Exp call, Context context, Text &preExp, Text &varDecls, Tex
match Config.simCodeTarget()
case "omsic" then
'omsi_on_sample_event(this_function, <%intSub(index,1)%>, omsic_get_model_state())'
case "omsicpp" then
'omsi_on_sample_event(this_function, <%intSub(index,1)%>, omsic_get_model_state())'
/*deactivated case "omsicpp" then
'omsi_on_sample_event(this_function, <%intSub(index,1)%>, omsic_get_model_state())'*/
else
'data->simulationInfo->samples[<%intSub(index, 1)%>]'
end match
Expand Down Expand Up @@ -7616,7 +7616,7 @@ template varArrayNameValues(SimVar var, Integer ix, Boolean isPre, Boolean isSta
::=
match Config.simCodeTarget()
case "omsic"
case "omsicpp"
/*deactivated case "omsicpp"*/
then
match var
case SIMVAR(varKind=PARAM())
Expand Down
8 changes: 8 additions & 0 deletions OMCompiler/Compiler/Template/CodegenFMU.tpl
Expand Up @@ -1385,6 +1385,14 @@ template fmuSourceMakefile(SimCode simCode, String FMUVersion)
<%\t%>rm -f <%fileNamePrefix%>.fmutmp/sources/<%fileNamePrefix%>_init.xml<%/*Already translated to .c*/%>
<%\t%>cp -a "<%makefileParams.omhome%>/share/omc/runtime/c/fmi/buildproject/"* <%fileNamePrefix%>.fmutmp/sources
<%\t%>cp -a <%fileNamePrefix%>_FMU.libs <%fileNamePrefix%>.fmutmp/sources/
<%if boolNot(boolOr(stringEq(makefileParams.platform, "win32"),stringEq(makefileParams.platform, "win64"))) then
match Config.simCodeTarget()
case "omsicpp" then
<<
<%\t%>chmod +x <%fileNamePrefix%>.sh
>>
end match
%>
<%\n%>
>>
end fmuSourceMakefile;
Expand Down
3 changes: 2 additions & 1 deletion OMCompiler/Compiler/Template/CodegenOMSICpp.tpl
Expand Up @@ -62,7 +62,8 @@ case SIMCODE(modelInfo=modelInfo as MODELINFO(__)) then

let &extraFuncs = buffer "" /*BUFD*/
let &extraFuncsDecl = buffer "" /*BUFD*/
let()= textFile(simulationOMSUCPPMainRunScript(simCode , &extraFuncs , &extraFuncsDecl, "", "", "", "exec"), '<%fileNamePrefix%><%simulationMainRunScriptSuffix(simCode , &extraFuncs , &extraFuncsDecl, "")%>')

let()= textFile(simulationOMSUCPPMainRunScript(simCode , &extraFuncs , &extraFuncsDecl, "", "", "", "exec"), '<%dotPath(modelInfo.name)%><%simulationMainRunScriptSuffix(simCode , &extraFuncs , &extraFuncsDecl, "")%>')

""
end translateModel;
Expand Down
Expand Up @@ -176,9 +176,11 @@ void OMSUSystem::initialize()
fs::path resources_foler("resources");
fs::path resource_location = fs::path(_osu_working_dir);
resource_location /= resources_foler;
string path = string("file:") + resource_location.string();

jm_status_enu_t instantiateModelStatus = fmi2_import_instantiate(
_osu_me->instance, _osu_name.c_str(), fmi2_model_exchange,
resource_location.string().c_str(), fmi2_false);
path.c_str(), fmi2_false);
if (instantiateModelStatus == jm_status_error)
{
_osu_me->solving_mode = omsi_none_mode;
Expand Down

0 comments on commit 109bf99

Please sign in to comment.