OpenModelica / OpenModelica

OpenModelica is an open-source Modelica-based modeling and simulation environment intended for industrial and academic usage.
https://openmodelica.org
Other
820 stars 305 forks source link

The NF is inefficient in handling flexible multibody model with 3D array equations #11609

Open casella opened 10 months ago

casella commented 10 months ago

Steps to reproduce

Get the Flex package from https://github.com/casella/FlexBeam and instantiate Flex.Test.FreeVibration with the following test script:

loadFile("D:/Lavoro/Modelica/FlexBeam/GIT/Flex/package.mo");getErrorString();
setCommandLineOptions("-d=execstat,evaluateAllParameters");getErrorString();
instantiateModel(Flex.Test.FreeVibration);getErrorString();

Flattening this model takes about 30 s on my computer, which I'd say is a bit too much for a model with 1803 equations. This is the breakdown:

[1] 00:12:30 Translation Notification
Performance of FrontEnd - loaded program: time 0.001473/0.001473, allocations: 19.98 kB / 1.153 GB, free: 88.44 MB / 443.6 MB

[2] 00:12:30 Translation Notification
Performance of FrontEnd - Absyn->SCode: time 0.0704/0.07195, allocations: 49.63 MB / 1.201 GB, free: 38.74 MB / 443.6 MB

[3] 00:12:30 Translation Notification
Performance of NFInst.instantiate(Flex.Test.FreeVibration): time 0.01025/0.08226, allocations: 5.996 MB / 1.207 GB, free: 32.71 MB / 443.6 MB

[4] 00:12:30 Translation Notification
Performance of NFInst.instExpressions: time 0.00796/0.09027, allocations: 2.532 MB / 1.21 GB, free: 30.18 MB / 443.6 MB

[5] 00:12:30 Translation Notification
Performance of NFInst.updateImplicitVariability: time 0.0006772/0.09099, allocations: 99.69 kB / 1.21 GB, free: 30.08 MB / 443.6 MB

[6] 00:12:30 Translation Notification
Performance of NFTyping.typeComponents: time 0.001224/0.09225, allocations: 0.6692 MB / 1.21 GB, free: 29.41 MB / 443.6 MB

[7] 00:12:30 Translation Notification
Performance of NFTyping.typeBindings: time 0.001823/0.0941, allocations: 1.281 MB / 1.212 GB, free: 28.12 MB / 443.6 MB

[8] 00:12:30 Translation Notification
Performance of NFTyping.typeClassSections: time 0.002044/0.09617, allocations: 1.637 MB / 1.213 GB, free: 26.48 MB / 443.6 MB

[9] 00:12:30 Translation Notification
Performance of NFFlatten.flatten: time 0.02412/0.1203, allocations: 29.47 MB / 1.242 GB, free: 12.98 MB / 459.6 MB

[10] 00:12:30 Translation Notification
Performance of NFFlatten.resolveConnections: time 0.02482/0.1452, allocations: 19.02 MB / 1.261 GB, free: 9.898 MB / 475.6 MB

[11] 00:12:30 Translation Notification
Performance of NFEvalConstants.evaluate: time 0.09025/0.2355, allocations: 18.06 MB / 1.278 GB, free: 128.3 MB / 491.6 MB

[12] 00:12:30 Translation Notification
Performance of NFSimplifyModel.simplify: time 6.346/6.581, allocations: 1.955 GB / 3.233 GB, free: 13.74 MB / 1.23 GB

[13] 00:12:30 Translation Notification
Performance of NFPackage.collectConstants: time 0.9461/7.527, allocations: 181 MB / 3.41 GB, free: 166.6 MB / 1.277 GB

[14] 00:12:30 Translation Notification
Performance of NFFlatten.collectFunctions: time 0.7503/8.278, allocations: 181.6 MB / 3.587 GB, free: 53.7 MB / 1.277 GB

[15] 00:12:30 Translation Notification
Performance of NFScalarize.scalarize: time 1.147/9.425, allocations: 0.4901 GB / 4.077 GB, free: 8.043 MB / 1.527 GB

[16] 00:12:30 Translation Notification
Performance of NFVerifyModel.verify: time 1.146/10.57, allocations: 0.4902 GB / 4.567 GB, free: 6.914 MB / 1.886 GB

[17] 00:12:30 Translation Notification
Performance of NFConvertDAE.convert: time 2.962/13.53, allocations: 1.911 GB / 6.478 GB, free: 4.883 MB / 2.324 GB

[18] 00:12:30 Translation Notification
Performance of FrontEnd - DAE generated: time 2.9e-06/13.53, allocations: 0.7812 kB / 6.478 GB, free: 4.883 MB / 2.324 GB

[19] 00:12:30 Translation Notification
Performance of runFrontEnd: time 1e-06/13.53, allocations: 0 / 6.478 GB, free: 4.883 MB / 2.324 GB

[20] 00:12:30 Translation Notification
Performance of DAEDump.dumpStr: time 18.13/31.66, allocations: 6.293 GB / 12.77 GB, free: 34.38 MB / 5.588 GB

More than half of the time is taken to output the flat model in textual format, despite a significant amount of time (6 seconds) spent in simplifying it.

Analysis

The output file is huge, over 40 MB of size. I singled out what the problem is: the equation for beam.Ithth_bar11_der alone is 14 million character long.

Its defining equation is

  Ithth_bar11 =1e-10+ scalar(transpose(matrix(qf))*sum((transpose(B[i,:,:])*Sbar22*B[i,:,:]) for i in 1:N)*qf);

The problem of this apparently innocuous equation is that if one fully expands the matrix products inside the reduction, the number of elements that needs to be summed is mind-blowing. Most of them are zero, because array B[:,:,] is very sparse, but they are currently taken into account anyway, leading to a monstrous inflation of terms.

Obviously, the solution to this problem cannot be to leave it to the backend to simplify the expression, because that's too late.

Proposed fix

As I understand, the only way to handle this model is to curb the elements of the sum reduction expression that are zero right away while computing the reduction, not afterwards. Dymola swallows this model without a hiccup and has been doing that for 15 years, so I guess it does something like that.

The simplification of terms multiplied by variables equal to one can be left to the backend, as they are not that many.

@perost do you think this is easily doable in the NF?

For a smaller MWE, you can re-use model Test3DArray from #11412. That model is now flattened in about one second, but still contains an expression which is much longer than it ought to be:

