source: sasview/sansmodels/src/sans/models/c_models/fcc.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 34c2649, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

Re #4 Fixed warnings

  • Property mode set to 100644
File size: 5.6 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 "libSphere.h"
30        #include "fcc.h"
31}
32
33FCCrystalModel :: FCCrystalModel() {
34        scale      = Parameter(1.0);
35        dnn             = Parameter(220.0);
36        d_factor = Parameter(0.06);
37        radius     = Parameter(40.0, true);
38        radius.set_min(0.0);
39        sldSph   = Parameter(3.0e-6);
40        sldSolv   = Parameter(6.3e-6);
41        background = Parameter(0.0);
42        theta  = Parameter(0.0, true);
43        phi    = Parameter(0.0, true);
44        psi    = Parameter(0.0, true);
45}
46
47/**
48 * Function to evaluate 1D scattering function
49 * The NIST IGOR library is used for the actual calculation.
50 * @param q: q-value
51 * @return: function value
52 */
53double FCCrystalModel :: operator()(double q) {
54        double dp[7];
55
56        // Fill parameter array for IGOR library
57        // Add the background after averaging
58        dp[0] = scale();
59        dp[1] = dnn();
60        dp[2] = d_factor();
61        dp[3] = radius();
62        dp[4] = sldSph();
63        dp[5] = sldSolv();
64        dp[6] = 0.0;
65
66        // Get the dispersion points for the radius
67        vector<WeightPoint> weights_rad;
68        radius.get_weights(weights_rad);
69
70        // Perform the computation, with all weight points
71        double sum = 0.0;
72        double norm = 0.0;
73        double vol = 0.0;
74        double result;
75
76        // Loop over radius weight points
77        for(size_t i=0; i<weights_rad.size(); i++) {
78                dp[3] = weights_rad[i].value;
79
80                //Un-normalize SphereForm by volume
81                result = FCC_ParaCrystal(dp, q) * pow(weights_rad[i].value,3);
82                // This FIXES a singualrity the kernel in libigor.
83                if ( result == INFINITY || result == NAN){
84                        result = 0.0;
85                }
86                sum += weights_rad[i].weight
87                        * result;
88                //Find average volume
89                vol += weights_rad[i].weight
90                        * pow(weights_rad[i].value,3);
91
92                norm += weights_rad[i].weight;
93        }
94
95        if (vol != 0.0 && norm != 0.0) {
96                //Re-normalize by avg volume
97                sum = sum/(vol/norm);}
98        return sum/norm + background();
99}
100
101/**
102 * Function to evaluate 2D scattering function
103 * @param q_x: value of Q along x
104 * @param q_y: value of Q along y
105 * @return: function value
106 */
107double FCCrystalModel :: operator()(double qx, double qy) {
108        FCParameters dp;
109        dp.scale      = scale();
110        dp.dnn   = dnn();
111        dp.d_factor   = d_factor();
112        dp.radius  = radius();
113        dp.sldSph   = sldSph();
114        dp.sldSolv   = sldSolv();
115        dp.background = 0.0;
116        dp.theta  = theta();
117        dp.phi    = phi();
118        dp.psi    = psi();
119
120        // Get the dispersion points for the radius
121        vector<WeightPoint> weights_rad;
122        radius.get_weights(weights_rad);
123
124        // Get angular averaging for theta
125        vector<WeightPoint> weights_theta;
126        theta.get_weights(weights_theta);
127
128        // Get angular averaging for phi
129        vector<WeightPoint> weights_phi;
130        phi.get_weights(weights_phi);
131
132        // Get angular averaging for psi
133        vector<WeightPoint> weights_psi;
134        psi.get_weights(weights_psi);
135
136        // Perform the computation, with all weight points
137        double sum = 0.0;
138        double norm = 0.0;
139        double norm_vol = 0.0;
140        double vol = 0.0;
141        double pi = 4.0*atan(1.0);
142        // Loop over radius weight points
143        for(size_t i=0; i<weights_rad.size(); i++) {
144                dp.radius = weights_rad[i].value;
145                // Average over theta distribution
146                for(size_t j=0; j< weights_theta.size(); j++) {
147                        dp.theta = weights_theta[j].value;
148                        // Average over phi distribution
149                        for(size_t k=0; k< weights_phi.size(); k++) {
150                                dp.phi = weights_phi[k].value;
151                                // Average over phi distribution
152                                for(size_t l=0; l< weights_psi.size(); l++) {
153                                        dp.psi = weights_psi[l].value;
154                                        //Un-normalize SphereForm by volume
155                                        double _ptvalue = weights_rad[i].weight
156                                                                                * weights_theta[j].weight
157                                                                                * weights_phi[k].weight
158                                                                                * weights_psi[l].weight
159                                                                                * fc_analytical_2DXY(&dp, qx, qy);
160                                                                                //* pow(weights_rad[i].value,3.0);
161                                        // Consider when there is infinte or nan.
162                                        if ( _ptvalue == INFINITY || _ptvalue == NAN){
163                                                _ptvalue = 0.0;
164                                        }
165                                        if (weights_theta.size()>1) {
166                                                _ptvalue *= fabs(sin(weights_theta[j].value*pi/180.0));
167                                        }
168                                        sum += _ptvalue;
169                                        // This model dose not need the volume of spheres correction!!!
170                                        norm += weights_rad[i].weight
171                                                        * weights_theta[j].weight
172                                                        * weights_phi[k].weight
173                                                        * weights_psi[l].weight;
174                                }
175                        }
176                }
177        }
178        // Averaging in theta needs an extra normalization
179        // factor to account for the sin(theta) term in the
180        // integration (see documentation).
181        if (weights_theta.size()>1) norm = norm / asin(1.0);
182
183        if (vol != 0.0 && norm_vol != 0.0) {
184                //Re-normalize by avg volume
185                sum = sum/(vol/norm_vol);}
186
187        return sum/norm + background();
188}
189
190/**
191 * Function to evaluate 2D scattering function
192 * @param pars: parameters of the FCCCrystal
193 * @param q: q-value
194 * @param phi: angle phi
195 * @return: function value
196 */
197double FCCrystalModel :: evaluate_rphi(double q, double phi) {
198        return (*this).operator()(q);
199}
200
201/**
202 * Function to calculate effective radius
203 * @return: effective radius value
204 */
205double FCCrystalModel :: calculate_ER() {
206        //NOT implemented yet!!!
207        return 0.0;
208}
Note: See TracBrowser for help on using the repository browser.