Skip to content

Commit

Permalink
use CevalScript.getFullPathFromUri to get animation file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich committed Oct 19, 2016
1 parent f45d03b commit 1ccc53d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 64 deletions.
37 changes: 15 additions & 22 deletions Compiler/BackEnd/VisualXML.mo
Expand Up @@ -46,6 +46,7 @@ import BackendDAE;
import BackendDAEUtil;
import BackendEquation;
import BackendVariable;
import CevalScript;
import ComponentReference;
import DAE;
import DAEUtil;
Expand Down Expand Up @@ -88,7 +89,7 @@ public function visualizationInfoXML"dumps an xml containing information about v
author:Waurich TUD 2015-04"
input BackendDAE.BackendDAE daeIn;
input String fileName;
input list<tuple<String,String>> packagePaths;
input Absyn.Program program;
output BackendDAE.BackendDAE daeOut;
protected
BackendDAE.EqSystems eqs, eqs0;
Expand Down Expand Up @@ -117,7 +118,7 @@ algorithm

//fill theses visualization objects with information
allVarLst := listAppend(globalKnownVarLst,listAppend(allVarLst,aliasVarLst));
(visuals,_,_) := List.mapFold2(allVisuals, fillVisualizationObjects,allVarLst, packagePaths);
(visuals,_,_) := List.mapFold2(allVisuals, fillVisualizationObjects,allVarLst, program);
//print("\nvisuals :\n"+stringDelimitList(List.map(visuals,printVisualization),"\n")+"\n");

//dump xml file
Expand Down Expand Up @@ -208,12 +209,12 @@ protected function fillVisualizationObjects"gets the identifier of a visualizati
author:Waurich TUD 2015-04"
input DAE.ComponentRef crefIn;
input list<BackendDAE.Var> allVarsIn;
input list<tuple<String,String>> packagePathsIn;
input Absyn.Program programIn;
output Visualization visOut;
output list<BackendDAE.Var> allVarsOut;
output list<tuple<String,String>> packagePathsOut;
output Absyn.Program programOut;
algorithm
(visOut,allVarsOut,packagePathsOut) := matchcontinue(crefIn,allVarsIn,packagePathsIn)
(visOut,allVarsOut,programOut) := matchcontinue(crefIn,allVarsIn,programIn)
local
String name;
list<String> nameChars,prefix;
Expand All @@ -230,8 +231,8 @@ algorithm
vis := SHAPE(crefIn,"",arrayCreate(3,{DAE.RCONST(-1),DAE.RCONST(-1),DAE.RCONST(-1)}),
arrayCreate(3,DAE.RCONST(-1)), arrayCreate(3,DAE.RCONST(-1)), arrayCreate(3,DAE.RCONST(-1)),arrayCreate(3,DAE.RCONST(-1)),
DAE.RCONST(-1),DAE.RCONST(-1),DAE.RCONST(-1),DAE.RCONST(-1), arrayCreate(3,DAE.RCONST(-1)), DAE.RCONST(-1));
(_,vis) := List.fold2(allVarsIn,fillVisualizationObjects1,true,packagePathsIn,({},vis));
then (vis,allVarsIn,packagePathsIn);
(_,vis) := List.fold2(allVarsIn,fillVisualizationObjects1,true,programIn,({},vis));
then (vis,allVarsIn,programIn);
else
algorithm
print("fillVisualizationObjects failed! - not yet supported type");
Expand Down Expand Up @@ -293,7 +294,7 @@ protected function fillVisualizationObjects1"checks if a variable belongs to a c
author:Waurich TUD 2015-04"
input BackendDAE.Var varIn; //check this var
input Boolean storeProtectedCrefs; // if you want to store the protected crefs instead of the bidning expression
input list<tuple<String,String>> packagePaths;
input Absyn.Program program;
input tuple<list<BackendDAE.Var>,Visualization> tplIn; // fold <vars for other visualization objects, the current visualization >
output tuple<list<BackendDAE.Var>,Visualization> tplOut;
algorithm
Expand All @@ -308,7 +309,7 @@ algorithm
//this var belongs to the visualization object
//crefIdent := makeCrefQualFromString(ident); // make a qualified cref out of the shape ident
(cref1,true) := splitCrefAfter(cref,ident); // check if this occures in the qualified var cref
vis := fillShapeObject(cref1,varIn,storeProtectedCrefs,packagePaths,vis);
vis := fillShapeObject(cref1,varIn,storeProtectedCrefs,program,vis);
then (vars, vis);
else
algorithm
Expand All @@ -320,23 +321,15 @@ end fillVisualizationObjects1;
protected function getFullCADFilePath "Get the absolute path for the given modelica uri.
author: vwaurich TUD 2016-10"
input String sIn;
input list<tuple<String,String>> packagePaths;
input Absyn.Program program;
output String sOut = sIn;
protected
String head,packName,file, path;
list<String> hierarchy, chars;
algorithm
chars := stringListStringChar(sIn);
if listLength(chars) > 11 and stringEqual(stringDelimitList(List.firstN(chars,11),""),"modelica://") then
(head,packName,file) := System.uriToClassAndPath(sIn);
//Check if its a file reference and create absolute path
if stringEqual(head,"modelica://") then
(_,path) := List.find1(packagePaths,packagePathEqual,packName);
hierarchy := System.strtok(path, "/");
hierarchy := List.firstN(hierarchy,listLength(hierarchy)-1);
//print("hierarchy: "+stringDelimitList(hierarchy," ")+"\n");
sOut := head+stringDelimitList(hierarchy,"/")+file;
end if;
sOut := "modelica://"+CevalScript.getFullPathFromUri(program,sIn,true);
end if;
end getFullCADFilePath;

