Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Conflicts:
	SimulationRuntime/cpp/Core/System/AlgLoopSolverFactory.cpp
	SimulationRuntime/cpp/Solver/Kinsol/Kinsol.cpp
  • Loading branch information
RuedKamp committed Aug 10, 2015
2 parents 2d7e724 + 9819b58 commit 6ac5418
Show file tree
Hide file tree
Showing 64 changed files with 2,087 additions and 4,125 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -85,6 +85,7 @@ SimulationRuntime/c/util/java_interface/src/org/openmodelica/corba/parser/OMCorb
SimulationRuntime/c/util/java_interface/src/org/openmodelica/corba/parser/OMCorbaDefinitionsParser.java
SimulationRuntime/c/util/java_interface/src/org/openmodelica/corba/parser/OMCorbaDefinitions.tokens
SimulationRuntime/cpp/Makefile
SimulationRuntime/cpp/Makefile.env
SimulationRuntime/cpp/Build/
SimulationRuntime/cpp/Debug/
SimulationRuntime/cpp/.cproject
Expand Down
466 changes: 251 additions & 215 deletions Compiler/BackEnd/Differentiate.mo

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions Compiler/BackEnd/HpcOmTaskGraph.mo
Expand Up @@ -5062,7 +5062,7 @@ algorithm
tpl2::sortedSystComps := sortedSystComps;
(comp1,i1) := tpl1;
(comp2,i2) := tpl2;
if BackendDAEUtil.componentsEqual(comp1,comp2) and intEq(i1,i2) then isEqual:= true;
if componentsEqual(tpl1, tpl2) then isEqual:= true;
else
isEqual := false;
print("comp " + intString(i1) + BackendDump.printComponent(comp1) + " is not equal to " + "comp" + intString(i2) + BackendDump.printComponent(comp2) + "\n");
Expand Down Expand Up @@ -5231,7 +5231,7 @@ protected function compareComponents "author: marcusw
output Boolean res;
protected
String comp1Str,comp2Str;
Integer minLength, comp1Idx, comp2Idx;
Integer minLength, compRes, comp1Idx, comp2Idx;
BackendDAE.StrongComponent comp1, comp2;
algorithm
if(componentsEqual(iComp1, iComp2)) then
Expand All @@ -5242,7 +5242,12 @@ algorithm
comp1Str := BackendDump.printComponent(comp1) + "_" + intString(comp1Idx);
comp2Str := BackendDump.printComponent(comp2) + "_" + intString(comp2Idx);
minLength := intMin(stringLength(comp1Str), stringLength(comp2Str));
res := intLt(System.strncmp(comp1Str, comp2Str, minLength), 0);
compRes := System.strncmp(comp1Str, comp2Str, minLength);
if(intEq(compRes, 0)) then
res := intLt(stringLength(comp1Str), stringLength(comp2Str));
else
res := intLt(compRes, 0);
end if;
end if;
end compareComponents;

Expand Down
6 changes: 1 addition & 5 deletions Compiler/BackEnd/OpenTURNS.mo
Expand Up @@ -77,13 +77,9 @@ constant String cStrWrapperCompileCmd = "wrapper_template.compile.cmd";
constant String cStrInvokeOpenTurnsCmd = "invoke.cmd";

public function generateOpenTURNSInterface "generates the dll and the python script for connections with OpenTURNS"
input FCore.Cache cache;
input FCore.Graph graph;
input BackendDAE.BackendDAE inDaelow;
input DAE.FunctionTree inFunctionTree;
input Absyn.Path inPath;
input Absyn.Program inProgram;
input DAE.DAElist inDAElist;
input String templateFile "the filename to the template file (python script)";
output String scriptFile "the name of the generated file";

