Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 36 additions & 37 deletions mcstas-comps/contrib/Al_window.comp
Original file line number Diff line number Diff line change
Expand Up @@ -44,60 +44,59 @@ SETTING PARAMETERS (thickness=0.001)
/* Neutron parameters: (x,y,z,vx,vy,vz,t,sx,sy,sz,p) */
SHARE
%{
/* ToDo: Should be component local names. */
#ifndef AL_WINDOW
#define avogadro 6.022 /* 10E23 Atoms per mole (mol-1) */
#define Al_sigma_a .231 /* Absorption cross section per atom (barns) at 2200m/s */
#define Al_sigma_i .0082 /* Incoherent scattering cross section per atom (barns) */
#define Al_rho 2.7 /* density (gcm-3) */
#define Al_mmol 27 /* molar mass Al (gmol-1) */
#define Al_my_s (Al_rho / Al_mmol * Al_sigma_i * avogadro * 10) /* inc. XS (barn) */
#define Al_my_a_v (Al_rho / Al_mmol * Al_sigma_a * avogadro * 10 * 2200 )
/* Define Constants for Polynomial Fit of
sigma_tot(lambda)=A+B1*X+B2*X^2+B3*X^3+B4*X^4+... */
#define Al_pf_A 1.34722
#define Al_pf_B1 .12409
#define Al_pf_B2 .01078
#define Al_pf_B3 -3.25895e-5
#define Al_pf_B4 3.74731e-6
#define AL_WINDOW
#endif
/* ToDo: Should be component local names. */
#ifndef AL_WINDOW
#define avogadro 6.022 /* 10E23 Atoms per mole (mol-1) */
#define Al_sigma_a .231 /* Absorption cross section per atom (barns) at 2200m/s */
#define Al_sigma_i .0082 /* Incoherent scattering cross section per atom (barns) */
#define Al_rho 2.7 /* density (gcm-3) */
#define Al_mmol 27 /* molar mass Al (gmol-1) */
#define Al_my_s (Al_rho / Al_mmol * Al_sigma_i * avogadro * 10) /* inc. XS (barn) */
#define Al_my_a_v (Al_rho / Al_mmol * Al_sigma_a * avogadro * 10 * 2200 )
/* Define Constants for Polynomial Fit of
sigma_tot(lambda)=A+B1*X+B2*X^2+B3*X^3+B4*X^4+... */
#define Al_pf_A 1.34722
#define Al_pf_B1 .12409
#define Al_pf_B2 .01078
#define Al_pf_B3 -3.25895e-5
#define Al_pf_B4 3.74731e-6
#define AL_WINDOW
#endif
%}

TRACE
%{
double v; /* Neutron velocity */
double dt0; /* Flight times through sample */
double v; /* Neutron velocity */
double dt0; /* Flight times through sample */
double dist;
double Al_s_tot_lambda,Al_my_tot,Al_my_a ; /* total XS (barn), total scattering length (m-1), absorption scat. length */
double lambda; /* neutrons wavelength */
double Al_s_tot_lambda, Al_my_tot, Al_my_a; /* total XS (barn), total scattering length (m-1), absorption scat. length */
double lambda; /* neutrons wavelength */

PROP_Z0;

dt0=thickness/vz;
v=sqrt(vx*vx+vy*vy+vz*vz);
PROP_DT(dt0);
dist=v*dt0;
dt0 = thickness / vz;
v = sqrt (vx * vx + vy * vy + vz * vz);
PROP_DT (dt0);
dist = v * dt0;

lambda=sqrt(81.81/(VS2E*v*v));
Al_s_tot_lambda= Al_pf_A+Al_pf_B1*lambda+ Al_pf_B2*lambda*lambda+ Al_pf_B3*lambda*lambda*lambda;
Al_s_tot_lambda+=Al_pf_B4*lambda*lambda*lambda*lambda;
Al_my_tot=Al_rho / Al_mmol * Al_s_tot_lambda * avogadro * 10;
Al_my_a = Al_my_a_v/v;
lambda = sqrt (81.81 / (VS2E * v * v));
Al_s_tot_lambda = Al_pf_A + Al_pf_B1 * lambda + Al_pf_B2 * lambda * lambda + Al_pf_B3 * lambda * lambda * lambda;
Al_s_tot_lambda += Al_pf_B4 * lambda * lambda * lambda * lambda;
Al_my_tot = Al_rho / Al_mmol * Al_s_tot_lambda * avogadro * 10;
Al_my_a = Al_my_a_v / v;

p *=exp(-Al_my_a*dist);/* neutron passes window without any interaction */
p *= exp (-Al_my_a * dist); /* neutron passes window without any interaction */

/* TODO: scatter in Debye-Scherrer cone */

%}

