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

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

updated documents

  • Property mode set to 100644
File size: 4.5 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        effect_radius      = Parameter(50.0, true);
36        effect_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] = effect_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        effect_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.effect_radius      = effect_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        effect_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.effect_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 * Function to calculate effective radius
130 * @return: effective radius value
131 */
132double SquareWellStructure :: calculate_ER() {
133//NOT implemented yet!!!
134}
135// Testing code
136/*
137int main(void)
138{
139        SquareWellModel c = SquareWellModel();
140
141        printf("I(Qx=%g,Qy=%g) = %g\n", 0.001, 0.001, c(0.001, 0.001));
142        printf("I(Q=%g) = %g\n", 0.001, c(0.001));
143        c.radius.dispersion = new GaussianDispersion();
144        c.radius.dispersion->npts = 100;
145        c.radius.dispersion->width = 5;
146
147        //c.length.dispersion = GaussianDispersion();
148        //c.length.dispersion.npts = 20;
149        //c.length.dispersion.width = 65;
150
151        printf("I(Q=%g) = %g\n", 0.001, c(0.001));
152        printf("I(Q=%g) = %g\n", 0.001, c(0.001));
153        printf("I(Qx=%g, Qy=%g) = %g\n", 0.001, 0.001, c(0.001, 0.001));
154        printf("I(Q=%g,  Phi=%g) = %g\n", 0.00447, .7854, c.evaluate_rphi(sqrt(0.00002), .7854));
155
156
157
158        double i_avg = c(0.01, 0.01);
159        double i_1d = c(sqrt(0.0002));
160
161        printf("\nI(Qx=%g, Qy=%g) = %g\n", 0.01, 0.01, i_avg);
162        printf("I(Q=%g)         = %g\n", sqrt(0.0002), i_1d);
163        printf("ratio %g %g\n", i_avg/i_1d, i_1d/i_avg);
164
165
166        return 0;
167}
168*/
Note: See TracBrowser for help on using the repository browser.