Expand Down Expand Up @@ -117,7 +113,7 @@ algorithm
//print("strippedDae :");
//BackendDump.dump(strippedDae);
_ := System.realtimeTock(ClockIndexes.RT_CLOCK_BACKEND); // Is this necessary?
(_,libs,fileDir,_,_) := SimCodeMain.generateModelCode(strippedDae,inProgram,inDAElist,inPath,cname_str,SOME(simSettings),Absyn.FUNCTIONARGS({},{}));
(libs, fileDir, _, _) := SimCodeMain.generateModelCode(strippedDae, inProgram, inPath, cname_str, SOME(simSettings), Absyn.FUNCTIONARGS({}, {}));

//print("..compiling, fileNamePrefix = "+fileNamePrefix+"\n");
CevalScript.compileModel(fileNamePrefix , libs);
Expand Down
12 changes: 10 additions & 2 deletions Compiler/BackEnd/Tearing.mo
Expand Up @@ -1707,11 +1707,16 @@ protected
BackendDAE.AdjacencyMatrixTEnhanced meT;
BackendDAE.BackendDAEType DAEtype;
BackendDAE.TearingSet strictTearingSet;
BackendDAE.StateSets stateSets;
Option<BackendDAE.TearingSet> casualTearingSet;
list<BackendDAE.Equation> eqn_lst;
list<BackendDAE.Var> var_lst;
Boolean linear,simulation,b;
Boolean linear,simulation,b,noDynamicStateSelection;
algorithm

BackendDAE.EQSYSTEM(stateSets = stateSets) := isyst;
noDynamicStateSelection := listEmpty(stateSets);

BackendDAE.SHARED(backendDAEType=DAEtype) := ishared;
simulation := stringEq(BackendDump.printBackendDAEType2String(DAEtype), "simulation");

Expand Down Expand Up @@ -1827,7 +1832,7 @@ algorithm
// Determine casual tearing set if dynamic tearing is enabled
// *****************************************************************

if simulation and Config.dynamicTearing() then
if simulation and noDynamicStateSelection and Config.dynamicTearing() then

if Flags.isSet(Flags.TEARING_DUMP) or Flags.isSet(Flags.TEARING_DUMPVERBOSE) then
print("\n\nDetermine CASUAL TEARING SET\n" + BORDER + BORDER + "\n\n");
Expand Down Expand Up @@ -1927,6 +1932,9 @@ algorithm
end if;

else
if Flags.isSet(Flags.TEARING_DUMP) or Flags.isSet(Flags.TEARING_DUMPVERBOSE) then
print("Note:\n=====\nNo dynamic Tearing for this strong component. Check if\n- flag 'dynamicTearing' is set\n- strong component contains statesets\n- system belongs to simulation\n\n");
end if;
if not b and not Flags.getConfigBool(Flags.FORCE_TEARING) then
if Flags.isSet(Flags.TEARING_DUMP) or Flags.isSet(Flags.TEARING_DUMPVERBOSE) then
print("\nNote:\n=====\nTearing set is discarded because it is not smaller than the original set. Use +forceTearing to prevent this.\n\n");
Expand Down
49 changes: 25 additions & 24 deletions Compiler/FrontEnd/ClassLoader.mo
Expand Up @@ -128,20 +128,6 @@ algorithm
end matchcontinue;
end loadClass;

protected function existRegularFile
"Checks if a file exists"
input String filename;
algorithm
true := System.regularFileExists(filename);
end existRegularFile;

public function existDirectoryFile
"Checks if a directory exist"
input String filename;
algorithm
true := System.directoryExists(filename);
end existDirectoryFile;

