source: sasview/sansmodels/src/sans/models/c_models/SquareWell.cpp @ 5a0d01b3

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 5a0d01b3 was 770bab1, checked in by Jae Cho <jhjcho@…>, 14 years ago

removed some c functions

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