source: sasview/sansmodels/src/sans/models/test/prototypes/test_2dsim.py @ ae3ce4e

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 ae3ce4e was ae3ce4e, checked in by Mathieu Doucet <doucetm@…>, 17 years ago

Moving sansmodels to trunk

  • Property mode set to 100644
File size: 2.1 KB
Line 
1from sans_extension.prototypes.c_models import CCanvas
2from sans.models.SphereModel import SphereModel
3from sans.models.CoreShellModel import CoreShellModel
4
5import math
6
7# Sphere ###############################
8sphere = SphereModel()
9sphere.setParam('radius',40.0)
10sphere.setParam('contrast',1.0)
11sphere.setParam('scale',1.0)
12sphere.setParam('background',0.0)
13
14can = CCanvas()
15
16print "ID", can.add()
17can.setParam(0,1,40.0)
18 
19
20for q in [1,0.1,0.05,0.02,0.01,0.001,0.0001]:
21    ana = sphere.run([q,1.0])
22    sim = can.evaluate([q,1.0])
23
24    print "Sphere: ANA = %g   SIM = %g   (%g)" %(ana, sim, sim/ana)
25
26
27
28
29# Core-shell ###########################
30# This is a core shell model where the weight-average
31# of the SLDs is zero. The I(q) should go to zero as q->0.
32
33import time
34t_0 = time.time()
35
36sphere = CoreShellModel()
37# Core radius
38radius = 10.0
39thickness = 5.0
40sphere.setParam('radius', radius)
41# Shell thickness
42sphere.setParam('thickness', thickness)
43sphere.setParam('core_sld', 1.0)
44
45core_vol = 4.0/3.0*math.pi*radius*radius*radius
46outer_radius = radius+thickness
47shell_vol = 4.0/3.0*math.pi*outer_radius*outer_radius*outer_radius - core_vol
48shell_sld = -1.0*core_vol/shell_vol
49print "Shell SLD", shell_sld
50
51sphere.setParam('shell_sld', shell_sld)
52sphere.setParam('solvent_sld',0.0)
53sphere.setParam('background',0.0)
54sphere.setParam('scale',1.0)
55
56can = CCanvas()
57
58print "ID", can.add()
59can.setParam(0,1, outer_radius)
60can.setParam(0,2, shell_sld)
61
62
63print "ID", can.add()
64can.setParam(1,1, radius)
65can.setParam(1,2, 1.0)
66
67print "VOLS inner = %g, outer = %g, shell = %g" % (core_vol, shell_vol+core_vol, shell_vol)
68
69f = open('core-shell.txt','w')
70f.write("<q_cs>   <ans_cs>   <sim_cs>\n")
71for q in [1,0.1,0.05,0.04,0.03,0.02,0.01,0.005,0.001,0.0001]:
72#for i in range(400):
73    #q = 0.0001+i*0.005
74    ana = sphere.run([q,1.0])
75    sim = can.evaluate([q,1.0])
76    f.write("%g  %g  %g\n" %(q, ana, sim))
77    print "Core-shell: q=%g  ANA = %g   SIM = %g   (%g)" %(q, ana, sim, sim/ana)
78
79f.close()
80
81
82print "Time: ", time.time()-t_0
Note: See TracBrowser for help on using the repository browser.