/******************************************************************************* * * McStas, the neutron ray-tracing package * Maintained by Kristian Nielsen and Kim Lefmann, * Copyright 1997-2000 Risoe National Laboratory, Roskilde, Denmark * * %I * Written by: KL * Modified by: KL, KN, October 5, 1998 * Date: October 30, 1997 * Version: $Revision: 1.1.1.1 $ * Origin: McStas release * * Neutron source with flat energy spectrum and arbitrary flux * * %D * The routine is a circular neutron source, which aims at a square target * centered at the beam (in order to improve MC-acceptance rate). The angular * divergence is then given by the dimensions of the target. The neutron energy is * uniformly distrubuted between E0-dE and E0+dE. * * ToDo: More flexible specification of E distribution. * * %P * radius: (m) Radius of circle in (x,y,0) plane where neutrons * are generated. * dist: (m) Distance to target along z axis. * xw: (m) Width(x) of target * yh: (m) Height(y) of target * E0: (meV) Mean energy of neutrons. * dE: (meV) Energy spread of neutrons. * * %L * * Test results (not up-to-date). * * %E *******************************************************************************/ DEFINE COMPONENT Source_flat DEFINITION PARAMETERS () SETTING PARAMETERS (radius, dist, xw, yh, E0, dE) OUTPUT PARAMETERS (hdiv, vdiv, p_in) STATE PARAMETERS (x,y,z,vx,vy,vz,t,s1,s2,p) DECLARE %{ double hdiv,vdiv; double p_in; %} INITIALIZE %{ hdiv = atan(xw/(2.0*dist)); vdiv = atan(yh/(2.0*dist)); p_in = (4*hdiv*vdiv)/(4*PI); /* Small angle approx. */ %} TRACE %{ double theta0,phi0,chi,theta,phi,E,v,r; p=p_in; z=0; chi=2*PI*rand01(); /* Choose point on source */ r=sqrt(rand01())*radius; /* with uniform distribution. */ x=r*cos(chi); y=r*sin(chi); theta0= -atan(x/dist); /* Angles to aim at target centre */ phi0= -atan(y/dist); theta=theta0+hdiv*randpm1(); /* Small angle approx. */ phi=phi0+vdiv*randpm1(); E=E0+dE*randpm1(); /* Assume linear distribution */ v=sqrt(E)*SE2V; vz=v*cos(phi)*cos(theta); vy=v*sin(phi); vx=v*cos(phi)*sin(theta); %} MCDISPLAY %{ magnify("xy"); circle("xy",0,0,0,radius); %} END