MCDISPLAY
%{
/* A bit ugly; hard-coded dimensions. */
line(0,0,0,0.2,0,0);
line(0,0,0,0,0.2,0);
line(0,0,0,0,0,0.2);

line (0, 0, 0, 0.2, 0, 0);
line (0, 0, 0, 0, 0.2, 0);
line (0, 0, 0, 0, 0, 0.2);
%}

END
Expand Down
43 changes: 18 additions & 25 deletions mcstas-comps/contrib/CavitiesIn.comp
Original file line number Diff line number Diff line change
Expand Up @@ -49,44 +49,37 @@ DECLARE

INITIALIZE
%{
xcc = floor(fabs(xc));
ycc = floor(fabs(yc));
if (xcc==0) xcc=1;
if (ycc==0) ycc=1;
xcc = floor (fabs (xc));
ycc = floor (fabs (yc));
if (xcc == 0)
xcc = 1;
if (ycc == 0)
ycc = 1;
mcs_xc = 0;
mcs_yc = 0;
%}

TRACE
%{
PROP_Z0;
if (x<-0.5*xw || x>0.5*xw || y<-0.5*yw || y>0.5*yw)
if (x < -0.5 * xw || x > 0.5 * xw || y < -0.5 * yw || y > 0.5 * yw)
ABSORB;
else
{
else {
SCATTER;
mcs_xc = floor((x+0.5*xw)*xcc/xw);
mcs_yc = floor((y+0.5*yw)*ycc/yw);
x = x+(-mcs_xc-0.5+0.5*xcc)*xw/xcc;
y = y+(-mcs_yc-0.5+0.5*ycc)*yw/ycc;
}
mcs_xc = floor ((x + 0.5 * xw) * xcc / xw);
mcs_yc = floor ((y + 0.5 * yw) * ycc / yw);
x = x + (-mcs_xc - 0.5 + 0.5 * xcc) * xw / xcc;
y = y + (-mcs_yc - 0.5 + 0.5 * ycc) * yw / ycc;
}
%}

MCDISPLAY
%{

multiline(3, -(double)xw, 0.5*yw, 0.0,
-0.5*xw, 0.5*yw, 0.0,
-0.5*xw, (double)yw, 0.0);
multiline(3, (double)xw, 0.5*yw, 0.0,
0.5*xw, 0.5*yw, 0.0,
0.5*xw, (double)yw, 0.0);
multiline(3, -(double)xw,-0.5*yw, 0.0,
-0.5*xw, -0.5*yw, 0.0,
-0.5*xw,-(double)yw, 0.0);
multiline(3, (double)xw,-0.5*yw, 0.0,
0.5*xw, -0.5*yw, 0.0,
0.5*xw,-(double)yw, 0.0);

multiline (3, -(double)xw, 0.5 * yw, 0.0, -0.5 * xw, 0.5 * yw, 0.0, -0.5 * xw, (double)yw, 0.0);
multiline (3, (double)xw, 0.5 * yw, 0.0, 0.5 * xw, 0.5 * yw, 0.0, 0.5 * xw, (double)yw, 0.0);
multiline (3, -(double)xw, -0.5 * yw, 0.0, -0.5 * xw, -0.5 * yw, 0.0, -0.5 * xw, -(double)yw, 0.0);
multiline (3, (double)xw, -0.5 * yw, 0.0, 0.5 * xw, -0.5 * yw, 0.0, 0.5 * xw, -(double)yw, 0.0);
%}

