Skip to content

Commit

Permalink
The "Boolean asInSimulationCode" parameter of the dumpXMLDAE() API me…
Browse files Browse the repository at this point in the history
…thod was changed in "String translationLevel".

Allowed strings are: flat, optimiser, backEnd.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5772 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Filippo Donida committed Jul 1, 2010
1 parent 8e0b9af commit a6335a6
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 41 deletions.
98 changes: 68 additions & 30 deletions Compiler/CevalScript.mo
Expand Up @@ -136,7 +136,7 @@ algorithm
Option<list<tuple<Integer, Integer, DAELow.Equation>>> jac;
Values.Value ret_val,simValue,size_value,value,v;
DAE.Exp filenameprefix,exp,starttime,stoptime,tolerance,interval,method,size_expression,
funcref,bool_exp,storeInTemp,noClean,options, asInSimulationCode,addOriginalIncidenceMatrix,
funcref,bool_exp,storeInTemp,noClean,options, translationLevel,addOriginalIncidenceMatrix,
addSolvingInfo,addMathMLCode,dumpResiduals;
Absyn.ComponentRef cr_1;
Integer size,length,rest;
Expand Down Expand Up @@ -2099,7 +2099,7 @@ algorithm
path = Absyn.IDENT(name = "dumpXMLDAE"),
expLst =
{DAE.CODE(Absyn.C_TYPENAME(className),_),
asInSimulationCode,
translationLevel,
addOriginalIncidenceMatrix,
addSolvingInfo,
addMathMLCode,
Expand All @@ -2115,7 +2115,7 @@ algorithm
local
String xml_filename,xml_contents;
equation
(cache,st,xml_filename,xml_contents) = dumpXMLDAE(cache, env, exp, st_1, msg);
(cache,st,xml_filename,xml_contents) = dumpXMLDAE(cache,env, exp, st_1, msg);
then
(cache,ValuesUtil.makeArray({Values.STRING(xml_filename),Values.STRING(xml_contents)}),st);

Expand All @@ -2125,7 +2125,7 @@ algorithm
expLst =
{
DAE.CODE(Absyn.C_TYPENAME(className),_),
asInSimulationCode,
translationLevel,
addOriginalIncidenceMatrix,
addSolvingInfo,
addMathMLCode,
Expand All @@ -2138,7 +2138,7 @@ algorithm
instClsLst = ic,
lstVarVal = iv,
compiledFunctions = cf)),msg) /* failing build_model */
then (cache,ValuesUtil.makeArray({Values.STRING("Xml dump error"),Values.STRING("")}),st_1);
then (cache,ValuesUtil.makeArray({Values.STRING("Xml dump error."),Values.STRING("")}),st_1);
end matchcontinue;
end cevalInteractiveFunctions;

Expand Down Expand Up @@ -3563,9 +3563,9 @@ algorithm
(outCache,outInteractiveSymbolTable3,xml_filename,xml_contents):=
matchcontinue (inCache,inEnv,inExp,inInteractiveSymbolTable,inMsg)
local
Boolean cdToTemp,asInSimulationCode;
Boolean cdToTemp;
Real starttime_r,stoptime_r,interval_r,tolerance_r;
String file_dir,cname_str,init_filename,method_str,filenameprefix,makefilename,oldDir,tempDir;
String file_dir,cname_str,init_filename,method_str,filenameprefix,makefilename,oldDir,tempDir,translationLevel;
list<SCode.Class> sp;
list<Interactive.InstantiatedClass> ic;
list<Interactive.InteractiveVariable> iv;
Expand All @@ -3580,24 +3580,25 @@ algorithm
Interactive.InteractiveSymbolTable st,st_1;
Ceval.Msg msg;
Values.Value ret_val;

