File: SAXSEllipticCylinders.comp

package info (click to toggle)
mccode 3.5.19%2Bds5-2
  • links: PTS, VCS
  • area: main
  • in suites: 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 (180 lines) | stat: -rw-r--r-- 4,984 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*******************************************************************************
* McXtrace, x-ray tracing package
*         Copyright, All rights reserved
*         DTU Physics, Kgs. Lyngby, Denmark
*         Synchrotron SOLEIL, Saint-Aubin, France
*
* Component: SAXSEllipticCylinders
*
* %Identification
* Written by: Martin Cramer Pedersen (mcpe@nbi.dk)
* Date: May 2, 2012
* Origin: KU-Science
*
* A sample of monodisperse cylindrical particles with elliptic cross section in 
* solution.
*
* %Description
* A component simulating the scattering from a box-shaped, thin solution
* of monodisperse, cylindrical particles with elliptic cross section.
*
* Example: SAXSEllipticCylinders( xwidth = 0.01, yheight = 0.01, zdepth = 0.01, SampleToDetectorDistance = 0.48, DetectorRadius = 0.1 )
*
* %Parameters
* R1: [AA]             First semiaxis of the cross section of the elliptic cylinder.
* R2: [AA]             Second semiaxis of the cross section of the elliptic cylinder.
* Height: [AA]         Height of the cylinder.
* 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 x-rays).
* DetectorRadius: [m]  Radius of the detector (for focusing the scattered x-rays).
*
* %End
*******************************************************************************/

DEFINE COMPONENT SAXSEllipticCylinders



SETTING PARAMETERS (R1 = 20.0, R2 = 40.0, Height = 100.0, Concentration = 0.01, DeltaRho = 1.0e-14, AbsorptionCrosssection = 0.0,
    xwidth, yheight, zdepth, SampleToDetectorDistance, DetectorRadius)

DEPENDENCY " @GSLFLAGS@ "
NOACC

/*X-ray Parameters (x, y, z, kx, ky, kz, phi, t, Ex, Ey, Ez, p)*/
SHARE
%{
  #include <gsl/gsl_sf_bessel.h>
%}
DECLARE
%{
  double Prefactor;
  double Absorption;
  double NumberDensity;
%}

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);
	}

	Prefactor = NumberDensity * pow(PI * Height * R1 * R2, 2) * pow(DeltaRho, 2);

	Absorption = AbsorptionCrosssection;
%}

TRACE
%{
	double l0; 
	double l1; 
	double l_full;
	double l;
	double l_1;
	double Formfactor1;
	double Formfactor2;
	double Intensity;
	double SolidAngle;
	double qx; 
	double qy; 
	double qz;
	double q;
	double k;
	double dl;
	double kx_i;
	double ky_i;
	double kz_i;
	double ProjectedRadius;
	char Intersect = 0;

	/* variables needed for integration over alpha */
	int i;
	const int NumberOfStepsInAlpha = 30;
	double Alpha;
	const double AlphaMin = 0.0;
	const double AlphaMax = PI / 2.0;
	const double AlphaStep = (AlphaMax - AlphaMin) / (1.0 * NumberOfStepsInAlpha);

	/* Variables needed in integration over beta */
	int j;
	const int NumberOfStepsInBeta = 30;
	double Beta;
	const double BetaMin = 0.0;
	const double BetaMax = PI / 2.0;
	const double BetaStep = (BetaMax - BetaMin) / (1.0 * NumberOfStepsInBeta);

	Intersect = box_intersect(&l0, &l1, x, y, z, kx, ky, kz, xwidth, yheight, zdepth);

	if (Intersect) {

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

		// Compute properties of photon
		k = sqrt(pow(kx, 2) + pow(ky, 2) + pow(kz, 2));
		l_full = l1 - l0;
		dl = rand01() * (l1 - l0) + l0; 
		PROP_DL(dl);                  
		l = dl - l0;

		// Store properties of incoming photon
		kx_i = kx;
		ky_i = ky;
		kz_i = kz;

		/* Generate new direction of photon */
		randvec_target_circle(&kx, &ky, &kz, &SolidAngle, 0, 0, SampleToDetectorDistance, DetectorRadius);

		NORM(kx, ky, kz);

		kx *= k;
		ky *= k;
		kz *= k;

		/* Compute q */
		qx = kx_i - kx;
		qy = ky_i - ky;
		qz = kz_i - kz;

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

		/* Compute scattering */
		Intensity = 0.0;

		for (i = 0; i < NumberOfStepsInAlpha; ++i) {
			Alpha = (i + 0.5) * AlphaStep;

			for (j = 0; j < NumberOfStepsInBeta; ++j) {
				Beta = (j + 0.5) * BetaStep;
				ProjectedRadius = sqrt(pow(R1 * sin(Beta), 2) + pow(R2 * cos(Beta), 2));

				Formfactor1 = gsl_sf_bessel_J1(q * ProjectedRadius * sin(Alpha)) / (q * ProjectedRadius * sin(Alpha));
				Formfactor2 = sin(q * Height * cos(Alpha) / 2.0) / (q * Height * cos(Alpha) / 2.0);

				Intensity += 2 / PI * sin(Alpha) * Prefactor * pow(2 * Formfactor1 * Formfactor2, 2) * AlphaStep * BetaStep;
			}
		}

		p *= l_full * SolidAngle / (4.0 * PI) * Intensity * exp(- Absorption * (l + l1));

		SCATTER;
	}
%}

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

END