source: sasview/src/sas/models/c_extension/c_models/RectangularHollowPrism.cpp @ db46d13

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

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

  • Property mode set to 100644
File size: 5.4 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 "RectangularHollowPrism.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 thickness;
43    double sldPipe;
44    double sldSolv;
45    double background;
46} RectangularHollowPrismParameters;
47
48
49RectangularHollowPrismModel :: RectangularHollowPrismModel() {
50    scale      = Parameter(1.0);
51    short_side = Parameter(35.0, true);
52    short_side.set_min(1.0);
53    b2a_ratio   = Parameter(1.0, true);
54    b2a_ratio.set_min(1.0);
55    c2a_ratio   = Parameter(1.0, true);
56    c2a_ratio.set_min(1.0);
57    thickness = Parameter(1.0, true);
58    thickness.set_min(0.0);
59    sldPipe   = Parameter(6.3e-6);
60    sldSolv   = Parameter(1.0e-6);
61    background = Parameter(0.0);
62}
63
64/**
65 * Function to evaluate 1D scattering function
66 * @param q: q-value
67 * @return: function value
68 */
69double RectangularHollowPrismModel :: operator()(double q) {
70
71    double dp[8];
72
73    // Fill parameter array for IGOR library
74    // Add the background after averaging
75    dp[0] = scale();
76    dp[1] = short_side();
77    dp[2] = b2a_ratio();
78    dp[3] = c2a_ratio();
79    dp[4] = thickness();
80    dp[5] = sldPipe();
81    dp[6] = sldSolv();
82    dp[7] = 0.0;
83
84    // Get the dispersion points for a
85    vector<WeightPoint> weights_short_side;
86    short_side.get_weights(weights_short_side);
87
88    // Get the dispersion points for b/a ratio
89    vector<WeightPoint> weights_b2a_ratio;
90    b2a_ratio.get_weights(weights_b2a_ratio);
91
92    // Get the dispersion points for c/a ratio
93    vector<WeightPoint> weights_c2a_ratio;
94    c2a_ratio.get_weights(weights_c2a_ratio);
95
96    // Get the dispersion points for the thickness
97    vector<WeightPoint> weights_thickness;
98    thickness.get_weights(weights_thickness);
99
100    // Perform the computation, with all weight points
101    double sum = 0.0;
102    double norm = 0.0;
103    double vol = 0.0;
104
105    // Loop over short_side weight points
106    for (int i=0; i < (int)weights_short_side.size(); i++) {
107
108        dp[1] = weights_short_side[i].value;
109
110        // Loop over b/a ratios
111        for (int j=0; j < (int)weights_b2a_ratio.size(); j++) {
112
113            dp[2] = weights_b2a_ratio[j].value;
114
115            // Loop over c/a ratios
116            for (int k=0; k < (int)weights_c2a_ratio.size(); k++) {
117
118                dp[3] = weights_c2a_ratio[k].value;
119
120                // Loop over thicknesses
121                for (int l=0; l < (int)weights_thickness.size(); l++) {
122
123                    dp[4] = weights_thickness[l].value;
124
125                        // Un-normalize  by volume = abc - (a-2*t)*(b-2*t)*(c-2*t)
126
127                            double a = dp[1];
128                            double b = dp[1] * dp[2];
129                            double c = dp[1] * dp[3];
130                            double t = dp[4];
131                            double vol_i = a*b*c - (a-2*t)*(b-2*t)*(c-2*t);
132
133                        sum += weights_short_side[i].weight *
134                               weights_b2a_ratio[j].weight *
135                               weights_c2a_ratio[k].weight *
136                                       weights_thickness[l].weight *
137                               RectangularHollowPrism(dp, q) *
138                               vol_i;
139
140                        //Find average volume (ABC)
141
142                        vol += weights_short_side[i].weight *
143                               weights_b2a_ratio[j].weight *
144                               weights_c2a_ratio[k].weight *
145                                       weights_thickness[l].weight *
146                               vol_i;
147
148                        norm += weights_short_side[i].weight *
149                                weights_b2a_ratio[j].weight *
150                                weights_c2a_ratio[k].weight *
151                                        weights_thickness[l].weight;
152                }
153            }
154            }
155    }
156
157    if (vol != 0.0 && norm != 0.0) {
158        //Re-normalize by avg volume
159        sum = sum/(vol/norm);}
160
161    return sum/norm + background();
162   
163}
164
165/**
166 * Function to evaluate 2D scattering function
167 * @param q_x: value of Q along x
168 * @param q_y: value of Q along y
169 * @return: function value
170 */
171double RectangularHollowPrismModel :: operator()(double qx, double qy) {
172    return 1.0;
173}
174
175
176/**
177 * Function to evaluate 2D scattering function
178 * @param pars: parameters of the cylinder
179 * @param q: q-value
180 * @param phi: angle phi
181 * @return: function value
182 */
183double RectangularHollowPrismModel :: evaluate_rphi(double q, double phi) {
184    double qx = q*cos(phi);
185    double qy = q*sin(phi);
186    return (*this).operator()(qx, qy);
187}
188
189/**
190 * Function to calculate effective radius
191 * @return: effective radius value
192 */
193double RectangularHollowPrismModel :: calculate_ER() {
194    return 1.0;
195
196}
197double RectangularHollowPrismModel :: calculate_VR() {
198  return 1.0;
199}
Note: See TracBrowser for help on using the repository browser.