source: sasview/sansmodels/src/sans/models/c_models/polygausscoil.cpp @ 2c63e80e

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 2c63e80e was 34c2649, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

Re #4 Fixed warnings

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[c724ccd]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 "libTwoPhase.h"
30        #include "polygausscoil.h"
31}
32
33Poly_GaussCoil :: Poly_GaussCoil() {
34        scale      = Parameter(1.0);
35        rg     = Parameter(60.0, true);
36        rg.set_min(0.0);
37        poly_m   = Parameter(2.0);
38        background = Parameter(0.001);
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 Poly_GaussCoil :: operator()(double q) {
48        double dp[4];
49
50        // Fill parameter array for IGOR library
51        // Add the background after averaging
52        dp[0] = scale();
53        dp[1] = rg();
54        dp[2] = poly_m();
55        dp[3] = 0.0;
56
57        // Get the dispersion points for the radius
[8569cb9]58        vector<WeightPoint> weights_rad;
59        rg.get_weights(weights_rad);
[c724ccd]60
61        // Perform the computation, with all weight points
62        double sum = 0.0;
63
[8569cb9]64
[c724ccd]65        double norm = 0.0;
66        double vol = 0.0;
67
68        // Loop over radius weight points
[34c2649]69        for(size_t i=0; i<weights_rad.size(); i++) {
[c724ccd]70                dp[1] = weights_rad[i].value;
71
72                //Un-normalize SphereForm by volume
73                sum += weights_rad[i].weight
74                        * PolyGaussCoil(dp, q) * pow(weights_rad[i].value,3);
75                //Find average volume
76                vol += weights_rad[i].weight
77                        * pow(weights_rad[i].value,3);
78
79                norm += weights_rad[i].weight;
80        }
81
82        if (vol != 0.0 && norm != 0.0) {
83                //Re-normalize by avg volume
84                sum = sum/(vol/norm);}
85        return sum/norm + background();
[8569cb9]86
[c724ccd]87
88        sum = PolyGaussCoil(dp, q);
89        return sum + background();
90}
91
92/**
93 * Function to evaluate 2D scattering function
94 * @param q_x: value of Q along x
95 * @param q_y: value of Q along y
96 * @return: function value
97 */
98double Poly_GaussCoil :: operator()(double qx, double qy) {
99        double q = sqrt(qx*qx + qy*qy);
100        return (*this).operator()(q);
101}
102
103/**
104 * Function to evaluate 2D scattering function
105 * @param pars: parameters of the sphere
106 * @param q: q-value
107 * @param phi: angle phi
108 * @return: function value
109 */
110double Poly_GaussCoil :: evaluate_rphi(double q, double phi) {
111        return (*this).operator()(q);
112}
113
114/**
115 * Function to calculate effective radius
116 * @return: effective radius value
117 */
118double Poly_GaussCoil :: calculate_ER() {
119        double rad_out = 0.0;
120
121        // Perform the computation, with all weight points
122        double sum = 0.0;
123        double norm = 0.0;
124
125        // Get the dispersion points for the radius
126        vector<WeightPoint> weights_rad;
127        rg.get_weights(weights_rad);
128        // Loop over radius weight points to average the radius value
[34c2649]129        for(size_t i=0; i<weights_rad.size(); i++) {
[c724ccd]130                sum += weights_rad[i].weight
131                        * weights_rad[i].value;
132                norm += weights_rad[i].weight;
133        }
134        if (norm != 0){
135                //return the averaged value
136                rad_out =  sum/norm;}
137        else{
138                //return normal value
139                rad_out = rg();}
140
141        return rad_out;
142}
Note: See TracBrowser for help on using the repository browser.