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

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

calculation of the effective radius are added

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[0f5bc9f]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 *
[836fe6e]20 */
[0f5bc9f]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"
[5eb9154]30        #include "sphere.h"
[0f5bc9f]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}
[5eb9154]97
98/**
99 * Function to calculate effective radius
100 * @param pars: parameters of the sphere
101 * @return: effective radius value
102 */
103double SphereModel :: calculate_ER() {
104        SphereParameters dp;
105        dp.scale = scale();
106        dp.radius = radius();
107        dp.contrast = contrast();
108        dp.background = background();
109        double rad_out = 0.0;
110
111        // Perform the computation, with all weight points
112        double sum = 0.0;
113        double norm = 0.0;
114
115        // Get the dispersion points for the radius
116        vector<WeightPoint> weights_rad;
117        radius.get_weights(weights_rad);
118        // Loop over radius weight points to average the radius value
119        for(int i=0; i<weights_rad.size(); i++) {
120                sum += weights_rad[i].weight
121                        * weights_rad[i].value;
122                norm += weights_rad[i].weight;
123        }
124        if (norm != 0){
125                //return the averaged value
126                rad_out =  sum/norm;}
127        else{
128                //return normal value
129                rad_out = radius();}
130
131        return rad_out;
132}
Note: See TracBrowser for help on using the repository browser.