source: sasview/sansmodels/src/sans/models/c_models/fractal.cpp @ 67e258c

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 67e258c was c724ccd, checked in by Jae Cho <jhjcho@…>, 15 years ago

More models added and correction of Wrappergenerator on model parameter value precision

  • 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 "models.hh"
24#include "parameters.hh"
25#include <stdio.h>
26using namespace std;
27
28extern "C" {
29        #include "libTwoPhase.h"
30        #include "fractal.h"
31}
32
33FractalModel :: FractalModel() {
34        scale      = Parameter(1.0);
35    radius = Parameter(5.0, true);
36    radius.set_min(0.0);
37    fractal_dim = Parameter(2.0);
38    cor_length = Parameter(100.0);
39    sldBlock = Parameter(2.0e-6);
40    sldSolv= Parameter(6.35e-6);
41        background = Parameter(0.0);
42}
43
44/**
45 * Function to evaluate 1D scattering function
46 * The NIST IGOR library is used for the actual calculation.
47 * @param q: q-value
48 * @return: function value
49 */
50double FractalModel :: operator()(double q) {
51        double dp[7];
52
53        // Fill parameter array for IGOR library
54        // Add the background after averaging
55        dp[0] = scale();
56        dp[1] = radius();
57        dp[2] = fractal_dim();
58        dp[3] = cor_length();
59        dp[4] = sldBlock();
60        dp[5] = sldSolv();
61        dp[6] = 0.0;
62
63        // Get the dispersion points for the radius
64        vector<WeightPoint> weights_rad;
65        radius.get_weights(weights_rad);
66
67        // Perform the computation, with all weight points
68        double sum = 0.0;
69        double norm = 0.0;
70        double vol = 0.0;
71
72        // Loop over radius weight points
73        for(int i=0; i<weights_rad.size(); i++) {
74                dp[1] = weights_rad[i].value;
75
76                //Un-normalize Fractal by volume
77                sum += weights_rad[i].weight
78                        * Fractal(dp, fabs(q)) * pow(weights_rad[i].value,3);
79                //Find average volume
80                vol += weights_rad[i].weight
81                        * pow(weights_rad[i].value,3);
82
83                norm += weights_rad[i].weight;
84        }
85
86        if (vol != 0.0 && norm != 0.0) {
87                //Re-normalize by avg volume
88                sum = sum/(vol/norm);}
89        return sum/norm + background();
90}
91
92/**
93 * Function to evaluate 2D scattering function
94 * @param q_x: value of Q along x
95 * @param q_y: value of Q along y
96 * @return: function value
97 */
98double FractalModel :: operator()(double qx, double qy) {
99        double q = sqrt(qx*qx + qy*qy);
100        return (*this).operator()(q);
101}
102
103/**
104 * Function to evaluate 2D scattering function
105 * @param pars: parameters of the FractalModel
106 * @param q: q-value
107 * @param phi: angle phi
108 * @return: function value
109 */
110double FractalModel :: evaluate_rphi(double q, double phi) {
111        return (*this).operator()(q);
112}
113
114/**
115 * Function to calculate effective radius
116 * @return: effective radius value
117 */
118double FractalModel :: calculate_ER() {
119        //NOT implemented yet!!! 'cause None shape Model
120}
Note: See TracBrowser for help on using the repository browser.