[230f479] | 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> |
---|
| 25 | using namespace std; |
---|
| 26 | #include "massfractal.h" |
---|
| 27 | extern "C" { |
---|
| 28 | #include "libmultifunc/libfunc.h" |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | static 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 | |
---|
| 67 | MassFractalModel :: 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 | */ |
---|
| 80 | double 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 | */ |
---|
| 103 | double 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 | */ |
---|
| 115 | double 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 | */ |
---|
| 123 | double MassFractalModel :: calculate_ER() { |
---|
| 124 | //NOT implemented yet!!! 'cause None shape Model |
---|
| 125 | return 0.0; |
---|
| 126 | } |
---|
| 127 | double MassFractalModel :: calculate_VR() { |
---|
| 128 | return 1.0; |
---|
| 129 | } |
---|