END
39 changes: 16 additions & 23 deletions mcstas-comps/contrib/CavitiesOut.comp
Original file line number Diff line number Diff line change
Expand Up @@ -48,42 +48,35 @@ DECLARE

INITIALIZE
%{
xcc = floor(fabs(xc));
ycc = floor(fabs(yc));
if (xcc==0) xcc=1;
if (ycc==0) ycc=1;
xcc = floor (fabs (xc));
ycc = floor (fabs (yc));
if (xcc == 0)
xcc = 1;
if (ycc == 0)
ycc = 1;
mcs_xc = 0;
mcs_yc = 0;
%}

TRACE
%{
PROP_Z0;
if (x<-0.5*xw/xcc || x>0.5*xw/xcc || y<-0.5*yw/ycc || y>0.5*yw/ycc)
if (x < -0.5 * xw / xcc || x > 0.5 * xw / xcc || y < -0.5 * yw / ycc || y > 0.5 * yw / ycc)
ABSORB;
else
{
else {
SCATTER;
x = x+(mcs_xc+0.5-0.5*xcc)*xw/xcc;
y = y+(mcs_yc+0.5-0.5*ycc)*yw/ycc;
}
x = x + (mcs_xc + 0.5 - 0.5 * xcc) * xw / xcc;
y = y + (mcs_yc + 0.5 - 0.5 * ycc) * yw / ycc;
}
%}

MCDISPLAY
%{

multiline(3, -(double)xw, 0.5*yw, 0.0,
-0.5*xw, 0.5*yw, 0.0,
-0.5*xw, (double)yw, 0.0);
multiline(3, (double)xw, 0.5*yw, 0.0,
0.5*xw, 0.5*yw, 0.0,
0.5*xw, (double)yw, 0.0);
multiline(3, -(double)xw,-0.5*yw, 0.0,
-0.5*xw, -0.5*yw, 0.0,
-0.5*xw,-(double)yw, 0.0);
multiline(3, (double)xw,-0.5*yw, 0.0,
0.5*xw, -0.5*yw, 0.0,
0.5*xw,-(double)yw, 0.0);

multiline (3, -(double)xw, 0.5 * yw, 0.0, -0.5 * xw, 0.5 * yw, 0.0, -0.5 * xw, (double)yw, 0.0);
multiline (3, (double)xw, 0.5 * yw, 0.0, 0.5 * xw, 0.5 * yw, 0.0, 0.5 * xw, (double)yw, 0.0);
multiline (3, -(double)xw, -0.5 * yw, 0.0, -0.5 * xw, -0.5 * yw, 0.0, -0.5 * xw, -(double)yw, 0.0);
multiline (3, (double)xw, -0.5 * yw, 0.0, 0.5 * xw, -0.5 * yw, 0.0, 0.5 * xw, -(double)yw, 0.0);
%}

END
79 changes: 34 additions & 45 deletions mcstas-comps/contrib/Collimator_ROC.comp
Original file line number Diff line number Diff line change
Expand Up @@ -64,64 +64,53 @@ ROC_ttmin=0, ROC_ttmax=100, ROC_sign=1)
/* Neutron parameters: (x,y,z,vx,vy,vz,t,sx,sy,sz,p) */
INITIALIZE
%{
if (ROC_pitch <= 0 || ROC_ri > ROC_ro || ROC_ro <= 0
|| ROC_h <=0 || ROC_ttmin > ROC_ttmax)
fprintf(stderr,"Collimator_ROC: error: %s: Invalid geometrical parameters.\n", NAME_CURRENT_COMP);
if (ROC_pitch <= 0 || ROC_ri > ROC_ro || ROC_ro <= 0 || ROC_h <= 0 || ROC_ttmin > ROC_ttmax)
fprintf (stderr, "Collimator_ROC: error: %s: Invalid geometrical parameters.\n", NAME_CURRENT_COMP);
%}

