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
178 changes: 81 additions & 97 deletions mcstas-comps/sasmodels/SasView_adsorbed_layer.comp
Original file line number Diff line number Diff line change
Expand Up @@ -139,155 +139,139 @@ double Iq_adsorbed_layer(

INITIALIZE
%{
shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */
if (xwidth && yheight && zdepth)
shape=1;
shape = -1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */
if (xwidth && yheight && zdepth)
shape = 1;
else if (R > 0 && yheight)
shape=0;
shape = 0;
else if (R > 0 && !yheight)
shape=2;
shape = 2;
if (shape < 0)
exit(fprintf(stderr, "SasView_model: %s: sample has invalid dimensions.\n"
"ERROR Please check parameter values.\n", NAME_CURRENT_COMP));
exit (fprintf (stderr,
"SasView_model: %s: sample has invalid dimensions.\n"
"ERROR Please check parameter values.\n",
NAME_CURRENT_COMP));

/* now compute target coords if a component index is supplied */
if (!target_index && !target_x && !target_y && !target_z) target_index=1;
if (target_index)
{
if (!target_index && !target_x && !target_y && !target_z)
target_index = 1;
if (target_index) {
Coords ToTarget;
ToTarget = coords_sub(POS_A_COMP_INDEX(INDEX_CURRENT_COMP+target_index),POS_A_CURRENT_COMP);
ToTarget = rot_apply(ROT_A_CURRENT_COMP, ToTarget);
coords_get(ToTarget, &target_x, &target_y, &target_z);
ToTarget = coords_sub (POS_A_COMP_INDEX (INDEX_CURRENT_COMP + target_index), POS_A_CURRENT_COMP);
ToTarget = rot_apply (ROT_A_CURRENT_COMP, ToTarget);
coords_get (ToTarget, &target_x, &target_y, &target_z);
}

if (!(target_x || target_y || target_z)) {
printf("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n",
NAME_CURRENT_COMP);
target_z=1;
printf ("SasView_model: %s: The target is not defined. Using direct beam (Z-axis).\n", NAME_CURRENT_COMP);
target_z = 1;
}

my_a_v = model_abs*2200*100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */

my_a_v = model_abs * 2200 * 100; /* Is not yet divided by v. 100: Convert barns -> fm^2 */
%}


TRACE
%{
double t0, t1, v, l_full, l, l_1, dt, d_phi, my_s;
double aim_x=0, aim_y=0, aim_z=1, axis_x, axis_y, axis_z;
double aim_x = 0, aim_y = 0, aim_z = 1, axis_x, axis_y, axis_z;
double arg, tmp_vx, tmp_vy, tmp_vz, vout_x, vout_y, vout_z;
double f, solid_angle, vx_i, vy_i, vz_i, q, qx, qy, qz;
char intersect=0;
char intersect = 0;

/* Intersection neutron trajectory / sample (sample surface) */
if (shape == 0){
intersect = cylinder_intersect(&t0, &t1, x, y, z, vx, vy, vz, R, yheight);}
else if (shape == 1){
intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);}
else if (shape == 2){
intersect = sphere_intersect(&t0, &t1, x, y, z, vx, vy, vz, R);}
if(intersect)
{
if(t0 < 0)
if (shape == 0) {
intersect = cylinder_intersect (&t0, &t1, x, y, z, vx, vy, vz, R, yheight);
} else if (shape == 1) {
intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);
} else if (shape == 2) {
intersect = sphere_intersect (&t0, &t1, x, y, z, vx, vy, vz, R);
}
if (intersect) {
if (t0 < 0)
ABSORB;

/* Neutron enters at t=t0. */
v = sqrt(vx*vx + vy*vy + vz*vz);
v = sqrt (vx * vx + vy * vy + vz * vz);
l_full = v * (t1 - t0); /* Length of full path through sample */
dt = rand01()*(t1 - t0) + t0; /* Time of scattering */
PROP_DT(dt); /* Point of scattering */
l = v*(dt-t0); /* Penetration in sample */
dt = rand01 () * (t1 - t0) + t0; /* Time of scattering */
PROP_DT (dt); /* Point of scattering */
l = v * (dt - t0); /* Penetration in sample */

vx_i=vx;
vy_i=vy;
vz_i=vz;
vx_i = vx;
vy_i = vy;
vz_i = vz;
if ((target_x || target_y || target_z)) {
aim_x = target_x-x; /* Vector pointing at target (anal./det.) */
aim_y = target_y-y;
aim_z = target_z-z;
aim_x = target_x - x; /* Vector pointing at target (anal./det.) */
aim_y = target_y - y;
aim_z = target_z - z;
}
if(focus_aw && focus_ah) {
randvec_target_rect_angular(&vx, &vy, &vz, &solid_angle,
aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP);
} else if(focus_xw && focus_yh) {
randvec_target_rect(&vx, &vy, &vz, &solid_angle,
aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP);
if (focus_aw && focus_ah) {
randvec_target_rect_angular (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_aw, focus_ah, ROT_A_CURRENT_COMP);
} else if (focus_xw && focus_yh) {
randvec_target_rect (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_xw, focus_yh, ROT_A_CURRENT_COMP);
} else {
randvec_target_circle(&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r);
randvec_target_circle (&vx, &vy, &vz, &solid_angle, aim_x, aim_y, aim_z, focus_r);
}
NORM(vx, vy, vz);
NORM (vx, vy, vz);
vx *= v;
vy *= v;
vz *= v;
qx = V2K*(vx_i-vx);
qy = V2K*(vy_i-vy);
qz = V2K*(vz_i-vz);
q = sqrt(qx*qx+qy*qy+qz*qz);
double trace_radius=radius;
if ( pd_radius!=0.0 ){
trace_radius = (randnorm()*pd_radius+1.0)*radius;
qx = V2K * (vx_i - vx);
qy = V2K * (vy_i - vy);
qz = V2K * (vz_i - vz);
q = sqrt (qx * qx + qy * qy + qz * qz);

double trace_radius = radius;
if (pd_radius != 0.0) {
trace_radius = (randnorm () * pd_radius + 1.0) * radius;
}




// Sample dependent. Retrieved from SasView./////////////////////
float Iq_out;
Iq_out = 1;

Iq_out = Iq_adsorbed_layer(q, second_moment, adsorbed_amount, density_shell, trace_radius, volfraction, sld_shell, sld_solvent);

Iq_out = Iq_adsorbed_layer (q, second_moment, adsorbed_amount, density_shell, trace_radius, volfraction, sld_shell, sld_solvent);

float vol;
vol = 1;

// Scale by 1.0E2 [SasView: 1/cm -> McStas: 1/m]
Iq_out = model_scale*Iq_out / vol * 1.0E2;
Iq_out = model_scale * Iq_out / vol * 1.0E2;

l_1 = v*t1;
p *= l_full*solid_angle/(4*PI)*Iq_out*exp(-my_a_v*(l+l_1)/v);
l_1 = v * t1;
p *= l_full * solid_angle / (4 * PI) * Iq_out * exp (-my_a_v * (l + l_1) / v);
SCATTER;
}
%}

MCDISPLAY
%{

if (shape == 0) { /* cylinder */
circle("xz", 0, yheight/2.0, 0, R);
circle("xz", 0, -yheight/2.0, 0, R);
line(-R, -yheight/2.0, 0, -R, +yheight/2.0, 0);
line(+R, -yheight/2.0, 0, +R, +yheight/2.0, 0);
line(0, -yheight/2.0, -R, 0, +yheight/2.0, -R);
line(0, -yheight/2.0, +R, 0, +yheight/2.0, +R);
}
else if (shape == 1) { /* box */
double xmin = -0.5*xwidth;
double xmax = 0.5*xwidth;
double ymin = -0.5*yheight;
double ymax = 0.5*yheight;
double zmin = -0.5*zdepth;
double zmax = 0.5*zdepth;
multiline(5, xmin, ymin, zmin,
xmax, ymin, zmin,
xmax, ymax, zmin,
xmin, ymax, zmin,
xmin, ymin, zmin);
multiline(5, xmin, ymin, zmax,
xmax, ymin, zmax,
xmax, ymax, zmax,
xmin, ymax, zmax,
xmin, ymin, zmax);
line(xmin, ymin, zmin, xmin, ymin, zmax);
line(xmax, ymin, zmin, xmax, ymin, zmax);
line(xmin, ymax, zmin, xmin, ymax, zmax);
line(xmax, ymax, zmin, xmax, ymax, zmax);
}
else if (shape == 2) { /* sphere */
circle("xy", 0, 0.0, 0, R);
circle("xz", 0, 0.0, 0, R);
circle("yz", 0, 0.0, 0, R);
if (shape == 0) { /* cylinder */
circle ("xz", 0, yheight / 2.0, 0, R);
circle ("xz", 0, -yheight / 2.0, 0, R);
line (-R, -yheight / 2.0, 0, -R, +yheight / 2.0, 0);
line (+R, -yheight / 2.0, 0, +R, +yheight / 2.0, 0);
line (0, -yheight / 2.0, -R, 0, +yheight / 2.0, -R);
line (0, -yheight / 2.0, +R, 0, +yheight / 2.0, +R);
} else if (shape == 1) { /* box */
double xmin = -0.5 * xwidth;
double xmax = 0.5 * xwidth;
double ymin = -0.5 * yheight;
double ymax = 0.5 * yheight;
double zmin = -0.5 * zdepth;
double zmax = 0.5 * zdepth;
multiline (5, xmin, ymin, zmin, xmax, ymin, zmin, xmax, ymax, zmin, xmin, ymax, zmin, xmin, ymin, zmin);
multiline (5, xmin, ymin, zmax, xmax, ymin, zmax, xmax, ymax, zmax, xmin, ymax, zmax, xmin, ymin, zmax);
line (xmin, ymin, zmin, xmin, ymin, zmax);
line (xmax, ymin, zmin, xmax, ymin, zmax);
line (xmin, ymax, zmin, xmin, ymax, zmax);
line (xmax, ymax, zmin, xmax, ymax, zmax);
} else if (shape == 2) { /* sphere */
circle ("xy", 0, 0.0, 0, R);
circle ("xz", 0, 0.0, 0, R);
circle ("yz", 0, 0.0, 0, R);
}
%}
END
Expand Down
Loading