protected function loadClassFromMps
"Loads a class or classes from a set of paths in OPENMODELICALIBRARY"
input String id;
Expand Down Expand Up @@ -272,7 +258,10 @@ algorithm
mp_1 = stringAppendList({mp,pd,pack});
packagefile = stringAppendList({mp_1,pd,"package.mo"});
orderfile = stringAppendList({mp_1,pd,"package.order"});
existRegularFile(packagefile);
if not System.regularFileExists(packagefile) then
Error.addInternalError("Expected file " + packagefile + " to exist", sourceInfo());
fail();
end if;
// print("Look for " + packagefile + "\n");
(cl as Absyn.CLASS(name,pp,fp,ep,r,Absyn.PARTS(tv,ca,cp,ann,cmt),info)) = parsePackageFile(packagefile, strategy, true, within_, id);
// print("Got " + packagefile + "\n");
Expand Down Expand Up @@ -347,14 +336,16 @@ algorithm
pd = System.pathDelimiter();
file = mp + pd + id + "/package.mo";
bDirectoryAndFileExists = System.directoryExists(mp + pd + id) and System.regularFileExists(file);
if (bDirectoryAndFileExists)
then
if bDirectoryAndFileExists then
cl = loadCompletePackageFromMp(id,id,mp,strategy,w1,Error.getNumErrorMessages());
ei = Absyn.makeClassElement(cl);
cps = mergeBefore(Absyn.PUBLIC({ei}),acc);
else
file = mp + pd + id + ".mo";
true = System.regularFileExists(file);
if not System.regularFileExists(file) then
Error.addInternalError("Expected file " + file + " to exist", sourceInfo());
fail();
end if;
cl = parsePackageFile(file, strategy, false, w1, id);
ei = Absyn.makeClassElement(cl);
cps = mergeBefore(Absyn.PUBLIC({ei}),acc);
Expand Down Expand Up @@ -383,14 +374,24 @@ algorithm
Absyn.PROGRAM(cs,w2) := getProgramFromStrategy(name, strategy);
classNames := List.map(cs, Absyn.getClassName);
str := stringDelimitList(classNames,", ");
Error.assertionOrAddSourceMessage(listLength(cs)==1, Error.LIBRARY_ONE_PACKAGE_PER_FILE, {str}, SOURCEINFO(name,true,0,0,0,0,0.0));
cl::{} := cs;
Absyn.CLASS(name=cname,body=body,info=info) := cl;
Error.assertionOrAddSourceMessage(stringEqual(cname,pack), Error.LIBRARY_UNEXPECTED_NAME, {pack,cname}, info);
if not listLength(cs)==1 then
Error.addSourceMessage(Error.LIBRARY_ONE_PACKAGE_PER_FILE, {str}, SOURCEINFO(name,true,0,0,0,0,0.0));
fail();
end if;
(cl as Absyn.CLASS(name=cname,body=body,info=info))::{} := cs;
if not stringEqual(cname,pack) then
Error.addSourceMessage(Error.LIBRARY_UNEXPECTED_NAME, {pack,cname}, info);
fail();
end if;
s1 := Absyn.withinString(w1);
s2 := Absyn.withinString(w2);
Error.assertionOrAddSourceMessage(Absyn.withinEqual(w1,w2) or Config.languageStandardAtMost(Config.MODELICA_2_X()), Error.LIBRARY_UNEXPECTED_WITHIN, {s1,s2}, info);
Error.assertionOrAddSourceMessage((not expectPackage) or Absyn.isParts(body), Error.LIBRARY_EXPECTED_PARTS, {pack}, info);
if not (Absyn.withinEqual(w1,w2) or Config.languageStandardAtMost(Config.MODELICA_2_X())) then
Error.addSourceMessage(Error.LIBRARY_UNEXPECTED_WITHIN, {s1,s2}, info);
fail();
elseif expectPackage and not Absyn.isParts(body) then
Error.addSourceMessage(Error.LIBRARY_EXPECTED_PARTS, {pack}, info);
fail();
end if;
end parsePackageFile;

protected function getBothPackageAndFilename
Expand Down
8 changes: 3 additions & 5 deletions Compiler/Main/Main.mo
Expand Up @@ -596,8 +596,8 @@ algorithm
if Config.simulationCg() then
info := BackendDAE.EXTRA_INFO(DAEUtil.daeDescription(dae), Absyn.pathString(inClassName));
dlow := BackendDAECreate.lower(dae, inCache, inEnv, info);
dlow := BackendDAEUtil.getSolvedSystem(dlow,"");
simcodegen(dlow, inClassName, ap, dae);
dlow := BackendDAEUtil.getSolvedSystem(dlow, "");
simcodegen(dlow, inClassName, ap);
end if;
end optimizeDae;

