From: Rainer M. <ra...@tb...> - 2006-08-22 15:50:34
|
Hi Nicolas, I think, you are using a wrong piecewise statement. In the MathML for each piece, the result must come before the condition not after the condition as in your piecewise construct. I have communicated with the other EBI Nicolas about this a month ago, maybe he can sent you the more detailed example I had sent back then. See http://www.zvon.org/xxl/MathML/Output/el_piecewise.html for correct piecewise elements. This was an error in an early version of the SBML test suite or in some official SBML example models. So the older versions of the odeSolver was also wrong because we were using the test suite and official SBML examples as a standard. Then there is another problem with your example. You use a piecewise with the conditions time == 150 and time == 120 so the whole piecewise is undefined at any other times then exactly 150 or 120. So you would need to add a default value (otherwise)! Then of course equality expressions like this are problematic because SOSlib wouldn't detect it unless the printstep is set to a value so 150 and 120 are output step, or by chance the internal integrator comes exactly to this time point. So such an equality expression should rather be in an event, which might in future versions of SOSlib be handled by exact event detection :) Maybe we have to care for such cases in SOSlib also for piecewise. In summary: In infix output of libSBML/SOSlib WRONG: 1: species_0000003 = piecewise(eq(time, 150), 10, eq(time, 120), 5) CORRECT, E.G.: 1: species_0000003 = piecewise(10, lt(time, 150), 5, gt(time, 150)); The "correct" example is still problematic and we might have found a bug here. 10 befire time 150 and 5 afterwards. Of course this is also not correct, because at time 150 its again undefined. Unfortunately SOSlib seems to interpret this as 0, issue an error message, but keep integrating, unstead of exiting. Integrating 1.00 |finished. Results stored. Error 20107 Piecewise function failed; no true piece Printing results to XMGrace! So this is a bug, actually! Rainer On Tue, 22 Aug 2006, Nicolas Rodriguez wrote: > Hi, > > I applied the patch below, in fact, I compiled the latest cvs version of > SBML_odeSolver. > > There is still a problem with the piecewise element apparently. > I attached to the message the sbml file we are using to do our tests, in case > something is wrong with it. > > cerveza: test] odeSolver piecewiseTest.xml > Error 20107 Piecewise function failed; several true pieces > Error 20107 Piecewise function failed; several true pieces > Error 20107 Piecewise function failed; several true pieces > cerveza: test] > > May be I am not understanding well how the evaluateAST is working, but it > seems to me that you are evaluating half of the piece elements in the current > algorithms. > > I would see more something like that : > > case AST_FUNCTION_PIECEWISE: > /** Piecewise: */ > found = 0; > /** Go through all the piece element with 2 AST children for each piece, > */ > for ( i=0; i < (childnum-1); i = i + 1 ) > { > ASTNode_t *pieceElement = child(n, i); > if ( evaluateAST(child(pieceElement, 0), data) ) > { > found++; > result = evaluateAST(child(pieceElement, 1), data); > } > } > // otherwise case > ... > >> Replace the code starting at line 470: >> >> case AST_FUNCTION_PIECEWISE: >> if ( evaluateAST(child(n,0),data) ) { >> result = evaluateAST(child(n,1),data); >> } >> else { >> result = evaluateAST(child(n,2),data); >> } >> break; >> >> with >> >> case AST_FUNCTION_PIECEWISE: >> /** Piecewise: */ >> found = 0; >> /** Go through n pieces with 2 AST children for each piece, */ >> for ( i=0; i<(childnum-1); i=i+2 ) >> { >> if ( evaluateAST(child(n, i+1), data) ) >> { >> found++; >> result = evaluateAST(child(n, i), data); >> } >> } >> /** odd number of AST children: if no piece was true, otherwise >> remains */ >> /* i should be equal to childnum for even number piecewise AST >> and equal to childnum-1 for odd numbered piecewise ASTs */ >> if ( i == childnum-1 && found == 0 ) >> { >> found++; >> result = evaluateAST(child(n, i), data); >> } >> if ( found == 0 ) >> SolverError_error(ERROR_ERROR_TYPE, >> SOLVER_ERROR_AST_EVALUATION_FAILED_PIECEWISE, >> "Piecewise function failed; no true piece"); >> if ( found > 1 ) >> SolverError_error(ERROR_ERROR_TYPE, >> SOLVER_ERROR_AST_EVALUATION_FAILED_PIECEWISE, >> "Piecewise function failed; several true pieces"); >> break; >> >> >> ---- end of replacement code ---- > > |