/[escript]/trunk/doc/examples/pyvisi/heatedblock_with_pyvisi.py
ViewVC logotype

Contents of /trunk/doc/examples/pyvisi/heatedblock_with_pyvisi.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1153 - (show annotations)
Thu May 17 06:33:54 2007 UTC (13 years, 1 month ago) by jongui
File MIME type: text/x-python
File size: 2114 byte(s)
Made some minor modifications and fixed minor bugs. Most tests appear to pass on the Altix although there are two tests which occasionally throw an error related to memory corruption.
1 # Import the necessary modules.
2 from esys.escript import *
3 from esys.escript.linearPDEs import LinearPDE
4 from esys.finley import Brick
5 from esys.pyvisi import Scene, DataCollector, Velocity, Camera
6 from esys.pyvisi.constant import *
7 import os
8
9 PYVISI_EXAMPLE_IMAGES_PATH = "data_sample_images"
10 X_SIZE = 400
11 Y_SIZE = 400
12 JPG_RENDERER = Renderer.ONLINE_JPG
13
14 #... set some parameters ...
15 lam=1.
16 mu=0.1
17 alpha=1.e-6
18 xc=[0.3,0.3,1.]
19 beta=8.
20 T_ref=0.
21 T_0=1.
22
23 #... generate domain ...
24 mydomain = Brick(l0=1.,l1=1., l2=1.,n0=10, n1=10, n2=10)
25 x=mydomain.getX()
26 #... set temperature ...
27 T=T_0*exp(-beta*length(x-xc))
28 #... open symmetric PDE ...
29 mypde=LinearPDE(mydomain)
30 mypde.setSymmetryOn()
31
32 #... set coefficients ...
33 C=Tensor4(0.,Function(mydomain))
34 for i in range(mydomain.getDim()):
35 for j in range(mydomain.getDim()):
36 C[i,i,j,j]+=lam
37 C[j,i,j,i]+=mu
38 C[j,i,i,j]+=mu
39 msk=whereZero(x[0])*[1.,0.,0.] \
40 +whereZero(x[1])*[0.,1.,0.] \
41 +whereZero(x[2])*[0.,0.,1.]
42 sigma0=(lam+2./3.*mu)*alpha*(T-T_ref)*kronecker(mydomain)
43 mypde.setValue(A=C,X=sigma0,q=msk)
44
45 #... solve pde ...
46 u=mypde.getSolution()
47 #... calculate von-Misses
48 g=grad(u)
49 sigma=mu*(g+transpose(g))+lam*trace(g)*kronecker(mydomain)-sigma0
50 sigma_mises=sqrt(((sigma[0,0]-sigma[1,1])**2+(sigma[1,1]-sigma[2,2])**2+ \
51 (sigma[2,2]-sigma[0,0])**2)/6. \
52 +sigma[0,1]**2 + sigma[1,2]**2 + sigma[2,0]**2)
53
54 # Create a Scene.
55 s = Scene(renderer = JPG_RENDERER, x_size = X_SIZE, y_size = Y_SIZE)
56
57 # Create a DataCollector reading directly from an escript object.
58 dc = DataCollector(source = Source.ESCRIPT)
59 dc.setData(disp = u, stress = sigma_mises)
60
61 # Create a Velocity.
62 v = Velocity(scene = s, data_collector = dc, viewport = Viewport.SOUTH_WEST,
63 arrow = Arrow.THREE_D, color_mode = ColorMode.SCALAR,
64 lut = Lut.COLOR, cell_to_point = True, outline = True)
65 v.setScaleFactor(scale_factor = 0.3)
66
67 # Create a Camera.
68 c = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
69 c.isometricView()
70
71 # Render the object.
72 s.render(image_name = os.path.join(PYVISI_EXAMPLE_IMAGES_PATH,\
73 "heatedblock.jpg"))

  ViewVC Help
Powered by ViewVC 1.1.26