1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
|
/*******************************************************************************
*
* McStas, neutron ray-tracing package
* Copyright (C) 1997-2008, All rights reserved
* Risoe National Laboratory, Roskilde, Denmark
* Institut Laue Langevin, Grenoble, France
*
* Component: SasView_lamellar_hg_stack_caille
*
* %Identification
* Written by: Jose Robledo
* Based on sasmodels from SasView
* Origin: FZJ / DTU / ESS DMSC
*
*
* SasView lamellar_hg_stack_caille model component as sample description.
*
* %Description
*
* SasView_lamellar_hg_stack_caille component, generated from lamellar_hg_stack_caille.c in sasmodels.
*
* Example:
* SasView_lamellar_hg_stack_caille(length_tail, length_head, Nlayers, d_spacing, Caille_parameter, sld, sld_head, sld_solvent,
* model_scale=1.0, model_abs=0.0, xwidth=0.01, yheight=0.01, zdepth=0.005, R=0,
* int target_index=1, target_x=0, target_y=0, target_z=1,
* focus_xw=0.5, focus_yh=0.5, focus_aw=0, focus_ah=0, focus_r=0,
* pd_length_tail=0.0, pd_length_head=0.0)
*
* %Parameters
* INPUT PARAMETERS:
* length_tail: [Ang] ([0, inf]) Tail thickness.
* length_head: [Ang] ([0, inf]) head thickness.
* Nlayers: [] ([1, inf]) Number of layers.
* d_spacing: [Ang] ([0.0, inf]) lamellar d-spacing of Caille S(Q).
* Caille_parameter: [] ([0.0, 0.8]) Caille parameter.
* sld: [1e-6/Ang^2] ([-inf, inf]) Tail scattering length density.
* sld_head: [1e-6/Ang^2] ([-inf, inf]) Head scattering length density.
* sld_solvent: [1e-6/Ang^2] ([-inf, inf]) Solvent scattering length density.
* Optional parameters:
* model_abs: [ ] Absorption cross section density at 2200 m/s.
* model_scale: [ ] Global scale factor for scattering kernel. For systems without inter-particle interference, the form factors can be related to the scattering intensity by the particle volume fraction.
* xwidth: [m] ([-inf, inf]) Horiz. dimension of sample, as a width.
* yheight: [m] ([-inf, inf]) vert . dimension of sample, as a height for cylinder/box
* zdepth: [m] ([-inf, inf]) depth of sample
* R: [m] Outer radius of sample in (x,z) plane for cylinder/sphere.
* target_x: [m] relative focus target position.
* target_y: [m] relative focus target position.
* target_z: [m] relative focus target position.
* target_index: [ ] Relative index of component to focus at, e.g. next is +1.
* focus_xw: [m] horiz. dimension of a rectangular area.
* focus_yh: [m], vert. dimension of a rectangular area.
* focus_aw: [deg], horiz. angular dimension of a rectangular area.
* focus_ah: [deg], vert. angular dimension of a rectangular area.
* focus_r: [m] case of circular focusing, focusing radius.
* pd_length_tail: [] (0,inf) defined as (dx/x), where x is de mean value and dx the standard devition of the variable.
* pd_length_head: [] (0,inf) defined as (dx/x), where x is de mean value and dx the standard devition of the variable
*
* %Link
* %End
*******************************************************************************/
DEFINE COMPONENT SasView_lamellar_hg_stack_caille
SETTING PARAMETERS (
length_tail=10,
length_head=2,
Nlayers=30,
d_spacing=40.0,
Caille_parameter=0.001,
sld=0.4,
sld_head=2.0,
sld_solvent=6,
model_scale=1.0,
model_abs=0.0,
xwidth=0.01,
yheight=0.01,
zdepth=0.005,
R=0,
target_x=0,
target_y=0,
target_z=1,
int target_index=1,
focus_xw=0.5,
focus_yh=0.5,
focus_aw=0,
focus_ah=0,
focus_r=0,
pd_length_tail=0.0,
pd_length_head=0.0)
SHARE %{
%include "sas_kernel_header.c"
/* BEGIN Required header for SASmodel lamellar_hg_stack_caille */
#define HAS_Iq
#ifndef SAS_HAVE_lamellar_hg_stack_caille
#define SAS_HAVE_lamellar_hg_stack_caille
#line 1 "lamellar_hg_stack_caille"
/* LamellarCailleHG kernel - allows for name changes of passed parameters ...
Maths identical to LamellarCaille apart from the line for P(Q)
*/
static double
Iq_lamellar_hg_stack_caille(double qval,
double length_tail,
double length_head,
double fp_Nlayers,
double dd,
double Cp,
double tail_sld,
double head_sld,
double solvent_sld)
{
int Nlayers = (int)(fp_Nlayers+0.5); //cast to an integer for the loop
double inten,Pq,Sq,alpha,temp,t2;
//double dQ, dQDefault, t1, t3;
// from wikipedia 0.577215664901532860606512090082402431042159335
const double Euler = 0.577215664901533; // Euler's constant, increased sig figs for new models Feb 2015
//dQDefault = 0.0; //[=] 1/A, q-resolution, default value
//dQ = dQDefault; // REMOVED UNUSED dQ calculations for new models Feb 2015
Pq = (head_sld-solvent_sld)*(sin(qval*(length_head+length_tail))-sin(qval*length_tail))
+ (tail_sld-solvent_sld)*sin(qval*length_tail);
Pq *= Pq;
Pq *= 4.0/(qval*qval);
Sq = 0.0;
for(int ii=1; ii < Nlayers; ii++) {
temp = 0.0;
alpha = Cp/4.0/M_PI/M_PI*(log(M_PI*ii) + Euler);
//t1 = 2.0*dQ*dQ*dd*dd*alpha;
t2 = 2.0*qval*qval*dd*dd*alpha;
//t3 = dQ*dQ*dd*dd*ii*ii;
temp = 1.0-(double)ii/(double)Nlayers;
//temp *= cos(dd*qval*ii/(1.0+t1));
temp *= cos(dd*qval*ii);
//if (temp < 0) printf("q=%g: ii=%d, cos(dd*q*ii)=cos(%g) < 0\n",qval,ii,dd*qval*ii);
//temp *= exp(-1.0*(t2 + t3)/(2.0*(1.0+t1)) );
temp *= exp(-t2/2.0);
//temp /= sqrt(1.0+t1);
Sq += temp;
}
Sq *= 2.0;
Sq += 1.0;
//if (Sq < 0) printf("q=%g: S(q) =%g\n", qval, Sq);
inten = 2.0*M_PI*Pq*Sq/(dd*qval*qval);
inten *= 1.0e-04; // 1/A to 1/cm
return inten;
}
#endif // SAS_HAVE_lamellar_hg_stack_caille
/* END Required header for SASmodel lamellar_hg_stack_caille */
%}
DECLARE
%{
double shape;
double my_a_v;
%}
INITIALIZE
%{
shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere */
if (xwidth && yheight && zdepth)
shape=1;
else if (R > 0 && yheight)
shape=0;
else if (R > 0 && !yheight)
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));
/* 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)
{
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);
}
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;
}
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 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;
/* 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)
ABSORB;
/* Neutron enters at t=t0. */
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 */
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;
}
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);
}
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_length_tail=length_tail;
double trace_length_head=length_head;
if ( pd_length_tail!=0.0 || pd_length_head!=0.0 ){
trace_length_tail = (randnorm()*pd_length_tail+1.0)*length_tail;
trace_length_head = (randnorm()*pd_length_head+1.0)*length_head;
}
// Sample dependent. Retrieved from SasView./////////////////////
float Iq_out;
Iq_out = 1;
Iq_out = Iq_lamellar_hg_stack_caille(q, trace_length_tail, trace_length_head, Nlayers, d_spacing, Caille_parameter, sld, sld_head, 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;
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);
}
%}
END
|