source: sasview/sansmodels/src/sans/models/c_models/flexcyl_ellipX.cpp @ 00c2141

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 00c2141 was 8dcfb2e, checked in by Jae Cho <jhjcho@…>, 14 years ago

correted param name

  • Property mode set to 100644
File size: 6.0 KB
Line 
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 "models.hh"
24#include "parameters.hh"
25#include <stdio.h>
26using namespace std;
27
28extern "C" {
29        #include "libCylinder.h"
30        #include "libStructureFactor.h"
31        #include "flexcyl_ellipX.h"
32}
33
34FlexCylEllipXModel :: FlexCylEllipXModel() {
35        scale      = Parameter(1.0);
36        length     = Parameter(1000.0, true);
37        length.set_min(0.0);
38        kuhn_length = Parameter(100.0, true);
39        kuhn_length.set_min(0.0);
40        radius  = Parameter(20.0, true);
41        radius.set_min(0.0);
42        axis_ratio = Parameter(1.5);
43        axis_ratio.set_min(0.0);
44        sldCyl   = Parameter(1.0e-6);
45        sldSolv   = Parameter(6.3e-6);
46        background = Parameter(0.0001);
47}
48
49/**
50 * Function to evaluate 1D scattering function
51 * The NIST IGOR library is used for the actual calculation.
52 * @param q: q-value
53 * @return: function value
54 */
55double FlexCylEllipXModel :: operator()(double q) {
56        double dp[8];
57
58        // Fill parameter array for IGOR library
59        // Add the background after averaging
60        dp[0] = scale();
61        dp[1] = length();
62        dp[2] = kuhn_length();
63        dp[3] = radius();
64        dp[4] = axis_ratio();
65        dp[5] = sldCyl();
66        dp[6] = sldSolv();
67        dp[7] = 0.0;
68
69        // Get the dispersion points for the length
70        vector<WeightPoint> weights_len;
71        length.get_weights(weights_len);
72
73        // Get the dispersion points for the kuhn_length
74        vector<WeightPoint> weights_kuhn;
75        kuhn_length.get_weights(weights_kuhn);
76
77        // Get the dispersion points for the radius
78        vector<WeightPoint> weights_rad;
79        radius.get_weights(weights_rad);
80
81        // Get the dispersion points for the axis_ratio
82        vector<WeightPoint> weights_ratio;
83        axis_ratio.get_weights(weights_ratio);
84
85        // Perform the computation, with all weight points
86        double sum = 0.0;
87        double norm = 0.0;
88        double vol = 0.0;
89
90        // Loop over length weight points
91        for(int i=0; i< (int)weights_len.size(); i++) {
92                dp[1] = weights_len[i].value;
93
94                // Loop over kuhn_length weight points
95                for(int j=0; j< (int)weights_kuhn.size(); j++) {
96                        dp[2] = weights_kuhn[j].value;
97
98                        // Loop over radius weight points
99                        for(int k=0; k< (int)weights_rad.size(); k++) {
100                                dp[3] = weights_rad[k].value;
101                                // Loop over axis_ratio weight points
102                                for(int l=0; l< (int)weights_ratio.size(); l++) {
103                                        dp[4] = weights_ratio[l].value;
104
105                                        //Un-normalize by volume
106                                        sum += weights_len[i].weight * weights_kuhn[j].weight*weights_rad[k].weight
107                                                * weights_ratio[l].weight * FlexCyl_Ellip(dp, q)
108                                                * (pow(weights_rad[k].value,2.0) * weights_ratio[l].value * weights_len[i].value);
109                                        //Find weighted volume
110                                        vol += weights_rad[k].weight * weights_kuhn[j].weight
111                                                * weights_len[i].weight * weights_ratio[l].weight
112                                                *pow(weights_rad[k].value,2.0)* weights_ratio[l].weight*weights_len[i].value;
113                                        norm += weights_len[i].weight * weights_kuhn[j].weight
114                                                *weights_rad[k].weight* weights_ratio[l].weight;
115                                }
116                        }
117                }
118        }
119        if (vol != 0.0 && norm != 0.0) {
120                //Re-normalize by avg volume
121                sum = sum/(vol/norm);}
122
123        return sum/norm + background();
124}
125
126/**
127 * Function to evaluate 2D scattering function
128 * @param q_x: value of Q along x
129 * @param q_y: value of Q along y
130 * @return: function value
131 */
132double FlexCylEllipXModel :: operator()(double qx, double qy) {
133        double q = sqrt(qx*qx + qy*qy);
134        return (*this).operator()(q);
135}
136
137/**
138 * Function to evaluate 2D scattering function
139 * @param pars: parameters of the triaxial ellipsoid
140 * @param q: q-value
141 * @param phi: angle phi
142 * @return: function value
143 */
144double FlexCylEllipXModel :: evaluate_rphi(double q, double phi) {
145        //double qx = q*cos(phi);
146        //double qy = q*sin(phi);
147        return (*this).operator()(q);
148}
149/**
150 * Function to calculate effective radius
151 * @return: effective radius value
152 */
153double FlexCylEllipXModel :: calculate_ER() {
154        FlexCylEXParameters dp;
155
156        dp.radius  = radius();
157        dp.length     = length();
158        dp.axis_ratio  = axis_ratio();
159
160        double rad_out = 0.0;
161        double suf_rad = sqrt(dp.radius*dp.radius*dp.axis_ratio );
162        // Perform the computation, with all weight points
163        double sum = 0.0;
164        double norm = 0.0;
165
166        // Get the dispersion points for the total length
167        vector<WeightPoint> weights_length;
168        length.get_weights(weights_length);
169
170        // Get the dispersion points for minor radius
171        vector<WeightPoint> weights_radius ;
172        radius.get_weights(weights_radius);
173
174        // Get the dispersion points for axis ratio = major_radius/minor_radius
175        vector<WeightPoint> weights_ratio ;
176        axis_ratio.get_weights(weights_ratio);
177
178        // Loop over major shell weight points
179        for(int i=0; i< (int)weights_length.size(); i++) {
180                dp.length = weights_length[i].value;
181                for(int k=0; k< (int)weights_radius.size(); k++) {
182                        dp.radius = weights_radius[k].value;
183                        // Loop over axis_ratio weight points
184                        for(int l=0; l< (int)weights_ratio.size(); l++) {
185                                dp.axis_ratio = weights_ratio[l].value;
186                                suf_rad = sqrt(dp.radius  * dp.radius  * dp.axis_ratio);
187                                //Note: output of "DiamCyl(dp.length,dp.radius)" is DIAMETER.
188                                sum +=weights_length[i].weight * weights_radius[k].weight
189                                                * weights_ratio[l].weight *DiamCyl(dp.length,suf_rad)/2.0;
190                                norm += weights_length[i].weight* weights_radius[k].weight* weights_ratio[l].weight;
191                        }
192                }
193        }
194        if (norm != 0){
195                //return the averaged value
196                rad_out =  sum/norm;}
197        else{
198                //return normal value
199                //Note: output of "DiamCyl(dp.length,dp.radius)" is DIAMETER.
200                rad_out = DiamCyl(dp.length,suf_rad)/2.0;}
201
202        return rad_out;
203}
Note: See TracBrowser for help on using the repository browser.