source: sasview/sansmodels/src/c_models/massfractal.cpp @ 046af80

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 046af80 was 08648c0, checked in by Jae Cho <jhjcho@…>, 13 years ago

more s king's fractal models: todo: doc, test

  • Property mode set to 100644
File size: 3.0 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 */
21
22#include <math.h>
23#include "parameters.hh"
24#include <stdio.h>
25using namespace std;
26#include "massfractal.h"
27extern "C" {
28#include "libmultifunc/libfunc.h"
29}
30
31static double mass_fractal_kernel(double dp[], double q) {
32  //fit parameters
33  double scale = dp[0];
34  double radius = dp[1];
35  double mass_dim = dp[2];
36  double co_length = dp[3];
37  double background = dp[4];
38  //others
39  double pq = 0.0;
40  double sq = 0.0;
41  double mmo = 0.0;
42  //result
43  double result = 0.0;
44  if( (q*radius) == 0.0){
45                pq = 1.0;
46  }
47  else{
48        //calculate P(q) for the spherical subunits; not normalized
49        pq = pow((3.0*(sin(q*radius) - q*radius*cos(q*radius))/pow((q*radius),3)),2);
50  }
51  mmo = mass_dim-1.0;
52  //calculate S(q)
53  sq = exp(gamln(mmo))*sin((mmo)*atan(q*co_length));
54  sq *= pow(co_length, mmo);
55  sq /= pow((1.0 + (q*co_length)*(q*co_length)),(mmo/2.0));
56
57
58  sq /= q;
59  //combine and return
60  result = pq * sq;
61  result *= scale;
62  result += background;
63
64  return(result);
65}
66
67MassFractalModel :: MassFractalModel() {
68  scale      = Parameter(1.0);
69  radius = Parameter(10.0);
70  mass_dim = Parameter(1.9);
71  co_length = Parameter(100.0);
72  background = Parameter(0.0);
73}
74
75/**
76 * Function to evaluate 1D scattering function
77 * @param q: q-value
78 * @return: function value
79 */
80double MassFractalModel :: operator()(double q) {
81  double dp[5];
82
83  // Add the background after averaging
84  dp[0] = scale();
85  dp[1] = radius();
86  dp[2] = mass_dim();
87  dp[3] = co_length();
88  dp[4] = 0.0;
89
90  // Perform the computation
91  double sum = 0.0;
92
93  sum = mass_fractal_kernel(dp, fabs(q));
94  return sum + background();
95}
96
97/**
98 * Function to evaluate 2D scattering function
99 * @param q_x: value of Q along x
100 * @param q_y: value of Q along y
101 * @return: function value
102 */
103double MassFractalModel :: operator()(double qx, double qy) {
104  double q = sqrt(qx*qx + qy*qy);
105  return (*this).operator()(q);
106}
107
108/**
109 * Function to evaluate 2D scattering function
110 * @param pars: parameters of the FractalModel
111 * @param q: q-value
112 * @param phi: angle phi
113 * @return: function value
114 */
115double MassFractalModel :: evaluate_rphi(double q, double phi) {
116  return (*this).operator()(q);
117}
118
119/**
120 * Function to calculate effective radius
121 * @return: effective radius value
122 */
123double MassFractalModel :: calculate_ER() {
124  //NOT implemented yet!!! 'cause None shape Model
125  return 0.0;
126}
Note: See TracBrowser for help on using the repository browser.