source: sasview/sansmodels/src/c_models/flexiblecylinder.cpp @ 046af80

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 046af80 was 82c11d3, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

refactored bunch of models

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