Changeset 92c84b1 in OpenModelica
- Timestamp:
- 2012-11-15T22:46:18+01:00 (11 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:
- c572316
- Parents:
- 9339461
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Compiler/BackEnd/ExpressionSolve.mo
r048d38f7 r92c84b1 308 308 (outExp,outAsserts) := matchcontinue (inExp1,inExp2,inExp3,linearExps) 309 309 local 310 DAE.Exp lhs,dere,zeroe,rhs,e, a,z;310 DAE.Exp lhs,dere,zeroe,rhs,e,z,a; 311 311 DAE.ComponentRef cr,cr1; 312 312 DAE.Exp invCr; 313 DAE.Type tp; 313 314 list<DAE.Exp> factors; 314 DAE.Type tp;315 315 list<DAE.Statement> asserts; 316 String estr,se1,se2,sa;317 316 318 317 // cr = (e1(0)-e2(0))/(der(e1-e2,cr)) … … 356 355 true = Expression.isZero(inExp1); 357 356 (e,a) = solve3(inExp2,inExp3); 358 (rhs,asserts) = solve(e,a,inExp3); 359 tp = Expression.typeof(a); 357 tp = Expression.typeof(e); 360 358 (z,_) = Expression.makeZeroExpression(Expression.arrayDimension(tp)); 361 se1 = ExpressionDump.printExpStr(inExp1); 362 se2 = ExpressionDump.printExpStr(inExp2); 363 sa = ExpressionDump.printExpStr(a); 364 estr = stringAppendList({"Singular expression ",se1," = ",se2," because ",sa," is Zero!"}); 365 then 366 (rhs,DAE.STMT_ASSERT(DAE.RELATION(a,DAE.NEQUAL(tp),z,-1,NONE()),DAE.SCONST(estr),DAE.ASSERTIONLEVEL_ERROR,DAE.emptyElementSource)::asserts); 359 (rhs,asserts) = solve(e,z,inExp3); 360 asserts = generateAssert(inExp1,inExp2,inExp3,a,asserts); 361 then 362 (rhs,asserts); 367 363 368 364 // swapped args: a*(b-c) = 0 solve for b … … 371 367 true = Expression.isZero(inExp2); 372 368 (e,a) = solve3(inExp1,inExp3); 373 (rhs,asserts) = solve(e,a,inExp3); 374 tp = Expression.typeof(a); 369 tp = Expression.typeof(e); 375 370 (z,_) = Expression.makeZeroExpression(Expression.arrayDimension(tp)); 376 se1 = ExpressionDump.printExpStr(inExp2); 377 se2 = ExpressionDump.printExpStr(inExp1); 378 sa = ExpressionDump.printExpStr(a); 379 estr = stringAppendList({"Singular expression ",se1," = ",se2," because ",sa," is Zero!"}); 380 then 381 (rhs,DAE.STMT_ASSERT(DAE.RELATION(a,DAE.NEQUAL(tp),z,-1,NONE()),DAE.SCONST(estr),DAE.ASSERTIONLEVEL_ERROR,DAE.emptyElementSource)::asserts); 371 (rhs,asserts) = solve(e,z,inExp3); 372 asserts = generateAssert(inExp1,inExp2,inExp3,a,asserts); 373 then 374 (rhs,asserts); 382 375 /* 383 376 case (_,_,DAE.CREF(componentRef = cr),_) … … 422 415 end solve2; 423 416 417 protected function generateAssert 418 input DAE.Exp inExp1; 419 input DAE.Exp inExp2; 420 input DAE.Exp inExp3; 421 input DAE.Exp a; 422 input list<DAE.Statement> inAsserts; 423 output list<DAE.Statement> outAsserts; 424 algorithm 425 (outExp,outAsserts) := matchcontinue (inExp1,inExp2,inExp3,a,inAsserts) 426 local 427 DAE.Exp a,z; 428 DAE.Type tp; 429 list<DAE.Statement> asserts; 430 String estr,se1,se2,sa; 431 case (_,_,_,_,_) 432 equation 433 // zero check already done 434 true = Expression.isConst(a); 435 then 436 inAsserts; 437 else 438 equation 439 tp = Expression.typeof(a); 440 (z,_) = Expression.makeZeroExpression(Expression.arrayDimension(tp)); 441 se1 = ExpressionDump.printExpStr(inExp2); 442 se2 = ExpressionDump.printExpStr(inExp1); 443 sa = ExpressionDump.printExpStr(a); 444 estr = stringAppendList({"Singular expression ",se1," = ",se2," because ",sa," is Zero!"}); 445 then 446 DAE.STMT_ASSERT(DAE.RELATION(a,DAE.NEQUAL(tp),z,-1,NONE()),DAE.SCONST(estr),DAE.ASSERTIONLEVEL_ERROR,DAE.emptyElementSource)::inAsserts; 447 end matchcontinue; 448 end generateAssert; 449 424 450 protected function solve3 425 451 "function: solve3
Note: See TracChangeset
for help on using the changeset viewer.