Expand All @@ -354,11 +347,11 @@ author:Waurich TUD 2015-04"
input DAE.ComponentRef cref;
input BackendDAE.Var var;
input Boolean storeProtectedCrefs;
input list<tuple<String,String>> packagePaths;
input Absyn.Program program;
input Visualization visIn;
output Visualization visOut;
algorithm
visOut := matchcontinue(cref,var,storeProtectedCrefs,packagePaths,visIn)
visOut := matchcontinue(cref,var,storeProtectedCrefs,program,visIn)
local
Option<DAE.Exp> bind;
DAE.ComponentRef ident;
Expand All @@ -371,7 +364,7 @@ algorithm
array<list<DAE.Exp>> T;
case(DAE.CREF_IDENT(ident="shapeType"),BackendDAE.VAR(bindExp=SOME(DAE.SCONST(svalue))),_ ,_ , SHAPE(ident=ident, shapeType=shapeType, T=T, r=r, r_shape=r_shape, lengthDir=lengthDir, widthDir=widthDir, length=length, width=width, height=height, extra=extra, color=color, specularCoeff=specularCoeff))
algorithm
svalue := getFullCADFilePath(svalue,packagePaths);
svalue := getFullCADFilePath(svalue,program);
then (SHAPE(ident, svalue, T, r, r_shape, lengthDir, widthDir, length, width, height, extra, color, specularCoeff));

case(DAE.CREF_QUAL(ident="R",componentRef=DAE.CREF_IDENT(ident="T", subscriptLst = {DAE.INDEX(DAE.ICONST(pos)),DAE.INDEX(DAE.ICONST(pos1))})),BackendDAE.VAR(bindExp=bind),_ ,_ , SHAPE(ident=ident, shapeType=shapeType, T=T, r=r, r_shape=r_shape, lengthDir=lengthDir, widthDir=widthDir, length=length, width=width, height=height, extra=extra, color=color, specularCoeff=specularCoeff))
Expand Down
8 changes: 4 additions & 4 deletions Compiler/SimCode/HpcOmSimCodeMain.mo
Expand Up @@ -82,14 +82,14 @@ public function createSimCode "
input list<String> includeDirs;
input list<String> libs;
input list<String> libPaths;
input list<tuple<String,String>> packagePaths;
input Absyn.Program program;
input Option<SimCode.SimulationSettings> simSettingsOpt;
input list<SimCode.RecordDeclaration> recordDecls;
input tuple<Integer, HashTableExpToIndex.HashTable, list<DAE.Exp>> literals;
input Absyn.FunctionArgs args;
output SimCode.SimCode simCode;
algorithm
simCode := matchcontinue (inBackendDAE, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths,packagePaths,simSettingsOpt, recordDecls, literals, args)
simCode := matchcontinue (inBackendDAE, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths,program,simSettingsOpt, recordDecls, literals, args)
local
Integer lastEqMappingIdx;
BackendDAE.EqSystems eqs;
Expand Down Expand Up @@ -137,7 +137,7 @@ algorithm
//-----
(simCode,(lastEqMappingIdx,equationSccMapping)) =
SimCodeUtil.createSimCode( inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions,
externalFunctionIncludes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals, args );
externalFunctionIncludes, includeDirs, libs,libPaths,program, simSettingsOpt, recordDecls, literals, args );

//get simCode-backendDAE mappings
//----------------------------
Expand Down Expand Up @@ -192,7 +192,7 @@ algorithm
System.realtimeTick(ClockIndexes.RT_CLOCK_EXECSTAT_HPCOM_MODULES);
(simCode,(lastEqMappingIdx,equationSccMapping)) =
SimCodeUtil.createSimCode( inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions,
externalFunctionIncludes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals, args );
externalFunctionIncludes, includeDirs, libs,libPaths,program, simSettingsOpt, recordDecls, literals, args );

