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 "masssurfacefractal.h" |
---|
27 | |
---|
28 | |
---|
29 | |
---|
30 | static double mass_surface_fractal_kernel(double dp[], double q) { |
---|
31 | //fit parameters |
---|
32 | double scale = dp[0]; |
---|
33 | double mass_dim = dp[1]; |
---|
34 | double surface_dim = dp[2]; |
---|
35 | double cluster_rg = dp[3]; |
---|
36 | double primary_rg = dp[4]; |
---|
37 | double background = dp[5]; |
---|
38 | |
---|
39 | //others |
---|
40 | double tot_dim = 0.0; |
---|
41 | double rc_norm = 0.0; |
---|
42 | double rp_norm = 0.0; |
---|
43 | double x_val1 = 0.0; |
---|
44 | double x_val2 = 0.0; |
---|
45 | double form_factor = 0.0; |
---|
46 | double inv_form = 0.0; |
---|
47 | |
---|
48 | // This model is valid only for 0<dm<=6 and 0<ds<=6 |
---|
49 | // Not valid values => reject as 0.0 |
---|
50 | if (mass_dim < 1e-16){ |
---|
51 | return background; |
---|
52 | } |
---|
53 | if (mass_dim > 6.0){ |
---|
54 | return background; |
---|
55 | } |
---|
56 | if (surface_dim < 1e-16){ |
---|
57 | return background; |
---|
58 | } |
---|
59 | if (surface_dim > 6.0){ |
---|
60 | return background; |
---|
61 | } |
---|
62 | tot_dim = 6.0 - surface_dim - mass_dim; |
---|
63 | //singulars |
---|
64 | if (tot_dim < 0.0){ |
---|
65 | return background; |
---|
66 | } |
---|
67 | |
---|
68 | //computation |
---|
69 | mass_dim /= 2.0; |
---|
70 | tot_dim /= 2.0; |
---|
71 | rc_norm = cluster_rg * cluster_rg / (3.0 * mass_dim); |
---|
72 | if (tot_dim < 1.0e-16){ |
---|
73 | tot_dim = 1.0e-16; |
---|
74 | } |
---|
75 | rp_norm = primary_rg * primary_rg / (3.0 * tot_dim); |
---|
76 | |
---|
77 | //x for P |
---|
78 | x_val1 = 1.0 + q * q * rc_norm; |
---|
79 | x_val2 = 1.0 + q * q * rp_norm; |
---|
80 | |
---|
81 | inv_form = pow(x_val1, mass_dim) * pow(x_val2, tot_dim); |
---|
82 | |
---|
83 | //another singular |
---|
84 | if (inv_form == 0.0) return background; |
---|
85 | |
---|
86 | form_factor = 1.0; |
---|
87 | form_factor /= inv_form; |
---|
88 | |
---|
89 | //scale and background |
---|
90 | form_factor *= scale; |
---|
91 | form_factor += background; |
---|
92 | return (form_factor); |
---|
93 | } |
---|
94 | |
---|
95 | MassSurfaceFractal :: MassSurfaceFractal() { |
---|
96 | scale = Parameter(1.0); |
---|
97 | mass_dim = Parameter(1.8); |
---|
98 | surface_dim = Parameter(2.3); |
---|
99 | cluster_rg = Parameter(86.7); |
---|
100 | primary_rg = Parameter(4000.0); |
---|
101 | background = Parameter(0.0); |
---|
102 | } |
---|
103 | |
---|
104 | /** |
---|
105 | * Function to evaluate 1D scattering function |
---|
106 | * @param q: q-value |
---|
107 | * @return: function value |
---|
108 | */ |
---|
109 | double MassSurfaceFractal :: operator()(double q) { |
---|
110 | double dp[6]; |
---|
111 | |
---|
112 | // Fill parameter array for IGOR library |
---|
113 | // Add the background after averaging |
---|
114 | dp[0] = scale(); |
---|
115 | dp[1] = mass_dim(); |
---|
116 | dp[2] = surface_dim(); |
---|
117 | dp[3] = cluster_rg(); |
---|
118 | dp[4] = primary_rg(); |
---|
119 | dp[5] = 0.0; |
---|
120 | |
---|
121 | //computation: no polydispersion |
---|
122 | double sum = 0.0; |
---|
123 | sum = mass_surface_fractal_kernel(dp, q); |
---|
124 | |
---|
125 | return sum + background(); |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | * Function to evaluate 2D scattering function |
---|
130 | * @param q_x: value of Q along x |
---|
131 | * @param q_y: value of Q along y |
---|
132 | * @return: function value |
---|
133 | */ |
---|
134 | double MassSurfaceFractal :: operator()(double qx, double qy) { |
---|
135 | double q = sqrt(qx*qx + qy*qy); |
---|
136 | return (*this).operator()(q); |
---|
137 | } |
---|
138 | |
---|
139 | /** |
---|
140 | * Function to evaluate 2D scattering function |
---|
141 | * @param pars: parameters of the FractalModel |
---|
142 | * @param q: q-value |
---|
143 | * @param phi: angle phi |
---|
144 | * @return: function value |
---|
145 | */ |
---|
146 | double MassSurfaceFractal :: evaluate_rphi(double q, double phi) { |
---|
147 | return (*this).operator()(q); |
---|
148 | } |
---|
149 | |
---|
150 | /** |
---|
151 | * Function to calculate effective radius |
---|
152 | * @return: effective radius value |
---|
153 | */ |
---|
154 | double MassSurfaceFractal :: calculate_ER() { |
---|
155 | //NOT implemented yet!!! 'cause None shape Model |
---|
156 | return 0.0; |
---|
157 | } |
---|
158 | double MassSurfaceFractal :: calculate_VR() { |
---|
159 | return 1.0; |
---|
160 | } |
---|