TRACE
%{
double ROC_angle,x0,z0,x1,z1,a,r,xp,zp;
double d,dt,pi,t0,t1,t2,t3,twotheta;
double ROC_angle, x0, z0, x1, z1, a, r, xp, zp;
double d, dt, pi, t0, t1, t2, t3, twotheta;

if (cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, ROC_ri, ROC_h) && t1 > 0)
{
if (cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, ROC_ri, ROC_h) && t1 > 0) {
int MyAbsorb = 0;

if (t0 < 0) t0 = t1;
twotheta = -atan2(x+vx*t0,z+vz*t0);
if (( (double)ROC_sign*twotheta*RAD2DEG >= ROC_ttmin ) && ( (double)ROC_sign*twotheta*RAD2DEG <= ROC_ttmax ))
{
if (cylinder_intersect(&t2, &t3, x, y, z, vx, vy, vz, ROC_ro, ROC_h) && t3 >0)
{
dt=(x*vz-z*vx)/(vx*vx+vz*vz);
xp=vz*dt;
zp=-vx*dt;
d=sqrt(xp*xp+zp*zp);
pi=1.0-RAD2DEG*fabs(asin(d/ROC_ro)-asin(d/ROC_ri))/ROC_pitch;
if (pi>0)
p*=pi;
else MyAbsorb = 1;
}
else MyAbsorb = 1;
}
else MyAbsorb = 1;
if (MyAbsorb)
{
PROP_DT(t0);
if (t0 < 0)
t0 = t1;
twotheta = -atan2 (x + vx * t0, z + vz * t0);
if (((double)ROC_sign * twotheta * RAD2DEG >= ROC_ttmin) && ((double)ROC_sign * twotheta * RAD2DEG <= ROC_ttmax)) {
if (cylinder_intersect (&t2, &t3, x, y, z, vx, vy, vz, ROC_ro, ROC_h) && t3 > 0) {
dt = (x * vz - z * vx) / (vx * vx + vz * vz);
xp = vz * dt;
zp = -vx * dt;
d = sqrt (xp * xp + zp * zp);
pi = 1.0 - RAD2DEG * fabs (asin (d / ROC_ro) - asin (d / ROC_ri)) / ROC_pitch;
if (pi > 0)
p *= pi;
else
MyAbsorb = 1;
} else
MyAbsorb = 1;
} else
MyAbsorb = 1;
if (MyAbsorb) {
PROP_DT (t0);
ABSORB;
}
}
else ABSORB;

} else
ABSORB;
%}
MCDISPLAY
%{
double ROC_angle,x0,z0,x1,z1;
double ROC_angle, x0, z0, x1, z1;


for (ROC_angle=ROC_ttmin; ROC_angle <= ROC_ttmax; ROC_angle += ROC_pitch)
{
x0=ROC_ri*sin(ROC_angle*DEG2RAD);
z0=ROC_ri*cos(ROC_angle*DEG2RAD);
x1=x0/ROC_ri*ROC_ro;
z1=z0/ROC_ri*ROC_ro;
multiline(5,
x0, ROC_h/2, z0,
x0, -ROC_h/2, z0,
x1, -ROC_h/2, z1,
x1, ROC_h/2, z1,
x0, ROC_h/2, z0);
for (ROC_angle = ROC_ttmin; ROC_angle <= ROC_ttmax; ROC_angle += ROC_pitch) {
x0 = ROC_ri * sin (ROC_angle * DEG2RAD);
z0 = ROC_ri * cos (ROC_angle * DEG2RAD);
x1 = x0 / ROC_ri * ROC_ro;
z1 = z0 / ROC_ri * ROC_ro;
multiline (5, x0, ROC_h / 2, z0, x0, -ROC_h / 2, z0, x1, -ROC_h / 2, z1, x1, ROC_h / 2, z1, x0, ROC_h / 2, z0);
}
%}
END
Loading
Loading