case (cache,env,(exp as DAE.CALL(path = Absyn.IDENT(name = _),
expLst = {DAE.CODE(Absyn.C_TYPENAME(classname),_),DAE.BCONST(bool=true),addOriginalIncidenceMatrix,addSolvingInfo,addMathMLCode,dumpResiduals,fileprefix,storeInTemp})),
expLst = {DAE.CODE(Absyn.C_TYPENAME(classname),_),DAE.SCONST(string=translationLevel),addOriginalIncidenceMatrix,addSolvingInfo,addMathMLCode,dumpResiduals,fileprefix,storeInTemp})),
(st_1 as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg)
local
Boolean x;
Integer[:] ass1,ass2;
DAE.DAElist dae_1,dae;
DAELow.DAELow dlow,dlow_1,indexed_dlow,indexed_dlow_1;
DAELow.DAELow dlow;
list<Integer>[:] m,mT;
list<DAE.Element> dael;
list<Interactive.InstantiatedClass> ic_1,ic;
list<SCode.Class> p_1,sp;
list<list<Integer>> comps;
list<Absyn.Path> funcpaths;
list<DAE.Element> funcelems;
DAE.FunctionTree funcs;
equation
//asInSimulationCode==true => it's necessary to do all the translation's steps before dumping with xml
//translationLevel=DAE.SCONST(string="flat")
true=stringEqual(translationLevel,"flat");
_ = Error.getMessagesStr() "Clear messages";
(cache,Values.BOOL(cdToTemp),SOME(st)) = Ceval.ceval(cache,env, storeInTemp, true, SOME(st_1), NONE, msg);
oldDir = System.pwd();
Expand All @@ -3608,29 +3609,21 @@ algorithm
(cache,env,_,dae_1) = Inst.instantiateClass(cache, InnerOuter.emptyInstHierarchy, p_1, classname);
dae = DAEUtil.transformIfEqToExpr(dae_1,false);
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(classname,dae,env));
dlow = DAELow.lower(dae, true, true);
m = DAELow.incidenceMatrix(dlow);
mT = DAELow.transposeMatrix(m);
funcs = DAEUtil.daeFunctionTree(dae);
(ass1,ass2,dlow_1,m,mT) = DAELow.matchingAlgorithm(dlow, m, mT, (DAELow.INDEX_REDUCTION(),DAELow.EXACT(), DAELow.REMOVE_SIMPLE_EQN()),funcs);
// late Inline
dlow_1 = Inline.inlineCalls(NONE(),SOME(funcs),{DAE.NORM_INLINE(),DAE.AFTER_INDEX_RED_INLINE()},dlow_1);
(comps) = DAELow.strongComponents(m, mT, ass1, ass2);
indexed_dlow = DAELow.translateDae(dlow_1,NONE());
indexed_dlow_1 = DAELow.calculateValues(indexed_dlow);
dlow = DAELow.lower(dae, true, true);//Verificare cosa fa
xml_filename = Util.stringAppendList({filenameprefix,".xml"});
funcpaths = SimCode.getCalledFunctions(dae, indexed_dlow_1);
funcpaths = SimCode.getCalledFunctions(dae, dlow);
funcelems = SimCode.generateFunctions2(p_1, funcpaths);
Print.clearBuf();
XMLDump.dumpDAELow(indexed_dlow_1,funcpaths,funcelems,addOriginalIncidenceMatrix,addSolvingInfo,addMathMLCode,dumpResiduals);
XMLDump.dumpDAELow(dlow,funcpaths,funcelems,addOriginalIncidenceMatrix,addSolvingInfo,addMathMLCode,dumpResiduals);
xml_contents = Print.getString();
Print.clearBuf();
System.writeFile(xml_filename,xml_contents);
then
(cache,st,xml_contents,stringAppend("The model has been dumped to xml file: ",xml_filename));

case (cache,env,(exp as DAE.CALL(path = Absyn.IDENT(name = _),
expLst = {DAE.CODE(Absyn.C_TYPENAME(classname),_),DAE.BCONST(bool=false),addOriginalIncidenceMatrix,addSolvingInfo,addMathMLCode,dumpResiduals,fileprefix,storeInTemp})),
expLst = {DAE.CODE(Absyn.C_TYPENAME(classname),_),DAE.SCONST(string=translationLevel),
addOriginalIncidenceMatrix,addSolvingInfo,addMathMLCode,dumpResiduals,fileprefix,storeInTemp})),
(st_1 as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg)
local
Boolean x;
Expand All @@ -3642,9 +3635,10 @@ algorithm
list<SCode.Class> p_1,sp;
list<Absyn.Path> funcpaths;
list<DAE.Element> funcelems;
DAE.FunctionTree funcs;
equation
//translationLevel=DAE.SCONST(string="optimiser")
//asInSimulationCode==false => it's NOT necessary to do all the translation's steps before dumping with xml
true=stringEqual(translationLevel,"optimiser");
_ = Error.getMessagesStr() "Clear messages";
(cache,Values.BOOL(cdToTemp),SOME(st)) = Ceval.ceval(cache,env, storeInTemp, true, SOME(st_1), NONE, msg);
oldDir = System.pwd();
Expand All @@ -3658,10 +3652,7 @@ algorithm
dlow = DAELow.lower(dae, true, true);
m = DAELow.incidenceMatrix(dlow);
mT = DAELow.transposeMatrix(m);
funcs = DAEUtil.daeFunctionTree(dae);
(_,_,dlow_1,m,mT) = DAELow.matchingAlgorithm(dlow, m, mT, (DAELow.INDEX_REDUCTION(),DAELow.EXACT(), DAELow.REMOVE_SIMPLE_EQN()),funcs);
// late Inline
dlow_1 = Inline.inlineCalls(NONE(),SOME(funcs),{DAE.NORM_INLINE(),DAE.AFTER_INDEX_RED_INLINE()},dlow_1);
(_,_,dlow_1,m,mT) = DAELow.matchingAlgorithm(dlow, m, mT, (DAELow.INDEX_REDUCTION(),DAELow.EXACT(), DAELow.REMOVE_SIMPLE_EQN()),DAEUtil.daeFunctionTree(dae));
xml_filename = Util.stringAppendList({filenameprefix,".xml"});
funcpaths = SimCode.getCalledFunctions(dae, dlow_1);
funcelems = SimCode.generateFunctions2(p_1, funcpaths);
Expand All @@ -3672,6 +3663,53 @@ algorithm
System.writeFile(xml_filename,xml_contents);
then
(cache,st,xml_contents,stringAppend("The model has been dumped to xml file: ",xml_filename));

