source: sasmodels/sasmodels/models/surface_fractal.c @ 513efc5

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 513efc5 was 513efc5, checked in by piotr, 8 years ago

Code review issues from PK addressed.

Added Taylor expansion utility function.

  • Property mode set to 100644
File size: 2.0 KB
Line 
1double form_volume(double radius);
2
3double Iq(double q,
4          double radius,
5          double surface_dim,
6          double cutoff_length);
7
8double Iqxy(double qx, double qy,
9            double radius,
10            double surface_dim,
11            double cutoff_length);
12
13static double _gamln(double q)
14{
15    // Lanczos approximation to the Gamma function.
16    // Should be refactored out to lib/, if used elsewhere.
17    double x,y,tmp,ser;
18    double coeff[6]=
19        {76.18009172947146,     -86.50532032941677,
20         24.01409824083091,     -1.231739572450155,
21          0.1208650973866179e-2,-0.5395239384953e-5};
22    int j;
23
24    y=x=q;
25    tmp  = x+5.5;
26    tmp -= (x+0.5)*log(tmp);
27    ser  = 1.000000000190015;
28    for (j=0; j<=5; j++) {
29        y+=1.0;
30        ser += coeff[j]/y;
31    }
32    return -tmp+log(2.5066282746310005*ser/x);
33}
34
35static double _surface_fractal_kernel(double q,
36    double radius,
37    double surface_dim,
38    double cutoff_length)
39{
40    double pq, sq, mmo, result;
41
42    //Replaced the original formula with Taylor expansion near zero.
43    //pq = pow((3.0*(sin(q*radius) - q*radius*cos(q*radius))/pow((q*radius),3)),2);
44
45    pq = J1c(q*radius);
46    pq = pq*pq;
47
48    //calculate S(q)
49    mmo = 5.0 - surface_dim;
50    sq  = exp(_gamln(mmo))*sin(-(mmo)*atan(q*cutoff_length));
51    sq *= pow(cutoff_length, mmo);
52    sq /= pow((1.0 + (q*cutoff_length)*(q*cutoff_length)),(mmo/2.0));
53    sq /= q;
54
55    //combine and return
56    result = pq * sq;
57
58    return result;
59}
60double form_volume(double radius){
61
62    return 1.333333333333333*M_PI*radius*radius*radius;
63}
64
65double Iq(double q,
66    double radius,
67    double surface_dim,
68    double cutoff_length
69    )
70{
71    return _surface_fractal_kernel(q, radius, surface_dim, cutoff_length);
72}
73
74// Iqxy is never called since no orientation or magnetic parameters.
75double Iqxy(double qx, double qy,
76    double radius,
77    double surface_dim,
78    double cutoff_length)
79{
80    double q = sqrt(qx*qx + qy*qy);
81    return _surface_fractal_kernel(q, radius, surface_dim, cutoff_length);
82}
83
Note: See TracBrowser for help on using the repository browser.