MethodicalAcceleratorDesign / MAD-NG

MAD Next-Generation official repository
GNU General Public License v3.0
32 stars 11 forks source link

Bug in print method for tpsa #440

Closed 17IMMANUEL17 closed 5 months ago

17IMMANUEL17 commented 6 months ago

The print method relies on the descriptor and this generates the following bug: when we create a tpsa using a descriptor of order mo but we force the tpsa to have a lower maximum order , let us call it 'lo', than mo then the print method will use mo as the maximum order instead of lo. Whereas, when we create two tpsas using two different descriptors of different maximum order we see the correct behaviour.

local d = gtpsad(2,10) 
local t1 = ctpsa(d) 
local t2 = ctpsa(d,9) 
t1:print()
t2:print()

 -UNNAMED-:  C, NV =   2, MO = 10
 ******************************************************************************

         ALL COMPONENTS ZERO

 -UNNAMED-:  C, NV =   2, MO = 10
 ****************************************************************************** ```

local d = gtpsad(2,10) 
local d2 = gtpsa(2,9)
local t1 = ctpsa(d) 
local t2 = ctpsa(d2) 
t1:print()
t2:print()

 -UNNAMED-:  C, NV =   2, MO = 10
******************************************************************************

         ALL COMPONENTS ZERO

 -UNNAMED-:  C, NV =   2, MO = 9
****************************************************************************** ```
ldeniau commented 5 months ago

Same misunderstanding as for issue #438. The print function must be symmetrical to the scan function, and the header is there to specify the descriptor to which the tpsa belongs. When a tpsa is read, its order is by default set to the global order t->mo = d->mo. In the new version (branch tpsa-newlazy), t->mo is adjusted to the order of the highest non-zero homogeneous polynomials, i.e. t->mo = t->hi after reading and the user is free to increase t->mo to the desired value afterwards. This is possible because the new version keeps track of the allocated order, which is still d->mo >= t->mo.