source: sasview/sansmodels/src/sans/models/c_models/sphere.cpp @ e2f7b92

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

updated documents

  • Property mode set to 100644
File size: 3.2 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 */
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 "libSphere.h"
30        #include "sphere.h"
31}
32
33SphereModel :: SphereModel() {
34        scale      = Parameter(1.0);
35        radius     = Parameter(20.0, true);
36        radius.set_min(0.0);
37        contrast   = Parameter(3.e-6);
38        background = Parameter(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 SphereModel :: 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] = radius();
54        dp[2] = contrast();
55        dp[3] = 0.0;
56
57        // Get the dispersion points for the radius
58        vector<WeightPoint> weights_rad;
59        radius.get_weights(weights_rad);
60
61        // Perform the computation, with all weight points
62        double sum = 0.0;
63        double norm = 0.0;
64
65        // Loop over radius weight points
66        for(int i=0; i<weights_rad.size(); i++) {
67                dp[1] = weights_rad[i].value;
68
69                sum += weights_rad[i].weight
70                        * SphereForm(dp, q);
71                norm += weights_rad[i].weight;
72        }
73        return sum/norm + background();
74}
75
76/**
77 * Function to evaluate 2D scattering function
78 * @param q_x: value of Q along x
79 * @param q_y: value of Q along y
80 * @return: function value
81 */
82double SphereModel :: operator()(double qx, double qy) {
83        double q = sqrt(qx*qx + qy*qy);
84        return (*this).operator()(q);
85}
86
87/**
88 * Function to evaluate 2D scattering function
89 * @param pars: parameters of the sphere
90 * @param q: q-value
91 * @param phi: angle phi
92 * @return: function value
93 */
94double SphereModel :: evaluate_rphi(double q, double phi) {
95        return (*this).operator()(q);
96}
97
98/**
99 * Function to calculate effective radius
100 * @return: effective radius value
101 */
102double SphereModel :: calculate_ER() {
103        SphereParameters dp;
104        dp.scale = scale();
105        dp.radius = radius();
106        dp.contrast = contrast();
107        dp.background = background();
108        double rad_out = 0.0;
109
110        // Perform the computation, with all weight points
111        double sum = 0.0;
112        double norm = 0.0;
113
114        // Get the dispersion points for the radius
115        vector<WeightPoint> weights_rad;
116        radius.get_weights(weights_rad);
117        // Loop over radius weight points to average the radius value
118        for(int i=0; i<weights_rad.size(); i++) {
119                sum += weights_rad[i].weight
120                        * weights_rad[i].value;
121                norm += weights_rad[i].weight;
122        }
123        if (norm != 0){
124                //return the averaged value
125                rad_out =  sum/norm;}
126        else{
127                //return normal value
128                rad_out = radius();}
129
130        return rad_out;
131}
Note: See TracBrowser for help on using the repository browser.