From f45d03b38e9ffac58c9845d977708dd04c4898b9 Mon Sep 17 00:00:00 2001 From: vwaurich Date: Wed, 19 Oct 2016 09:00:09 +0200 Subject: [PATCH] get absolute paths of resource files which are used for animation --- Compiler/BackEnd/VisualXML.mo | 78 +++++++++++++++++++++------- Compiler/Script/GlobalScriptDump.mo | 77 +++++++++++++++++++++++++++ Compiler/SimCode/HpcOmSimCodeMain.mo | 11 ++-- Compiler/SimCode/SimCodeMain.mo | 32 +++++++----- Compiler/SimCode/SimCodeUtil.mo | 24 ++++++++- 5 files changed, 183 insertions(+), 39 deletions(-) diff --git a/Compiler/BackEnd/VisualXML.mo b/Compiler/BackEnd/VisualXML.mo index 4d23eda6c87..4df235e2ee9 100644 --- a/Compiler/BackEnd/VisualXML.mo +++ b/Compiler/BackEnd/VisualXML.mo @@ -56,6 +56,7 @@ import List; import Util; import Tpl; import VisualXMLTpl; +import System; //---------------------------- // Visualization types @@ -87,6 +88,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> packagePaths; output BackendDAE.BackendDAE daeOut; protected BackendDAE.EqSystems eqs, eqs0; @@ -115,7 +117,7 @@ algorithm //fill theses visualization objects with information allVarLst := listAppend(globalKnownVarLst,listAppend(allVarLst,aliasVarLst)); - (visuals,_) := List.mapFold(allVisuals, fillVisualizationObjects,allVarLst); + (visuals,_,_) := List.mapFold2(allVisuals, fillVisualizationObjects,allVarLst, packagePaths); //print("\nvisuals :\n"+stringDelimitList(List.map(visuals,printVisualization),"\n")+"\n"); //dump xml file @@ -206,16 +208,18 @@ protected function fillVisualizationObjects"gets the identifier of a visualizati author:Waurich TUD 2015-04" input DAE.ComponentRef crefIn; input list allVarsIn; + input list> packagePathsIn; output Visualization visOut; output list allVarsOut; + output list> packagePathsOut; algorithm - (visOut,allVarsOut) := matchcontinue(crefIn,allVarsIn) + (visOut,allVarsOut,packagePathsOut) := matchcontinue(crefIn,allVarsIn,packagePathsIn) local String name; list nameChars,prefix; Visualization vis; list allVars; - case(_,_) + case(_,_,_) algorithm //nameChars := stringListStringChar(nameIn); //(prefix,nameChars) := List.split(nameChars,6); @@ -226,8 +230,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.fold1(allVarsIn,fillVisualizationObjects1,true,({},vis)); - then (vis,allVarsIn); + (_,vis) := List.fold2(allVarsIn,fillVisualizationObjects1,true,packagePathsIn,({},vis)); + then (vis,allVarsIn,packagePathsIn); else algorithm print("fillVisualizationObjects failed! - not yet supported type"); @@ -289,6 +293,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> packagePaths; input tuple,Visualization> tplIn; // fold output tuple,Visualization> tplOut; algorithm @@ -303,7 +308,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,vis); + vis := fillShapeObject(cref1,varIn,storeProtectedCrefs,packagePaths,vis); then (vars, vis); else algorithm @@ -312,15 +317,48 @@ algorithm end matchcontinue; end fillVisualizationObjects1; +protected function getFullCADFilePath "Get the absolute path for the given modelica uri. +author: vwaurich TUD 2016-10" + input String sIn; + input list> packagePaths; + output String sOut = sIn; +protected + String head,packName,file, path; + list 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; + end if; +end getFullCADFilePath; + +protected function packagePathEqual "find function for getFullCADFilePath +author: vwaurich TUD 2016-10" + input tuple tpl; + input String name; + output Boolean b = false; +algorithm + b := stringEqual(name,Util.tuple21(tpl)); +end packagePathEqual; + protected function fillShapeObject"sets the visualization info in the visualization object author:Waurich TUD 2015-04" input DAE.ComponentRef cref; input BackendDAE.Var var; input Boolean storeProtectedCrefs; + input list> packagePaths; input Visualization visIn; output Visualization visOut; algorithm - visOut := matchcontinue(cref,var,storeProtectedCrefs,visIn) + visOut := matchcontinue(cref,var,storeProtectedCrefs,packagePaths,visIn) local Option bind; DAE.ComponentRef ident; @@ -331,10 +369,12 @@ algorithm array color, r, lengthDir, widthDir, r_shape ; list T0; array> 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)) + 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); 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)) + 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)) algorithm if isSome(bind) then exp := if not Expression.isConstValue(Util.getOption(bind)) and storeProtectedCrefs then BackendVariable.varExp(var) else Util.getOption(bind); @@ -345,7 +385,7 @@ algorithm T := arrayUpdate(T,pos,T0); then (SHAPE(ident, shapeType, T, r, r_shape, lengthDir, widthDir, length, width, height, extra, color, specularCoeff)); - case(DAE.CREF_IDENT(ident="r", subscriptLst = {DAE.INDEX(DAE.ICONST(pos))}),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)) + case(DAE.CREF_IDENT(ident="r", subscriptLst = {DAE.INDEX(DAE.ICONST(pos))}),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)) algorithm if isSome(bind) then exp := if not Expression.isConstValue(Util.getOption(bind)) and storeProtectedCrefs then BackendVariable.varExp(var) else Util.getOption(bind); @@ -354,7 +394,7 @@ algorithm r := arrayUpdate(r,pos,exp); then (SHAPE(ident, shapeType, T, r, r_shape, lengthDir, widthDir, length, width, height, extra, color, specularCoeff)); - case(DAE.CREF_IDENT(ident="r_shape", subscriptLst = {DAE.INDEX(DAE.ICONST(pos))}),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)) + case(DAE.CREF_IDENT(ident="r_shape", subscriptLst = {DAE.INDEX(DAE.ICONST(pos))}),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)) algorithm if isSome(bind) then exp := if not Expression.isConstValue(Util.getOption(bind)) and storeProtectedCrefs then BackendVariable.varExp(var) else Util.getOption(bind); @@ -363,7 +403,7 @@ algorithm r_shape := arrayUpdate(r_shape,pos,exp); then (SHAPE(ident, shapeType, T, r, r_shape, lengthDir, widthDir, length, width, height, extra, color, specularCoeff)); - case(DAE.CREF_IDENT(ident="lengthDirection", subscriptLst = {DAE.INDEX(DAE.ICONST(pos))}),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)) + case(DAE.CREF_IDENT(ident="lengthDirection", subscriptLst = {DAE.INDEX(DAE.ICONST(pos))}),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)) algorithm if isSome(bind) then exp := if not Expression.isConstValue(Util.getOption(bind)) and storeProtectedCrefs then BackendVariable.varExp(var) else Util.getOption(bind); @@ -372,7 +412,7 @@ algorithm lengthDir := arrayUpdate(lengthDir,pos,exp); then (SHAPE(ident, shapeType, T, r, r_shape, lengthDir, widthDir, length, width, height, extra, color, specularCoeff)); - case(DAE.CREF_IDENT(ident="widthDirection", subscriptLst = {DAE.INDEX(DAE.ICONST(pos))}),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)) + case(DAE.CREF_IDENT(ident="widthDirection", subscriptLst = {DAE.INDEX(DAE.ICONST(pos))}),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)) algorithm if isSome(bind) then exp := if not Expression.isConstValue(Util.getOption(bind)) and storeProtectedCrefs then BackendVariable.varExp(var) else Util.getOption(bind); @@ -381,7 +421,7 @@ algorithm widthDir := arrayUpdate(widthDir,pos,exp); then (SHAPE(ident, shapeType, T, r, r_shape, lengthDir, widthDir, length, width, height, extra, color, specularCoeff)); - case(DAE.CREF_IDENT(ident="length"),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)) + case(DAE.CREF_IDENT(ident="length"),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)) algorithm if isSome(bind) then exp := if not Expression.isConstValue(Util.getOption(bind)) and storeProtectedCrefs then BackendVariable.varExp(var) else Util.getOption(bind); @@ -389,7 +429,7 @@ algorithm end if; then (SHAPE(ident, shapeType, T, r, r_shape, lengthDir, widthDir, exp, width, height, extra, color, specularCoeff)); - case(DAE.CREF_IDENT(ident="width"),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)) + case(DAE.CREF_IDENT(ident="width"),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)) algorithm if isSome(bind) then exp := if not Expression.isConstValue(Util.getOption(bind)) and storeProtectedCrefs then BackendVariable.varExp(var) else Util.getOption(bind); @@ -397,7 +437,7 @@ algorithm end if; then (SHAPE(ident, shapeType, T, r, r_shape, lengthDir, widthDir, length, exp, height, extra, color, specularCoeff)); - case(DAE.CREF_IDENT(ident="height"),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)) + case(DAE.CREF_IDENT(ident="height"),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)) algorithm if isSome(bind) then exp := if not Expression.isConstValue(Util.getOption(bind)) and storeProtectedCrefs then BackendVariable.varExp(var) else Util.getOption(bind); @@ -405,7 +445,7 @@ algorithm end if; then (SHAPE(ident, shapeType, T, r, r_shape, lengthDir, widthDir, length, width, exp, extra, color, specularCoeff)); - case(DAE.CREF_IDENT(ident="extra"),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)) + case(DAE.CREF_IDENT(ident="extra"),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)) algorithm if isSome(bind) then exp := if not Expression.isConstValue(Util.getOption(bind)) and storeProtectedCrefs then BackendVariable.varExp(var) else Util.getOption(bind); @@ -413,7 +453,7 @@ algorithm end if; then (SHAPE(ident, shapeType, T, r, r_shape, lengthDir, widthDir, length, width, height, exp, color, specularCoeff)); - case(DAE.CREF_IDENT(ident="color", subscriptLst = {DAE.INDEX(DAE.ICONST(pos))}),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)) + case(DAE.CREF_IDENT(ident="color", subscriptLst = {DAE.INDEX(DAE.ICONST(pos))}),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)) algorithm if isSome(bind) then exp := if not Expression.isConstValue(Util.getOption(bind)) and storeProtectedCrefs then BackendVariable.varExp(var) else Util.getOption(bind); @@ -422,7 +462,7 @@ algorithm color := arrayUpdate(color,pos,exp); then (SHAPE(ident, shapeType, T, r, r_shape, lengthDir, widthDir, length, width, height, extra, color, specularCoeff)); - case(DAE.CREF_IDENT(ident="specularCoefficient"),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)) + case(DAE.CREF_IDENT(ident="specularCoefficient"),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)) algorithm if isSome(bind) then exp := if not Expression.isConstValue(Util.getOption(bind)) and storeProtectedCrefs then BackendVariable.varExp(var) else Util.getOption(bind); diff --git a/Compiler/Script/GlobalScriptDump.mo b/Compiler/Script/GlobalScriptDump.mo index a0d4bfe99f8..00d2df2d803 100644 --- a/Compiler/Script/GlobalScriptDump.mo +++ b/Compiler/Script/GlobalScriptDump.mo @@ -77,5 +77,82 @@ algorithm end match; end printIstmtStr; +protected function loadedFileString +"author: vwaurich TUD 10-2016" + input GlobalScript.LoadedFile file; + output String s = ""; +protected + Absyn.Path p; + list paths; +algorithm + GlobalScript.FILE(classNamesQualified = paths) := file; + for p in paths loop + s := s +"\n"+ Absyn.pathString(p); + end for; +end loadedFileString; + +public function printAST +"author: vwaurich TUD 10-2016" + input Absyn.Program pr; +protected + String s=""; + Absyn.Class class_; + list classes; + Absyn.Within within_ ; +algorithm + Absyn.PROGRAM(classes, within_) := pr; + for class_ in classes loop + s := s+classString(class_)+"\n"; + end for; + print(s); +end printAST; + +protected function classString +"author: vwaurich TUD 10-2016" + input Absyn.Class cl; + output String s; +protected + Absyn.Ident id; +algorithm + Absyn.CLASS(name = id) := cl; + s := id +": "+ Absyn.classFilename(cl); +end classString; + +protected function InstantiatedClassString +"author: vwaurich TUD 10-2016" + input GlobalScript.InstantiatedClass file; + output String s="CLASS:"; +protected + Absyn.Path p; + list paths; +algorithm + GlobalScript.INSTCLASS(qualName = p) := file; + s := Absyn.pathString(p); +end InstantiatedClassString; + +public function printGlobalScript +"author: vwaurich TUD 10-2016" + input GlobalScript.SymbolTable st; +protected + list loadedFiles; + list instClsLst; + GlobalScript.InstantiatedClass cls; + GlobalScript.LoadedFile file; + Absyn.Program ast; +algorithm + loadedFiles := st.loadedFiles; + instClsLst := st.instClsLst; + ast := st.ast; + print("Loaded Files"+intString(listLength(loadedFiles))+" InstantiatedClasses:"+intString(listLength(instClsLst))+"\n"); + for file in loadedFiles loop + print(loadedFileString(file)+"\n"); + end for; + for cls in instClsLst loop + print(InstantiatedClassString(cls)+"\n"); + end for; + print("AST\n"); + printAST(ast); +end printGlobalScript; + annotation(__OpenModelica_Interface="frontend"); end GlobalScriptDump; diff --git a/Compiler/SimCode/HpcOmSimCodeMain.mo b/Compiler/SimCode/HpcOmSimCodeMain.mo index 84f537784f3..4681a3bbe10 100644 --- a/Compiler/SimCode/HpcOmSimCodeMain.mo +++ b/Compiler/SimCode/HpcOmSimCodeMain.mo @@ -82,13 +82,14 @@ public function createSimCode " input list includeDirs; input list libs; input list libPaths; + input list> packagePaths; input Option simSettingsOpt; input list recordDecls; input tuple> literals; input Absyn.FunctionArgs args; output SimCode.SimCode simCode; algorithm - simCode := matchcontinue (inBackendDAE, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths,simSettingsOpt, recordDecls, literals, args) + simCode := matchcontinue (inBackendDAE, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths,packagePaths,simSettingsOpt, recordDecls, literals, args) local Integer lastEqMappingIdx; BackendDAE.EqSystems eqs; @@ -127,7 +128,7 @@ algorithm list> partitions, activatorsForPartitions; list stateToActivators; - case (BackendDAE.DAE(eqs=_), _, _, _, _,_, _, _, _, _, _, _, _) equation + case (BackendDAE.DAE(eqs=_), _, _, _, _,_, _, _, _, _, _, _, _, _) equation // DO MULTI-RATE-PARTITIONING true = Flags.isSet(Flags.MULTIRATE_PARTITION); print("DO MULTIRATE\n"); @@ -136,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, simSettingsOpt, recordDecls, literals, args ); + externalFunctionIncludes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals, args ); //get simCode-backendDAE mappings //---------------------------- @@ -178,7 +179,7 @@ algorithm then simCode; - case (BackendDAE.DAE(eqs=eqs), _, _, _, _,_, _, _, _, _, _, _, _) equation + case (BackendDAE.DAE(eqs=eqs), _, _, _, _,_, _, _, _, _, _, _, _, _) equation // DO HPCOM PARALLELIZATION true = Flags.isSet(Flags.HPCOM); @@ -191,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, simSettingsOpt, recordDecls, literals, args ); + externalFunctionIncludes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals, args ); //get simCode-backendDAE mappings //---------------------------- diff --git a/Compiler/SimCode/SimCodeMain.mo b/Compiler/SimCode/SimCodeMain.mo index 0f529a522f5..b38dc80779f 100644 --- a/Compiler/SimCode/SimCodeMain.mo +++ b/Compiler/SimCode/SimCodeMain.mo @@ -144,14 +144,15 @@ protected Absyn.ComponentRef a_cref; list libPaths; tuple> literals; + list> 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) := + (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, SOME(simSettings), recordDecls, literals, Absyn.FUNCTIONARGS({},{}), isFMU=true, FMUVersion=FMUVersion); + className, filenamePrefix, fileDir, functions, includes, includeDirs, libs, libPaths,packagePaths, SOME(simSettings), recordDecls, literals, Absyn.FUNCTIONARGS({},{}), isFMU=true, FMUVersion=FMUVersion); timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE); ExecStat.execStat("SimCode"); @@ -189,14 +190,15 @@ protected list libPaths; Absyn.ComponentRef a_cref; tuple> literals; + list> 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) := + (libs, libPaths, includes, includeDirs, recordDecls, functions, literals, packagePaths) := SimCodeUtil.createFunctions(p, inBackendDAE); (simCode,_) := SimCodeUtil.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, - className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths, simSettingsOpt, recordDecls, literals,Absyn.FUNCTIONARGS({},{})); + className, filenamePrefix, fileDir, functions, includes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals,Absyn.FUNCTIONARGS({},{})); timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE); ExecStat.execStat("SimCode"); @@ -412,6 +414,7 @@ protected list recordDecls; Absyn.ComponentRef a_cref; tuple> literals; + list> packagePaths; algorithm if Flags.isSet(Flags.GRAPHML) then HpcOmTaskGraph.dumpTaskGraph(inBackendDAE, filenamePrefix); @@ -420,8 +423,8 @@ algorithm a_cref := Absyn.pathToCref(className); fileDir := CevalScriptBackend.getFileDir(a_cref, p); - (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, simSettingsOpt, recordDecls, literals, args); + (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); timeSimCode := System.realtimeTock(ClockIndexes.RT_CLOCK_SIMCODE); ExecStat.execStat("SimCode"); @@ -453,6 +456,7 @@ protected function createSimCode " input list includeDirs; input list libs; input list libPaths; + input list> packagePaths; input Option simSettingsOpt; input list recordDecls; input tuple> literals; @@ -461,17 +465,17 @@ protected function createSimCode " input String FMUVersion=""; output SimCode.SimCode simCode; algorithm - simCode := matchcontinue(inBackendDAE, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths,simSettingsOpt, recordDecls, literals, args) + simCode := matchcontinue(inBackendDAE, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths, packagePaths,simSettingsOpt, recordDecls, literals, args) local Integer numProc; SimCode.SimCode tmpSimCode; - case(_, _, _, _, _, _, _, _, _, _,_, _, _) equation + 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, simSettingsOpt, recordDecls, literals, args); + then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals, args); - case(_, _, _, _, _, _, _, _, _, _,_, _, _) equation + case(_, _, _, _, _, _, _, _, _, _,_, _, _, _) equation true = Flags.isSet(Flags.HPCOM); // either generate code for profiling or for parallel simulation @@ -482,9 +486,9 @@ 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, simSettingsOpt, recordDecls, literals, args); + then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs,libPaths,packagePaths, simSettingsOpt, recordDecls, literals, args); - case(_, _, _, _, _, _, _, _, _,_, _, _, _) equation + case(_, _, _, _, _, _, _, _, _,_, _, _, _, _) equation true = Flags.isSet(Flags.HPCOM); // either generate code for profiling or for parallel simulation @@ -494,10 +498,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,simSettingsOpt, recordDecls, literals, args); + then HpcOmSimCodeMain.createSimCode(inBackendDAE, inInitDAE, inUseHomotopy, inInitDAE_lambda0, inRemovedInitialEquationLst, inPrimaryParameters, inAllPrimaryParameters, inClassName, filenamePrefix, inString11, functions, externalFunctionIncludes, includeDirs, libs, libPaths,packagePaths,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, 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,packagePaths, simSettingsOpt, recordDecls, literals, args, isFMU=isFMU, FMUVersion=FMUVersion); then tmpSimCode; end matchcontinue; end createSimCode; diff --git a/Compiler/SimCode/SimCodeUtil.mo b/Compiler/SimCode/SimCodeUtil.mo index 1b577d6135f..604c2a7609d 100644 --- a/Compiler/SimCode/SimCodeUtil.mo +++ b/Compiler/SimCode/SimCodeUtil.mo @@ -175,6 +175,7 @@ public function createSimCode "entry point to create SimCode from BackendDAE." input list includeDirs; input list libs; input list libPaths; + input list> packagePaths; input Option simSettingsOpt; input list recordDecls; input tuple> literals; @@ -262,7 +263,7 @@ algorithm backendMapping := setUpBackendMapping(inBackendDAE); if Flags.isSet(Flags.VISUAL_XML) then - dlow := VisualXML.visualizationInfoXML(dlow, filenamePrefix); + dlow := VisualXML.visualizationInfoXML(dlow, filenamePrefix, packagePaths); end if; if Flags.isSet(Flags.ITERATION_VARS) then @@ -562,6 +563,7 @@ public function createFunctions output list outRecordDecls; output list outFunctions; output tuple> outLiterals; + output list> packagePaths; protected list funcelems; DAE.FunctionTree functionTree; @@ -574,12 +576,32 @@ 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> packagePaths = {}; //(packageName, absolute path) +protected + String pack, path; + Absyn.Class class_; + list 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;