/[escript]/trunk/pyvisi/test/python/run_escript_with_lazy_evaluation.py
ViewVC logotype

Contents of /trunk/pyvisi/test/python/run_escript_with_lazy_evaluation.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1158 - (show annotations)
Tue May 22 04:24:01 2007 UTC (12 years, 8 months ago) by jongui
File MIME type: text/x-python
File size: 8107 byte(s)
Made some changes to fix the memory leak problem. However, the problem still persists for run_escript_with_lazy_evaluation.py, run_streamline.py and run_streamline_with_lazy_evaluation.py.

1 # Import the necessary modules.
2 from esys.escript import *
3 from esys.escript.pdetools import Locator
4 from esys.escript.linearPDEs import LinearPDE
5 from esys.finley import Rectangle, Brick
6 from numarray import identity,zeros,ones
7 from esys.pyvisi import Scene, DataCollector, Map, Velocity, Ellipsoid, Camera
8 from esys.pyvisi.constant import *
9 import unittest, os
10 from stat import ST_SIZE
11
12 try:
13 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
14 except KeyError:
15 PYVISI_WORKDIR='.'
16 try:
17 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
18 except KeyError:
19 PYVISI_TEST_DATA_ROOT='.'
20
21 PYVISI_TEST_ESCRIPT_REFERENCE_IMAGES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT,\
22 "data_reference_images", "escript")
23 PYVISI_TEST_ESCRIPT_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
24 "data_sample_images", "escript")
25
26 MIN_IMAGE_SIZE = 100
27 X_SIZE = 400
28 Y_SIZE = 400
29 JPG_RENDERER = Renderer.OFFLINE_JPG
30
31 class TestEscript:
32 def render(self, file):
33 self.scene.render(image_name = \
34 os.path.join(PYVISI_TEST_ESCRIPT_IMAGES_PATH, file))
35
36 self.failUnless(os.stat(os.path.join(PYVISI_TEST_ESCRIPT_IMAGES_PATH, \
37 file))[ST_SIZE] > MIN_IMAGE_SIZE)
38
39 class TestEscriptMap(unittest.TestCase, TestEscript):
40 def tearDown(self):
41 del self.scene
42
43 def testEscriptMap(self):
44 #... set some parameters ...
45 #xc=[0.02,0.002]
46 #r=0.001
47 #qc=50.e6
48 #Tref=0.
49 #rhocp=2.6e6
50 #eta=75.
51 #kappa=240.
52 #tend=5.
53 # ... time, time step size and counter ...
54 t=0
55 #h=0.1
56 i=0
57
58 #... generate domain ...
59 mydomain = Rectangle(l0=0.05,l1=0.01,n0=250, n1=50)
60 #... open PDE ...
61 #mypde=LinearPDE(mydomain)
62 #mypde.setSymmetryOn()
63 #mypde.setValue(A=kappa*kronecker(mydomain),D=rhocp/h,d=eta,y=eta*Tref)
64 # ... set heat source: ....
65 #x=mydomain.getX()
66 #qH=qc*whereNegative(length(x-xc)-r)
67 # ... set initial temperature ....
68 #T=Tref
69
70 # Create a Scene.
71 s = Scene(renderer = JPG_RENDERER, x_size = X_SIZE, y_size = Y_SIZE)
72 self.scene = s
73
74 # Create a DataCollector reading directly from escript objects.
75 dc = DataCollector(source = Source.ESCRIPT)
76
77 # Create a Map.
78 m = Map(scene = s, data_collector = dc,
79 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
80 cell_to_point = False, outline = True)
81
82 # Create a Camera.
83 c = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
84
85 # ... start iteration:
86 while t<0.5:
87 t+=0.1
88 i+=1
89 #t+=h
90 #mypde.setValue(Y=qH+rhocp/h*T)
91 #T=mypde.getSolution()
92
93 #======= syntetic data =========
94 T=length(mydomain.getX())
95 dc.setData(temp = T)
96
97 # Render the object.
98 self.render("TestEscriptMap%02d.jpg" % i)
99
100 class TestEscriptVelocity(unittest.TestCase, TestEscript):
101 def tearDown(self):
102 del self.scene
103
104 def testEscriptVelocity(self):
105 #... set some parameters ...
106 #lam=1.
107 #mu=0.1
108 #alpha=1.e-6
109 #xc=[0.3,0.3,1.]
110 #beta=8.
111 #T_ref=0.
112 #T_0=1.
113 #... generate domain ...
114 mydomain = Brick(l0=1.,l1=1., l2=1.,n0=10, n1=10, n2=10)
115 #x=mydomain.getX()
116 #... set temperature ...
117 #T=T_0*exp(-beta*length(x-xc))
118 #... open symmetric PDE ...
119 #mypde=LinearPDE(mydomain)
120 #mypde.setSymmetryOn()
121 #... set coefficients ...
122 #C=Tensor4(0.,Function(mydomain))
123 #for i in range(mydomain.getDim()):
124 # for j in range(mydomain.getDim()):
125 # C[i,i,j,j]+=lam
126 # C[j,i,j,i]+=mu
127 # C[j,i,i,j]+=mu
128 #msk=whereZero(x[0])*[1.,0.,0.] \
129 # +whereZero(x[1])*[0.,1.,0.] \
130 # +whereZero(x[2])*[0.,0.,1.]
131 #sigma0=(lam+2./3.*mu)*alpha*(T-T_ref)*kronecker(mydomain)
132 #mypde.setValue(A=C,X=sigma0,q=msk)
133 #... solve pde ...
134 #u=mypde.getSolution()
135 #==============
136 #... calculate von-Misses
137 #u=mydomain.getX()
138 #g=grad(u)
139 #sigma=mu*(g+transpose(g))+lam*trace(g)*kronecker(mydomain)-sigma0
140 #sigma_mises=\
141 # sqrt(((sigma[0,0]-sigma[1,1])**2+(sigma[1,1]-sigma[2,2])**2+ \
142 # (sigma[2,2]-sigma[0,0])**2)/6. \
143 # +sigma[0,1]**2 + sigma[1,2]**2 + sigma[2,0]**2)
144 #
145 # Create a Scene.
146 s = Scene(renderer = JPG_RENDERER, x_size = X_SIZE, y_size = Y_SIZE)
147 self.scene = s
148
149 # Create a DataCollector reading directly from an escript object.
150 dc = DataCollector(source = Source.ESCRIPT)
151 T=length(mydomain.getX())
152 #dc.setData(disp = u, stress = sigma_mises)
153 dc.setData(disp = T, stress = T)
154
155 # Create a Velocity.
156 v = Velocity(scene = s, data_collector = dc,
157 viewport = Viewport.SOUTH_WEST,
158 arrow = Arrow.THREE_D, color_mode = ColorMode.SCALAR,
159 lut = Lut.COLOR, cell_to_point = True, outline = True)
160 v.setScaleFactor(scale_factor = 0.3)
161
162 # Create a Camera.
163 c = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
164 c.isometricView()
165
166 # Render the object.
167 self.render("TestEscriptVelocity.jpg")
168
169 ne=32 # number of cells in x_0 and x_1 directions
170 width=10000. # length in x_0 and x_1 directions
171 #lam=3.462e9
172 #mu=3.462e9
173 #rho=1154.
174 #tend=60
175 #h=(1./5.)*sqrt(rho/(lam+2*mu))*(width/ne)
176
177 #U0=0.01 # amplitude of point source
178 class TestEscriptEllipsoid(unittest.TestCase, TestEscript):
179 def tearDown(self):
180 del self.scene
181
182 def testEscriptEllipsoid(self):
183 mydomain=Brick(ne,ne,10,l0=width,l1=width,l2=10.*width/32.)
184 #self.wavePropagation(mydomain,h,tend,lam,mu,rho,U0)
185 self.wavePropagation(mydomain)
186
187 def wavePropagation(self, mydomain):
188 #x=domain.getX()
189 # ... open new PDE ...
190 #mypde=LinearPDE(domain)
191 #mypde.setSolverMethod(LinearPDE.LUMPING)
192 #kronecker=identity(mypde.getDim())
193
194 # spherical source at middle of bottom face
195
196 #xc=[width/2.,width/2.,0.]
197 # define small radius around point xc
198 # Lsup(x) returns the maximum value of the argument x
199 #src_radius = 0.1*Lsup(domain.getSize())
200 #dunit=numarray.array([1.,0.,0.]) # defines direction of point source
201
202 #mypde.setValue(D=kronecker*rho)
203 # ... set initial values ....
204 #n=0
205 # initial value of displacement at point source is constant
206 # (U0=0.01) for first two time steps
207 #u=U0*whereNegative(length(x-xc)-src_radius)*dunit
208 #u_last=U0*whereNegative(length(x-xc)-src_radius)*dunit
209 t=0
210
211 # define the location of the point source
212 #L=Locator(domain,numarray.array(xc))
213 # find potential at point source
214 #u_pc=L.getValue(u)
215
216 #u_pc_x = u_pc[0]
217 #u_pc_y = u_pc[1]
218 #u_pc_z = u_pc[2]
219
220 # open file to save displacement at point source
221 #u_pc_data=open('./data/U_pc.out','w')
222 #u_pc_data.write("%f %f %f %f\n"%(t,u_pc_x,u_pc_y,u_pc_z))
223
224 # Create a Scene.
225 s = Scene(renderer = JPG_RENDERER, x_size = X_SIZE, y_size = Y_SIZE)
226 self.scene = s
227
228 # Create a DataCollector reading directly from escript objects.
229 dc = DataCollector(source = Source.ESCRIPT)
230
231 # Create an Ellipsoid.
232 e = Map(scene = s, data_collector = dc,
233 viewport = Viewport.SOUTH_WEST,
234 lut = Lut.COLOR, cell_to_point = True, outline = True)
235 #e.setScaleFactor(scale_factor = 0.7)
236 #e.setMaxScaleFactor(max_scale_factor = 1000)
237 #e.setRatio(ratio = 10)
238
239 # Create a Camera.
240 c = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
241 c.isometricView()
242
243 while t<0.4:
244 t+=0.1
245 # ... get current stress ....
246 #g=grad(u)
247 #stress=lam*trace(g)*kronecker+mu*(g+transpose(g))
248 # ... get new acceleration ....
249 #mypde.setValue(X=-stress)
250 #a=mypde.getSolution()
251 # ... get new displacement ...
252 #u_new=2*u-u_last+h**2*a
253 # ... shift displacements ....
254 #u_last=u
255 #u=u_new
256 #t+=h
257 #n+=1
258 #u_pc=L.getValue(u)
259
260 #u_pc_x=u_pc[0]
261 #u_pc_y=u_pc[1]
262 #u_pc_z=u_pc[2]
263
264 # ... save current acceleration in units of gravity and displacements
265 # === syntetic data
266 u=domain.getX()
267 #T=length(mydomain.getX())
268 #if n==1 or n%10==0:
269 #dc.setData(acceleration = length(a)/9.81, displacement = u,
270 # tensor = stress, Ux = u[0])
271 dc.setData(acceleration = length(u), displacement = u, tensor = grad(u), Ux = u[0])
272 # Render the object.
273 self.render("TestEscriptEllipsoid%02d.jpg" % (t/10))
274
275
276 if __name__ == '__main__':
277 suite = unittest.TestSuite()
278 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestEscriptMap))
279 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestEscriptVelocity))
280 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestEscriptEllipsoid))
281 unittest.TextTestRunner(verbosity=2).run(suite)
282

  ViewVC Help
Powered by ViewVC 1.1.26