1 | /** |
---|
2 | * Scattering model for a lamellar |
---|
3 | * TODO: Add 2D analysis |
---|
4 | */ |
---|
5 | |
---|
6 | #include "lamellarPS.h" |
---|
7 | #include <math.h> |
---|
8 | #include "libCylinder.h" |
---|
9 | #include <stdio.h> |
---|
10 | #include <stdlib.h> |
---|
11 | |
---|
12 | /*LamellarPS_kernel() was moved from libigor to get rid of polydipersity in del(thickness) that we provide from control panel. |
---|
13 | /* LamellarPSX : calculates the form factor of a lamellar structure - with S(q) effects included |
---|
14 | ------- |
---|
15 | ------- resolution effects ARE NOT included, but only a CONSTANT default value, not the real q-dependent resolution!! |
---|
16 | |
---|
17 | */ |
---|
18 | double |
---|
19 | LamellarPS_kernel(double dp[], double q) |
---|
20 | { |
---|
21 | double scale,dd,del,contr,NN,Cp,bkg; //local variables of coefficient wave |
---|
22 | double inten, qval,Pq,Sq,alpha,temp,t1,t2,t3,dQ; |
---|
23 | double Pi,Euler,dQDefault,fii; |
---|
24 | int ii,NNint; |
---|
25 | Euler = 0.5772156649; // Euler's constant |
---|
26 | dQDefault = 0.0;//0.0025; //[=] 1/A, q-resolution, default value |
---|
27 | dQ = dQDefault; |
---|
28 | |
---|
29 | Pi = 4.0*atan(1.0); |
---|
30 | qval = q; |
---|
31 | |
---|
32 | scale = dp[0]; |
---|
33 | dd = dp[1]; |
---|
34 | del = dp[2]; |
---|
35 | contr = dp[3]; |
---|
36 | NN = trunc(dp[4]); //be sure that NN is an integer |
---|
37 | Cp = dp[5]; |
---|
38 | bkg = dp[6]; |
---|
39 | |
---|
40 | Pq = 2.0*contr*contr/qval/qval*(1.0-cos(qval*del)); |
---|
41 | |
---|
42 | NNint = (int)NN; //cast to an integer for the loop |
---|
43 | ii=0; |
---|
44 | Sq = 0.0; |
---|
45 | for(ii=1;ii<(NNint-1);ii+=1) { |
---|
46 | |
---|
47 | fii = (double)ii; //do I really need to do this? |
---|
48 | |
---|
49 | temp = 0.0; |
---|
50 | alpha = Cp/4.0/Pi/Pi*(log(Pi*ii) + Euler); |
---|
51 | t1 = 2.0*dQ*dQ*dd*dd*alpha; |
---|
52 | t2 = 2.0*qval*qval*dd*dd*alpha; |
---|
53 | t3 = dQ*dQ*dd*dd*ii*ii; |
---|
54 | |
---|
55 | temp = 1.0-ii/NN; |
---|
56 | temp *= cos(dd*qval*ii/(1.0+t1)); |
---|
57 | temp *= exp(-1.0*(t2 + t3)/(2.0*(1.0+t1)) ); |
---|
58 | temp /= sqrt(1.0+t1); |
---|
59 | |
---|
60 | Sq += temp; |
---|
61 | } |
---|
62 | |
---|
63 | Sq *= 2.0; |
---|
64 | Sq += 1.0; |
---|
65 | |
---|
66 | inten = 2.0*Pi*scale*Pq*Sq/(dd*qval*qval); |
---|
67 | |
---|
68 | inten *= 1.0e8; // 1/A to 1/cm |
---|
69 | |
---|
70 | return(inten+bkg); |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | * Function to evaluate 1D scattering function |
---|
75 | * @param pars: parameters of the lamellar |
---|
76 | * @param q: q-value |
---|
77 | * @return: function value |
---|
78 | */ |
---|
79 | double lamellarPS_analytical_1D(LamellarPSParameters *pars, double q) { |
---|
80 | double dp[7]; |
---|
81 | |
---|
82 | // Fill paramater array |
---|
83 | dp[0] = pars->scale; |
---|
84 | dp[1] = pars->spacing; |
---|
85 | dp[2] = pars->delta; |
---|
86 | dp[3] = pars->contrast; |
---|
87 | dp[4] = pars->n_plates; |
---|
88 | dp[5] = pars->caille; |
---|
89 | dp[6] = pars->background; |
---|
90 | |
---|
91 | // Call library function to evaluate model |
---|
92 | return LamellarPS_kernel(dp, q); |
---|
93 | } |
---|
94 | /** |
---|
95 | * Function to evaluate 2D scattering function |
---|
96 | * @param pars: parameters of the lamellar |
---|
97 | * @param q: q-value |
---|
98 | * @return: function value |
---|
99 | */ |
---|
100 | double lamellarPS_analytical_2DXY(LamellarPSParameters *pars, double qx, double qy) { |
---|
101 | double q; |
---|
102 | q = sqrt(qx*qx+qy*qy); |
---|
103 | return lamellarPS_analytical_1D(pars, q); |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | /** |
---|
108 | * Function to evaluate 2D scattering function |
---|
109 | * @param pars: parameters of the lamellar |
---|
110 | * @param q: q-value |
---|
111 | * @param phi: angle phi |
---|
112 | * @return: function value |
---|
113 | */ |
---|
114 | double lamellarPS_analytical_2D(LamellarPSParameters *pars, double q, double phi) { |
---|
115 | return lamellarPS_analytical_1D(pars,q); |
---|
116 | } |
---|
117 | |
---|
118 | /** |
---|
119 | * Function to evaluate 2D scattering function |
---|
120 | * @param pars: parameters of the lamellar |
---|
121 | * @param q: q-value |
---|
122 | * @param q_x: q_x / q |
---|
123 | * @param q_y: q_y / q |
---|
124 | * @return: function value |
---|
125 | */ |
---|
126 | |
---|
127 | |
---|