source: sasview/src/sas/models/c_extension/c_models/RectangularPrism.cpp @ 79492222

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 79492222 was 79492222, checked in by krzywon, 9 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 4.6 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 *    TODO: add 2D function
21 */
22
23#include <math.h>
24#include "parameters.hh"
25#include <stdio.h>
26#include <iostream>
27using namespace std;
28
29extern "C" {
30    #include "libCylinder.h"
31    #include "libStructureFactor.h"
32    #include "libmultifunc/libfunc.h"
33}
34#include "RectangularPrism.h"
35
36// Convenience parameter structure
37typedef struct {
38    double scale;
39    double short_side;
40    double b2a_ratio;
41    double c2a_ratio;
42    double sldPipe;
43    double sldSolv;
44    double background;
45} RectangularPrismParameters;
46
47
48RectangularPrismModel :: RectangularPrismModel() {
49    scale      = Parameter(1.0);
50    short_side = Parameter(35.0, true);
51    short_side.set_min(1.0);
52    b2a_ratio   = Parameter(1.0, true);
53    b2a_ratio.set_min(1.0);
54    c2a_ratio   = Parameter(1.0, true);
55    c2a_ratio.set_min(1.0);
56    sldPipe   = Parameter(6.3e-6);
57    sldSolv   = Parameter(1.0e-6);
58    background = Parameter(0.0);
59}
60
61/**
62 * Function to evaluate 1D scattering function
63 * @param q: q-value
64 * @return: function value
65 */
66double RectangularPrismModel :: operator()(double q) {
67
68    double dp[7];
69
70    // Fill parameter array for IGOR library
71    // Add the background after averaging
72    dp[0] = scale();
73    dp[1] = short_side();
74    dp[2] = b2a_ratio();
75    dp[3] = c2a_ratio();
76    dp[4] = sldPipe();
77    dp[5] = sldSolv();
78    dp[6] = 0.0;
79
80    // Get the dispersion points for a
81    vector<WeightPoint> weights_short_side;
82    short_side.get_weights(weights_short_side);
83
84    // Get the dispersion points for b/a ratio
85    vector<WeightPoint> weights_b2a_ratio;
86    b2a_ratio.get_weights(weights_b2a_ratio);
87
88    // Get the dispersion points for c/a ratio
89    vector<WeightPoint> weights_c2a_ratio;
90    c2a_ratio.get_weights(weights_c2a_ratio);
91
92    // Perform the computation, with all weight points
93    double sum = 0.0;
94    double norm = 0.0;
95    double vol = 0.0;
96
97    // Loop over short_side weight points
98    for (int i=0; i < (int)weights_short_side.size(); i++) {
99
100        dp[1] = weights_short_side[i].value;
101
102        // Loop over b/a ratios
103        for (int j=0; j < (int)weights_b2a_ratio.size(); j++) {
104
105            dp[2] = weights_b2a_ratio[j].value;
106
107            // Loop over c/a ratios
108            for (int k=0; k < (int)weights_c2a_ratio.size(); k++) {
109
110                dp[3] = weights_c2a_ratio[k].value;
111
112                    // Un-normalize  by volume = a * (a * b/a) * (a * c/a)
113                double vol_i = dp[1] * dp[1] * dp[2] * dp[1] * dp[3];
114
115                    sum += weights_short_side[i].weight *
116                           weights_b2a_ratio[j].weight *
117                           weights_c2a_ratio[k].weight *
118                           RectangularPrism(dp, q) *
119                           vol_i;
120
121                    //Find average volume (ABC)
122
123                    vol += weights_short_side[i].weight *
124                           weights_b2a_ratio[j].weight *
125                           weights_c2a_ratio[k].weight *
126                           vol_i;
127
128                    norm += weights_short_side[i].weight *
129                            weights_b2a_ratio[j].weight *
130                            weights_c2a_ratio[k].weight;
131            }
132        }                   
133    }
134
135    if (vol != 0.0 && norm != 0.0) {
136        //Re-normalize by avg volume
137        sum = sum/(vol/norm);}
138
139    return sum/norm + background();
140   
141}
142
143/**
144 * Function to evaluate 2D scattering function
145 * @param q_x: value of Q along x
146 * @param q_y: value of Q along y
147 * @return: function value
148 */
149double RectangularPrismModel :: operator()(double qx, double qy) {
150    return 1.0;
151}
152
153
154/**
155 * Function to evaluate 2D scattering function
156 * @param pars: parameters of the cylinder
157 * @param q: q-value
158 * @param phi: angle phi
159 * @return: function value
160 */
161double RectangularPrismModel :: evaluate_rphi(double q, double phi) {
162    double qx = q*cos(phi);
163    double qy = q*sin(phi);
164    return (*this).operator()(qx, qy);
165}
166
167/**
168 * Function to calculate effective radius
169 * @return: effective radius value
170 */
171double RectangularPrismModel :: calculate_ER() {
172    return 1.0;
173
174}
175double RectangularPrismModel :: calculate_VR() {
176  return 1.0;
177}
Note: See TracBrowser for help on using the repository browser.