diff --git a/docs/manuals/mcstas/kernelcalls.tex b/docs/manuals/mcstas/kernelcalls.tex index 62ae059dc0..f2caac26a8 100644 --- a/docs/manuals/mcstas/kernelcalls.tex +++ b/docs/manuals/mcstas/kernelcalls.tex @@ -79,6 +79,14 @@ \subsection{Neutron propagation} \item \textbfMCRH{PROP\_GRAV\_DT}$(dt,Ax,Ay,Az)$. Like \textbf{PROP\_DT}, but it also includes gravity using the acceleration $(Ax,Ay,Az)$. In addition to adjusting $(x,y,z)$ and $t$, also $(vx,vy,vz)$ is modified. +\item \textbfMCRH{PROP\_NO\_G\_DT}$(dt)$. Propagates the neutron through the + time interval $dt$ using straight-line motion, regardless of the global + gravitation setting. The negative-time and back-propagation rules are the + same as for \textbf{PROP\_DT}. +\item \textbfMCRH{PROP\_NO\_G\_X0}, \textbfMCRH{PROP\_NO\_G\_Y0}, and + \textbfMCRH{PROP\_NO\_G\_Z0}. Propagate the neutron to the corresponding + local coordinate plane using straight-line motion, regardless of the global + gravitation setting. \item \textbfMCRH{ALLOW\_BACKPROP}. Indicates that the next propagation routine will not remove the neutron ray, even if negative propagation times are found. Subsequent propagations are not affected. diff --git a/mccode/nlib/share/mcstas-r.h b/mccode/nlib/share/mcstas-r.h index 0b61255415..33bea2eded 100644 --- a/mccode/nlib/share/mcstas-r.h +++ b/mccode/nlib/share/mcstas-r.h @@ -201,6 +201,30 @@ void SCATTER_func(_class_particle *_particle); /* provides function to SCATTER f } while(0) +/* Propagation variants that always use straight-line motion. */ +#define PROP_NO_G_DT(dt) \ + do { \ + if(dt < 0 && allow_backprop == 0) { RESTORE=1; ABSORB; }; \ + mcPROP_DT(dt); \ + DISALLOW_BACKPROP; \ + } while(0) + +#define PROP_NO_G_Z0 \ + do { \ + mcPROP_Z0; \ + } while(0) + +#define PROP_NO_G_X0 \ + do { \ + mcPROP_X0; \ + } while(0) + +#define PROP_NO_G_Y0 \ + do { \ + mcPROP_Y0; \ + } while(0) + + #ifdef DEBUG #define DEBUG_STATE() if(!mcdotrace); else \ diff --git a/mcstas-comps/examples/Tests_grammar/Unittest_PROP_NO_G/Unittest_PROP_NO_G.instr b/mcstas-comps/examples/Tests_grammar/Unittest_PROP_NO_G/Unittest_PROP_NO_G.instr new file mode 100644 index 0000000000..7895f43e35 --- /dev/null +++ b/mcstas-comps/examples/Tests_grammar/Unittest_PROP_NO_G/Unittest_PROP_NO_G.instr @@ -0,0 +1,51 @@ +/******************************************************************************* +* McStas, neutron ray-tracing package +* +* Instrument: Unittest_PROP_NO_G +* +* %Identification +* Written by: Mads Bertelsen +* Date: September 2026 +* Origin: ESS +* %INSTRUMENT_SITE: Tests_grammar +* +* Test for the PROP_NO_G_DT propagation macro. +* +* %Description +* A long-wavelength beam is focused onto a small detector 10 m away. The +* intermediate Arm uses PROP_NO_G_DT, so the beam should remain focused even +* when gravity is enabled. +* +* %Example: -g Detector: PropNoGMonitor_I=7.95774e-8 +* +* %End +*******************************************************************************/ +DEFINE INSTRUMENT Unittest_PROP_NO_G() + +TRACE + +COMPONENT Origin = Progress_bar() + AT (0, 0, 0) ABSOLUTE + +COMPONENT Source = Source_simple( + radius = 0.01, + dist = 10, + focus_xw = 0.01, + focus_yh = 0.01, + lambda0 = 30, + dlambda = 0, + flux = 0) + AT (0, 0, 0) RELATIVE Origin + +COMPONENT PropNoG = Arm() + AT (0, 0, 0) RELATIVE Source +EXTEND %{ + PROP_NO_G_DT(10/vz); +%} + +COMPONENT PropNoGMonitor = Monitor( + xwidth = 0.01, + yheight = 0.01) + AT (0, 0, 10) RELATIVE PropNoG + +END diff --git a/support/common/editors/mccode.lang b/support/common/editors/mccode.lang index e7dd2f6361..54002c0c42 100644 --- a/support/common/editors/mccode.lang +++ b/support/common/editors/mccode.lang @@ -397,9 +397,13 @@ RESTORE_NEUTRON PROP_GRAV_DT PROP_DT + PROP_NO_G_DT PROP_Z0 PROP_X0 PROP_Y0 + PROP_NO_G_Z0 + PROP_NO_G_X0 + PROP_NO_G_Y0 vec_prod scalar_prod NORM diff --git a/support/common/editors/mccode.vim b/support/common/editors/mccode.vim index fada7871c1..f52551edab 100644 --- a/support/common/editors/mccode.vim +++ b/support/common/editors/mccode.vim @@ -65,10 +65,14 @@ \ RESTORE_NEUTRON \ PROP_GRAV_DT \ PROP_DT + \ PROP_NO_G_DT \ PROP_DL \ PROP_Z0 \ PROP_X0 \ PROP_Y0 + \ PROP_NO_G_Z0 + \ PROP_NO_G_X0 + \ PROP_NO_G_Y0 \ vec_prod \ scalar_prod \ NORM