McStasMcXtrace / mccode-antlr

McCode grammar implemented with ANTLR4
1 stars 0 forks source link

`Expr` operations need a simplify option #58

Closed g5t closed 2 months ago

g5t commented 2 months ago

For a component positioned based on an instrument parameter, e.g.,

DEFINE INSTRUMENT instrument(dist)
TRACE
COMPONENT origin = Arm() AT (0, 0, 0) ABSOLUTE
COMPONENT source = Source_simple() AT (0, 0, 0) RELATIVE origin
COMPONENT sample = Arm() AT (0, 0, dist) RELATIVE source
END

moreniius is unable to set the correct transformation dependency chain in part due to needing the direction and length of the vector [0, 0, dist].

Utilities already allow for the length, identified correctly as abs(dist), but the direction [0, 0, dist]/abs(dist) is not simplified to, e.g. [0, 0, sign(dist)].


What is likely needed in this case for full conversion to NeXus Structure is length=dist and direction=[0, 0, 1].

g5t commented 2 months ago

As noted in https://github.com/g5t/moreniius/issue/4, a solution without this has been identified and implemented.

Improving the situation in mccode_antlr would likely require replacing Expr trees with a more-widely used alternate -- perhaps going so far as to make use of sympy (and pymbolic could be a useful stepping stone along that path).