s = {{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}} + {{(B[1,1,1] * 0.3333333333333333 + B[1,4,1] * 0.16666666666666666) * B[1,1,1] + (B[1,1,1] * 0.16666666666666666 + B[1,4,1] * 0.3333333333333333) * B[1,4,1], (B[1,1,1] * 0.3333333333333333 + B[1,4,1] * 0.16666666666666666) * B[1,1,2] + (B[1,1,1] * 0.16666666666666666 + B[1,4,1] * 0.3333333333333333) * B[1,4,2], (B[1,1,1] * 0.3333333333333333 + B[1,4,1] * 0.16666666666666666) * B[1,1,3] + (B[1,1,1] * 0.16666666666666666 + B[1,4,1] * 0.3333333333333333) * B[1,4,3], (B[1,1,1] * 0.3333333333333333 + B[1,4,1] * 0.16666666666666666) * B[1,1,4] + (B[1,1,1] * 0.16666666666666666 + B[1,4,1] * 0.3333333333333333) * B[1,4,4], (B[1,1,1] * 0.3333333333333333 + B[1,4,1] * 0.16666666666666666) * B[1,1,5] + (B[1,1,1] * 0.16666666666666666 + B[1,4,1] * 0.3333333333333333) * B[1,4,5], (B[1,1,1] * 0.3333333333333333 + B[1,4,1] * 0.16666666666666666) * B[1,1,6] + (B[1,1,1] * 0.16666666666666666 + B[1,4,1] * 0.3333333333333333) * B[1,4,6], (B[1,1,1] * 0.3333333333333333 + B[1,4,1] * 0.16666666666666666) * B[1,1,7] + (B[1,1,1] * 0.16666666666666666 + B[1,4,1] * 0.3333333333333333) * B[1,4,7], (B[1,1,1] * 0.3333333333333333 + B[1,4,1] * 0.16666666666666666) * B[1,1,8] + (B[1,1,1] * 0.16666666666666666 + B[1,4,1] * 0.3333333333333333) * B[1,4,8], (B[1,1,1] * 0.3333333333333333 + B[1,4,1] * 0.16666666666666666) * B[1,1,9] + (B[1,1,1] * 0.16666666666666666 + B[1,4,1] * 0.3333333333333333) * B[1,4,9]}, {(B[1,1,2] * 0.3333333333333333 + B[1,4,2] * 0.16666666666666666) * B[1,1,1] + (B[1,1,2] * 0.16666666666666666 + B[1,4,2] * 0.3333333333333333) * B[1,4,1], (B[1,1,2] * 0.3333333333333333 + B[1,4,2] * 0.16666666666666666) * B[1,1,2] + (B[1,1,2] * 0.16666666666666666 + B[1,4,2] * 0.3333333333333333) * B[1,4,2], (B[1,1,2] * 0.3333333333333333 + B[1,4,2] * 0.16666666666666666) * B[1,1,3] + (B[1,1,2] * 0.16666666666666666 + B[1,4,2] * 0.3333333333333333) * B[1,4,3], (B[1,1,2] * 0.3333333333333333 + B[1,4,2] * 0.16666666666666666) * B[1,1,4] + (B[1,1,2] * 0.16666666666666666 + B[1,4,2] * 0.3333333333333333) * B[1,4,4], (B[1,1,2] * 0.3333333333333333 + B[1,4,2] * 0.16666666666666666) * B[1,1,5] + (B[1,1,2] * 0.16666666666666666 + B[1,4,2] * 0.3333333333333333) * B[1,4,5], (B[1,1,2] * 0.3333333333333333 + B[1,4,2] * 0.16666666666666666) * B[1,1,6] + (B[1,1,2] * 0.16666666666666666 + B[1,4,2] * 0.3333333333333333) * B[1,4,6], (B[1,1,2] * 0.3333333333333333 + B[1,4,2] * 0.16666666666666666) * B[1,1,7] + (B[1,1,2] * 0.16666666666666666 + B[1,4,2] * 0.3333333333333333) * B[1,4,7], (B[1,1,2] * 0.3333333333333333 + B[1,4,2] * 0.16666666666666666) * B[1,1,8] + (B[1,1,2] * 0.16666666666666666 + B[1,4,2] * 0.3333333333333333) * B[1,4,8], (B[1,1,2] * 0.3333333333333333 + B[1,4,2] * 0.16666666666666666) * B[1,1,9] + (B[1,1,2] * 0.16666666666666666 + B[1,4,2] * 0.3333333333333333) * B[1,4,9]}, {(B[1,1,3] * 0.3333333333333333 + B[1,4,3] * 0.16666666666666666) * B[1,1,1] + (B[1,1,3] * 0.16666666666666666 + B[1,4,3] * 0.3333333333333333) * B[1,4,1], (B[1,1,3] * 0.3333333333333333 + B[1,4,3] * 0.16666666666666666) * B[1,1,2] + (B[1,1,3] * 0.16666666666666666 + B[1,4,3] * 0.3333333333333333) * B[1,4,2], (B[1,1,3] * 0.3333333333333333 + B[1,4,3] * 0.16666666666666666) * B[1,1,3] + (B[1,1,3] * 0.16666666666666666 + B[1,4,3] * 0.3333333333333333) * B[1,4,3], (B[1,1,3] * 0.3333333333333333 + B[1,4,3] * 0.16666666666666666) * B[1,1,4] + (B[1,1,3] * 0.16666666666666666 + B[1,4,3] * 0.3333333333333333) * B[1,4,4], (B[1,1,3] * 0.3333333333333333 + B[1,4,3] * 0.16666666666666666) * B[1,1,5] + (B[1,1,3] * 0.16666666666666666 + B[1,4,3] * 0.3333333333333333) * B[1,4,5], (B[1,1,3] * 0.3333333333333333 + B[1,4,3] * 0.16666666666666666) * B[1,1,6] + (B[1,1,3] * 0.16666666666666666 + B[1,4,3] * 0.3333333333333333) * B[1,4,6], (B[1,1,3] * 0.3333333333333333 + B[1,4,3] * 0.16666666666666666) * B[1,1,7] + (B[1,1,3] * 0.16666666666666666 + B[1,4,3] * 0.3333333333333333) * B[1,4,7], (B[1,1,3] * 0.3333333333333333 + B[1,4,3] * 0.16666666666666666) * B[1,1,8] + (B[1,1,3] * 0.16666666666666666 + B[1,4,3] * 0.3333333333333333) * B[1,4,8], (B[1,1,3] * 0.3333333333333333 + B[1,4,3] * 0.16666666666666666) * B[1,1,9] + (B[1,1,3] * 0.16666666666666666 + B[1,4,3] * 0.3333333333333333) * B[1,4,9]}, {(B[1,1,4] * 0.3333333333333333 + B[1,4,4] * 0.16666666666666666) * B[1,1,1] + (B[1,1,4] * 0.16666666666666666 + B[1,4,4] * 0.3333333333333333) * B[1,4,1], (B[1,1,4] * 0.3333333333333333 + B[1,4,4] * 0.16666666666666666) * B[1,1,2] + (B[1,1,4] * 0.16666666666666666 + B[1,4,4] * 0.3333333333333333) * B[1,4,2], (B[1,1,4] * 0.3333333333333333 + B[1,4,4] * 0.16666666666666666) * B[1,1,3] + (B[1,1,4] * 0.16666666666666666 + B[1,4,4] * 0.3333333333333333) * B[1,4,3], (B[1,1,4] * 0.3333333333333333 + B[1,4,4] * 0.16666666666666666) * B[1,1,4] + (B[1,1,4] * 0.16666666666666666 + B[1,4,4] * 0.3333333333333333) * B[1,4,4], (B[1,1,4] * 0.3333333333333333 + B[1,4,4] * 0.16666666666666666) * B[1,1,5] + (B[1,1,4] * 0.16666666666666666 + B[1,4,4] * 0.3333333333333333) * B[1,4,5], (B[1,1,4] * 0.3333333333333333 + B[1,4,4] * 0.16666666666666666) * B[1,1,6] + (B[1,1,4] * 0.16666666666666666 + B[1,4,4] * 0.3333333333333333) * B[1,4,6], (B[1,1,4] * 0.3333333333333333 + B[1,4,4] * 0.16666666666666666) * B[1,1,7] + (B[1,1,4] * 0.16666666666666666 + B[1,4,4] * 0.3333333333333333) * B[1,4,7], (B[1,1,4] * 0.3333333333333333 + B[1,4,4] * 0.16666666666666666) * B[1,1,8] + (B[1,1,4] * 0.16666666666666666 + B[1,4,4] * 0.3333333333333333) * B[1,4,8], (B[1,1,4] * 0.3333333333333333 + B[1,4,4] * 0.16666666666666666) * B[1,1,9] + (B[1,1,4] * 0.16666666666666666 + B[1,4,4] * 0.3333333333333333) * B[1,4,9]}, {(B[1,1,5] * 0.3333333333333333 + B[1,4,5] * 0.16666666666666666) * B[1,1,1] + (B[1,1,5] * 0.16666666666666666 + B[1,4,5] * 0.3333333333333333) * B[1,4,1], (B[1,1,5] * 0.3333333333333333 + B[1,4,5] * 0.16666666666666666) * B[1,1,2] + (B[1,1,5] * 0.16666666666666666 + B[1,4,5] * 0.3333333333333333) * B[1,4,2], (B[1,1,5] * 0.3333333333333333 + B[1,4,5] * 0.16666666666666666) * B[1,1,3] + (B[1,1,5] * 0.16666666666666666 + B[1,4,5] * 0.3333333333333333) * B[1,4,3], (B[1,1,5] * 0.3333333333333333 + B[1,4,5] * 0.16666666666666666) * B[1,1,4] + (B[1,1,5] * 0.16666666666666666 + B[1,4,5] * 0.3333333333333333) * B[1,4,4], (B[1,1,5] * 0.3333333333333333 + B[1,4,5] * 0.16666666666666666) * B[1,1,5] + (B[1,1,5] * 0.16666666666666666 + B[1,4,5] * 0.3333333333333333) * B[1,4,5], (B[1,1,5] * 0.3333333333333333 + B[1,4,5] * 0.16666666666666666) * B[1,1,6] + (B[1,1,5] * 0.16666666666666666 + B[1,4,5] * 0.3333333333333333) * B[1,4,6], (B[1,1,5] * 0.3333333333333333 + B[1,4,5] * 0.16666666666666666) * B[1,1,7] + (B[1,1,5] * 0.16666666666666666 + B[1,4,5] * 0.3333333333333333) * B[1,4,7], (B[1,1,5] * 0.3333333333333333 + B[1,4,5] * 0.16666666666666666) * B[1,1,8] + (B[1,1,5] * 0.16666666666666666 + B[1,4,5] * 0.3333333333333333) * B[1,4,8], (B[1,1,5] * 0.3333333333333333 + B[1,4,5] * 0.16666666666666666) * B[1,1,9] + (B[1,1,5] * 0.16666666666666666 + B[1,4,5] * 0.3333333333333333) * B[1,4,9]}, {(B[1,1,6] * 0.3333333333333333 + B[1,4,6] * 0.16666666666666666) * B[1,1,1] + (B[1,1,6] * 0.16666666666666666 + B[1,4,6] * 0.3333333333333333) * B[1,4,1], (B[1,1,6] * 0.3333333333333333 + B[1,4,6] * 0.16666666666666666) * B[1,1,2] + (B[1,1,6] * 0.16666666666666666 + B[1,4,6] * 0.3333333333333333) * B[1,4,2], (B[1,1,6] * 0.3333333333333333 + B[1,4,6] * 0.16666666666666666) * B[1,1,3] + (B[1,1,6] * 0.16666666666666666 + B[1,4,6] * 0.3333333333333333) * B[1,4,3], (B[1,1,6] * 0.3333333333333333 + B[1,4,6] * 0.16666666666666666) * B[1,1,4] + (B[1,1,6] * 0.16666666666666666 + B[1,4,6] * 0.3333333333333333) * B[1,4,4], (B[1,1,6] * 0.3333333333333333 + B[1,4,6] * 0.16666666666666666) * B[1,1,5] + (B[1,1,6] * 0.16666666666666666 + B[1,4,6] * 0.3333333333333333) * B[1,4,5], (B[1,1,6] * 0.3333333333333333 + B[1,4,6] * 0.16666666666666666) * B[1,1,6] + (B[1,1,6] * 0.16666666666666666 + B[1,4,6] * 0.3333333333333333) * B[1,4,6], (B[1,1,6] * 0.3333333333333333 + B[1,4,6] * 0.16666666666666666) * B[1,1,7] + (B[1,1,6] * 0.16666666666666666 + B[1,4,6] * 0.3333333333333333) * B[1,4,7], (B[1,1,6] * 0.3333333333333333 + B[1,4,6] * 0.16666666666666666) * B[1,1,8] + (B[1,1,6] * 0.16666666666666666 + B[1,4,6] * 0.3333333333333333) * B[1,4,8], (B[1,1,6] * 0.3333333333333333 + B[1,4,6] * 0.16666666666666666) * B[1,1,9] + (B[1,1,6] * 0.16666666666666666 + B[1,4,6] * 0.3333333333333333) * B[1,4,9]}, {(B[1,1,7] * 0.3333333333333333 + B[1,4,7] * 0.16666666666666666) * B[1,1,1] + (B[1,1,7] * 0.16666666666666666 + B[1,4,7] * 0.3333333333333333) * B[1,4,1], (B[1,1,7] * 0.3333333333333333 + B[1,4,7] * 0.16666666666666666) * B[1,1,2] + (B[1,1,7] * 0.16666666666666666 + B[1,4,7] * 0.3333333333333333) * B[1,4,2], (B[1,1,7] * 0.3333333333333333 + B[1,4,7] * 0.16666666666666666) * B[1,1,3] + (B[1,1,7] * 0.16666666666666666 + B[1,4,7] * 0.3333333333333333) * B[1,4,3], (B[1,1,7] * 0.3333333333333333 + B[1,4,7] * 0.16666666666666666) * B[1,1,4] + (B[1,1,7] * 0.16666666666666666 + B[1,4,7] * 0.3333333333333333) * B[1,4,4], (B[1,1,7] * 0.3333333333333333 + B[1,4,7] * 0.16666666666666666) * B[1,1,5] + (B[1,1,7] * 0.16666666666666666 + B[1,4,7] * 0.3333333333333333) * B[1,4,5], (B[1,1,7] * 0.3333333333333333 + B[1,4,7] * 0.16666666666666666) * B[1,1,6] + (B[1,1,7] * 0.16666666666666666 + B[1,4,7] * 0.3333333333333333) * B[1,4,6], (B[1,1,7] * 0.3333333333333333 + B[1,4,7] * 0.16666666666666666) * B[1,1,7] + (B[1,1,7] * 0.16666666666666666 + B[1,4,7] * 0.3333333333333333) * B[1,4,7], (B[1,1,7] * 0.3333333333333333 + B[1,4,7] * 0.16666666666666666) * B[1,1,8] + (B[1,1,7] * 0.16666666666666666 + B[1,4,7] * 0.3333333333333333) * B[1,4,8], (B[1,1,7] * 0.3333333333333333 + B[1,4,7] * 0.16666666666666666) * B[1,1,9] + (B[1,1,7] * 0.16666666666666666 + B[1,4,7] * 0.3333333333333333) * B[1,4,9]}, {(B[1,1,8] * 0.3333333333333333 + B[1,4,8] * 0.16666666666666666) * B[1,1,1] + (B[1,1,8] * 0.16666666666666666 + B[1,4,8] * 0.3333333333333333) * B[1,4,1], (B[1,1,8] * 0.3333333333333333 + B[1,4,8] * 0.16666666666666666) * B[1,1,2] + (B[1,1,8] * 0.16666666666666666 + B[1,4,8] * 0.3333333333333333) * B[1,4,2], (B[1,1,8] * 0.3333333333333333 + B[1,4,8] * 0.16666666666666666) * B[1,1,3] + (B[1,1,8] * 0.16666666666666666 + B[1,4,8] * 0.3333333333333333) * B[1,4,3], (B[1,1,8] * 0.3333333333333333 + B[1,4,8] * 0.16666666666666666) * B[1,1,4] + (B[1,1,8] * 0.16666666666666666 + B[1,4,8] * 0.3333333333333333) * B[1,4,4], (B[1,1,8] * 0.3333333333333333 + B[1,4,8] * 0.16666666666666666) * B[1,1,5] + (B[1,1,8] * 0.16666666666666666 + B[1,4,8] * 0.3333333333333333) * B[1,4,5], (B[1,1,8] * 0.3333333333333333 + B[1,4,8] * 0.16666666666666666) * B[1,1,6] + (B[1,1,8] * 0.16666666666666666 + B[1,4,8] * 0.3333333333333333) * B[1,4,6], (B[1,1,8] * 0.3333333333333333 + B[1,4,8] * 0.16666666666666666) * B[1,1,7] + (B[1,1,8] * 0.16666666666666666 + B[1,4,8] * 0.3333333333333333) * B[1,4,7], (B[1,1,8] * 0.3333333333333333 + B[1,4,8] * 0.16666666666666666) * B[1,1,8] + (B[1,1,8] * 0.16666666666666666 + B[1,4,8] * 0.3333333333333333) * B[1,4,8], (B[1,1,8] * 0.3333333333333333 + B[1,4,8] * 0.16666666666666666) * B[1,1,9] + (B[1,1,8] * 0.16666666666666666 + B[1,4,8] * 0.3333333333333333) * B[1,4,9]}, {(B[1,1,9] * 0.3333333333333333 + B[1,4,9] * 0.16666666666666666) * B[1,1,1] + (B[1,1,9] * 0.16666666666666666 + B[1,4,9] * 0.3333333333333333) * B[1,4,1], (B[1,1,9] * 0.3333333333333333 + B[1,4,9] * 0.16666666666666666) * B[1,1,2] + (B[1,1,9] * 0.16666666666666666 + B[1,4,9] * 0.3333333333333333) * B[1,4,2], (B[1,1,9] * 0.3333333333333333 + B[1,4,9] * 0.16666666666666666) * B[1,1,3] + (B[1,1,9] * 0.16666666666666666 + B[1,4,9] * 0.3333333333333333) * B[1,4,3], (B[1,1,9] * 0.3333333333333333 + B[1,4,9] * 0.16666666666666666) * B[1,1,4] + (B[1,1,9] * 0.16666666666666666 + B[1,4,9] * 0.3333333333333333) * B[1,4,4], (B[1,1,9] * 0.3333333333333333 + B[1,4,9] * 0.16666666666666666) * B[1,1,5] + (B[1,1,9] * 0.16666666666666666 + B[1,4,9] * 0.3333333333333333) * B[1,4,5], (B[1,1,9] * 0.3333333333333333 + B[1,4,9] * 0.16666666666666666) * B[1,1,6] + (B[1,1,9] * 0.16666666666666666 + B[1,4,9] * 0.3333333333333333) * B[1,4,6], (B[1,1,9] * 0.3333333333333333 + B[1,4,9] * 0.16666666666666666) * B[1,1,7] + (B[1,1,9] * 0.16666666666666666 + B[1,4,9] * 0.3333333333333333) * B[1,4,7], (B[1,1,9] * 0.3333333333333333 + B[1,4,9] * 0.16666666666666666) * B[1,1,8] + (B[1,1,9] * 0.16666666666666666 + B[1,4,9] * 0.3333333333333333) * B[1,4,8], (B[1,1,9] * 0.3333333333333333 + B[1,4,9] * 0.16666666666666666) * B[1,1,9] + (B[1,1,9] * 0.16666666666666666 + B[1,4,9] * 0.3333333333333333) * B[1,4,9]}} + {{(B[2,1,1] * 0.3333333333333333 + B[2,4,1] * 0.16666666666666666) * B[2,1,1] + (B[2,1,1] * 0.16666666666666666 + B[2,4,1] * 0.3333333333333333) * B[2,4,1], (B[2,1,1] * 0.3333333333333333 + B[2,4,1] * 0.16666666666666666) * B[2,1,2] + (B[2,1,1] * 0.16666666666666666 + B[2,4,1] * 0.3333333333333333) * B[2,4,2], (B[2,1,1] * 0.3333333333333333 + B[2,4,1] * 0.16666666666666666) * B[2,1,3] + (B[2,1,1] * 0.16666666666666666 + B[2,4,1] * 0.3333333333333333) * B[2,4,3], (B[2,1,1] * 0.3333333333333333 + B[2,4,1] * 0.16666666666666666) * B[2,1,4] + (B[2,1,1] * 0.16666666666666666 + B[2,4,1] * 0.3333333333333333) * B[2,4,4], (B[2,1,1] * 0.3333333333333333 + B[2,4,1] * 0.16666666666666666) * B[2,1,5] + (B[2,1,1] * 0.16666666666666666 + B[2,4,1] * 0.3333333333333333) * B[2,4,5], (B[2,1,1] * 0.3333333333333333 + B[2,4,1] * 0.16666666666666666) * B[2,1,6] + (B[2,1,1] * 0.16666666666666666 + B[2,4,1] * 0.3333333333333333) * B[2,4,6], (B[2,1,1] * 0.3333333333333333 + B[2,4,1] * 0.16666666666666666) * B[2,1,7] + (B[2,1,1] * 0.16666666666666666 + B[2,4,1] * 0.3333333333333333) * B[2,4,7], (B[2,1,1] * 0.3333333333333333 + B[2,4,1] * 0.16666666666666666) * B[2,1,8] + (B[2,1,1] * 0.16666666666666666 + B[2,4,1] * 0.3333333333333333) * B[2,4,8], (B[2,1,1] * 0.3333333333333333 + B[2,4,1] * 0.16666666666666666) * B[2,1,9] + (B[2,1,1] * 0.16666666666666666 + B[2,4,1] * 0.3333333333333333) * B[2,4,9]}, {(B[2,1,2] * 0.3333333333333333 + B[2,4,2] * 0.16666666666666666) * B[2,1,1] + (B[2,1,2] * 0.16666666666666666 + B[2,4,2] * 0.3333333333333333) * B[2,4,1], (B[2,1,2] * 0.3333333333333333 + B[2,4,2] * 0.16666666666666666) * B[2,1,2] + (B[2,1,2] * 0.16666666666666666 + B[2,4,2] * 0.3333333333333333) * B[2,4,2], (B[2,1,2] * 0.3333333333333333 + B[2,4,2] * 0.16666666666666666) * B[2,1,3] + (B[2,1,2] * 0.16666666666666666 + B[2,4,2] * 0.3333333333333333) * B[2,4,3], (B[2,1,2] * 0.3333333333333333 + B[2,4,2] * 0.16666666666666666) * B[2,1,4] + (B[2,1,2] * 0.16666666666666666 + B[2,4,2] * 0.3333333333333333) * B[2,4,4], (B[2,1,2] * 0.3333333333333333 + B[2,4,2] * 0.16666666666666666) * B[2,1,5] + (B[2,1,2] * 0.16666666666666666 + B[2,4,2] * 0.3333333333333333) * B[2,4,5], (B[2,1,2] * 0.3333333333333333 + B[2,4,2] * 0.16666666666666666) * B[2,1,6] + (B[2,1,2] * 0.16666666666666666 + B[2,4,2] * 0.3333333333333333) * B[2,4,6], (B[2,1,2] * 0.3333333333333333 + B[2,4,2] * 0.16666666666666666) * B[2,1,7] + (B[2,1,2] * 0.16666666666666666 + B[2,4,2] * 0.3333333333333333) * B[2,4,7], (B[2,1,2] * 0.3333333333333333 + B[2,4,2] * 0.16666666666666666) * B[2,1,8] + (B[2,1,2] * 0.16666666666666666 + B[2,4,2] * 0.3333333333333333) * B[2,4,8], (B[2,1,2] * 0.3333333333333333 + B[2,4,2] * 0.16666666666666666) * B[2,1,9] + (B[2,1,2] * 0.16666666666666666 + B[2,4,2] * 0.3333333333333333) * B[2,4,9]}, {(B[2,1,3] * 0.3333333333333333 + B[2,4,3] * 0.16666666666666666) * B[2,1,1] + (B[2,1,3] * 0.16666666666666666 + B[2,4,3] * 0.3333333333333333) * B[2,4,1], (B[2,1,3] * 0.3333333333333333 + B[2,4,3] * 0.16666666666666666) * B[2,1,2] + (B[2,1,3] * 0.16666666666666666 + B[2,4,3] * 0.3333333333333333) * B[2,4,2], (B[2,1,3] * 0.3333333333333333 + B[2,4,3] * 0.16666666666666666) * B[2,1,3] + (B[2,1,3] * 0.16666666666666666 + B[2,4,3] * 0.3333333333333333) * B[2,4,3], (B[2,1,3] * 0.3333333333333333 + B[2,4,3] * 0.16666666666666666) * B[2,1,4] + (B[2,1,3] * 0.16666666666666666 + B[2,4,3] * 0.3333333333333333) * B[2,4,4], (B[2,1,3] * 0.3333333333333333 + B[2,4,3] * 0.16666666666666666) * B[2,1,5] + (B[2,1,3] * 0.16666666666666666 + B[2,4,3] * 0.3333333333333333) * B[2,4,5], (B[2,1,3] * 0.3333333333333333 + B[2,4,3] * 0.16666666666666666) * B[2,1,6] + (B[2,1,3] * 0.16666666666666666 + B[2,4,3] * 0.3333333333333333) * B[2,4,6], (B[2,1,3] * 0.3333333333333333 + B[2,4,3] * 0.16666666666666666) * B[2,1,7] + (B[2,1,3] * 0.16666666666666666 + B[2,4,3] * 0.3333333333333333) * B[2,4,7], (B[2,1,3] * 0.3333333333333333 + B[2,4,3] * 0.16666666666666666) * B[2,1,8] + (B[2,1,3] * 0.16666666666666666 + B[2,4,3] * 0.3333333333333333) * B[2,4,8], (B[2,1,3] * 0.3333333333333333 + B[2,4,3] * 0.16666666666666666) * B[2,1,9] + (B[2,1,3] * 0.16666666666666666 + B[2,4,3] * 0.3333333333333333) * B[2,4,9]}, {(B[2,1,4] * 0.3333333333333333 + B[2,4,4] * 0.16666666666666666) * B[2,1,1] + (B[2,1,4] * 0.16666666666666666 + B[2,4,4] * 0.3333333333333333) * B[2,4,1], (B[2,1,4] * 0.3333333333333333 + B[2,4,4] * 0.16666666666666666) * B[2,1,2] + (B[2,1,4] * 0.16666666666666666 + B[2,4,4] * 0.3333333333333333) * B[2,4,2], (B[2,1,4] * 0.3333333333333333 + B[2,4,4] * 0.16666666666666666) * B[2,1,3] + (B[2,1,4] * 0.16666666666666666 + B[2,4,4] * 0.3333333333333333) * B[2,4,3], (B[2,1,4] * 0.3333333333333333 + B[2,4,4] * 0.16666666666666666) * B[2,1,4] + (B[2,1,4] * 0.16666666666666666 + B[2,4,4] * 0.3333333333333333) * B[2,4,4], (B[2,1,4] * 0.3333333333333333 + B[2,4,4] * 0.16666666666666666) * B[2,1,5] + (B[2,1,4] * 0.16666666666666666 + B[2,4,4] * 0.3333333333333333) * B[2,4,5], (B[2,1,4] * 0.3333333333333333 + B[2,4,4] * 0.16666666666666666) * B[2,1,6] + (B[2,1,4] * 0.16666666666666666 + B[2,4,4] * 0.3333333333333333) * B[2,4,6], (B[2,1,4] * 0.3333333333333333 + B[2,4,4] * 0.16666666666666666) * B[2,1,7] + (B[2,1,4] * 0.16666666666666666 + B[2,4,4] * 0.3333333333333333) * B[2,4,7], (B[2,1,4] * 0.3333333333333333 + B[2,4,4] * 0.16666666666666666) * B[2,1,8] + (B[2,1,4] * 0.16666666666666666 + B[2,4,4] * 0.3333333333333333) * B[2,4,8], (B[2,1,4] * 0.3333333333333333 + B[2,4,4] * 0.16666666666666666) * B[2,1,9] + (B[2,1,4] * 0.16666666666666666 + B[2,4,4] * 0.3333333333333333) * B[2,4,9]}, {(B[2,1,5] * 0.3333333333333333 + B[2,4,5] * 0.16666666666666666) * B[2,1,1] + (B[2,1,5] * 0.16666666666666666 + B[2,4,5] * 0.3333333333333333) * B[2,4,1], (B[2,1,5] * 0.3333333333333333 + B[2,4,5] * 0.16666666666666666) * B[2,1,2] + (B[2,1,5] * 0.16666666666666666 + B[2,4,5] * 0.3333333333333333) * B[2,4,2], (B[2,1,5] * 0.3333333333333333 + B[2,4,5] * 0.16666666666666666) * B[2,1,3] + (B[2,1,5] * 0.16666666666666666 + B[2,4,5] * 0.3333333333333333) * B[2,4,3], (B[2,1,5] * 0.3333333333333333 + B[2,4,5] * 0.16666666666666666) * B[2,1,4] + (B[2,1,5] * 0.16666666666666666 + B[2,4,5] * 0.3333333333333333) * B[2,4,4], (B[2,1,5] * 0.3333333333333333 + B[2,4,5] * 0.16666666666666666) * B[2,1,5] + (B[2,1,5] * 0.16666666666666666 + B[2,4,5] * 0.3333333333333333) * B[2,4,5], (B[2,1,5] * 0.3333333333333333 + B[2,4,5] * 0.16666666666666666) * B[2,1,6] + (B[2,1,5] * 0.16666666666666666 + B[2,4,5] * 0.3333333333333333) * B[2,4,6], (B[2,1,5] * 0.3333333333333333 + B[2,4,5] * 0.16666666666666666) * B[2,1,7] + (B[2,1,5] * 0.16666666666666666 + B[2,4,5] * 0.3333333333333333) * B[2,4,7], (B[2,1,5] * 0.3333333333333333 + B[2,4,5] * 0.16666666666666666) * B[2,1,8] + (B[2,1,5] * 0.16666666666666666 + B[2,4,5] * 0.3333333333333333) * B[2,4,8], (B[2,1,5] * 0.3333333333333333 + B[2,4,5] * 0.16666666666666666) * B[2,1,9] + (B[2,1,5] * 0.16666666666666666 + B[2,4,5] * 0.3333333333333333) * B[2,4,9]}, {(B[2,1,6] * 0.3333333333333333 + B[2,4,6] * 0.16666666666666666) * B[2,1,1] + (B[2,1,6] * 0.16666666666666666 + B[2,4,6] * 0.3333333333333333) * B[2,4,1], (B[2,1,6] * 0.3333333333333333 + B[2,4,6] * 0.16666666666666666) * B[2,1,2] + (B[2,1,6] * 0.16666666666666666 + B[2,4,6] * 0.3333333333333333) * B[2,4,2], (B[2,1,6] * 0.3333333333333333 + B[2,4,6] * 0.16666666666666666) * B[2,1,3] + (B[2,1,6] * 0.16666666666666666 + B[2,4,6] * 0.3333333333333333) * B[2,4,3], (B[2,1,6] * 0.3333333333333333 + B[2,4,6] * 0.16666666666666666) * B[2,1,4] + (B[2,1,6] * 0.16666666666666666 + B[2,4,6] * 0.3333333333333333) * B[2,4,4], (B[2,1,6] * 0.3333333333333333 + B[2,4,6] * 0.16666666666666666) * B[2,1,5] + (B[2,1,6] * 0.16666666666666666 + B[2,4,6] * 0.3333333333333333) * B[2,4,5], (B[2,1,6] * 0.3333333333333333 + B[2,4,6] * 0.16666666666666666) * B[2,1,6] + (B[2,1,6] * 0.16666666666666666 + B[2,4,6] * 0.3333333333333333) * B[2,4,6], (B[2,1,6] * 0.3333333333333333 + B[2,4,6] * 0.16666666666666666) * B[2,1,7] + (B[2,1,6] * 0.16666666666666666 + B[2,4,6] * 0.3333333333333333) * B[2,4,7], (B[2,1,6] * 0.3333333333333333 + B[2,4,6] * 0.16666666666666666) * B[2,1,8] + (B[2,1,6] * 0.16666666666666666 + B[2,4,6] * 0.3333333333333333) * B[2,4,8], (B[2,1,6] * 0.3333333333333333 + B[2,4,6] * 0.16666666666666666) * B[2,1,9] + (B[2,1,6] * 0.16666666666666666 + B[2,4,6] * 0.3333333333333333) * B[2,4,9]}, {(B[2,1,7] * 0.3333333333333333 + B[2,4,7] * 0.16666666666666666) * B[2,1,1] + (B[2,1,7] * 0.16666666666666666 + B[2,4,7] * 0.3333333333333333) * B[2,4,1], (B[2,1,7] * 0.3333333333333333 + B[2,4,7] * 0.16666666666666666) * B[2,1,2] + (B[2,1,7] * 0.16666666666666666 + B[2,4,7] * 0.3333333333333333) * B[2,4,2], (B[2,1,7] * 0.3333333333333333 + B[2,4,7] * 0.16666666666666666) * B[2,1,3] + (B[2,1,7] * 0.16666666666666666 + B[2,4,7] * 0.3333333333333333) * B[2,4,3], (B[2,1,7] * 0.3333333333333333 + B[2,4,7] * 0.16666666666666666) * B[2,1,4] + (B[2,1,7] * 0.16666666666666666 + B[2,4,7] * 0.3333333333333333) * B[2,4,4], (B[2,1,7] * 0.3333333333333333 + B[2,4,7] * 0.16666666666666666) * B[2,1,5] + (B[2,1,7] * 0.16666666666666666 + B[2,4,7] * 0.3333333333333333) * B[2,4,5], (B[2,1,7] * 0.3333333333333333 + B[2,4,7] * 0.16666666666666666) * B[2,1,6] + (B[2,1,7] * 0.16666666666666666 + B[2,4,7] * 0.3333333333333333) * B[2,4,6], (B[2,1,7] * 0.3333333333333333 + B[2,4,7] * 0.16666666666666666) * B[2,1,7] + (B[2,1,7] * 0.16666666666666666 + B[2,4,7] * 0.3333333333333333) * B[2,4,7], (B[2,1,7] * 0.3333333333333333 + B[2,4,7] * 0.16666666666666666) * B[2,1,8] + (B[2,1,7] * 0.16666666666666666 + B[2,4,7] * 0.3333333333333333) * B[2,4,8], (B[2,1,7] * 0.3333333333333333 + B[2,4,7] * 0.16666666666666666) * B[2,1,9] + (B[2,1,7] * 0.16666666666666666 + B[2,4,7] * 0.3333333333333333) * B[2,4,9]}, {(B[2,1,8] * 0.3333333333333333 + B[2,4,8] * 0.16666666666666666) * B[2,1,1] + (B[2,1,8] * 0.16666666666666666 + B[2,4,8] * 0.3333333333333333) * B[2,4,1], (B[2,1,8] * 0.3333333333333333 + B[2,4,8] * 0.16666666666666666) * B[2,1,2] + (B[2,1,8] * 0.16666666666666666 + B[2,4,8] * 0.3333333333333333) * B[2,4,2], (B[2,1,8] * 0.3333333333333333 + B[2,4,8] * 0.16666666666666666) * B[2,1,3] + (B[2,1,8] * 0.16666666666666666 + B[2,4,8] * 0.3333333333333333) * B[2,4,3], (B[2,1,8] * 0.3333333333333333 + B[2,4,8] * 0.16666666666666666) * B[2,1,4] + (B[2,1,8] * 0.16666666666666666 + B[2,4,8] * 0.3333333333333333) * B[2,4,4], (B[2,1,8] * 0.3333333333333333 + B[2,4,8] * 0.16666666666666666) * B[2,1,5] + (B[2,1,8] * 0.16666666666666666 + B[2,4,8] * 0.3333333333333333) * B[2,4,5], (B[2,1,8] * 0.3333333333333333 + B[2,4,8] * 0.16666666666666666) * B[2,1,6] + (B[2,1,8] * 0.16666666666666666 + B[2,4,8] * 0.3333333333333333) * B[2,4,6], (B[2,1,8] * 0.3333333333333333 + B[2,4,8] * 0.16666666666666666) * B[2,1,7] + (B[2,1,8] * 0.16666666666666666 + B[2,4,8] * 0.3333333333333333) * B[2,4,7], (B[2,1,8] * 0.3333333333333333 + B[2,4,8] * 0.16666666666666666) * B[2,1,8] + (B[2,1,8] * 0.16666666666666666 + B[2,4,8] * 0.3333333333333333) * B[2,4,8], (B[2,1,8] * 0.3333333333333333 + B[2,4,8] * 0.16666666666666666) * B[2,1,9] + (B[2,1,8] * 0.16666666666666666 + B[2,4,8] * 0.3333333333333333) * B[2,4,9]}, {(B[2,1,9] * 0.3333333333333333 + B[2,4,9] * 0.16666666666666666) * B[2,1,1] + (B[2,1,9] * 0.16666666666666666 + B[2,4,9] * 0.3333333333333333) * B[2,4,1], (B[2,1,9] * 0.3333333333333333 + B[2,4,9] * 0.16666666666666666) * B[2,1,2] + (B[2,1,9] * 0.16666666666666666 + B[2,4,9] * 0.3333333333333333) * B[2,4,2], (B[2,1,9] * 0.3333333333333333 + B[2,4,9] * 0.16666666666666666) * B[2,1,3] + (B[2,1,9] * 0.16666666666666666 + B[2,4,9] * 0.3333333333333333) * B[2,4,3], (B[2,1,9] * 0.3333333333333333 + B[2,4,9] * 0.16666666666666666) * B[2,1,4] + (B[2,1,9] * 0.16666666666666666 + B[2,4,9] * 0.3333333333333333) * B[2,4,4], (B[2,1,9] * 0.3333333333333333 + B[2,4,9] * 0.16666666666666666) * B[2,1,5] + (B[2,1,9] * 0.16666666666666666 + B[2,4,9] * 0.3333333333333333) * B[2,4,5], (B[2,1,9] * 0.3333333333333333 + B[2,4,9] * 0.16666666666666666) * B[2,1,6] + (B[2,1,9] * 0.16666666666666666 + B[2,4,9] * 0.3333333333333333) * B[2,4,6], (B[2,1,9] * 0.3333333333333333 + B[2,4,9] * 0.16666666666666666) * B[2,1,7] + (B[2,1,9] * 0.16666666666666666 + B[2,4,9] * 0.3333333333333333) * B[2,4,7], (B[2,1,9] * 0.3333333333333333 + B[2,4,9] * 0.16666666666666666) * B[2,1,8] + (B[2,1,9] * 0.16666666666666666 + B[2,4,9] * 0.3333333333333333) * B[2,4,8], (B[2,1,9] * 0.3333333333333333 + B[2,4,9] * 0.16666666666666666) * B[2,1,9] + (B[2,1,9] * 0.16666666666666666 + B[2,4,9] * 0.3333333333333333) * B[2,4,9]}} + {{(B[3,1,1] * 0.3333333333333333 + B[3,4,1] * 0.16666666666666666) * B[3,1,1] + (B[3,1,1] * 0.16666666666666666 + B[3,4,1] * 0.3333333333333333) * B[3,4,1], (B[3,1,1] * 0.3333333333333333 + B[3,4,1] * 0.16666666666666666) * B[3,1,2] + (B[3,1,1] * 0.16666666666666666 + B[3,4,1] * 0.3333333333333333) * B[3,4,2], (B[3,1,1] * 0.3333333333333333 + B[3,4,1] * 0.16666666666666666) * B[3,1,3] + (B[3,1,1] * 0.16666666666666666 + B[3,4,1] * 0.3333333333333333) * B[3,4,3], (B[3,1,1] * 0.3333333333333333 + B[3,4,1] * 0.16666666666666666) * B[3,1,4] + (B[3,1,1] * 0.16666666666666666 + B[3,4,1] * 0.3333333333333333) * B[3,4,4], (B[3,1,1] * 0.3333333333333333 + B[3,4,1] * 0.16666666666666666) * B[3,1,5] + (B[3,1,1] * 0.16666666666666666 + B[3,4,1] * 0.3333333333333333) * B[3,4,5], (B[3,1,1] * 0.3333333333333333 + B[3,4,1] * 0.16666666666666666) * B[3,1,6] + (B[3,1,1] * 0.16666666666666666 + B[3,4,1] * 0.3333333333333333) * B[3,4,6], (B[3,1,1] * 0.3333333333333333 + B[3,4,1] * 0.16666666666666666) * B[3,1,7] + (B[3,1,1] * 0.16666666666666666 + B[3,4,1] * 0.3333333333333333) * B[3,4,7], (B[3,1,1] * 0.3333333333333333 + B[3,4,1] * 0.16666666666666666) * B[3,1,8] + (B[3,1,1] * 0.16666666666666666 + B[3,4,1] * 0.3333333333333333) * B[3,4,8], (B[3,1,1] * 0.3333333333333333 + B[3,4,1] * 0.16666666666666666) * B[3,1,9] + (B[3,1,1] * 0.16666666666666666 + B[3,4,1] * 0.3333333333333333) * B[3,4,9]}, {(B[3,1,2] * 0.3333333333333333 + B[3,4,2] * 0.16666666666666666) * B[3,1,1] + (B[3,1,2] * 0.16666666666666666 + B[3,4,2] * 0.3333333333333333) * B[3,4,1], (B[3,1,2] * 0.3333333333333333 + B[3,4,2] * 0.16666666666666666) * B[3,1,2] + (B[3,1,2] * 0.16666666666666666 + B[3,4,2] * 0.3333333333333333) * B[3,4,2], (B[3,1,2] * 0.3333333333333333 + B[3,4,2] * 0.16666666666666666) * B[3,1,3] + (B[3,1,2] * 0.16666666666666666 + B[3,4,2] * 0.3333333333333333) * B[3,4,3], (B[3,1,2] * 0.3333333333333333 + B[3,4,2] * 0.16666666666666666) * B[3,1,4] + (B[3,1,2] * 0.16666666666666666 + B[3,4,2] * 0.3333333333333333) * B[3,4,4], (B[3,1,2] * 0.3333333333333333 + B[3,4,2] * 0.16666666666666666) * B[3,1,5] + (B[3,1,2] * 0.16666666666666666 + B[3,4,2] * 0.3333333333333333) * B[3,4,5], (B[3,1,2] * 0.3333333333333333 + B[3,4,2] * 0.16666666666666666) * B[3,1,6] + (B[3,1,2] * 0.16666666666666666 + B[3,4,2] * 0.3333333333333333) * B[3,4,6], (B[3,1,2] * 0.3333333333333333 + B[3,4,2] * 0.16666666666666666) * B[3,1,7] + (B[3,1,2] * 0.16666666666666666 + B[3,4,2] * 0.3333333333333333) * B[3,4,7], (B[3,1,2] * 0.3333333333333333 + B[3,4,2] * 0.16666666666666666) * B[3,1,8] + (B[3,1,2] * 0.16666666666666666 + B[3,4,2] * 0.3333333333333333) * B[3,4,8], (B[3,1,2] * 0.3333333333333333 + B[3,4,2] * 0.16666666666666666) * B[3,1,9] + (B[3,1,2] * 0.16666666666666666 + B[3,4,2] * 0.3333333333333333) * B[3,4,9]}, {(B[3,1,3] * 0.3333333333333333 + B[3,4,3] * 0.16666666666666666) * B[3,1,1] + (B[3,1,3] * 0.16666666666666666 + B[3,4,3] * 0.3333333333333333) * B[3,4,1], (B[3,1,3] * 0.3333333333333333 + B[3,4,3] * 0.16666666666666666) * B[3,1,2] + (B[3,1,3] * 0.16666666666666666 + B[3,4,3] * 0.3333333333333333) * B[3,4,2], (B[3,1,3] * 0.3333333333333333 + B[3,4,3] * 0.16666666666666666) * B[3,1,3] + (B[3,1,3] * 0.16666666666666666 + B[3,4,3] * 0.3333333333333333) * B[3,4,3], (B[3,1,3] * 0.3333333333333333 + B[3,4,3] * 0.16666666666666666) * B[3,1,4] + (B[3,1,3] * 0.16666666666666666 + B[3,4,3] * 0.3333333333333333) * B[3,4,4], (B[3,1,3] * 0.3333333333333333 + B[3,4,3] * 0.16666666666666666) * B[3,1,5] + (B[3,1,3] * 0.16666666666666666 + B[3,4,3] * 0.3333333333333333) * B[3,4,5], (B[3,1,3] * 0.3333333333333333 + B[3,4,3] * 0.16666666666666666) * B[3,1,6] + (B[3,1,3] * 0.16666666666666666 + B[3,4,3] * 0.3333333333333333) * B[3,4,6], (B[3,1,3] * 0.3333333333333333 + B[3,4,3] * 0.16666666666666666) * B[3,1,7] + (B[3,1,3] * 0.16666666666666666 + B[3,4,3] * 0.3333333333333333) * B[3,4,7], (B[3,1,3] * 0.3333333333333333 + B[3,4,3] * 0.16666666666666666) * B[3,1,8] + (B[3,1,3] * 0.16666666666666666 + B[3,4,3] * 0.3333333333333333) * B[3,4,8], (B[3,1,3] * 0.3333333333333333 + B[3,4,3] * 0.16666666666666666) * B[3,1,9] + (B[3,1,3] * 0.16666666666666666 + B[3,4,3] * 0.3333333333333333) * B[3,4,9]}, {(B[3,1,4] * 0.3333333333333333 + B[3,4,4] * 0.16666666666666666) * B[3,1,1] + (B[3,1,4] * 0.16666666666666666 + B[3,4,4] * 0.3333333333333333) * B[3,4,1], (B[3,1,4] * 0.3333333333333333 + B[3,4,4] * 0.16666666666666666) * B[3,1,2] + (B[3,1,4] * 0.16666666666666666 + B[3,4,4] * 0.3333333333333333) * B[3,4,2], (B[3,1,4] * 0.3333333333333333 + B[3,4,4] * 0.16666666666666666) * B[3,1,3] + (B[3,1,4] * 0.16666666666666666 + B[3,4,4] * 0.3333333333333333) * B[3,4,3], (B[3,1,4] * 0.3333333333333333 + B[3,4,4] * 0.16666666666666666) * B[3,1,4] + (B[3,1,4] * 0.16666666666666666 + B[3,4,4] * 0.3333333333333333) * B[3,4,4], (B[3,1,4] * 0.3333333333333333 + B[3,4,4] * 0.16666666666666666) * B[3,1,5] + (B[3,1,4] * 0.16666666666666666 + B[3,4,4] * 0.3333333333333333) * B[3,4,5], (B[3,1,4] * 0.3333333333333333 + B[3,4,4] * 0.16666666666666666) * B[3,1,6] + (B[3,1,4] * 0.16666666666666666 + B[3,4,4] * 0.3333333333333333) * B[3,4,6], (B[3,1,4] * 0.3333333333333333 + B[3,4,4] * 0.16666666666666666) * B[3,1,7] + (B[3,1,4] * 0.16666666666666666 + B[3,4,4] * 0.3333333333333333) * B[3,4,7], (B[3,1,4] * 0.3333333333333333 + B[3,4,4] * 0.16666666666666666) * B[3,1,8] + (B[3,1,4] * 0.16666666666666666 + B[3,4,4] * 0.3333333333333333) * B[3,4,8], (B[3,1,4] * 0.3333333333333333 + B[3,4,4] * 0.16666666666666666) * B[3,1,9] + (B[3,1,4] * 0.16666666666666666 + B[3,4,4] * 0.3333333333333333) * B[3,4,9]}, {(B[3,1,5] * 0.3333333333333333 + B[3,4,5] * 0.16666666666666666) * B[3,1,1] + (B[3,1,5] * 0.16666666666666666 + B[3,4,5] * 0.3333333333333333) * B[3,4,1], (B[3,1,5] * 0.3333333333333333 + B[3,4,5] * 0.16666666666666666) * B[3,1,2] + (B[3,1,5] * 0.16666666666666666 + B[3,4,5] * 0.3333333333333333) * B[3,4,2], (B[3,1,5] * 0.3333333333333333 + B[3,4,5] * 0.16666666666666666) * B[3,1,3] + (B[3,1,5] * 0.16666666666666666 + B[3,4,5] * 0.3333333333333333) * B[3,4,3], (B[3,1,5] * 0.3333333333333333 + B[3,4,5] * 0.16666666666666666) * B[3,1,4] + (B[3,1,5] * 0.16666666666666666 + B[3,4,5] * 0.3333333333333333) * B[3,4,4], (B[3,1,5] * 0.3333333333333333 + B[3,4,5] * 0.16666666666666666) * B[3,1,5] + (B[3,1,5] * 0.16666666666666666 + B[3,4,5] * 0.3333333333333333) * B[3,4,5], (B[3,1,5] * 0.3333333333333333 + B[3,4,5] * 0.16666666666666666) * B[3,1,6] + (B[3,1,5] * 0.16666666666666666 + B[3,4,5] * 0.3333333333333333) * B[3,4,6], (B[3,1,5] * 0.3333333333333333 + B[3,4,5] * 0.16666666666666666) * B[3,1,7] + (B[3,1,5] * 0.16666666666666666 + B[3,4,5] * 0.3333333333333333) * B[3,4,7], (B[3,1,5] * 0.3333333333333333 + B[3,4,5] * 0.16666666666666666) * B[3,1,8] + (B[3,1,5] * 0.16666666666666666 + B[3,4,5] * 0.3333333333333333) * B[3,4,8], (B[3,1,5] * 0.3333333333333333 + B[3,4,5] * 0.16666666666666666) * B[3,1,9] + (B[3,1,5] * 0.16666666666666666 + B[3,4,5] * 0.3333333333333333) * B[3,4,9]}, {(B[3,1,6] * 0.3333333333333333 + B[3,4,6] * 0.16666666666666666) * B[3,1,1] + (B[3,1,6] * 0.16666666666666666 + B[3,4,6] * 0.3333333333333333) * B[3,4,1], (B[3,1,6] * 0.3333333333333333 + B[3,4,6] * 0.16666666666666666) * B[3,1,2] + (B[3,1,6] * 0.16666666666666666 + B[3,4,6] * 0.3333333333333333) * B[3,4,2], (B[3,1,6] * 0.3333333333333333 + B[3,4,6] * 0.16666666666666666) * B[3,1,3] + (B[3,1,6] * 0.16666666666666666 + B[3,4,6] * 0.3333333333333333) * B[3,4,3], (B[3,1,6] * 0.3333333333333333 + B[3,4,6] * 0.16666666666666666) * B[3,1,4] + (B[3,1,6] * 0.16666666666666666 + B[3,4,6] * 0.3333333333333333) * B[3,4,4], (B[3,1,6] * 0.3333333333333333 + B[3,4,6] * 0.16666666666666666) * B[3,1,5] + (B[3,1,6] * 0.16666666666666666 + B[3,4,6] * 0.3333333333333333) * B[3,4,5], (B[3,1,6] * 0.3333333333333333 + B[3,4,6] * 0.16666666666666666) * B[3,1,6] + (B[3,1,6] * 0.16666666666666666 + B[3,4,6] * 0.3333333333333333) * B[3,4,6], (B[3,1,6] * 0.3333333333333333 + B[3,4,6] * 0.16666666666666666) * B[3,1,7] + (B[3,1,6] * 0.16666666666666666 + B[3,4,6] * 0.3333333333333333) * B[3,4,7], (B[3,1,6] * 0.3333333333333333 + B[3,4,6] * 0.16666666666666666) * B[3,1,8] + (B[3,1,6] * 0.16666666666666666 + B[3,4,6] * 0.3333333333333333) * B[3,4,8], (B[3,1,6] * 0.3333333333333333 + B[3,4,6] * 0.16666666666666666) * B[3,1,9] + (B[3,1,6] * 0.16666666666666666 + B[3,4,6] * 0.3333333333333333) * B[3,4,9]}, {(B[3,1,7] * 0.3333333333333333 + B[3,4,7] * 0.16666666666666666) * B[3,1,1] + (B[3,1,7] * 0.16666666666666666 + B[3,4,7] * 0.3333333333333333) * B[3,4,1], (B[3,1,7] * 0.3333333333333333 + B[3,4,7] * 0.16666666666666666) * B[3,1,2] + (B[3,1,7] * 0.16666666666666666 + B[3,4,7] * 0.3333333333333333) * B[3,4,2], (B[3,1,7] * 0.3333333333333333 + B[3,4,7] * 0.16666666666666666) * B[3,1,3] + (B[3,1,7] * 0.16666666666666666 + B[3,4,7] * 0.3333333333333333) * B[3,4,3], (B[3,1,7] * 0.3333333333333333 + B[3,4,7] * 0.16666666666666666) * B[3,1,4] + (B[3,1,7] * 0.16666666666666666 + B[3,4,7] * 0.3333333333333333) * B[3,4,4], (B[3,1,7] * 0.3333333333333333 + B[3,4,7] * 0.16666666666666666) * B[3,1,5] + (B[3,1,7] * 0.16666666666666666 + B[3,4,7] * 0.3333333333333333) * B[3,4,5], (B[3,1,7] * 0.3333333333333333 + B[3,4,7] * 0.16666666666666666) * B[3,1,6] + (B[3,1,7] * 0.16666666666666666 + B[3,4,7] * 0.3333333333333333) * B[3,4,6], (B[3,1,7] * 0.3333333333333333 + B[3,4,7] * 0.16666666666666666) * B[3,1,7] + (B[3,1,7] * 0.16666666666666666 + B[3,4,7] * 0.3333333333333333) * B[3,4,7], (B[3,1,7] * 0.3333333333333333 + B[3,4,7] * 0.16666666666666666) * B[3,1,8] + (B[3,1,7] * 0.16666666666666666 + B[3,4,7] * 0.3333333333333333) * B[3,4,8], (B[3,1,7] * 0.3333333333333333 + B[3,4,7] * 0.16666666666666666) * B[3,1,9] + (B[3,1,7] * 0.16666666666666666 + B[3,4,7] * 0.3333333333333333) * B[3,4,9]}, {(B[3,1,8] * 0.3333333333333333 + B[3,4,8] * 0.16666666666666666) * B[3,1,1] + (B[3,1,8] * 0.16666666666666666 + B[3,4,8] * 0.3333333333333333) * B[3,4,1], (B[3,1,8] * 0.3333333333333333 + B[3,4,8] * 0.16666666666666666) * B[3,1,2] + (B[3,1,8] * 0.16666666666666666 + B[3,4,8] * 0.3333333333333333) * B[3,4,2], (B[3,1,8] * 0.3333333333333333 + B[3,4,8] * 0.16666666666666666) * B[3,1,3] + (B[3,1,8] * 0.16666666666666666 + B[3,4,8] * 0.3333333333333333) * B[3,4,3], (B[3,1,8] * 0.3333333333333333 + B[3,4,8] * 0.16666666666666666) * B[3,1,4] + (B[3,1,8] * 0.16666666666666666 + B[3,4,8] * 0.3333333333333333) * B[3,4,4], (B[3,1,8] * 0.3333333333333333 + B[3,4,8] * 0.16666666666666666) * B[3,1,5] + (B[3,1,8] * 0.16666666666666666 + B[3,4,8] * 0.3333333333333333) * B[3,4,5], (B[3,1,8] * 0.3333333333333333 + B[3,4,8] * 0.16666666666666666) * B[3,1,6] + (B[3,1,8] * 0.16666666666666666 + B[3,4,8] * 0.3333333333333333) * B[3,4,6], (B[3,1,8] * 0.3333333333333333 + B[3,4,8] * 0.16666666666666666) * B[3,1,7] + (B[3,1,8] * 0.16666666666666666 + B[3,4,8] * 0.3333333333333333) * B[3,4,7], (B[3,1,8] * 0.3333333333333333 + B[3,4,8] * 0.16666666666666666) * B[3,1,8] + (B[3,1,8] * 0.16666666666666666 + B[3,4,8] * 0.3333333333333333) * B[3,4,8], (B[3,1,8] * 0.3333333333333333 + B[3,4,8] * 0.16666666666666666) * B[3,1,9] + (B[3,1,8] * 0.16666666666666666 + B[3,4,8] * 0.3333333333333333) * B[3,4,9]}, {(B[3,1,9] * 0.3333333333333333 + B[3,4,9] * 0.16666666666666666) * B[3,1,1] + (B[3,1,9] * 0.16666666666666666 + B[3,4,9] * 0.3333333333333333) * B[3,4,1], (B[3,1,9] * 0.3333333333333333 + B[3,4,9] * 0.16666666666666666) * B[3,1,2] + (B[3,1,9] * 0.16666666666666666 + B[3,4,9] * 0.3333333333333333) * B[3,4,2], (B[3,1,9] * 0.3333333333333333 + B[3,4,9] * 0.16666666666666666) * B[3,1,3] + (B[3,1,9] * 0.16666666666666666 + B[3,4,9] * 0.3333333333333333) * B[3,4,3], (B[3,1,9] * 0.3333333333333333 + B[3,4,9] * 0.16666666666666666) * B[3,1,4] + (B[3,1,9] * 0.16666666666666666 + B[3,4,9] * 0.3333333333333333) * B[3,4,4], (B[3,1,9] * 0.3333333333333333 + B[3,4,9] * 0.16666666666666666) * B[3,1,5] + (B[3,1,9] * 0.16666666666666666 + B[3,4,9] * 0.3333333333333333) * B[3,4,5], (B[3,1,9] * 0.3333333333333333 + B[3,4,9] * 0.16666666666666666) * B[3,1,6] + (B[3,1,9] * 0.16666666666666666 + B[3,4,9] * 0.3333333333333333) * B[3,4,6], (B[3,1,9] * 0.3333333333333333 + B[3,4,9] * 0.16666666666666666) * B[3,1,7] + (B[3,1,9] * 0.16666666666666666 + B[3,4,9] * 0.3333333333333333) * B[3,4,7], (B[3,1,9] * 0.3333333333333333 + B[3,4,9] * 0.16666666666666666) * B[3,1,8] + (B[3,1,9] * 0.16666666666666666 + B[3,4,9] * 0.3333333333333333) * B[3,4,8], (B[3,1,9] * 0.3333333333333333 + B[3,4,9] * 0.16666666666666666) * B[3,1,9] + (B[3,1,9] * 0.16666666666666666 + B[3,4,9] * 0.3333333333333333) * B[3,4,9]}};