Expand All @@ -606,7 +606,6 @@ protected function simcodegen "
input BackendDAE.BackendDAE inBackendDAE;
input Absyn.Path inClassName;
input Absyn.Program inProgram;
input DAE.DAElist inDAE;
protected
String cname;
SimCode.SimulationSettings sim_settings;
Expand All @@ -624,8 +623,7 @@ algorithm
SimCodeMain.createSimulationSettings(0.0, 1.0, 500, 1e-6, "dassl", "", "mat", ".*", "");

System.realtimeTock(ClockIndexes.RT_CLOCK_BACKEND); // Is this necessary?
SimCodeMain.generateModelCode(inBackendDAE, inProgram, inDAE, inClassName,
cname, SOME(sim_settings), Absyn.FUNCTIONARGS({}, {}));
SimCodeMain.generateModelCode(inBackendDAE, inProgram, inClassName, cname, SOME(sim_settings), Absyn.FUNCTIONARGS({}, {}));
SimCodeFunctionUtil.execStat("Codegen Done");
end if;
end simcodegen;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -3065,7 +3065,7 @@ algorithm
dlow = BackendDAECreate.lower(dae,cache,env,BackendDAE.EXTRA_INFO(description,filenameprefix));
//print("lowered class\n");
//print("calling generateOpenTurnsInterface\n");
scriptFile = OpenTURNS.generateOpenTURNSInterface(cache,inEnv,dlow,funcs,className,p,dae,templateFile);
scriptFile = OpenTURNS.generateOpenTURNSInterface(dlow, className, p, templateFile);
then
(cache,scriptFile,inSt);

Expand Down
50 changes: 22 additions & 28 deletions Compiler/SimCode/SimCodeMain.mo
Expand Up @@ -116,13 +116,11 @@ protected function generateModelCodeFMU "
template-based code generator on it."
input BackendDAE.BackendDAE inBackendDAE;
input Absyn.Program p;
input DAE.DAElist dae;
input Absyn.Path className;
input String FMUVersion;
input String FMUType;
input String filenamePrefix;
input Option<SimCode.SimulationSettings> simSettingsOpt;
output BackendDAE.BackendDAE outIndexedBackendDAE;
output list<String> libs;
output String fileDir;
output Real timeSimCode;
Expand All @@ -141,10 +139,10 @@ algorithm
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMCODE);
a_cref := Absyn.pathToCref(className);
fileDir := CevalScriptBackend.getFileDir(a_cref, p);
(libs,libPaths,includes, includeDirs, recordDecls, functions, outIndexedBackendDAE, _, literals) :=
SimCodeUtil.createFunctions(p, dae, inBackendDAE, className);
simCode := createSimCode(outIndexedBackendDAE,
className, filenamePrefix, fileDir, functions, includes, includeDirs, libs, libPaths,simSettingsOpt, recordDecls, literals,Absyn.FUNCTIONARGS({},{}));
(libs,libPaths,includes, includeDirs, recordDecls, functions, literals) :=
SimCodeUtil.createFunctions(p, inBackendDAE);
simCode := createSimCode(inBackendDAE,
className, filenamePrefix, fileDir, functions, includes, includeDirs, libs, libPaths, simSettingsOpt, recordDecls, literals,Absyn.FUNCTIONARGS({},{}));
timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE);
SimCodeFunctionUtil.execStat("SimCode");

