source: sasview/sansmodels/src/c_models/FractalQtoN.cpp @ 077207b

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 077207b was f518eef, checked in by Robert Whitley <robert.whitley@…>, 12 years ago

Refs #84. Add the FractalO_Z model.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1
2/*
3        This software was developed by the University of Tennessee as part of the
4        Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
5        project funded by the US National Science Foundation.
6
7        If you use DANSE applications to do scientific research that leads to
8        publication, we ask that you acknowledge the use of the software with the
9        following sentence:
10
11        "This work benefited from DANSE software developed under NSF award DMR-0520547."
12
13        copyright 2008, University of Tennessee
14
15    See Schmidt, J Appl Cryst, 24, (1991), 414-435, Eqn (19)
16    See Hurd, Schaefer & Martin, 35, (1987), 2361-2364
17
18    Ported to C++ from Fortran by Robert Whitley (2012)
19*/
20
21#include <math.h>
22#include "parameters.hh"
23#include <stdio.h>
24#include "FractalQtoN.h"
25using namespace std;
26
27FractalO_Z::FractalO_Z()
28{
29    scale = Parameter(10000.0, true);
30    m_fractal = Parameter(1.8);
31    cluster_rg = Parameter(3250.0);
32    s_fractal = Parameter(2.5);
33    primary_rg = Parameter(82.0);
34    background = Parameter(0.01);
35}
36
37double FractalO_Z :: operator()(double q)
38{
39    double dp[3];
40    dp[0] = m_fractal();
41    dp[1] = s_fractal();
42   
43   
44    if (dp[0] <= 0)
45    {
46        //std::cout << "\n\nThe mass fractal dimension must be > 0!";
47        //std::cout << "\nWill set to 3.";
48        dp[0] = 3.0;
49    }
50    else 
51    {
52        if (dp[0] > 6)
53        {
54            //std::cout << "\n\nThe mass fractal dimension must be <= 6!";
55            //std::cout << "\nWill be set to 3.";
56            dp[0] = 3.0;
57        }
58    }
59   
60    if (dp[1] <= 0)
61    {
62        //std::cout << "\n\nThe surface dimension must be > 0!";
63        //std::cout << "\nWill be set to 2.";
64        dp[1] = 2.0;
65    }
66    else
67    {
68        if (dp[1] > 6)
69        {
70            //std::cout << "\n\nThe surface dimension must be <= 6!";
71            //std::cout << "\nWill be set to 2.";
72            dp[1] = 2.0;
73        }
74    }
75   
76    double a(dp[0]/2.0);
77    double b((cluster_rg() * cluster_rg())/(3.0*a) );
78   
79    // If C goes negative, it will crash with undefined exponentiation.
80    // So (Ds + Dm) <= 6
81    // c = ((ds-6.0)/-2.0)-a
82    if ((dp[1] > (6.0-dp[0])) && (primary_rg() > 0.0))
83    {
84        dp[1] = 6.0 - dp[0];
85        //std::cout << "\n\nThe surface fractal dimension must be <= (6-Dm)!\n";
86        //std::cout << setprecision(5) << fixed << dp[1];
87    }
88   
89    // c = (ds -6.0 + dm)/-2.0;
90    double c = (6.0 - dp[1] - dp[0])/2.0;
91    double d(0.0);
92   
93    // If c = 0 then it will crash with a floating divide by zero.
94    if (c == 0)
95    {
96        d = 1.0e+37;
97    }
98    else
99    {
100        d = (primary_rg() * primary_rg()) / (3.0 * c);
101    }
102
103    double eVar = q*q*b;
104    double fVar = q*q*d;
105    double g = pow((1.0+eVar),a);
106    double h = pow((1.0+fVar),c);
107    double i = g*h;
108    double result((scale()/i) + background() );
109    return result;
110}
111
112
113/**
114 * Function to evaluate 2D scattering function
115 * @param q_x: value of Q along x
116 * @param q_y: value of Q along y
117 * @return: function value
118 */
119double FractalO_Z :: operator()(double qx, double qy) {
120  double q = sqrt(qx*qx + qy*qy);
121  return (*this).operator()(q);
122}
123
124/**
125 * Function to evaluate 2D scattering function
126 * @param pars: parameters of the cylinder
127 * @param q: q-value
128 * @param phi: angle phi
129 * @return: function value
130 */
131double FractalO_Z :: evaluate_rphi(double q, double phi) {
132  double qx = q*cos(phi);
133  double qy = q*sin(phi);
134  return (*this).operator()(qx, qy);
135}
136/**
137 * Function to calculate effective radius
138 * @return: effective radius value
139 */
140double FractalO_Z :: calculate_ER() {
141  //NOT implemented yet!!!
142  return 0.0;
143}
144double FractalO_Z :: calculate_VR() {
145  return 1.0;
146}
Note: See TracBrowser for help on using the repository browser.