From 0aa00ea2edd5f033eed1d574564c3d7c1c80ff31 Mon Sep 17 00:00:00 2001 From: Jens Frenkel Date: Mon, 4 Apr 2011 15:16:31 +0000 Subject: [PATCH] - Bugfix removeSimpleEquationsX - Bugfix initialisation c_runtime windows - Util: bugfix arrayMapNoCopy_1 - add testcase testsimulate git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8487 f25d12d1-65f4-0310-ae8a-bbce733d8d8e --- Compiler/BackEnd/BackendDAEOptimize.mo | 2 +- Compiler/BackEnd/BackendDump.mo | 37 +++++++++++++++++++++---- Compiler/BackEnd/BackendVarTransform.mo | 6 +++- Compiler/Util/Util.mo | 6 ++-- Makefile.common | 3 ++ c_runtime/simulation_init.cpp | 7 +++-- 6 files changed, 48 insertions(+), 13 deletions(-) diff --git a/Compiler/BackEnd/BackendDAEOptimize.mo b/Compiler/BackEnd/BackendDAEOptimize.mo index f595afa662b..93ee4028fc3 100644 --- a/Compiler/BackEnd/BackendDAEOptimize.mo +++ b/Compiler/BackEnd/BackendDAEOptimize.mo @@ -1689,7 +1689,7 @@ algorithm (es,{}) = ExpressionSolve.solve(e1,e2,cre); // constant or alias (dae1,newvars,newvars1) = constOrAlias(var,cr,es,dae,mvars,mavars); - then (cr,i,es,dae1,newvars,mavars); + then (cr,i,es,dae1,newvars,newvars1); // a = b case({i,j},length,pos,dae,mvars,mavars) equation pos_1 = pos-1; diff --git a/Compiler/BackEnd/BackendDump.mo b/Compiler/BackEnd/BackendDump.mo index ab8c45d3e81..8375657accd 100644 --- a/Compiler/BackEnd/BackendDump.mo +++ b/Compiler/BackEnd/BackendDump.mo @@ -1065,8 +1065,9 @@ algorithm local Option min,max,start,fixed,nominal; String snominal; + Option isProtected; case NONE() then (); - case SOME(DAE.VAR_ATTR_REAL(min=(min,max),initial_=start,fixed=fixed,nominal=nominal)) + case SOME(DAE.VAR_ATTR_REAL(min=(min,max),initial_=start,fixed=fixed,nominal=nominal,isProtected=isProtected)) equation print("("); dumpOptExpression(min,"min"); @@ -1074,37 +1075,42 @@ algorithm dumpOptExpression(start,"start"); dumpOptExpression(fixed,"fixed"); dumpOptExpression(nominal,"nominal"); + dumpOptBoolean(isProtected,"protected"); print(") "); then (); - case SOME(DAE.VAR_ATTR_INT(min=(min,max),initial_=start,fixed=fixed)) + case SOME(DAE.VAR_ATTR_INT(min=(min,max),initial_=start,fixed=fixed,isProtected=isProtected)) equation print("("); dumpOptExpression(min,"min"); dumpOptExpression(max,"max"); dumpOptExpression(start,"start"); dumpOptExpression(fixed,"fixed"); + dumpOptBoolean(isProtected,"protected"); print(") "); then (); - case SOME(DAE.VAR_ATTR_BOOL(initial_=start,fixed=fixed)) + case SOME(DAE.VAR_ATTR_BOOL(initial_=start,fixed=fixed,isProtected=isProtected)) equation print("("); dumpOptExpression(start,"start"); dumpOptExpression(fixed,"fixed"); + dumpOptBoolean(isProtected,"protected"); print(") "); then (); - case SOME(DAE.VAR_ATTR_STRING(initial_=start)) + case SOME(DAE.VAR_ATTR_STRING(initial_=start,isProtected=isProtected)) equation print("("); dumpOptExpression(start,"start"); + dumpOptBoolean(isProtected,"protected"); print(") "); then (); - case SOME(DAE.VAR_ATTR_ENUMERATION(min=(min,max),start=start,fixed=fixed)) + case SOME(DAE.VAR_ATTR_ENUMERATION(min=(min,max),start=start,fixed=fixed,isProtected=isProtected)) equation print("("); dumpOptExpression(min,"min"); dumpOptExpression(max,"max"); dumpOptExpression(start,"start"); dumpOptExpression(fixed,"fixed"); + dumpOptBoolean(isProtected,"protected"); print(") "); then (); else (); @@ -1132,6 +1138,27 @@ algorithm end match; end dumpOptExpression; +protected function dumpOptBoolean +"function: dumpOptBoolean + Helper function to dump." + input Option inExp; + input String inString; +algorithm + _:= + match (inExp,inString) + local + Boolean e; + String s,se,str; + case (SOME(e),s) + equation + se = boolString(e); + str = stringAppendList({s," = ",se," "}); + print(str); + then (); + else (); + end match; +end dumpOptBoolean; + public function dumpIncidenceMatrix "function: dumpIncidenceMatrix author: PA diff --git a/Compiler/BackEnd/BackendVarTransform.mo b/Compiler/BackEnd/BackendVarTransform.mo index ec9e933d1cf..157b54e113f 100644 --- a/Compiler/BackEnd/BackendVarTransform.mo +++ b/Compiler/BackEnd/BackendVarTransform.mo @@ -91,11 +91,15 @@ algorithm case (((BackendDAE.ALGORITHM(index=indx,in_=expl,out=expl1,source = source)) :: es),repl) equation + expl = Util.listMap2(expl,VarTransform.replaceExp,repl,NONE()); + expl = Util.listMap(expl,ExpressionSimplify.simplify); + expl2 = Util.listMap2(expl1,VarTransform.replaceExp,repl,NONE()); + expl2 = Util.listMap(expl2,ExpressionSimplify.simplify); // original algorithm is done by replaceAlgorithms // inputs and ouputs are updated from DEALow.updateAlgorithmInputsOutputs es_1 = replaceEquations(es, repl); then - (BackendDAE.ALGORITHM(indx,expl,expl1,source) :: es_1); + (BackendDAE.ALGORITHM(indx,expl,expl2,source) :: es_1); case ((BackendDAE.SOLVED_EQUATION(componentRef = cr,exp = e,source = source) :: es),repl) equation diff --git a/Compiler/Util/Util.mo b/Compiler/Util/Util.mo index dc680e31643..9c237a791e3 100644 --- a/Compiler/Util/Util.mo +++ b/Compiler/Util/Util.mo @@ -1119,9 +1119,7 @@ See also listMap, arrayMap output tuple outTpl; end FuncType; algorithm - outArray := array; - outArg := inArg; -// (outArray,outArg) := arrayMapNoCopyHelp1_1(array,func,1,arrayLength(array),inArg); + (outArray,outArg) := arrayMapNoCopyHelp1_1(array,func,1,arrayLength(array),inArg); end arrayMapNoCopy_1; protected function arrayMapNoCopyHelp1_1 "help function to arrayMap" @@ -1153,7 +1151,7 @@ algorithm ((newElt,extarg)) = func((inArray[pos],inArg)); a = arrayUpdate(inArray,pos,newElt); (a1,extarg1) = arrayMapNoCopyHelp1_1(a,func,pos+1,len,extarg); - then (a1,extarg); + then (a1,extarg1); end matchcontinue; end arrayMapNoCopyHelp1_1; diff --git a/Makefile.common b/Makefile.common index 77ab433a91f..afc30df10df 100644 --- a/Makefile.common +++ b/Makefile.common @@ -57,6 +57,9 @@ testlog: testmos: (cd testsuite/mosfiles; time $(MAKE) -f Makefile) +testsimulation: + (cd testsuite; time $(MAKE) -f Makefile simulation) + testmo: (cd testsuite/mofiles; time $(MAKE) -f Makefile test) diff --git a/c_runtime/simulation_init.cpp b/c_runtime/simulation_init.cpp index 53f8314e91b..7151b722f59 100644 --- a/c_runtime/simulation_init.cpp +++ b/c_runtime/simulation_init.cpp @@ -186,8 +186,11 @@ int simplex_initialization(long& nz,double *z) } if (IFAULT == 1) { - printf("Error in initialization. Solver iterated %d times without finding a solution\n",(int)MAXF); - return -1; + leastSquare(&nz,z,&funcValue); + if (funcValue > SIMP) { + printf("Error in initialization. Solver iterated %d times without finding a solution\n",(int)MAXF); + return -1; + } } else if(IFAULT == 2 ) { printf("Error in initialization. Inconsistent initial conditions.\n"); return -1;