source: sasview/sansmodels/src/sans/models/c_models/lamellarPS_HG.cpp @ 8e91f01

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 8e91f01 was 27a0771, checked in by Gervaise Alina <gervyh@…>, 15 years ago

add more models

  • Property mode set to 100644
File size: 4.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: refactor so that we pull in the old sansmodels.c_extensions
21 *      TODO: add 2D function
22 */
23
24#include <math.h>
25#include "models.hh"
26#include "parameters.hh"
27#include <stdio.h>
28using namespace std;
29
30extern "C" {
31        #include "libCylinder.h"
32        #include "lamellarPS_HG.h"
33}
34
35LamellarPSHGModel :: LamellarPSHGModel() {
36        scale      = Parameter(1.0);
37        spacing    = Parameter(40.0);
38        deltaT     = Parameter(10.0, true);
39        deltaT.set_min(0.0);
40        deltaH     = Parameter(2.0, true);
41        deltaH.set_min(0.0);
42        sld_tail    = Parameter(4e-7);
43        sld_head    = Parameter(2e-6);
44        sld_solvent   = Parameter(6e-6);
45        n_plates     = Parameter(30);
46        caille = Parameter(0.001);
47        background = Parameter(0.001);
48
49}
50
51/**
52 * Function to evaluate 1D scattering function
53 * The NIST IGOR library is used for the actual calculation.
54 * @param q: q-value
55 * @return: function value
56 */
57double LamellarPSHGModel :: operator()(double q) {
58        double dp[10];
59
60        // Fill parameter array for IGOR library
61        // Add the background after averaging
62        dp[0] = scale();
63        dp[1] = spacing();
64        dp[2] = deltaT();
65        dp[3] = deltaH();
66        dp[4] = sld_tail();
67        dp[5] = sld_head();
68        dp[6] = sld_solvent();
69        dp[7] = n_plates();
70        dp[8] = caille();
71        dp[9] = background();
72       
73
74        // Get the dispersion points for (deltaT) thickness of the tail
75        vector<WeightPoint> weights_deltaT;
76        deltaT.get_weights(weights_deltaT);
77       
78        // Get the dispersion points for (deltaH) thickness of the head
79        vector<WeightPoint> weights_deltaH;
80        deltaH.get_weights(weights_deltaH);
81
82        // Perform the computation, with all weight points
83        double sum = 0.0;
84        double norm = 0.0;
85       
86        // Loop over deltaT  weight points
87        for(int i=0; i< (int)weights_deltaT.size(); i++) {
88                dp[2] = weights_deltaT[i].value;
89
90                // Loop over deltaH weight points
91                for(int j=0; j< (int)weights_deltaH.size(); j++) {
92                        dp[3] = weights_deltaH[j].value;
93
94                        sum += weights_deltaT[i].weight * weights_deltaH[j].weight *LamellarPS_HG(dp, q);
95                        norm += weights_deltaT[i].weight * weights_deltaH[j].weight;
96                }
97                               
98        }
99        return sum/norm + background();
100}
101/**
102 * Function to evaluate 2D scattering function
103 * @param q_x: value of Q along x
104 * @param q_y: value of Q along y
105 * @return: function value
106 */
107double LamellarPSHGModel :: operator()(double qx, double qy) {
108        LamellarPSHGParameters dp;
109        // Fill parameter array
110        dp.scale      = scale();
111        dp.spacing   = spacing();
112        dp.deltaT  = deltaT();
113        dp.deltaH = deltaH();
114        dp.sld_tail   = sld_tail();
115        dp.sld_head = sld_head();
116        dp.sld_solvent   = sld_solvent();
117        dp.n_plates = n_plates();
118        dp.caille = caille();
119        dp.background    = background();
120       
121        // Get the dispersion points for the deltaT
122        vector<WeightPoint> weights_deltaT;
123        deltaT.get_weights(weights_deltaT);
124
125        // Get the dispersion points for the deltaH
126        vector<WeightPoint> weights_deltaH;
127        deltaH.get_weights(weights_deltaH);
128
129        // Perform the computation, with all weight points
130        double sum = 0.0;
131        double norm = 0.0;
132
133        // Loop over deltaT weight points
134        for(int i=0; i< (int)weights_deltaT.size(); i++) {
135                dp.deltaT = weights_deltaT[i].value;
136               
137                // Loop over deltaH weight points
138                for(int j=0; j< (int)weights_deltaH.size(); j++) {
139                        dp.deltaH = weights_deltaH[j].value;
140
141                        sum += weights_deltaT[i].weight *weights_deltaH[j].weight *lamellarPS_HG_analytical_2DXY(&dp, qx, qy); 
142                        norm += weights_deltaT[i].weight * weights_deltaH[j].weight;   
143                }
144        }
145        return sum/norm + background();
146}
147
148
149/**
150 * Function to evaluate 2D scattering function
151 * @param pars: parameters of the lamellar
152 * @param q: q-value
153 * @param phi: angle phi
154 * @return: function value
155 */
156double LamellarPSHGModel :: evaluate_rphi(double q, double phi) {
157        double qx = q*cos(phi);
158        double qy = q*sin(phi);
159        return (*this).operator()(qx, qy);
160}
Note: See TracBrowser for help on using the repository browser.