Expand All @@ -159,11 +157,9 @@ protected function generateModelCodeXML "
template-based code generator on it."
input BackendDAE.BackendDAE inBackendDAE;
input Absyn.Program p;
input DAE.DAElist dae;
input Absyn.Path className;
input String filenamePrefix;
input Option<SimCode.SimulationSettings> simSettingsOpt;
output BackendDAE.BackendDAE outIndexedBackendDAE;
output list<String> libs;
output String fileDir;
output Real timeSimCode;
Expand All @@ -182,9 +178,9 @@ algorithm
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMCODE);
a_cref := Absyn.pathToCref(className);
fileDir := CevalScriptBackend.getFileDir(a_cref, p);
(libs, libPaths, includes, includeDirs, recordDecls, functions, outIndexedBackendDAE, _, literals) :=
SimCodeUtil.createFunctions(p, dae, inBackendDAE, className);
(simCode,_) := SimCodeUtil.createSimCode(outIndexedBackendDAE,
(libs, libPaths, includes, includeDirs, recordDecls, functions, literals) :=
SimCodeUtil.createFunctions(p, inBackendDAE);
(simCode,_) := SimCodeUtil.createSimCode(inBackendDAE,
className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths, simSettingsOpt, recordDecls, literals,Absyn.FUNCTIONARGS({},{}));
timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE);
SimCodeFunctionUtil.execStat("SimCode");
Expand Down Expand Up @@ -222,7 +218,7 @@ algorithm
String FMUVersion,FMUType,filenameprefix,file_dir,resstr;
DAE.DAElist dae;
FCore.Graph graph;
BackendDAE.BackendDAE dlow,dlow_1,indexed_dlow_1;
BackendDAE.BackendDAE dlow,dlow_1;
list<String> libs;
GlobalScript.SymbolTable st;
Absyn.Program p;
Expand Down Expand Up @@ -258,8 +254,8 @@ algorithm
dlow_1 = BackendDAEUtil.getSolvedSystem(dlow,inFileNamePrefix);
timeBackend = System.realtimeTock(ClockIndexes.RT_CLOCK_BACKEND);

(indexed_dlow_1,libs,file_dir,timeSimCode,timeTemplates) =
generateModelCodeFMU(dlow_1, p, dae, className, FMUVersion, FMUType, filenameprefix, inSimSettingsOpt);
(libs,file_dir,timeSimCode,timeTemplates) =
generateModelCodeFMU(dlow_1, p, className, FMUVersion, FMUType, filenameprefix, inSimSettingsOpt);

//reset config flag
Flags.setConfigBool(Flags.GENERATE_SYMBOLIC_LINEARIZATION, symbolicJacActivated);
Expand All @@ -274,7 +270,7 @@ algorithm
resstr = Absyn.pathStringNoQual(className);
resstr = stringAppendList({"SimCode: The model ",resstr," has been translated to FMU"});
then
(cache,Values.STRING(resstr),st,indexed_dlow_1,libs,file_dir, resultValues);
(cache,Values.STRING(resstr),st,dlow_1,libs,file_dir, resultValues);
case (_,_,_,_,_,_,_,_,_)
equation
resstr = Absyn.pathStringNoQual(className);
Expand Down Expand Up @@ -311,7 +307,7 @@ algorithm
String filenameprefix,file_dir,resstr,description;
DAE.DAElist dae;
FCore.Graph graph;
BackendDAE.BackendDAE dlow,dlow_1,indexed_dlow_1;
BackendDAE.BackendDAE dlow,dlow_1;
list<String> libs;
GlobalScript.SymbolTable st;
Absyn.Program p;
Expand All @@ -334,8 +330,8 @@ algorithm
dlow_1 = BackendDAEUtil.getSolvedSystem(dlow,inFileNamePrefix);
timeBackend = System.realtimeTock(ClockIndexes.RT_CLOCK_BACKEND);

