source: sasview/sansmodels/src/sans/models/c_extensions/pearlnecklace.c @ bea9277

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 bea9277 was 9cc3da6, checked in by Jae Cho <jhjcho@…>, 13 years ago

correction/comments

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/**
2 * pearl necklace model
3 */
4#include <math.h>
5#include "pearlnecklace.h"
6#include "libmultifunc/libfunc.h"
7#include <stdio.h>
8#include <stdlib.h>
9
10
11double pearl_necklace_kernel(double dp[], double q) {
12        // fit parameters
13        double scale = dp[0];
14        double radius = dp[1];
15        double edge_separation = dp[2];
16        double thick_string = dp[3];
17        double num_pearls = dp[4];
18        double sld_pearl = dp[5];
19        double sld_string = dp[6];
20        double sld_solv = dp[7];
21        double background = dp[8];
22
23        //relative slds
24        double contrast_pearl = sld_pearl - sld_solv;
25        double contrast_string = sld_string - sld_solv;
26
27        // number of string segments
28        double num_strings = num_pearls - 1.0;
29
30        //Pi
31        double pi = 4.0*atan(1.0);
32
33        // each volumes
34        double string_vol = edge_separation * pi * pow((thick_string / 2.0), 2);
35        double pearl_vol = 4.0 /3.0 * pi * pow(radius, 3);
36
37        //total volume
38        double tot_vol;
39        tot_vol = num_strings * string_vol;
40        tot_vol += num_pearls * pearl_vol;
41
42        //each masses
43        double m_r= contrast_string * string_vol;
44        double m_s= contrast_pearl * pearl_vol;
45
46        //sine functions of a pearl
47        double psi;
48        psi = sin(q*radius);
49        psi -= q * radius * cos(q * radius);
50        psi /= pow((q * radius), 3);
51        psi *= 3.0;
52
53        // Note take only 20 terms in Si series: 10 terms may be enough though.
54        double gamma;
55        gamma = Si(q* edge_separation);
56        gamma /= (q* edge_separation);
57        double beta;
58        beta = Si(q * (edge_separation + radius));
59        beta -= Si(q * radius);
60        beta /= (q* edge_separation);
61
62        //form factors
63        double sss; //pearls
64        double srr; //strings
65        double srs; //cross
66        // center to center distance between the neighboring pearls
67        double A_s = edge_separation + 2.0 * radius;
68
69        // form factor for num_pearls
70        sss = 1.0 - pow(sinc(q*A_s), num_pearls );
71        sss /= pow((1.0-sinc(q*A_s)), 2);
72        sss *= -sinc(q*A_s);
73        sss -= num_pearls/2.0;
74        sss += num_pearls/(1.0-sinc(q*A_s));
75        sss *= 2.0 * pow((m_s*psi), 2);
76
77        // form factor for num_strings (like thin rods)
78        double srr_1;
79        srr_1 = -pow(sinc(q*edge_separation/2.0), 2);
80
81        srr_1 += 2.0 * gamma;
82        srr_1 *= num_strings;
83        double srr_2;
84        srr_2 = 2.0/(1.0-sinc(q*A_s));
85        srr_2 *= num_strings;
86        srr_2 *= pow(beta, 2);
87        double srr_3;
88        srr_3 = 1.0 - pow(sinc(q*A_s), num_strings);
89        srr_3 /= pow((1.0-sinc(q*A_s)), 2);
90        srr_3 *= pow(beta, 2);
91        srr_3 *= -2.0;
92
93        // total srr
94        srr = srr_1 + srr_2 + srr_3;
95        srr *= pow(m_r, 2);
96
97        // form factor for correlations
98        srs = 1.0;
99        srs -= pow(sinc(q*A_s), num_strings);
100        srs /= pow((1.0-sinc(q*A_s)), 2);
101        srs *= -sinc(q*A_s);
102        srs += (num_strings/(1.0-sinc(q*A_s)));
103        srs *= 4.0;
104        srs *= (m_r * m_s * beta * psi);
105
106        double form_factor;
107        form_factor = sss + srr + srs;
108        form_factor /= (tot_vol * 1.0e-8); // norm by volume and A^-1 to cm^-1
109
110        // scale and background
111        form_factor *= scale;
112        form_factor += background;
113    return (form_factor);
114}
115
116/**
117 * Function to evaluate pearlnecklace function
118 * @param pars: parameters of pearlnecklace
119 * @param q: q-value
120 * @return: function value
121 */
122
123double pearl_necklace_analytical_1D(PeralNecklaceParameters *pars, double q) {
124        double dp[9];
125
126        dp[0] = pars->scale;
127        dp[1] = pars->radius;
128        dp[2] = pars->edge_separation;
129        dp[3] = pars->thick_string;
130        dp[4] = pars->num_pearls;
131        dp[5] = pars->sld_pearl;
132        dp[6] = pars->sld_string;
133        dp[7] = pars->sld_solv;
134        dp[8] = pars->background;
135
136        return pearl_necklace_kernel(dp, q);
137}
138
139/**
140 * Function to evaluate pearl_necklace function
141 * @param pars: parameters of PeralNecklace
142 * @param q: q-value
143 * @return: function value
144 */
145double pearl_necklace_analytical_2D(PeralNecklaceParameters *pars, double q, double phi) {
146        return pearl_necklace_analytical_1D(pars,q);
147}
148
149double pearl_necklace_analytical_2DXY(PeralNecklaceParameters *pars, double qx, double qy){
150        return pearl_necklace_analytical_1D(pars,sqrt(qx*qx+qy*qy));
151}
152
Note: See TracBrowser for help on using the repository browser.