source: sasview/sansmodels/src/sans/models/c_models/SquareWell.cpp @ 7a69683

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 7a69683 was 25579e8, checked in by Jae Cho <jhjcho@…>, 16 years ago

Enable structure factors

  • Property mode set to 100644
File size: 4.3 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 */
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 "SquareWell.h"
32}
33
34SquareWellStructure :: SquareWellStructure() {
35        radius      = Parameter(50.0, true);
36        radius.set_min(0.0);
37        volfraction = Parameter(0.04, true);
38        volfraction.set_min(0.0);
39        welldepth   = Parameter(1.50);
40        wellwidth  = Parameter(1.20);
41}
42
43/**
44 * Function to evaluate 1D scattering function
45 * The NIST IGOR library is used for the actual calculation.
46 * @param q: q-value
47 * @return: function value
48 */
49double SquareWellStructure :: operator()(double q) {
50        double dp[4];
51
52        // Fill parameter array for IGOR library
53        // Add the background after averaging
54        dp[0] = radius();
55        dp[1] = volfraction();
56        dp[2] = welldepth();
57        dp[3] = wellwidth();
58
59        // Get the dispersion points for the radius
60        vector<WeightPoint> weights_rad;
61        radius.get_weights(weights_rad);
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
71                sum += weights_rad[i].weight
72                                * SquareWellStruct(dp, q);
73                norm += weights_rad[i].weight;
74        }
75        return sum/norm ;
76}
77
78/**
79 * Function to evaluate 2D scattering function
80 * @param q_x: value of Q along x
81 * @param q_y: value of Q along y
82 * @return: function value
83 */
84double SquareWellStructure :: operator()(double qx, double qy) {
85        SquareWellParameters dp;
86        // Fill parameter array
87        dp.radius      = radius();
88        dp.volfraction = volfraction();
89        dp.welldepth   = welldepth();
90        dp.wellwidth   = wellwidth();
91
92        // Get the dispersion points for the radius
93        vector<WeightPoint> weights_rad;
94        radius.get_weights(weights_rad);
95
96        // Perform the computation, with all weight points
97        double sum = 0.0;
98        double norm = 0.0;
99
100        // Loop over radius weight points
101        for(int i=0; i<weights_rad.size(); i++) {
102                dp.radius = weights_rad[i].value;
103
104                                        double _ptvalue = weights_rad[i].weight
105                                                * SquareWell_analytical_2DXY(&dp, qx, qy);
106                                        sum += _ptvalue;
107
108                                        norm += weights_rad[i].weight;
109        }
110        // Averaging in theta needs an extra normalization
111        // factor to account for the sin(theta) term in the
112        // integration (see documentation).
113        return sum/norm;
114}
115
116/**
117 * Function to evaluate 2D scattering function
118 * @param pars: parameters of the cylinder
119 * @param q: q-value
120 * @param phi: angle phi
121 * @return: function value
122 */
123double SquareWellStructure :: evaluate_rphi(double q, double phi) {
124        double qx = q*cos(phi);
125        double qy = q*sin(phi);
126        return (*this).operator()(qx, qy);
127}
128
129// Testing code
130/*
131int main(void)
132{
133        SquareWellModel c = SquareWellModel();
134
135        printf("I(Qx=%g,Qy=%g) = %g\n", 0.001, 0.001, c(0.001, 0.001));
136        printf("I(Q=%g) = %g\n", 0.001, c(0.001));
137        c.radius.dispersion = new GaussianDispersion();
138        c.radius.dispersion->npts = 100;
139        c.radius.dispersion->width = 5;
140
141        //c.length.dispersion = GaussianDispersion();
142        //c.length.dispersion.npts = 20;
143        //c.length.dispersion.width = 65;
144
145        printf("I(Q=%g) = %g\n", 0.001, c(0.001));
146        printf("I(Q=%g) = %g\n", 0.001, c(0.001));
147        printf("I(Qx=%g, Qy=%g) = %g\n", 0.001, 0.001, c(0.001, 0.001));
148        printf("I(Q=%g,  Phi=%g) = %g\n", 0.00447, .7854, c.evaluate_rphi(sqrt(0.00002), .7854));
149
150
151
152        double i_avg = c(0.01, 0.01);
153        double i_1d = c(sqrt(0.0002));
154
155        printf("\nI(Qx=%g, Qy=%g) = %g\n", 0.01, 0.01, i_avg);
156        printf("I(Q=%g)         = %g\n", sqrt(0.0002), i_1d);
157        printf("ratio %g %g\n", i_avg/i_1d, i_1d/i_avg);
158
159
160        return 0;
161}
162*/
Note: See TracBrowser for help on using the repository browser.