(indexed_dlow_1,libs,file_dir,timeSimCode,timeTemplates) =
generateModelCodeXML(dlow_1, p, dae, className, filenameprefix, inSimSettingsOpt);
(libs,file_dir,timeSimCode,timeTemplates) =
generateModelCodeXML(dlow_1, p, className, filenameprefix, inSimSettingsOpt);
resultValues =
{("timeTemplates",Values.REAL(timeTemplates)),
("timeSimCode", Values.REAL(timeSimCode)),
Expand All @@ -345,7 +341,7 @@ algorithm
resstr = Absyn.pathStringNoQual(className);
resstr = stringAppendList({"SimCode: The model ",resstr," has been translated to XML"});
then
(cache,Values.STRING(resstr),st,indexed_dlow_1,libs,file_dir, resultValues);
(cache,Values.STRING(resstr),st,dlow_1,libs,file_dir, resultValues);
case (_,_,_,_,_,_, _)
equation
resstr = Absyn.pathStringNoQual(className);
Expand All @@ -363,12 +359,10 @@ public function generateModelCode "
template-based code generator on it."
input BackendDAE.BackendDAE inBackendDAE;
input Absyn.Program p;
input DAE.DAElist dae;
input Absyn.Path className;
input String filenamePrefix;
input Option<SimCode.SimulationSettings> simSettingsOpt;
input Absyn.FunctionArgs args;
output BackendDAE.BackendDAE outIndexedBackendDAE;
output list<String> libs;
output String fileDir;
output Real timeSimCode;
Expand All @@ -382,13 +376,13 @@ protected
tuple<Integer, HashTableExpToIndex.HashTable, list<DAE.Exp>> literals;
algorithm
if Flags.isSet(Flags.GRAPHML) then
HpcOmTaskGraph.dumpTaskGraph(inBackendDAE,filenamePrefix);
HpcOmTaskGraph.dumpTaskGraph(inBackendDAE, filenamePrefix);
end if;
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMCODE);
a_cref := Absyn.pathToCref(className);
fileDir := CevalScriptBackend.getFileDir(a_cref, p);
(libs, libPaths,includes, includeDirs, recordDecls, functions, outIndexedBackendDAE, _, literals) := SimCodeUtil.createFunctions(p, dae, inBackendDAE, className);
simCode := createSimCode(outIndexedBackendDAE, className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths, simSettingsOpt, recordDecls, literals, args);
(libs, libPaths,includes, includeDirs, recordDecls, functions, literals) := SimCodeUtil.createFunctions(p, inBackendDAE);
simCode := createSimCode(inBackendDAE, className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths, simSettingsOpt, recordDecls, literals, args);
timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE);
SimCodeFunctionUtil.execStat("SimCode");

Expand Down Expand Up @@ -625,7 +619,7 @@ algorithm
String filenameprefix, file_dir, resstr, description;
DAE.DAElist dae;
FCore.Graph graph;
BackendDAE.BackendDAE dlow, dlow_1, indexed_dlow_1;
BackendDAE.BackendDAE dlow, dlow_1;
list<String> libs;
GlobalScript.SymbolTable st;
Absyn.Program p;
Expand All @@ -651,14 +645,14 @@ algorithm
dlow_1 = BackendDAEUtil.getSolvedSystem(dlow,inFileNamePrefix);
timeBackend = System.realtimeTock(ClockIndexes.RT_CLOCK_BACKEND);

(indexed_dlow_1, libs, file_dir, timeSimCode, timeTemplates) =
generateModelCode(dlow_1, p, dae, className, filenameprefix, inSimSettingsOpt, args);
(libs, file_dir, timeSimCode, timeTemplates) =
generateModelCode(dlow_1, p, className, filenameprefix, inSimSettingsOpt, args);

resultValues = {("timeTemplates", Values.REAL(timeTemplates)),
("timeSimCode", Values.REAL(timeSimCode)),
("timeBackend", Values.REAL(timeBackend)),
("timeFrontend", Values.REAL(timeFrontend))};
then (cache, st, indexed_dlow_1, libs, file_dir, resultValues);
then (cache, st, dlow_1, libs, file_dir, resultValues);

case (_, _, _, _, _, _, _, _) equation
true = Flags.isSet(Flags.FAILTRACE);
Expand Down

0 comments on commit 6ac5418

Please sign in to comment.