# Non-linear equations treated as linear when using element-wise array operator functions

2 posts / 0 new
relztes
Offline
Joined: 2016-11-29
Non-linear equations treated as linear when using element-wise array operator functions

JModelica: 1.17

OS: Windows 10 Enterprise 64-bit

JModelica incorrectly treats equations as linear if the only non-linear term is an element-wise multiplication, division, or exponentiation. This gives completely inaccurate results. In the example below, the equation x^2+x=2 is written in four different ways. Two are treated as non-linear and produce the correct result (x=1). The other two are treated as linear and produce incorrect results. During each solver step, Ax=b is solved using A=2x_guess+1, where x_guess is the initial guess for x in this solver step. Adding an additional non-linear term forces JModelica to recognize the equation as non-linear.

Example:

Modelica 'SimpleTest.mo'

model SimpleTest "Example of problems in detecting non-linear equations involving .^"
Real a,b,c,d;
constant Real hack_const=0;
parameter Real hack_param=0;
equation
a^2 + a = 2; // Works
b.^2 + b = 2; // Doesn't work (uses linear solver)
c.^2 + c = 2 - hack_const*exp(c); // Doesn't work (uses linear solver)
d.^2 + d = 2 - hack_param*exp(d); // Works
end SimpleTest;

python:

test_fmu = compile_fmu('SimpleTest', 'SimpleTest.mo')
testModel.set_log_level(7)
testModel.set('_log_level',7)
testres = testModel.simulate()

Results:

>>> print 'time:',testres['time'],'\na:',testres['a'],'\nb:',testres['b'],'\nc:',testres['c'],'\nd:',testres['d']
time: [  0.00000000e+00   3.43225906e-05   3.43260229e-01   1.00000000e+00]
a: [ 1.  1.  1.  1.]
b: [ 0.62068966  0.89230769  0.71823204  0.75708155]
c: [ 0.62068966  0.89230769  0.71823204  0.75708155]
d: [ 1.  1.  1.  1.]

chria
Offline
Joined: 2009-07-29
Thanks! This is fixed with

Thanks!

This is fixed with https://trac.jmodelica.org/ticket/5329

Best

/Christian