File: SANSShells.comp

package info (click to toggle)
mccode 3.5.19%2Bds5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,113,256 kB
  • sloc: ansic: 40,697; python: 25,137; yacc: 8,438; sh: 5,405; javascript: 4,596; lex: 1,632; cpp: 742; perl: 296; lisp: 273; makefile: 226; fortran: 132
file content (166 lines) | stat: -rw-r--r-- 4,402 bytes parent folder | download
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
/*******************************************************************************
* McStas, neutron ray-tracing package
*         Copyright 1997-2003, All rights reserved
*         Risoe National Laboratory, Roskilde, Denmark
*         Institut Laue Langevin, Grenoble, France
*
* Component: SANSShells
*
* %I
* Written by: Martin Cramer Pedersen (mcpe@nbi.dk)
* Date: October 17, 2012
* Origin: KU-Science
*
* A sample of monodisperse shell-like particles in solution.
*
* %D
* A simple component simulating the scattering from a box-shaped, thin solution
* of monodisperse, shell-like particles.
*
* %P
* R: [AA]                        Average radius of the particles.
* Thickness: [AA]                Thickness of the shell - so that the outer radius is R + Thickness and the inner is R - Thickness.
* Concentration: [mM]            Concentration of sample.
* DeltaRho: [cm/AA^3]            Excess scattering length density of the particles.
* AbsorptionCrosssection: [1/m]  Absorption cross section of the sample.
* xwidth: [m]                    Dimension of component in the x-direction.
* yheight: [m]                   Dimension of component in the y-direction.
* zdepth: [m]                    Dimension of component in the z-direction.
* SampleToDetectorDistance: [m]  Distance from sample to detector (for focusing the scattered neutrons).
* DetectorRadius: [m]            Radius of the detector (for focusing the scattered neutrons).
*
* %E
*******************************************************************************/

DEFINE COMPONENT SANSShells



SETTING PARAMETERS (R = 100.0, Thickness = 5.0, Concentration = 0.01, DeltaRho = 1.0e-14, AbsorptionCrosssection = 0.0,
xwidth, yheight, zdepth, SampleToDetectorDistance, DetectorRadius)



DECLARE
%{
// Declarations
double Prefactor;
double Absorption;
double q;
double NumberDensity;

double RBig;
double RSmall;

double VolumeBigSphere;
double VolumeSmallSphere;
double Volume;
%}

INITIALIZE
%{
// Rescale concentration into number of aggregates per m^3 times 10^-4
NumberDensity = Concentration * 6.02214129e19;

// Computations
if (!xwidth || !yheight || !zdepth) {
		printf("%s: Sample has no volume, check parameters!\n", NAME_CURRENT_COMP);
	}

	if (Thickness >= R) {
		printf("%s: Thickness of shell larger than radius of shell!\n", NAME_CURRENT_COMP);
	}

	RBig = R + Thickness / 2.0;
	RSmall = R - Thickness / 2.0;

	VolumeBigSphere = 4.0 / 3.0 * PI * pow(RBig, 3);
	VolumeSmallSphere = 4.0 / 3.0 * PI * pow(RSmall, 3);

	Volume = VolumeBigSphere - VolumeSmallSphere;

	Prefactor = NumberDensity * pow(Volume, 2) * pow(DeltaRho, 2);

	Absorption = AbsorptionCrosssection;
%}

TRACE
%{
	// Declarations
	double t0;
	double t1;
	double l_full;
	double l;
	double l1;
	double FormfactorBigSphere;
	double FormfactorSmallSphere;
	double Formfactor;
	double SolidAngle;
	double qx;
	double qy;
	double qz;
	double v;
	double dt;
	double vx_i;
	double vy_i;
	double vz_i;
	char Intersect = 0;

	// Computation
	Intersect = box_intersect(&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zdepth);

	if (Intersect) {

		if (t0 < 0.0) {
			fprintf(stderr, "Neutron already inside sample %s - absorbing...\n", NAME_CURRENT_COMP);
			ABSORB;
    	}

		// Compute properties of neutron
		v = sqrt(pow(vx, 2) + pow(vy, 2) + pow(vz, 2));
		l_full = v * (t1 - t0);
		dt = rand01() * (t1 - t0) + t0;
		PROP_DT(dt);
	    l = v * (dt - t0);

		// Store properties of incoming neutron
		vx_i = vx;
		vy_i = vy;
		vz_i = vz;

		// Generate new direction of neutron
		randvec_target_circle(&vx, &vy, &vz, &SolidAngle, 0, 0, SampleToDetectorDistance, DetectorRadius);

		NORM(vx, vy, vz);

		vx *= v;
		vy *= v;
		vz *= v;

		// Compute q
		qx = V2K * (vx_i - vx);
		qy = V2K * (vy_i - vy);
		qz = V2K * (vz_i - vz);

		q = sqrt(pow(qx, 2) + pow(qy, 2) + pow(qz, 2));

		// Compute scattering
		l1 = v * t1;

		FormfactorBigSphere = 3.0 * (sin(q * RBig) - q * RBig * cos(q * RBig)) / pow(q * RBig, 3);
		FormfactorSmallSphere = 3.0 * (sin(q * RSmall) - q * RSmall * cos(q * RSmall)) / pow(q * RSmall, 3);
		Formfactor = (FormfactorBigSphere * VolumeBigSphere - FormfactorSmallSphere * VolumeSmallSphere) / (VolumeBigSphere - VolumeSmallSphere);

		p *= l_full * SolidAngle / (4.0 * PI) * Prefactor * pow(Formfactor, 2) * exp(- Absorption * (l + l1) / v);

		SCATTER;
	}
%}

MCDISPLAY
%{
	
  box(0, 0, 0, xwidth, yheight, zdepth,0, 0, 1, 0);
%}

END