source: sasview/sansmodels/src/sans/models/c_models/StickyHS.cpp @ 87fbc60

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

Enable structure factors

  • Property mode set to 100644
File size: 3.4 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 "StickyHS.h"
32}
33
34StickyHSStructure :: StickyHSStructure() {
35        radius      = Parameter(50.0, true);
36        radius.set_min(0.0);
37        volfraction = Parameter(0.10, true);
38        volfraction.set_min(0.0);
39        perturb = Parameter(0.05, true);
40        perturb.set_min(0.0);
41        stickiness = Parameter(0.20, true);;   
42        stickiness.set_min(0.0);
43}
44
45/**
46 * Function to evaluate 1D scattering function
47 * The NIST IGOR library is used for the actual calculation.
48 * @param q: q-value
49 * @return: function value
50 */
51double StickyHSStructure :: operator()(double q) {
52        double dp[4];
53
54        // Fill parameter array for IGOR library
55        // Add the background after averaging
56        dp[0] = radius();
57        dp[1] = volfraction();
58        dp[2] = perturb();
59        dp[3] = stickiness();
60
61        // Get the dispersion points for the radius
62        vector<WeightPoint> weights_rad;
63        radius.get_weights(weights_rad);
64
65        // Perform the computation, with all weight points
66        double sum = 0.0;
67        double norm = 0.0;
68
69        // Loop over radius weight points
70        for(int i=0; i<weights_rad.size(); i++) {
71                dp[0] = weights_rad[i].value;
72
73                sum += weights_rad[i].weight
74                                * StickyHS_Struct(dp, q);
75                norm += weights_rad[i].weight;
76        }
77        return sum/norm ;
78}
79
80/**
81 * Function to evaluate 2D scattering function
82 * @param q_x: value of Q along x
83 * @param q_y: value of Q along y
84 * @return: function value
85 */
86double StickyHSStructure :: operator()(double qx, double qy) {
87        StickyHSParameters dp;
88        // Fill parameter array
89        dp.radius      = radius();
90        dp.volfraction = volfraction();
91        dp.perturb = perturb();
92        dp.stickiness = stickiness();
93
94        // Get the dispersion points for the radius
95        vector<WeightPoint> weights_rad;
96        radius.get_weights(weights_rad);
97
98        // Perform the computation, with all weight points
99        double sum = 0.0;
100        double norm = 0.0;
101
102        // Loop over radius weight points
103        for(int i=0; i<weights_rad.size(); i++) {
104                dp.radius = weights_rad[i].value;
105
106                                        double _ptvalue = weights_rad[i].weight
107                                                * StickyHS_analytical_2DXY(&dp, qx, qy);
108                                        sum += _ptvalue;
109
110                                        norm += weights_rad[i].weight;
111        }
112        // Averaging in theta needs an extra normalization
113        // factor to account for the sin(theta) term in the
114        // integration (see documentation).
115        return sum/norm;
116}
117
118/**
119 * Function to evaluate 2D scattering function
120 * @param pars: parameters of the cylinder
121 * @param q: q-value
122 * @param phi: angle phi
123 * @return: function value
124 */
125double StickyHSStructure :: evaluate_rphi(double q, double phi) {
126        double qx = q*cos(phi);
127        double qy = q*sin(phi);
128        return (*this).operator()(qx, qy);
129}
Note: See TracBrowser for help on using the repository browser.