case (cache,env,(exp as DAE.CALL(path = Absyn.IDENT(name = _),
expLst = {DAE.CODE(Absyn.C_TYPENAME(classname),_),DAE.SCONST(string=translationLevel),addOriginalIncidenceMatrix,addSolvingInfo,addMathMLCode,dumpResiduals,fileprefix,storeInTemp})),
(st_1 as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg)
local
Boolean x;
Integer[:] ass1,ass2;
DAE.DAElist dae_1,dae;
DAELow.DAELow dlow,dlow_1,indexed_dlow,indexed_dlow_1;
list<Integer>[:] m,mT;
list<DAE.Element> dael;
list<Interactive.InstantiatedClass> ic_1,ic;
list<SCode.Class> p_1,sp;
list<list<Integer>> comps;
list<Absyn.Path> funcpaths;
list<DAE.Element> funcelems;
equation
//translationLevel=DAE.SCONST(string="backEnd")
//asInSimulationCode==true => it's necessary to do all the translation's steps before dumping with xml
true=stringEqual(translationLevel,"backEnd");
_ = Error.getMessagesStr() "Clear messages";
(cache,Values.BOOL(cdToTemp),SOME(st)) = Ceval.ceval(cache,env, storeInTemp, true, SOME(st_1), NONE, msg);
oldDir = System.pwd();
changeToTempDirectory(cdToTemp);
(cache,filenameprefix) = extractFilePrefix(cache,env, fileprefix, st, msg);
cname_str = Absyn.pathString(classname);
p_1 = SCodeUtil.translateAbsyn2SCode(p);
(cache,env,_,dae_1) = Inst.instantiateClass(cache, InnerOuter.emptyInstHierarchy, p_1, classname);
dae = DAEUtil.transformIfEqToExpr(dae_1,false);
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(classname,dae,env));
dlow = DAELow.lower(dae, true, true);
m = DAELow.incidenceMatrix(dlow);
mT = DAELow.transposeMatrix(m);
(ass1,ass2,dlow_1,m,mT) = DAELow.matchingAlgorithm(dlow, m, mT, (DAELow.INDEX_REDUCTION(),DAELow.EXACT(), DAELow.REMOVE_SIMPLE_EQN()),DAEUtil.daeFunctionTree(dae));
(comps) = DAELow.strongComponents(m, mT, ass1, ass2);
indexed_dlow = DAELow.translateDae(dlow_1,NONE());
indexed_dlow_1 = DAELow.calculateValues(indexed_dlow);
xml_filename = Util.stringAppendList({filenameprefix,".xml"});
funcpaths = SimCode.getCalledFunctions(dae, indexed_dlow_1);
funcelems = SimCode.generateFunctions2(p_1, funcpaths);
Print.clearBuf();
XMLDump.dumpDAELow(indexed_dlow_1,funcpaths,funcelems,addOriginalIncidenceMatrix,addSolvingInfo,addMathMLCode,dumpResiduals);
xml_contents = Print.getString();
Print.clearBuf();
System.writeFile(xml_filename,xml_contents);
then
(cache,st,xml_contents,stringAppend("The model has been dumped to xml file: ",xml_filename));
case (_,_,_,_,_)
then
fail();
Expand Down
26 changes: 15 additions & 11 deletions Compiler/Static.mo
Expand Up @@ -7620,33 +7620,37 @@ protected function elabCallInteractive "function: elabCallInteractive
className = Absyn.crefToPath(cr);
then (cache,DAE.CALL(Absyn.IDENT("checkExamplePackages"),{DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER()), DAE.SCONST(str)},false,true,DAE.ET_STRING(),DAE.NO_INLINE),DAE.PROP(DAE.T_BOOL_DEFAULT,DAE.C_CONST()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "dumpXMLDAE"),{Absyn.CREF(componentRef = cr)},args,impl,SOME(st))
local Absyn.Path className; DAE.Exp storeInTemp,asInSimulationCode,addOriginalIncidenceMatrix,addSolvingInfo,addMathMLCode,dumpResiduals;

