source: sasview/sansmodels/src/sans/models/c_models/flexiblecylinder.cpp @ 97603c0

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 97603c0 was c451be9, checked in by Jae Cho <jhjcho@…>, 15 years ago

corrections on the definition of polydispersity as suggested by steve K: should be normalized by average volume

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