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

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 db08737 was a1b2471, checked in by Jae Cho <jhjcho@…>, 14 years ago

added sld plot for onion model and etc…

  • Property mode set to 100644
File size: 4.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
[e096270]17
18        self.model = SphereExpShellModel(n_shells=1)
19        self.model2 = SphereExpShellModel(n_shells=1).model
20        self.model3 = CoreMultiShellModel(n_shells=1)
[a1b2471]21        self.model4 = VesicleModel()
[e096270]22       
23    def test_compare_Exp0_flat(self):
24        """
25        Check if Exp function with A_shell=0 gives the same value as Flat function
26        """
27        print "\n*****Note: All tests (test_compare_Exp0_flat and test_compare_Expsmall_line) were passes since Sept. 18, 2010..."
28        # Exp: func_shell = 2, Line: func_shell =1 , Flat: func_shell = 0.
29        # A_shell = The coefficient of the exponential function: exp(A_shell*(r-ro)/thick_shell)
30        # exp function by default
31        # exp function crosses over to flat func at A_shell=0
32        self.model.setParam("A_shell1", 0)
33        # set A_shell=1
34        self.model2.setParam("A_shell1", 1)
35        # change the function to flat function
36        self.model2.setParam("func_shell1", 0)
37        #self.model2.setParam("sld_in_shell1", 1.7e-006)
38        #self.model2.setParam("sld_out_shell1", 1.7e-006)
39       
40        # model3: set param values as same as the model2
41        self.model3.setParam("background", 0.0)
42        self.model3.setParam("rad_core", 200.0)
43        self.model3.setParam("scale", 1.0)
44        self.model3.setParam("sld_core", 1.0e-006)
45        self.model3.setParam("sld_shell1", 1.7e-006)
46        self.model3.setParam("sld_solv", 6.4e-006)
47        self.model3.setParam("thick_shell1", 50.0)
48       
49        #Compare exp(A=0) to flat (where A_shell is null) function
50        self.assertEqual(self.model.run(0.1),self.model2.run(0.1))
51        self.assertAlmostEqual(self.model2.run(0.1),self.model3.run(0.1),10)
52
[a1b2471]53    def test_compare_Exp0_flat_vesicle(self):
54        """
55        Check if Exp function with A_shell=0 gives the same value as Flat function of vesicle model when sld_solv=sld_core
56        """
57        print "\n*****Note: All tests (test_compare_Exp0_flat and test_compare_Expsmall_line) were passes since Sept. 18, 2010..."
58        # Exp: func_shell = 2, Line: func_shell =1 , Flat: func_shell = 0.
59        # A_shell = The coefficient of the exponential function: exp(A_shell*(r-ro)/thick_shell)
60        # exp function by default
61        # exp function crosses over to flat func at A_shell=0
62        self.model.setParam("A_shell1", 0)
63                # set A_shell=1
64        self.model2.setParam("A_shell1", 1)
65        # change the function to flat function
66        self.model2.setParam("func_shell1", 0)
67       
68        # model: set param values as same as the model2
69        self.model.setParam("background", 0.0)
70        self.model.setParam("rad_core", 100.0)
71        self.model.setParam("scale", 1.0)
72        self.model.setParam("sld_core", 6.36e-006)
73        self.model.setParam("sld_in_shell1", 5e-007)
74        self.model.setParam("sld_solv", 6.36e-006)
75        self.model.setParam("thick_shell1", 30.0)
76        # model2: set param values as same as the model2
77        self.model2.setParam("background", 0.0)
78        self.model2.setParam("rad_core", 100.0)
79        self.model2.setParam("scale", 1.0)
80        self.model2.setParam("sld_core", 6.36e-006)
81        self.model2.setParam("sld_in_shell1", 5e-007)
82        self.model2.setParam("sld_solv", 6.36e-006)
83        self.model2.setParam("thick_shell1", 30.0)
84        #Compare exp(A=0) to flat (where A_shell is null) function
85        self.assertEqual(self.model.run(0.1),self.model4.run(0.1))
86        self.assertEqual(self.model2.run(0.1),self.model4.run(0.1))
87        #self.assertAlmostEqual(self.model2.run(0.1),self.model3.run(0.1),10)
88
[e096270]89 
90    def test_compare_Expsmall_line(self):
91        """
92        Check if Exp function with A_shell-->0 gives the same value as linear function
93        """
94        # exp function crosses over to line func as A_shell-->0
95        self.model.setParam("A_shell1", 0.000001)
96        self.model2.setParam("A_shell1", 1)
97        # change the function to a line function
98        self.model2.setParam("func_shell1", 1)
99       
100        #Compare exp(A=0.000001) to linear (where A_shell is null) function   
101        self.assertAlmostEqual(self.model.run(0.1),self.model2.run(0.1),4)
102       
103 
104               
105if __name__ == '__main__':
106    unittest.main()
Note: See TracBrowser for help on using the repository browser.