which comes from the reduction expression in

  Real s[:,:] = sum(transpose(B[i, :, :])*Sbar11*B[i,:,:] for i in 1:N);

That equation should be expanded into a much shorter expression, as there are only a handful of non-zero B[:,:,:] elements.

The question for @kabdelhak and @phannebohm is how they want to handle this with the new backend. I guess in this case the trick will be that the array-preserving NF does not even try to expand the RHS of the equation shown above and passes it straight to the NB. Then, they will have to figure out a smart way to handle the sparse matrix product efficiently, without ever fully expanding it, which is a killer.

perost commented 10 months ago

11626 improves things a bit by simplifying e.g. {x[1], x[2]} + {y[1], y[2]} => {x[1] + y[1], x[2] + y[2]}. It was only really meant to get rid of the zero-arrays at the start of the expressions, which are used as start values when simplifying sum/product reductions and were not simplified away earlier. But it actually improves this model quite a bit, lowering the time to ~5s and reducing the output to "only" about 2MB. I'm not sure why though, it doesn't affect the smaller model from #11412 in the same way.

As for the fact that B is mostly non-zero, it's not really something the frontend can use since B is both a variable and defined by equations. I think the best solution would be for the frontend to not expand the sum expressions at all and leave it to the backend, which does seem to work fine if I manually disable things in the code. Ideally we should expand expressions a lot less, but it tends to break the backend in surprising ways unfortunately.

