source: sasmodels/sasmodels/models/hollow_cylinder.c @ ee60aa7

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since ee60aa7 was ee60aa7, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

clean up effective radius functions; improve mono_gauss_coil accuracy; start moving VR into C

  • Property mode set to 100644
File size: 3.2 KB
Line 
1//#define INVALID(v) (v.radius_core >= v.radius)
2
3static double
4_fq(double qab, double qc,
5    double radius, double thickness, double length)
6{
7    const double lam1 = sas_2J1x_x((radius+thickness)*qab);
8    const double lam2 = sas_2J1x_x(radius*qab);
9    const double gamma_sq = square(radius/(radius+thickness));
10    //Note: lim_{thickness -> 0} psi = sas_J0(radius*qab)
11    //Note: lim_{radius -> 0} psi = sas_2J1x_x(thickness*qab)
12    const double psi = (lam1 - gamma_sq*lam2)/(1.0 - gamma_sq);    //SRK 10/19/00
13    const double t2 = sas_sinx_x(0.5*length*qc);
14    return psi*t2;
15}
16
17// TODO: interface to form_volume/shell_volume not yet settled
18static double
19shell_volume(double *total, double radius, double thickness, double length)
20{
21    *total = M_PI*length*square(radius+thickness);
22    return *total - M_PI*length*radius*radius;
23}
24
25static double
26form_volume(double radius, double thickness, double length)
27{
28    double total;
29    return shell_volume(&total, radius, thickness, length);
30}
31
32static double
33radius_from_volume(double radius, double thickness, double length)
34{
35    const double volume_outer_cyl = M_PI*square(radius + thickness)*length;
36    return cbrt(0.75*volume_outer_cyl/M_PI);
37}
38
39static double
40radius_from_diagonal(double radius, double thickness, double length)
41{
42    return sqrt(square(radius + thickness) + 0.25*square(length));
43}
44
45static double
46effective_radius(int mode, double radius, double thickness, double length)
47{
48    switch (mode) {
49    case 1: // equivalent sphere
50        return radius_from_volume(radius, thickness, length);
51    case 2: // outer radius
52        return radius + thickness;
53    case 3: // half length
54        return 0.5*length;
55    case 4: // half outer min dimension
56        return (radius + thickness < 0.5*length ? radius + thickness : 0.5*length);
57    case 5: // half outer max dimension
58        return (radius + thickness > 0.5*length ? radius + thickness : 0.5*length);
59    case 6: // half outer diagonal
60        return radius_from_diagonal(radius,thickness,length);
61    }
62}
63
64static void
65Fq(double q, double *F1, double *F2, double radius, double thickness, double length,
66    double sld, double solvent_sld)
67{
68    const double lower = 0.0;
69    const double upper = 1.0;        //limits of numerical integral
70
71    double total_F1 = 0.0;            //initialize intergral
72    double total_F2 = 0.0;
73    for (int i=0;i<GAUSS_N;i++) {
74        const double cos_theta = 0.5*( GAUSS_Z[i] * (upper-lower) + lower + upper );
75        const double sin_theta = sqrt(1.0 - cos_theta*cos_theta);
76        const double form = _fq(q*sin_theta, q*cos_theta,
77                                radius, thickness, length);
78        total_F1 += GAUSS_W[i] * form;
79        total_F2 += GAUSS_W[i] * form * form;
80    }
81    total_F1 *= 0.5*(upper-lower);
82    total_F2 *= 0.5*(upper-lower);
83    const double s = (sld - solvent_sld) * form_volume(radius, thickness, length);
84    *F1 = 1e-2 * s * total_F1;
85    *F2 = 1e-4 * s*s * total_F2;
86}
87
88
89static double
90Iqac(double qab, double qc,
91    double radius, double thickness, double length,
92    double sld, double solvent_sld)
93{
94    const double form = _fq(qab, qc, radius, thickness, length);
95    const double s = (sld - solvent_sld) * form_volume(radius, thickness, length);
96    return 1.0e-4*square(s * form);
97}
Note: See TracBrowser for help on using the repository browser.