source: sasview/sansmodels/src/sans/models/c_models/DiamEllip.cpp @ 8bac371

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 8bac371 was 6110bb8, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

Re #5 fixing models that don't return anything when they should

  • Property mode set to 100644
File size: 3.8 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 "libStructureFactor.h"
30        #include "DiamEllip.h"
31}
32
33DiamEllipFunc :: DiamEllipFunc() {
34        radius_a      = Parameter(20.0, true);
35        radius_a.set_min(0.0);
36        radius_b      = Parameter(400, true);
37        radius_b.set_min(0.0);
38}
39
40/**
41 * Function to evaluate 1D scattering function
42 * The NIST IGOR library is used for the actual calculation.
43 * @param q: q-value
44 * @return: function value
45 */
46double DiamEllipFunc :: operator()(double q) {
47        double dp[2];
48
49        // Fill parameter array for IGOR library
50        // Add the background after averaging
51        dp[0] = radius_a();
52        dp[1] = radius_b();
53
54        // Get the dispersion points for the radius a
55        vector<WeightPoint> weights_rad_a;
56        radius_a.get_weights(weights_rad_a);
57
58        // Get the dispersion points for the radius b
59        vector<WeightPoint> weights_rad_b;
60        radius_b.get_weights(weights_rad_b);
61
62        // Perform the computation, with all weight points
63        double sum = 0.0;
64        double norm = 0.0;
65
66        // Loop over radius weight points
67        for(int i=0; i<weights_rad_a.size(); i++) {
68                dp[0] = weights_rad_a[i].value;
69                // Loop over length weight points
70                for(int j=0; j<weights_rad_b.size(); j++) {
71                        dp[1] = weights_rad_b[j].value;
72
73                        sum += weights_rad_a[i].weight*weights_rad_b[j].weight
74                                * DiamEllip(dp[0], dp[1]);
75                        norm += weights_rad_a[i].weight*weights_rad_b[j].weight;
76                }
77        }
78        return sum/norm ;
79}
80
81/**
82 * Function to evaluate 2D scattering function
83 * @param q_x: value of Q along x
84 * @param q_y: value of Q along y
85 * @return: function value
86 */
87double DiamEllipFunc :: operator()(double qx, double qy) {
88        double q = sqrt(qx*qx + qy*qy);
89        return (*this).operator()(q);
90}
91/**
92 * Function to evaluate 2D scattering function
93 * @param pars: parameters of the cylinder
94 * @param q: q-value
95 * @param phi: angle phi
96 * @return: function value
97 */
98double DiamEllipFunc :: evaluate_rphi(double q, double phi) {
99        double qx = q*cos(phi);
100        double qy = q*sin(phi);
101        return (*this).operator()(qx, qy);
102}
103/**
104 * Function to calculate effective radius
105 * @return: effective radius value
106 */
107double DiamEllipFunc :: calculate_ER() {
108//NOT implemented yet!!!
109  return 0.0;
110}
111// Testing code
112/*
113int main(void)
114{
115        SquareWellModel c = SquareWellModel();
116
117        printf("I(Qx=%g,Qy=%g) = %g\n", 0.001, 0.001, c(0.001, 0.001));
118        printf("I(Q=%g) = %g\n", 0.001, c(0.001));
119        c.radius.dispersion = new GaussianDispersion();
120        c.radius.dispersion->npts = 100;
121        c.radius.dispersion->width = 5;
122
123        //c.length.dispersion = GaussianDispersion();
124        //c.length.dispersion.npts = 20;
125        //c.length.dispersion.width = 65;
126
127        printf("I(Q=%g) = %g\n", 0.001, c(0.001));
128        printf("I(Q=%g) = %g\n", 0.001, c(0.001));
129        printf("I(Qx=%g, Qy=%g) = %g\n", 0.001, 0.001, c(0.001, 0.001));
130        printf("I(Q=%g,  Phi=%g) = %g\n", 0.00447, .7854, c.evaluate_rphi(sqrt(0.00002), .7854));
131
132
133
134        double i_avg = c(0.01, 0.01);
135        double i_1d = c(sqrt(0.0002));
136
137        printf("\nI(Qx=%g, Qy=%g) = %g\n", 0.01, 0.01, i_avg);
138        printf("I(Q=%g)         = %g\n", sqrt(0.0002), i_1d);
139        printf("ratio %g %g\n", i_avg/i_1d, i_1d/i_avg);
140
141
142        return 0;
143}
144*/
Note: See TracBrowser for help on using the repository browser.