casella commented 10 months ago

11626 improves things a bit by simplifying e.g. {x[1], x[2]} + {y[1], y[2]} => {x[1] + y[1], x[2] + y[2]}. It was only really meant to get rid of the zero-arrays at the start of the expressions, which are used as start values when simplifying sum/product reductions and were not simplified away earlier. But it actually improves this model quite a bit, lowering the time to ~5s and reducing the output to "only" about 2MB.

OK, I'll check that, thanks!

I'm not sure why though, it doesn't affect the smaller model from #11412 in the same way.

No idea, but in fact the part the really blew up with the multi-million lines of code was not the one I reproduced in #11412.

As for the fact that B is mostly non-zero, it's not really something the frontend can use since B is both a variable and defined by equations.

Sure, of course in general this is a job for the backend. My point was, if the frontend expands the expressions, then make an exception and take into account simple equations such as xxx = 0 to simplify expressions.

I think the best solution would be for the frontend to not expand the sum expressions at all and leave it to the backend, which does seem to work fine if I manually disable things in the code.

If the backend can already handle that, that's how it should be done. Maybe you could try that once Jenkins is up and running again and we have a stable situation with testing?

Ideally we should expand expressions a lot less, but it tends to break the backend in surprising ways unfortunately.

Yes, that's what I'm a bit afraid of.

BTW, is there a way you can run an on-demand library testsuite Jenkins job on a branch, without disrupting whatever we have on master? That could be useful in cases such as this one.