1 | /** |
---|
2 | This software was developed by the University of Tennessee as part of the |
---|
3 | Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
4 | project funded by the US National Science Foundation. |
---|
5 | |
---|
6 | If you use DANSE applications to do scientific research that leads to |
---|
7 | publication, we ask that you acknowledge the use of the software with the |
---|
8 | following sentence: |
---|
9 | |
---|
10 | "This work benefited from DANSE software developed under NSF award DMR-0520547." |
---|
11 | |
---|
12 | copyright 2008, University of Tennessee |
---|
13 | */ |
---|
14 | |
---|
15 | /** |
---|
16 | * Scattering model classes |
---|
17 | * The classes use the IGOR library found in |
---|
18 | * sansmodels/src/libigor |
---|
19 | * |
---|
20 | */ |
---|
21 | |
---|
22 | #include <math.h> |
---|
23 | #include "parameters.hh" |
---|
24 | #include <stdio.h> |
---|
25 | using namespace std; |
---|
26 | #include "surfacefractal.h" |
---|
27 | extern "C" { |
---|
28 | #include "libmultifunc/libfunc.h" |
---|
29 | } |
---|
30 | |
---|
31 | static double surface_fractal_kernel(double dp[], double q) { |
---|
32 | //fit parameters |
---|
33 | double scale = dp[0]; |
---|
34 | double radius = dp[1]; |
---|
35 | double surface_dim = dp[2]; |
---|
36 | double co_length = dp[3]; |
---|
37 | double background = dp[4]; |
---|
38 | //others |
---|
39 | double pq = 0.0; |
---|
40 | double sq = 0.0; |
---|
41 | double mmo = 0.0; |
---|
42 | //result |
---|
43 | double result = 0.0; |
---|
44 | if( (q*radius) == 0.0){ |
---|
45 | pq = 1.0; |
---|
46 | } |
---|
47 | else{ |
---|
48 | //calculate P(q) for the spherical subunits; not normalized |
---|
49 | pq = pow((3.0*(sin(q*radius) - q*radius*cos(q*radius))/pow((q*radius),3)),2); |
---|
50 | } |
---|
51 | mmo = 5.0 - surface_dim; |
---|
52 | |
---|
53 | //calculate S(q) |
---|
54 | sq = exp(gamln(mmo))*sin(-(mmo)*atan(q*co_length)); |
---|
55 | sq *= pow(co_length, mmo); |
---|
56 | sq /= pow((1.0 + (q*co_length)*(q*co_length)),(mmo/2.0)); |
---|
57 | sq /= q; |
---|
58 | //combine and return |
---|
59 | result = pq * sq; |
---|
60 | result *= scale; |
---|
61 | result += background; |
---|
62 | |
---|
63 | return(result); |
---|
64 | } |
---|
65 | |
---|
66 | SurfaceFractalModel :: SurfaceFractalModel() { |
---|
67 | scale = Parameter(1.0); |
---|
68 | radius = Parameter(10.0); |
---|
69 | surface_dim = Parameter(2.0); |
---|
70 | co_length = Parameter(500.0); |
---|
71 | background = Parameter(0.0); |
---|
72 | } |
---|
73 | |
---|
74 | /** |
---|
75 | * Function to evaluate 1D scattering function |
---|
76 | * @param q: q-value |
---|
77 | * @return: function value |
---|
78 | */ |
---|
79 | double SurfaceFractalModel :: operator()(double q) { |
---|
80 | double dp[5]; |
---|
81 | |
---|
82 | // Add the background after averaging |
---|
83 | dp[0] = scale(); |
---|
84 | dp[1] = radius(); |
---|
85 | dp[2] = surface_dim(); |
---|
86 | dp[3] = co_length(); |
---|
87 | dp[4] = 0.0; |
---|
88 | |
---|
89 | // Perform the computation |
---|
90 | double sum = 0.0; |
---|
91 | |
---|
92 | sum = surface_fractal_kernel(dp, fabs(q)); |
---|
93 | return sum + background(); |
---|
94 | } |
---|
95 | |
---|
96 | /** |
---|
97 | * Function to evaluate 2D scattering function |
---|
98 | * @param q_x: value of Q along x |
---|
99 | * @param q_y: value of Q along y |
---|
100 | * @return: function value |
---|
101 | */ |
---|
102 | double SurfaceFractalModel :: operator()(double qx, double qy) { |
---|
103 | double q = sqrt(qx*qx + qy*qy); |
---|
104 | return (*this).operator()(q); |
---|
105 | } |
---|
106 | |
---|
107 | /** |
---|
108 | * Function to evaluate 2D scattering function |
---|
109 | * @param pars: parameters of the SurfaceFractalModel |
---|
110 | * @param q: q-value |
---|
111 | * @param phi: angle phi |
---|
112 | * @return: function value |
---|
113 | */ |
---|
114 | double SurfaceFractalModel :: evaluate_rphi(double q, double phi) { |
---|
115 | return (*this).operator()(q); |
---|
116 | } |
---|
117 | |
---|
118 | /** |
---|
119 | * Function to calculate effective radius |
---|
120 | * @return: effective radius value |
---|
121 | */ |
---|
122 | double SurfaceFractalModel :: calculate_ER() { |
---|
123 | //NOT implemented yet!!! 'cause None shape Model |
---|
124 | return 0.0; |
---|
125 | } |
---|
126 | double SurfaceFractalModel :: calculate_VR() { |
---|
127 | return 1.0; |
---|
128 | } |
---|