McStasMcXtrace / McCode

The home of the McStas (neutrons) and McXtrace (x-rays) Monte-Carlo ray-tracing instrument simulation codes.
https://github.com/McStasMcXtrace/McCode/wiki
GNU General Public License v3.0
77 stars 52 forks source link

Don't add SPLIT on GROUP members #1617

Open willend opened 1 month ago

willend commented 1 month ago

Prompted by @g5t I just had a look at the NICOS virtual McStas models available at git clone https://forge.frm2.tum.de/review/mlz/mcstas/nicos-instruments

One of these (panda_bambus) has 501 (!!) Monochromator_curved in a GROUP that each have a SPLIT 20: grep SPLIT BAMBUS.instr | grep PG | wc -l

In targeted v. 2.7.2 this is (inadvertently?) handled by a single SPLIT on the GROUP it seems:

INFO: No output directory specified (--dir)
INFO: Using directory: "BAMBUS_20240527_114358"
INFO: Regenerating c-file: BAMBUS.c
Info:    'Al_window' is a contributed component.
Info:    Defining SPLIT from PG002_mono=Monochromator_curved() to END in instrument PANDA
Info:    Defining SPLIT from PANDA_cryst_phonon=Phonon_simple() to END in instrument PANDA
Info:    Defining SPLIT from PG002_ana_up1_1_1_1=Monochromator_curved() to END in instrument PANDA
CFLAGS=

... Whereas we in McStas-3.x get the start of building logic for 500 SPLITS - each with a Warning:

Warning: WARNING: Component PG002_ana_up1_1_1_1=Monochromator_curved() at line BAMBUS.instr:1051 is in GROUP analyzers and has a SPLIT.
        Move the SPLIT keyword before (outside) the component instance PG002_ana_up1_1_1_1 (first in GROUP)
Warning: WARNING: Component PG002_ana_up1_1_1_2=Monochromator_curved() at line BAMBUS.instr:1056 is in GROUP analyzers and has a SPLIT.
        Move the SPLIT keyword before (outside) the component instance PG002_ana_up1_1_1_1 (first in GROUP)
Warning: WARNING: Component PG002_ana_up1_1_1_3=Monochromator_curved() at line BAMBUS.instr:1061 is in GROUP analyzers and has a SPLIT.
        Move the SPLIT keyword before (outside) the component instance PG002_ana_up1_1_1_1 (first in GROUP)
Warning: WARNING: Component PG002_ana_up1_1_1_4=Monochromator_curved() at line BAMBUS.instr:1066 is in GROUP analyzers and has a SPLIT.
        Move the SPLIT keyword before (outside) the component instance PG002_ana_up1_1_1_1 (first in GROUP)
Warning: WARNING: Component PG002_ana_up1_1_1_5=Monochromator_curved() at line BAMBUS.instr:1071 is in GROUP analyzers and has a SPLIT.
        Move the SPLIT keyword before (outside) the component instance PG002_ana_up1_1_1_1 (first in GROUP)

Perhaps we should make that Warning a proper error instead...

willend commented 1 month ago

A number of existing instruments may include SPLIT on the first element of a GROUP - so I am currently aiming for a fatal error in case of any later SPLIT, i.e.

FATAL ERROR:
  Component PG002_ana_up1_1_1_2=Monochromator_curved() at line BAMBUS.instr:1057 is in GROUP analyzers and has a SPLIT.
    Only the first component of a GROUP may impose SPLIT, so please only include 
    SPLIT on PG002_ana_up1_1_1_1 (first in GROUP) or better yet to an earlier component!
willend commented 1 month ago

1st GROUP comp, raise a warning / recommendation:

INFO: No output directory specified (--dir)
INFO: Using directory: "BAMBUS_20240527_145301"
INFO: Regenerating c-file: BAMBUS.c
Info:    'Al_window' is a contributed component.
Warning:  Component PG002_ana_up1_1_1_1=Monochromator_curved() at line BAMBUS.instr:1052 is 1st in GROUP analyzers and has a SPLIT.
        Best practice is to move the SPLIT to an earlier component.

--> Added COMPONENT PG002_mono USERVAR ncol_23 with type int 

Exit in case of SPLIT on later GROUP comp:

INFO: No output directory specified (--dir)
INFO: Using directory: "BAMBUS_20240527_145534"
INFO: Regenerating c-file: BAMBUS.c
Info:    'Al_window' is a contributed component.
Warning:  Component PG002_ana_up1_1_1_1=Monochromator_curved() at line BAMBUS.instr:1052 is 1st in GROUP analyzers and has a SPLIT.
    Best practice is to move the SPLIT to an earlier component.

FATAL ERROR:
    Component PG002_ana_up1_1_1_2=Monochromator_curved() at line BAMBUS.instr:1057 is in GROUP analyzers and has a SPLIT.
    Only the first component of a GROUP may impose SPLIT, so please only include 
    SPLIT on PG002_ana_up1_1_1_1 (first in GROUP) or better yet to an earlier component!