//get simCode-backendDAE mappings
//----------------------------
Expand Down
29 changes: 14 additions & 15 deletions Compiler/SimCode/SimCodeMain.mo
Expand Up @@ -144,15 +144,14 @@ protected
Absyn.ComponentRef a_cref;
list<String> libPaths;
tuple<Integer,HashTableExpToIndex.HashTable,list<DAE.Exp>> literals;
list<tuple<String, String>> packagePaths;
algorithm
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMCODE);
a_cref := Absyn.pathToCref(className);
fileDir := CevalScriptBackend.getFileDir(a_cref, p);
(libs,libPaths,includes, includeDirs, recordDecls, functions, literals, packagePaths) :=
(libs,libPaths,includes, includeDirs, recordDecls, functions, literals) :=
SimCodeUtil.createFunctions(p, inBackendDAE);
simCode := createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters,
className, filenamePrefix, fileDir, functions, includes, includeDirs, libs, libPaths,packagePaths, SOME(simSettings), recordDecls, literals, Absyn.FUNCTIONARGS({},{}), isFMU=true, FMUVersion=FMUVersion);
className, filenamePrefix, fileDir, functions, includes, includeDirs, libs, libPaths, p, SOME(simSettings), recordDecls, literals, Absyn.FUNCTIONARGS({},{}), isFMU=true, FMUVersion=FMUVersion);
timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE);
ExecStat.execStat("SimCode");

Expand Down Expand Up @@ -190,15 +189,15 @@ protected
list<String> libPaths;
Absyn.ComponentRef a_cref;
tuple<Integer,HashTableExpToIndex.HashTable,list<DAE.Exp>> literals;
list<tuple<String, String>> packagePaths;
list<tuple<String, String>> program;
algorithm
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMCODE);
a_cref := Absyn.pathToCref(className);
fileDir := CevalScriptBackend.getFileDir(a_cref, p);
(libs, libPaths, includes, includeDirs, recordDecls, functions, literals, packagePaths) :=
(libs, libPaths, includes, includeDirs, recordDecls, functions, literals) :=
SimCodeUtil.createFunctions(p, inBackendDAE);
(simCode,_) := SimCodeUtil.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters,
className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals,Absyn.FUNCTIONARGS({},{}));
className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths, p, simSettingsOpt, recordDecls, literals,Absyn.FUNCTIONARGS({},{}));
timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE);
ExecStat.execStat("SimCode");

Expand Down Expand Up @@ -414,7 +413,7 @@ protected
list<SimCode.RecordDeclaration> recordDecls;
Absyn.ComponentRef a_cref;
tuple<Integer, HashTableExpToIndex.HashTable, list<DAE.Exp>> literals;
list<tuple<String, String>> packagePaths;
list<tuple<String, String>> program;
algorithm
if Flags.isSet(Flags.GRAPHML) then
HpcOmTaskGraph.dumpTaskGraph(inBackendDAE, filenamePrefix);
Expand All @@ -423,8 +422,8 @@ algorithm
a_cref := Absyn.pathToCref(className);
fileDir := CevalScriptBackend.getFileDir(a_cref, p);

(libs, libPaths, includes, includeDirs, recordDecls, functions, literals, packagePaths) := SimCodeUtil.createFunctions(p, inBackendDAE);
simCode := createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals, args);
(libs, libPaths, includes, includeDirs, recordDecls, functions, literals) := SimCodeUtil.createFunctions(p, inBackendDAE);
simCode := createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths, p, simSettingsOpt, recordDecls, literals, args);
timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE);
ExecStat.execStat("SimCode");

Expand Down Expand Up @@ -456,7 +455,7 @@ protected function createSimCode "
input list<String> includeDirs;
input list<String> libs;
input list<String> libPaths;
input list<tuple<String,String>> packagePaths;
input Absyn.Program program;
input Option<SimCode.SimulationSettings> simSettingsOpt;
input list<SimCode.RecordDeclaration> recordDecls;
input tuple<Integer, HashTableExpToIndex.HashTable, list<DAE.Exp>> literals;
Expand All @@ -465,15 +464,15 @@ protected function createSimCode "
input String FMUVersion="";
output SimCode.SimCode simCode;
algorithm
simCode := matchcontinue(inBackendDAE, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths, packagePaths,simSettingsOpt, recordDecls, literals, args)
simCode := matchcontinue(inBackendDAE, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths, program,simSettingsOpt, recordDecls, literals, args)
local
Integer numProc;
SimCode.SimCode tmpSimCode;

case(_, _, _, _, _, _, _, _, _, _,_, _, _, _) equation
// MULTI_RATE PARTITIONINIG
true = Flags.isSet(Flags.MULTIRATE_PARTITION);
then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals, args);
then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths, program, simSettingsOpt, recordDecls, literals, args);

