Changeset 17340ed in OpenModelica
- Timestamp:
- 2016-04-03T23:16:21+02:00 (8 years ago)
- Branches:
- Added-citation-metadata, maintenance/v1.14, maintenance/v1.15, maintenance/v1.16, maintenance/v1.17, maintenance/v1.18, maintenance/v1.19, maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, maintenance/v1.23, master, omlib-staging
- Children:
- a2edcfd
- Parents:
- d7ed464
- git-author:
- vruge <vruge@…> (04/03/16 23:16:21)
- git-committer:
- hudson <openmodelica@…> (04/03/16 23:16:21)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Compiler/BackEnd/BackendDAEOptimize.mo
r7eb2bd0 r17340ed 4153 4153 // 4154 4154 // e.g. (a,-b) = f(.) -> (a,c) = f(.) with c = -b 4155 // (a,b) = (c,d) -> a=c and b = d 4156 // {a,b} = {c,d} -> a=c and b = d 4155 4157 // (a,b) = f(a) fixed iterration var 4156 4158 // author: Vitalij Ruge 4157 4159 // ============================================================================= 4158 4160 4161 4159 4162 public function simplifyComplexFunction 4160 4163 input BackendDAE.BackendDAE inDAE; 4164 output BackendDAE.BackendDAE outDAE; 4165 algorithm 4166 outDAE := simplifyComplexFunction1(inDAE, true); 4167 end simplifyComplexFunction; 4168 4169 public function simplifyComplexFunction1 4170 input BackendDAE.BackendDAE inDAE; 4171 input Boolean withTmpVars = false; 4161 4172 output BackendDAE.BackendDAE outDAE = inDAE; 4162 4173 protected … … 4184 4195 case BackendDAE.SHARED(backendDAEType=BackendDAE.SIMULATION()) then "$OMC$CF$sim"; 4185 4196 case BackendDAE.SHARED(backendDAEType=BackendDAE.INITIALSYSTEM()) then "$OMC$CF$init"; 4186 else fail();4197 else "$OMC$CF$unknown"; 4187 4198 end match; 4188 4199 4189 4200 for syst in inDAE.eqs loop 4201 indRemove := {}; 4190 4202 BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns) := syst; 4191 4203 BackendDAE.EQUATION_ARRAY(numberOfElement = n) := eqns; 4192 4204 update := false; 4193 indRemove := {}; 4205 indRemove := {}; 4206 4194 4207 for i in 1:n loop 4195 eqn := BackendEquation.equationNth1(eqns, i); 4196 if BackendEquation.isComplexEquation(eqn) then 4197 BackendDAE.COMPLEX_EQUATION(left=left, right=right, size=size, attr= attr, source=source) := eqn; 4208 try 4209 eqn := BackendEquation.equationNth1(eqns, i); 4210 else 4211 continue; 4212 end try; 4213 if BackendEquation.isComplexEquation(eqn) or BackendEquation.isArrayEquation(eqn) then 4214 if BackendEquation.isComplexEquation(eqn) then 4215 BackendDAE.COMPLEX_EQUATION(size=size,left=left, right=right, attr= attr, source=source) := eqn; 4216 else 4217 BackendDAE.ARRAY_EQUATION(left=left, right=right, attr= attr, source=source) := eqn; 4218 end if; 4219 4198 4220 if Expression.isTuple(left) and Expression.isTuple(right) then // tuple() = tuple() 4199 4221 //print(BackendDump.equationString(eqn) + "--In--\n"); … … 4222 4244 end if; // isWild 4223 4245 end for; 4224 elseif Expression.isTuple(left) and Expression.isCall(right) then //tuple() = call() 4225 DAE.TUPLE(PR = left_lst) := left; 4226 DAE.CALL(path=path,expLst = expLst, attr= cattr) := right; 4227 expLst := {}; 4228 for e1 in left_lst loop 4229 if Expression.isCref(e1) then 4230 DAE.CREF(componentRef = cr) := e1; 4231 if Expression.expHasCrefNoPreOrStart(right, cr) then 4232 update := true; 4233 cr := ComponentReference.makeCrefIdent(tmpVarPrefix + intString(idx), Expression.typeof(e1) , {}); 4234 idx := idx + 1; 4235 e := Expression.crefExp(cr); 4236 tmpvar := BackendVariable.makeVar(cr); 4237 tmpvar := BackendVariable.setVarTS(tmpvar,SOME(BackendDAE.AVOID())); 4238 vars := BackendVariable.addVar(tmpvar, vars); 4239 4240 eqn1 := BackendDAE.EQUATION(e, e1, DAE.emptyElementSource, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC); 4241 eqns := BackendEquation.addEquation(eqn1, eqns); 4242 else 4243 e := e1; 4244 end if; 4246 elseif Expression.isArray(left) and Expression.isArray(right) 4247 then // array{} = array{} // not work with arrayType 4248 //print(BackendDump.equationString(eqn) + "--In--\n"); 4249 try 4250 left_lst := Expression.getArrayOrRangeContents(left); 4251 right_lst := Expression.getArrayOrRangeContents(right); 4252 update := true; 4253 indRemove := i :: indRemove; 4254 for e1 in left_lst loop 4255 e2 :: right_lst := right_lst; 4256 //print("=>" + ExpressionDump.printExpStr(e2) + " = " + ExpressionDump.printExpStr(e1) + "\n"); 4257 if not Expression.isWild(e1) then 4258 if Expression.isScalar(e2) then 4259 eqn1 := BackendEquation.generateEquation(e1, e2, source, attr); 4260 eqns := BackendEquation.addEquation(eqn1, eqns); 4261 //print(BackendDump.equationString(eqn1) + "--new--\n"); 4262 else 4263 expLst := simplifyComplexFunction2(e1); 4264 arrayLst := simplifyComplexFunction2(e2); 4265 for e_asub in arrayLst loop 4266 e3 :: expLst := expLst; 4267 eqn1 := BackendEquation.generateEquation(e_asub, e3, source, attr); 4268 eqns := BackendEquation.addEquation(eqn1, eqns); 4269 //print(BackendDump.equationString(eqn1) + "--new--\n"); 4270 end for; 4271 end if; //isScalar 4272 end if; // isWild 4273 end for; 4274 else 4275 continue; 4276 end try; 4277 elseif withTmpVars and Expression.isTuple(left) and Expression.isCall(right) //tuple() = call() 4278 then 4279 DAE.TUPLE(PR = left_lst) := left; 4280 DAE.CALL(path=path,expLst = expLst, attr= cattr) := right; 4281 expLst := {}; 4282 for e1 in left_lst loop 4283 if Expression.isCref(e1) then 4284 DAE.CREF(componentRef = cr) := e1; 4285 if Expression.expHasCrefNoPreOrStart(right, cr) then 4286 update := true; 4287 cr := ComponentReference.makeCrefIdent(tmpVarPrefix + intString(idx), Expression.typeof(e1) , {}); 4288 idx := idx + 1; 4289 e := Expression.crefExp(cr); 4290 tmpvar := BackendVariable.makeVar(cr); 4291 tmpvar := BackendVariable.setVarTS(tmpvar,SOME(BackendDAE.AVOID())); 4292 vars := BackendVariable.addVar(tmpvar, vars); 4293 4294 eqn1 := BackendDAE.EQUATION(e, e1, DAE.emptyElementSource, BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC); 4295 eqns := BackendEquation.addEquation(eqn1, eqns); 4296 else 4297 e := e1; 4298 end if; 4245 4299 elseif Expression.isUnaryCref(e1) then 4246 4300 update := true; … … 4285 4339 end for; // lhs 4286 4340 left := DAE.TUPLE(MetaModelica.Dangerous.listReverseInPlace(expLst)); 4287 eqn := Backend DAE.COMPLEX_EQUATION(size,left, right, source, attr);4341 eqn := BackendEquation.generateEquation(left, right, source, attr); 4288 4342 eqns := BackendEquation.setAtIndex(eqns, i, eqn); 4289 4343 end if; // lhs <-> rhs … … 4293 4347 4294 4348 if update then 4295 for i in indRemove loop 4349 for i in listReverse(indRemove) loop 4350 //print("\neqns:" + intString(i) + "\n"); 4351 //BackendDump.printEquationArray(eqns); 4296 4352 eqns := BackendEquation.equationRemove(i,eqns); 4297 4353 end for; … … 4304 4360 4305 4361 outDAE.eqs := systlst; 4306 end simplifyComplexFunction ;4362 end simplifyComplexFunction1; 4307 4363 4308 4364 function simplifyComplexFunction2
Note: See TracChangeset
for help on using the changeset viewer.