Skip to content

Commit

Permalink
Use the generated shell-script to run Cpp simulations. Respect the fi…
Browse files Browse the repository at this point in the history
…leNamePrefix parameter a bit more

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18626 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jan 13, 2014
1 parent b8c5a56 commit 2e94ffc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 84 deletions.
47 changes: 6 additions & 41 deletions Compiler/Script/CevalScript.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,6 @@ algorithm
cit = winCitation();
ifcpp=Util.equal(Config.simCodeTarget(),"Cpp");
ifmsvc = Util.equal(Config.simulationCodeTarget(),"msvc");
//exeDir=Util.if_(ifcpp,Settings.getInstallationDirectoryPath() +& "/bin/" ,compileDir);
exeDir=compileDir;
libDir= Settings.getInstallationDirectoryPath();
libDir = Util.if_(ifmsvc, libDir +& "/lib/omc/cpp/msvc",libDir+& "/lib/omc/cpp");
Expand All @@ -1430,45 +1429,13 @@ algorithm
stepsize_str = realString(stepsize);
num_intervalls_str = intString(interval);
tol_str = realString(tol);
simflags2=Util.if_(ifcpp,stringAppendList({"-r ",libDir," ","-m ",compileDir," ","-R ",result_file," ","-c ",configDir," ","-s ",starttime_str," ","-e ",stoptime_str," ","-f ", stepsize_str," ","-i ",method_str, " ","-v ",num_intervalls_str, " ","-y ",tol_str }), simflags);
executable1=Util.if_(ifcpp,"OMCpp"+& executable,executable);
executableSuffixedExe = stringAppend(executable1, System.getExeExt());
logFile = stringAppend(executable1,".log");
// adrpo: log file is deleted by buildModel! do NOT DELTE 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!
0 = Debug.bcallret1(System.regularFileExists(logFile),System.removeFile,logFile,0);
sim_call = stringAppendList({cit,exeDir,executableSuffixedExe,cit," ",simflags2});
System.realtimeTick(GlobalScript.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(GlobalScript.RT_CLOCK_SIMULATE_SIMULATION);
timeTotal = System.realtimeTock(GlobalScript.RT_CLOCK_SIMULATE_TOTAL);
(cache,simValue,newst) = createSimulationResultFromcallModelExecutable(resI,timeTotal,timeSimulation,resultValues,cache,className,vals,st,result_file,logFile);
then
(cache,simValue,newst);
/*
System.realtimeTick(GlobalScript.RT_CLOCK_SIMULATE_TOTAL);
(cache,st,compileDir,executable,method_str,outputFormat_str,_,simflags,resultValues) = buildModel(cache,env,vals,st_1,msg);
cit = winCitation();
ifcpp=Util.equal(Config.simCodeTarget(),"Cpp");
ifmsvc = Util.equal(Config.simulationCodeTarget(),"msvc");
exeDir=compileDir;
libDir= Settings.getInstallationDirectoryPath();
libDir = Util.if_(ifmsvc, libDir +& "/lib/omc/cpp/msvc",libDir+& "/lib/omc/cpp");
(cache,simSettings) = calculateSimulationSettings(cache,env,vals,st_1,msg);
SimCode.SIMULATION_SETTINGS(startTime=starttime,stopTime=stoptime,tolerance=tol,numberOfIntervals=interval,stepSize=stepsize,method = method_str, outputFormat = outputFormat_str)
= simSettings;
result_file = stringAppendList(List.consOnTrue(not Config.getRunningTestsuite(),compileDir,{executable,"_res.",outputFormat_str}));
executable1=Util.if_(ifcpp,executable+& "Run",executable);
executableSuffixedExe = stringAppend(executable1, System.getExeExt());
executableSuffixedExe2 = Util.if_(ifcpp,"OMCpp" +& executable1+&getRunScriptExtension( System.platform()),executableSuffixedExe);
logFile = stringAppend(executable1,".log");
executableSuffixedExe = stringAppend(executable, System.getExeExt());
logFile = stringAppend(executable,".log");
// adrpo: log file is deleted by buildModel! do NOT DELTE 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!
0 = Debug.bcallret1(System.regularFileExists(logFile),System.removeFile,logFile,0);
sim_call = stringAppendList({cit,exeDir,executableSuffixedExe2,cit," ",simflags});
sim_call = stringAppendList({cit,exeDir,executableSuffixedExe,cit," ",simflags});
System.realtimeTick(GlobalScript.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);
Expand All @@ -1477,7 +1444,7 @@ System.realtimeTick(GlobalScript.RT_CLOCK_SIMULATE_TOTAL);
(cache,simValue,newst) = createSimulationResultFromcallModelExecutable(resI,timeTotal,timeSimulation,resultValues,cache,className,vals,st,result_file,logFile);
then
(cache,simValue,newst);
*/

case (cache,env,"simulate",vals as Values.CODE(Absyn.C_TYPENAME(className))::_,st,_)
equation
omhome = Settings.getInstallationDirectoryPath() "simulation fail for some other reason than OPENMODELICAHOME not being set." ;
Expand Down Expand Up @@ -1552,10 +1519,8 @@ System.realtimeTick(GlobalScript.RT_CLOCK_SIMULATE_TOTAL);
(cache,st,compileDir,executable,method_str,outputFormat_str,_,simflags,resultValues) = buildModel(cache,env,vals,st_1,msg);
Values.REAL(linearizeTime) = getListNthShowError(vals,"try to get stop time",0,2);
cit = winCitation();
ifcpp=Util.equal(Config.simCodeTarget(),"Cpp");
executable1=Util.if_(ifcpp,"Simulation",executable);
executableSuffixedExe = stringAppend(executable1, System.getExeExt());
logFile = stringAppend(executable1,".log");
executableSuffixedExe = stringAppend(executable, System.getExeExt());
logFile = stringAppend(executable,".log");
0 = Debug.bcallret1(System.regularFileExists(logFile),System.removeFile,logFile,0);
strlinearizeTime = realString(linearizeTime);
sim_call = stringAppendList({cit,compileDir,executableSuffixedExe,cit," ","-l=",strlinearizeTime," ",simflags});
Expand Down
56 changes: 21 additions & 35 deletions Compiler/Template/CodegenCpp.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ template translateModel(SimCode simCode) ::=
let()= textFile(simulationFunctionsHeaderFile(simCode,modelInfo.functions,literals), 'OMCpp<%lastIdentOfPath(modelInfo.name)%>Functions.h')
let()= textFile(simulationFunctionsFile(simCode, modelInfo.functions,literals), 'OMCpp<%lastIdentOfPath(modelInfo.name)%>Functions.cpp')
let()= textFile(simulationMakefile(target,simCode), '<%fileNamePrefix%>.makefile')
let()= textFile(simulationMainRunScrip(simCode), 'OMCpp<%fileNamePrefix%>Run<%simulationMainRunScripSuffix(simCode)%>')
let()= textFile(simulationMainRunScrip(simCode), '<%fileNamePrefix%><%simulationMainRunScripSuffix(simCode)%>')
algloopfiles(listAppend(allEquations,initialEquations),simCode)
// empty result of the top-level template .., only side effects
end translateModel;
Expand Down Expand Up @@ -51,19 +51,10 @@ template simulationMainRunScrip(SimCode simCode)
::=
match simCode
case SIMCODE(makefileParams=MAKEFILE_PARAMS(__)) then
<<
<%simulationMainRunScrip2(makefileParams.platform,simCode)%>
>>
end simulationMainRunScrip;


template simulationMainRunScrip2(String platform, SimCode simCode)
"Generates code for header file for simulation target."
::=
match platform
(match makefileParams.platform
case "linux64"
case "linux32" then
match simCode
(match simCode
case SIMCODE(modelInfo=MODELINFO(__),makefileParams=MAKEFILE_PARAMS(__),simulationSettingsOpt = SOME(settings as SIMULATION_SETTINGS(__))) then
let start = settings.startTime
let end = settings.stopTime
Expand All @@ -77,7 +68,7 @@ let home = makefileParams.omhome
#!/bin/sh
exec ./OMCpp<%fileNamePrefix%> -s <%start%> -e <%end%> -f <%stepsize%> -v <%intervals%> -y <%tol%> -i <%solver%> -r <%simulationLibDir(simulationCodeTarget(),simCode)%> -m <%moLib%> -R <%simulationResults(getRunningTestsuite(),simCode)%> $*
>>
end match
end match)
case "win32"
case "win64" then
match simCode
Expand All @@ -94,8 +85,8 @@ let home = makefileParams.omhome
@echo off
<%moLib%>/OMCpp<%fileNamePrefix%>.exe -s <%start%> -e <%end%> -f <%stepsize%> -v <%intervals%> -y <%tol%> -i <%solver%> -r <%simulationLibDir(simulationCodeTarget(),simCode)%> -m <%moLib%> -R <%simulationResults(getRunningTestsuite(),simCode)%>
>>
end match
end simulationMainRunScrip2;
end match)
end simulationMainRunScrip;


template simulationLibDir(String target, SimCode simCode)
Expand All @@ -122,7 +113,7 @@ match simCode
case SIMCODE(modelInfo=MODELINFO(__),makefileParams=MAKEFILE_PARAMS(__),simulationSettingsOpt = SOME(settings as SIMULATION_SETTINGS(__))) then
let results = if test then "" else '<%makefileParams.compileDir%>/'
<<
<%results%><%lastIdentOfPath(modelInfo.name)%>_res.<%settings.outputFormat%>
<%results%><%fileNamePrefix%>_res.<%settings.outputFormat%>
>>
end simulationResults;

Expand All @@ -132,26 +123,15 @@ template simulationMainRunScripSuffix(SimCode simCode)
"Generates code for header file for simulation target."
::=
match simCode
case SIMCODE( makefileParams=MAKEFILE_PARAMS(__)) then
<<<%simulationMainRunScripSuffix2(makefileParams.platform,simCode)%>>>
case SIMCODE( makefileParams=params as MAKEFILE_PARAMS(__)) then
(match params.platform
case "win32"
case "win64" then
".bat"
else
".sh")
end simulationMainRunScripSuffix;



template simulationMainRunScripSuffix2(String platform,SimCode simCode)
"Generates code for header file for simulation target."
::=
match platform
case "linux64"
case "linux32" then
<<.sh>>
case "win32"
case "win64" then
<<.bat>>
end simulationMainRunScripSuffix2;



template simulationMainFile(SimCode simCode)
"Generates code for header file for simulation target."
::=
Expand Down Expand Up @@ -417,7 +397,13 @@ OFILES=$(CPPFILES:.cpp=.o)

<%lastIdentOfPath(modelInfo.name)%>: $(MAINFILE) $(OFILES)
<%\t%>$(CXX) -shared -I. -o $(SYSTEMOBJ) $(OFILES) $(CPPFLAGS) $(LDSYTEMFLAGS) -lOMCppSystem -lOMCppModelicaUtilities -lOMCppMath -lOMCppModelicaExternalC
<%\t%>$(CXX) $(CPPFLAGS) -I. -o $(MAINOBJ) $(MAINFILE) $(LDMAINFLAGS)
<%\t%>$(CXX) $(CPPFLAGS) -I. -o $(MAINOBJ) $(MAINFILE) $(LDMAINFLAGS)
<% if boolNot(stringEq(makefileParams.platform, "win32")) then
<<
<%\t%>chmod +x <%fileNamePrefix%>.sh
<%\t%>ln -s <%fileNamePrefix%>.sh <%fileNamePrefix%>
>>
%>
>>

end simulationMakefile;
Expand Down
8 changes: 4 additions & 4 deletions SimulationRuntime/cpp/Core/SimController/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main(int argc, const char* argv[])
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("runtime-libray,r", po::value<string>(),"path to cpp runtime libraries")
("runtime-library,r", po::value<string>(),"path to cpp runtime libraries")
("Modelica-system-library,m", po::value<string>(), "path to Modelica library")
("results-file,R", po::value<string>(),"name of results file")
("config-path,c", po::value< string >(), "path to xml files")
Expand All @@ -50,10 +50,10 @@ int main(int argc, const char* argv[])
double stepsize = stoptime/vm["number-of-intervalls"].as<int>();
double tollerance =vm["tollerance"].as<double>();
string solver = vm["solver"].as<string>();
if (vm.count("runtime-libray"))
if (vm.count("runtime-library"))
{
//cout << "runtime library path set to " << vm["runtime-libray"].as<string>() << std::endl;
runtime_lib_path = vm["runtime-libray"].as<string>();
//cout << "runtime library path set to " << vm["runtime-library"].as<string>() << std::endl;
runtime_lib_path = vm["runtime-library"].as<string>();

}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SimSettings OMCFactory::ReadSimulationParameter(int argc, const char* argv[])
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("runtime-libray,r", po::value<string>(),"path to cpp runtime libraries")
("runtime-library,r", po::value<string>(),"path to cpp runtime libraries")
("Modelica-system-library,m", po::value<string>(), "path to Modelica library")
("results-file,R", po::value<string>(),"name of results file")
("config-path,c", po::value< string >(), "path to xml files")
Expand All @@ -54,10 +54,10 @@ SimSettings OMCFactory::ReadSimulationParameter(int argc, const char* argv[])
double stepsize = stoptime/vm["number-of-intervalls"].as<int>();
double tollerance =vm["tollerance"].as<double>();
string solver = vm["solver"].as<string>();
if (vm.count("runtime-libray"))
if (vm.count("runtime-library"))
{
//cout << "runtime library path set to " << vm["runtime-libray"].as<string>() << std::endl;
runtime_lib_path = vm["runtime-libray"].as<string>();
//cout << "runtime library path set to " << vm["runtime-library"].as<string>() << std::endl;
runtime_lib_path = vm["runtime-library"].as<string>();

}
else
Expand Down

0 comments on commit 2e94ffc

Please sign in to comment.