source: sasview/sansmodels/src/sans/models/c_models/lamellarFF_HG.cpp @ 7a69683

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 7a69683 was 34c3020, checked in by Gervaise Alina <gervyh@…>, 15 years ago

add model1D

  • Property mode set to 100644
File size: 4.2 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 */
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 "libCylinder.h"
31        #include "lamellarFF_HG.h"
32}
33
34LamellarFFHGModel :: LamellarFFHGModel() {
35        scale      = Parameter(1.0);
36        t_length     = Parameter(15.0, true);
37        t_length.set_min(0.0);
38        h_thickness    = Parameter(10.0, true);
39        h_thickness.set_min(0.0);
40        sld_tail   = Parameter(4e-7);
41        sld_head  = Parameter(3e-6);
42        sld_solvent    = Parameter(6e-6);
43        background = Parameter(0.0);
44
45}
46
47/**
48 * Function to evaluate 1D scattering function
49 * The NIST IGOR library is used for the actual calculation.
50 * @param q: q-value
51 * @return: function value
52 */
53double LamellarFFHGModel :: operator()(double q) {
54        double dp[7];
55
56        // Fill parameter array for IGOR library
57        // Add the background after averaging
58        dp[0] = scale();
59        dp[1] = t_length();
60        dp[2] = h_thickness();
61        dp[3] = sld_tail();
62        dp[4] = sld_head();
63        dp[5] = sld_solvent();
64        dp[6] = background();
65
66        // Get the dispersion points for the tail length
67        vector<WeightPoint> weights_t_length;
68        t_length.get_weights(weights_t_length);
69
70        // Get the dispersion points for the head thickness
71        vector<WeightPoint> weights_h_thickness;
72        h_thickness.get_weights(weights_h_thickness);
73
74        // Perform the computation, with all weight points
75        double sum = 0.0;
76        double norm = 0.0;
77
78        // Loop over semi axis A weight points
79        for(int i=0; i< (int)weights_t_length.size(); i++) {
80                dp[1] = weights_t_length[i].value;
81
82                for (int j=0; j< (int)weights_h_thickness.size(); j++){
83                        dp[2] = weights_h_thickness[j].value;
84
85                        sum += weights_t_length[i].weight* weights_h_thickness[j].weight*LamellarFF_HG(dp, q);
86                        norm += weights_t_length[i].weight* weights_h_thickness[j].weight;
87                }
88                               
89        }
90        return sum/norm + background();
91}
92
93/**
94 * Function to evaluate 2D scattering function
95 * @param q_x: value of Q along x
96 * @param q_y: value of Q along y
97 * @return: function value
98 */
99
100double LamellarFFHGModel :: operator()(double qx, double qy) {
101        LamellarFF_HGParameters dp;
102
103        // Fill parameter array for IGOR library
104        // Add the background after averaging
105        dp.scale = scale();
106        dp.t_length = t_length();
107        dp.h_thickness = h_thickness();
108        dp.sld_tail = sld_tail();
109        dp.sld_head = sld_head();
110        dp.sld_solvent = sld_solvent();
111        dp.background = background();
112
113
114        // Get the dispersion points for the tail length
115        vector<WeightPoint> weights_t_length;
116        t_length.get_weights(weights_t_length);
117
118        // Get the dispersion points for the head thickness
119        vector<WeightPoint> weights_h_thickness;
120        h_thickness.get_weights(weights_h_thickness);
121
122        // Perform the computation, with all weight points
123        double sum = 0.0;
124        double norm = 0.0;
125
126        // Loop over detla  weight points
127        for(int i=0; i< (int)weights_t_length.size(); i++) {
128                dp.t_length = weights_t_length[i].value;
129
130                for(int j=0; j< (int)weights_h_thickness.size(); j++) {
131                        dp.h_thickness = weights_h_thickness[j].value;
132
133                        sum += weights_t_length[i].weight* weights_h_thickness[j].weight
134                                * lamellarFF_HG_analytical_2DXY(&dp, qx, qy);
135                        norm += weights_t_length[i].weight* weights_h_thickness[j].weight;
136                }
137                               
138        }
139        return sum/norm + background();
140}
141
142/**
143 * Function to evaluate 2D scattering function
144 * @param pars: parameters of the lamellar
145 * @param q: q-value
146 * @param phi: angle phi
147 * @return: function value
148 */
149double LamellarFFHGModel :: evaluate_rphi(double q, double phi) {
150        double qx = q*cos(phi);
151        double qy = q*sin(phi);
152        return (*this).operator()(qx, qy);
153}
Note: See TracBrowser for help on using the repository browser.