Skip to content

Commit

Permalink
- the latest updates for DAEQuery.mo [exportDAEtoMatlab API]
Browse files Browse the repository at this point in the history
  used by Olof Bäck [ISY] and Daniel Gunnarsson [IEI].

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@3219 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Feb 20, 2008
1 parent 4f47921 commit 421ebaa
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
11 changes: 9 additions & 2 deletions Compiler/Ceval.mo
Expand Up @@ -3177,7 +3177,9 @@ algorithm
Exp.Exp fileprefix;
Env.Cache cache;
Integer elimLevel;
case (cache,env,className,(st as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg,fileprefix) /* mo file directory */
case (cache,env,className,(st as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg,fileprefix) /* mo file directory */
local
String flatModelicaStr;
equation
(cache,filenameprefix) = extractFilePrefix(cache,env, fileprefix, st, msg);
p_1 = SCode.elaborate(p);
Expand All @@ -3190,7 +3192,12 @@ algorithm
RTOpts.setEliminationLevel(0); // No variable eliminiation
dlow = DAELow.lower(dae, false, false);
RTOpts.setEliminationLevel(elimLevel); // Reset elimination level
filename = DAEQuery.writeIncidenceMatrix(dlow, filenameprefix);
flatModelicaStr = DAE.dumpStr(dae);
flatModelicaStr = stringAppend("EqStr={'", flatModelicaStr);
flatModelicaStr = System.stringReplace(flatModelicaStr, "\n", "%##%");
flatModelicaStr = System.stringReplace(flatModelicaStr, "%##%", "','");
flatModelicaStr = stringAppend(flatModelicaStr,"'}");
filename = DAEQuery.writeIncidenceMatrix(dlow, filenameprefix, flatModelicaStr);
str = stringAppend("The equation system was dumped to Matlab file:", filename);
then
(cache,Values.STRING(str),st,file_dir);
Expand Down
48 changes: 41 additions & 7 deletions Compiler/DAEQuery.mo
Expand Up @@ -50,19 +50,20 @@ import RTOpts;
public function writeIncidenceMatrix
input DAELow.DAELow dlow;
input String fileNamePrefix;
input String flatModelicaStr;
output String fileName;
algorithm
fileName := matchcontinue(dlow, fileNamePrefix)
fileName := matchcontinue(dlow, fileNamePrefix, flatModelicaStr)
local
String file, strIMatrix, strVariables;
String file, strIMatrix, strVariables, flatStr;
list<String>[:] m;
case (dlow, fileNamePrefix)
case (dlow, fileNamePrefix, flatStr)
equation
file = stringAppend(fileNamePrefix, "_imatrix.m");
m = incidenceMatrix(dlow);
strIMatrix = getIncidenceMatrix(m);
strVariables = getVariables(dlow);
strIMatrix = Util.stringAppendList({strIMatrix, "\n", strVariables});
strIMatrix = Util.stringAppendList({strIMatrix, "\n", strVariables, "\n\n\n", flatStr});
System.writeFile(file, strIMatrix);
then
file;
Expand Down Expand Up @@ -678,13 +679,38 @@ algorithm
pStr = {ss};
then
pStr;
// if-expressions with different conditions than relations
// if-expressions with a variable
case (Exp.IFEXP(expCond = e1 as Exp.CREF(componentRef = cref1),expThen = e2,expElse = e3),vars) /* if expressions. */
local String ss,sb;
String ss, ss1, ss2, ss3;
Exp.ComponentRef cref1;
equation
sb = printExpStr(e1);
s1 = incidenceRowExp(e1, vars);
ss1 = getIncidenceRow(s1);
s2 = incidenceRowExp(e2, vars);
ss2 = getIncidenceRow(s2);
s3 = incidenceRowExp(e3, vars);
ss3 = getIncidenceRow(s3);
ss = Util.stringAppendList({"{'if', ","'", sb, "' {",ss1,"}",",{", ss2, "},", ss3, "}"});
pStr = {ss};
then
pStr;
// if-expressions with any other alternative than what we handled until now
case (Exp.IFEXP(expCond = e1,expThen = e2,expElse = e3),vars) /* if expressions. */
local String ss,sb;
String ss, ss1, ss2, ss3;
Exp.ComponentRef cref1;
equation
sb = printExpStr(e1);
s1 = incidenceRowExp(e1, vars);
ss1 = getIncidenceRow(s1);
s2 = incidenceRowExp(e2, vars);
ss2 = getIncidenceRow(s2);
s3 = incidenceRowExp(e3, vars);
pStr = Util.listFlatten({s1,s2,s3});
ss3 = getIncidenceRow(s3);
ss = Util.stringAppendList({"{'if', ","'", sb, "' {",ss1,"}",",{", ss2, "},", ss3, "}"});
pStr = {ss};
then
pStr;
case (Exp.CALL(path = Absyn.IDENT(name = "der"),expLst = {Exp.CREF(componentRef = cr)}),vars)
Expand All @@ -699,7 +725,15 @@ algorithm
pStr = Util.listMap(p, intString);
then
{};
case (Exp.CALL(path = Absyn.IDENT(name = "pre"),expLst = {Exp.CREF(componentRef = cr)}),vars) then {}; /* pre(v) is considered a known variable */
case (Exp.CALL(path = Absyn.IDENT(name = "pre"),expLst = {Exp.CREF(componentRef = cr)}),vars) /* pre(v) is considered a known variable */ //IS IT????
local String ss;
equation
(_,p) = DAELow.getVar(cr, vars);
pStr = Util.listMap(p, intString);
//ss = printExpStr(cr, vars);
//pStr = ss;
then
pStr;
case (Exp.CALL(expLst = expl),vars)
equation
lst = Util.listMap1(expl, incidenceRowExp, vars);
Expand Down

0 comments on commit 421ebaa

Please sign in to comment.