case(_, _, _, _, _, _, _, _, _, _,_, _, _, _) equation
true = Flags.isSet(Flags.HPCOM);
Expand All @@ -486,7 +485,7 @@ algorithm
numProc = Flags.getConfigInt(Flags.NUM_PROC);
true = numProc == 0;
print("hpcom computes the ideal number of processors. If you want to set the number manually, use the flag +n=_ \n");
then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals, args);
then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths,program, simSettingsOpt, recordDecls, literals, args);

case(_, _, _, _, _, _, _, _, _,_, _, _, _, _) equation
true = Flags.isSet(Flags.HPCOM);
Expand All @@ -498,10 +497,10 @@ algorithm

numProc = Flags.getConfigInt(Flags.NUM_PROC);
true = (numProc > 0);
then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths,packagePaths,simSettingsOpt, recordDecls, literals, args);
then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths,program,simSettingsOpt, recordDecls, literals, args);

else equation
(tmpSimCode, _) = SimCodeUtil.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals, args, isFMU=isFMU, FMUVersion=FMUVersion);
(tmpSimCode, _) = SimCodeUtil.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths,program, simSettingsOpt, recordDecls, literals, args, isFMU=isFMU, FMUVersion=FMUVersion);
then tmpSimCode;
end matchcontinue;
end createSimCode;
Expand Down
25 changes: 2 additions & 23 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -175,7 +175,7 @@ public function createSimCode "entry point to create SimCode from BackendDAE."
input list<String> includeDirs;
input list<String> libs;
input list<String> libPaths;
input list<tuple<String,String>> packagePaths;
input Absyn.Program program;
input Option<SimCode.SimulationSettings> simSettingsOpt;
input list<SimCode.RecordDeclaration> recordDecls;
input tuple<Integer, HashTableExpToIndex.HashTable, list<DAE.Exp>> literals;
Expand Down Expand Up @@ -263,7 +263,7 @@ algorithm

backendMapping := setUpBackendMapping(inBackendDAE);
if Flags.isSet(Flags.VISUAL_XML) then
dlow := VisualXML.visualizationInfoXML(dlow, filenamePrefix, packagePaths);
dlow := VisualXML.visualizationInfoXML(dlow, filenamePrefix, program);
end if;

if Flags.isSet(Flags.ITERATION_VARS) then
Expand Down Expand Up @@ -563,7 +563,6 @@ public function createFunctions
output list<SimCode.RecordDeclaration> outRecordDecls;
output list<SimCode.Function> outFunctions;
output tuple<Integer, HashTableExpToIndex.HashTable, list<DAE.Exp>> outLiterals;
output list<tuple<String, String>> packagePaths;
protected
list<DAE.Function> funcelems;
DAE.FunctionTree functionTree;
Expand All @@ -576,32 +575,12 @@ algorithm
funcelems := Inline.inlineCallsInFunctions(funcelems, (NONE(), {DAE.NORM_INLINE(), DAE.AFTER_INDEX_RED_INLINE()}), {});
(funcelems, outLiterals as (_, _, lits)) := simulationFindLiterals(inBackendDAE, funcelems);
(outFunctions, outRecordDecls, outIncludes, outIncludeDirs, outLibs, outLibPaths) := SimCodeFunctionUtil.elaborateFunctions(inProgram, funcelems, {}, lits, {}); // Do we need metarecords here as well?
packagePaths := getPackagePathInfo(inProgram);
//GlobalScriptDump.dumpAST(inProgram);
else
Error.addInternalError("Creation of Modelica functions failed.", sourceInfo());
fail();
end try;
end createFunctions;

protected function getPackagePathInfo " Create a list of tuples which store the loaded files and their absolute paths on the system.
This is used to get the paths for resource files which are needed e.g. for animation of CAD-files.
author: vwaurich TUD 2016-10"
input Absyn.Program inProgram;
output list<tuple<String,String>> packagePaths = {}; //(packageName, absolute path)
protected
String pack, path;
Absyn.Class class_;
list<Absyn.Class> classes;
algorithm
Absyn.PROGRAM(classes) := inProgram;
for class_ in classes loop
Absyn.CLASS(name = pack, info = SOURCEINFO(fileName = path)) := class_;
packagePaths := (pack,path)::packagePaths;
//print("getPackagePathInfo "+pack+" :"+path+"\n");
end for;
end getPackagePathInfo;

protected function getParamAsserts"splits the equationArray in variable-dependent and parameter-dependent equations.
author: Waurich TUD-2015-04"
input BackendDAE.Equation eqIn;
Expand Down

0 comments on commit 1ccc53d

Please sign in to comment.