source: sasview/sansmodels/src/sans/models/c_models/DiamCyl.cpp @ 27953d1

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 27953d1 was 6b38781, checked in by Jae Cho <jhjcho@…>, 16 years ago

Added 2nd virial coeff. functions

  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[6b38781]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 */
22
23#include <math.h>
24#include "models.hh"
25#include "parameters.hh"
26#include <stdio.h>
27using namespace std;
28
29extern "C" {
30        #include "libStructureFactor.h"
31        #include "DiamCyl.h"
32}
33
34DiamCylFunc :: DiamCylFunc() {
35        radius      = Parameter(20.0, true);
36        radius.set_min(0.0);
37        length      = Parameter(400, true);
38        length.set_min(0.0);
39}
40
41/**
42 * Function to evaluate 1D scattering function
43 * The NIST IGOR library is used for the actual calculation.
44 * @param q: q-value
45 * @return: function value
46 */
47double DiamCylFunc :: operator()(double q) {
48        double dp[2];
49
50        // Fill parameter array for IGOR library
51        // Add the background after averaging
52        dp[0] = radius();
53        dp[1] = length();
54
55        // Get the dispersion points for the radius
56        vector<WeightPoint> weights_rad;
57        radius.get_weights(weights_rad);
58
59        // Get the dispersion points for the length
60        vector<WeightPoint> weights_len;
61        length.get_weights(weights_len);
62
63        // Perform the computation, with all weight points
64        double sum = 0.0;
65        double norm = 0.0;
66
67        // Loop over radius weight points
68        for(int i=0; i<weights_rad.size(); i++) {
69                dp[0] = weights_rad[i].value;
70                // Loop over length weight points
71                for(int j=0; j<weights_len.size(); j++) {
72                        dp[1] = weights_len[j].value;
73
74                        sum += weights_rad[i].weight
75                                                * weights_len[j].weight *DiamCyl(dp, q);
76                        norm += weights_rad[i].weight
77                                * weights_len[j].weight;
78                }
79        }
80        return sum/norm ;
81}
82
83/**
84 * Function to evaluate 2D scattering function
85 * @param q_x: value of Q along x
86 * @param q_y: value of Q along y
87 * @return: function value
88 */
89double DiamCylFunc :: operator()(double qx, double qy) {
90        DiamCyldParameters dp;
91        // Fill parameter array
92        dp.radius     = radius();
93        dp.length     = length();
94
95        // Get the dispersion points for the radius
96        vector<WeightPoint> weights_rad;
97        radius.get_weights(weights_rad);
98
99        // Get the dispersion points for the length
100        vector<WeightPoint> weights_len;
101        length.get_weights(weights_len);
102
103
104        // Perform the computation, with all weight points
105        double sum = 0.0;
106        double norm = 0.0;
107
108        // Loop over radius weight points
109        for(int i=0; i<weights_rad.size(); i++) {
110                dp.radius = weights_rad[i].value;
111
112                // Loop over length weight points
113                for(int j=0; j<weights_len.size(); j++) {
114                        dp.length = weights_len[j].value;
115                        double _ptvalue = weights_rad[i].weight
116                                * weights_len[j].weight
117                                * DiamCyld_analytical_2DXY(&dp, qx, qy);
118                        sum += _ptvalue;
119
120                        norm += weights_rad[i].weight
121                                * weights_len[j].weight;
122
123
124                        }
125                }
126        return sum/norm;
127}
128
129/**
130 * Function to evaluate 2D scattering function
131 * @param pars: parameters of the cylinder
132 * @param q: q-value
133 * @param phi: angle phi
134 * @return: function value
135 */
136double DiamCylFunc :: evaluate_rphi(double q, double phi) {
137        double qx = q*cos(phi);
138        double qy = q*sin(phi);
139        return (*this).operator()(qx, qy);
140}
141
142// Testing code
143
144/**
145int main(void)
146{
147        DiamCylFunc c = DiamCylFunc();
148
149        printf("I(Qx=%g,Qy=%g) = %g\n", 0.001, 0.001, c(0.001, 0.001));
150        printf("I(Q=%g) = %g\n", 0.001, c(0.001));
151        c.radius.dispersion = new GaussianDispersion();
152        c.radius.dispersion->npts = 100;
153        c.radius.dispersion->width = 20;
154
155        //c.length.dispersion = GaussianDispersion();
156        //c.length.dispersion.npts = 20;
157        //c.length.dispersion.width = 65;
158
159        //printf("I(Q=%g) = %g\n", 0.001, c(0.001));
160        //printf("I(Q=%g) = %g\n", 0.001, c(0.001));
161        //printf("I(Qx=%g, Qy=%g) = %g\n", 0.001, 0.001, c(0.001, 0.001));
162        //printf("I(Q=%g,  Phi=%g) = %g\n", 0.00447, .7854, c.evaluate_rphi(sqrt(0.00002), .7854));
163
164
165
166        double i_avg = c(0.01, 0.01);
167        double i_1d = c(sqrt(0.0002));
168
169        printf("\nI(Qx=%g, Qy=%g) = %g\n", 0.01, 0.01, i_avg);
170        printf("I(Q=%g)         = %g\n", sqrt(0.0002), i_1d);
171        printf("ratio %g %g\n", i_avg/i_1d, i_1d/i_avg);
172
173
174        return 0;
175}
176 **/
Note: See TracBrowser for help on using the repository browser.