case (cache,env,Absyn.CREF_IDENT(name = "dumpXMLDAE"),{Absyn.CREF(componentRef = cr)},args,impl,SOME(st))
local
Absyn.Path className;
DAE.Exp storeInTemp,translationLevel,addOriginalIncidenceMatrix,addSolvingInfo,addMathMLCode,dumpResiduals;
equation
className = Absyn.crefToPath(cr);
cname_str = Absyn.pathString(className);
(cache,asInSimulationCode) = getOptionalNamedArg(cache,env, SOME(st), impl, "asInSimulationCode",
DAE.T_BOOL_DEFAULT, args, DAE.BCONST(false));
(cache,translationLevel) = getOptionalNamedArg(cache, env, SOME(st), impl, "translationLevel",
DAE.T_STRING_DEFAULT, args, DAE.SCONST("flat"));
(cache,addOriginalIncidenceMatrix) = getOptionalNamedArg(cache,env, SOME(st), impl, "addOriginalIncidenceMatrix",
DAE.T_BOOL_DEFAULT, args, DAE.BCONST(false));
DAE.T_BOOL_DEFAULT, args, DAE.BCONST(false));
(cache,addSolvingInfo) = getOptionalNamedArg(cache,env, SOME(st), impl, "addSolvingInfo",
DAE.T_BOOL_DEFAULT, args, DAE.BCONST(false));
DAE.T_BOOL_DEFAULT, args, DAE.BCONST(false));
(cache,addMathMLCode) = getOptionalNamedArg(cache,env, SOME(st), impl, "addMathMLCode",
DAE.T_BOOL_DEFAULT, args, DAE.BCONST(false));
DAE.T_BOOL_DEFAULT, args, DAE.BCONST(false));
(cache,dumpResiduals) = getOptionalNamedArg(cache,env, SOME(st), impl, "dumpResiduals",
DAE.T_BOOL_DEFAULT, args, DAE.BCONST(false));
DAE.T_BOOL_DEFAULT, args, DAE.BCONST(false));
(cache,filenameprefix) = getOptionalNamedArg(cache,env, SOME(st), impl, "fileNamePrefix",
DAE.T_STRING_DEFAULT, args, DAE.SCONST(cname_str));
DAE.T_STRING_DEFAULT, args, DAE.SCONST(cname_str));
(cache,storeInTemp) = getOptionalNamedArg(cache,env, SOME(st), impl, "storeInTemp",
DAE.T_BOOL_DEFAULT, args, DAE.BCONST(false));
DAE.T_BOOL_DEFAULT, args, DAE.BCONST(false));
then
(cache,DAE.CALL(Absyn.IDENT("dumpXMLDAE"),
{DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER()),asInSimulationCode,addOriginalIncidenceMatrix,addSolvingInfo,addMathMLCode,dumpResiduals,filenameprefix,storeInTemp},false,true,DAE.ET_OTHER(),DAE.NO_INLINE),DAE.PROP(
{DAE.CODE(Absyn.C_TYPENAME(className),DAE.ET_OTHER()),translationLevel,addOriginalIncidenceMatrix,addSolvingInfo,addMathMLCode,dumpResiduals,filenameprefix,storeInTemp},false,true,DAE.ET_OTHER(),DAE.NO_INLINE),DAE.PROP(
(
DAE.T_ARRAY(DAE.DIM(SOME(2)),DAE.T_STRING_DEFAULT),NONE),DAE.C_VAR()),SOME(st));
end matchcontinue;
end elabCallInteractive;


protected function elabVariablenames "function: elabVariablenames
This function elaborates variablenames to DAE.Exp. A variablename can
be used in e.g. plot(model,{v1{3},v2.t}) It should only be used in interactive
Expand Down

0 comments on commit a6335a6

Please sign in to comment.