source: sasview/sansmodels/src/sans/models/test/utest_model_sphereexpshell.py @ 52b8b74

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 52b8b74 was 339ce67, checked in by Jae Cho <jhjcho@…>, 14 years ago

added some models and tests

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