source: sasview/sansmodels/test/utest_model_onionexpshell.py @ b11e127

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 b11e127 was 1f73bd2, checked in by Jae Cho <jhjcho@…>, 12 years ago

removed a problematic time test and put new

  • Property mode set to 100644
File size: 5.8 KB
Line 
1"""
2    Unit tests for specific models
3    @author: JHJ Cho / UTK
4"""
5
6import unittest
7
8class TestOnionExpShell1(unittest.TestCase):
9    """
10        Unit tests for OnionExpShellModel
11    """
12    def setUp(self):
13
14        from sans.models.OnionExpShellModel import OnionExpShellModel
15        from sans.models.CoreMultiShellModel import CoreMultiShellModel
16        from sans.models.VesicleModel import VesicleModel
17       
18        # intit models and the multifactor
19        self.model = OnionExpShellModel(1)
20        self.model2 = OnionExpShellModel(1).model
21        self.model3 = CoreMultiShellModel(1)
22        self.model4 = VesicleModel()
23        self.model5 = OnionExpShellModel(9)
24       
25    def test_compare_Exp0_flat(self):
26        """
27        Check if Exp function with A_shell=0 gives the same value as Flat function
28        """
29        print "\n*****Note: All tests (test_compare_Exp0_flat and test_compare_Expsmall_line) were passes since Sept. 18, 2010..."
30        # Exp: func_shell = 2, Line: func_shell =1 , Flat: func_shell = 0.
31        # A_shell = The coefficient of the exponential function: exp(A_shell*(r-ro)/thick_shell)
32        # exp function by default
33        # exp function crosses over to flat func at A_shell=0
34        self.model.setParam("A_shell1", 0)
35        # set A_shell=1
36        self.model2.setParam("A_shell1", 1)
37        # change the function to flat function
38        self.model2.setParam("func_shell1", 0)
39        #self.model2.setParam("sld_in_shell1", 1.7e-006)
40        #self.model2.setParam("sld_out_shell1", 1.7e-006)
41       
42        # model3: set param values as same as the model2
43        self.model3.setParam("background", 0.0)
44        self.model3.setParam("rad_core0", 200.0)
45        self.model3.setParam("scale", 1.0)
46        self.model3.setParam("sld_core0", 1.0e-006)
47        self.model3.setParam("sld_shell1", 1.7e-006)
48        self.model3.setParam("sld_solv", 6.4e-006)
49        self.model3.setParam("thick_shell1", 50.0)
50       
51        #Compare exp(A=0) to flat (where A_shell is null) function
52        self.assertEqual(self.model.run(0.1),self.model2.run(0.1))
53        self.assertAlmostEqual(self.model2.run(0.1),self.model3.run(0.1),10)
54       
55
56 
57    def test_compare_Expsmall_line(self):
58        """
59        Check if Exp function with A_shell-->0 gives the same value
60        as a linear function
61        """
62        # exp function crosses over to line func as A_shell-->0
63        self.model.setParam("A_shell1", 0.000001)
64        self.model2.setParam("A_shell1", 1)
65        # change the function to a line function
66        self.model2.setParam("func_shell1", 1)
67       
68        #Compare exp(A=0.000001) to linear (where A_shell is null) function   
69        self.assertAlmostEqual(self.model.run(0.1),self.model2.run(0.1),4)
70       
71    def test_compare_time_linear_flat_functions(self):
72        """
73        Compare the calculation time between func=1(linear) , and 2 (step).
74        """
75        from time import time
76        # using linear func
77        self.model5.model.setParam("func_shell1", 1)
78        #input
79        input = [0.01,0.01]
80        st = time()
81        for iter in range(0,100000):
82            out1 = self.model5.model.run(0.01)
83        time_linear = time()-st
84       
85        # using flat function
86        self.model5.model.setParam("func_shell1", 0)
87        st = time()
88        for iter in range(0,100000):
89            out2 = self.model5.model.run(0.01)
90        time_flat = time()-st
91       
92        print "time (linear) = %s, \n time (flat) = %s"% (time_linear,time_flat)
93       
94        #Compare time of the calculation: time_linear takes a bit longer
95        # but they are not much different 
96        self.assertNotEqual(out1, out2)
97        #self.assertAlmostEqual(time_linear, time_flat, 0)
98 
99    # this feature removed!!!
100    """
101    def test_compare_Exp0_flat_vesicle(self):
102    """
103    """
104        Check if Exp function with A_shell=0 gives the same value as Flat
105        function of vesicle model when sld_solv=sld_core
106        """
107    """
108        print "\n*****Note: All tests (test_compare_Exp0_flat and \
109            test_compare_Expsmall_line) were passes since Sept. 18, 2010..."
110        # Exp: func_shell = 2, Line: func_shell =1 , Flat: func_shell = 0.
111        # A_shell = The coefficient of the exponential function: exp(A_shell*(r-ro)/thick_shell)
112        # exp function by default
113        # exp function crosses over to flat func at A_shell=0
114        self.model.setParam("A_shell1", 0)
115                # set A_shell=1
116        self.model2.setParam("A_shell1", 1)
117        # change the function to flat function
118        self.model2.setParam("func_shell1", 0)
119       
120        # model: set param values as same as the model2
121        self.model.setParam("background", 0.0)
122        self.model.setParam("rad_core0", 100.0)
123        self.model.setParam("scale", 1.0)
124        self.model.setParam("sld_core0", 6.36e-006)
125        self.model.setParam("sld_in_shell1", 5e-007)
126        self.model.setParam("sld_solv", 6.36e-006)
127        self.model.setParam("thick_shell1", 30.0)
128        # model2: set param values as same as the model2
129        self.model2.setParam("background", 0.0)
130        self.model2.setParam("rad_core0", 100.0)
131        self.model2.setParam("scale", 1.0)
132        self.model2.setParam("sld_core0", 6.36e-006)
133        self.model2.setParam("sld_in_shell1", 5e-007)
134        self.model2.setParam("sld_solv", 6.36e-006)
135        self.model2.setParam("thick_shell1", 30.0)
136        #Compare exp(A=0) to flat (where A_shell is null) function
137        self.assertEqual(self.model.run(0.1),self.model4.run(0.1))
138        self.assertEqual(self.model2.run(0.1),self.model4.run(0.1))
139        #self.assertAlmostEqual(self.model2.run(0.1),self.model3.run(0.1),10)
140    """               
141if __name__ == '__main__':
142    unittest.main()
Note: See TracBrowser for help on using the repository browser.