/[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 1148 - (show annotations)
Wed May 16 22:45:33 2007 UTC (13 years, 11 months ago) by jongui
File MIME type: text/x-python
File size: 2112 byte(s)
Added the updated files for pyvisi and removed some incorrect reference images.
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 #... generate domain ...
23 mydomain = Brick(l0=1.,l1=1., l2=1.,n0=10, n1=10, n2=10)
24 x=mydomain.getX()
25 #... set temperature ...
26 T=T_0*exp(-beta*length(x-xc))
27 #... open symmetric PDE ...
28 mypde=LinearPDE(mydomain)
29 mypde.setSymmetryOn()
30 #... set coefficients ...
31 C=Tensor4(0.,Function(mydomain))
32 for i in range(mydomain.getDim()):
33 for j in range(mydomain.getDim()):
34 C[i,i,j,j]+=lam
35 C[j,i,j,i]+=mu
36 C[j,i,i,j]+=mu
37 msk=whereZero(x[0])*[1.,0.,0.] \
38 +whereZero(x[1])*[0.,1.,0.] \
39 +whereZero(x[2])*[0.,0.,1.]
40 sigma0=(lam+2./3.*mu)*alpha*(T-T_ref)*kronecker(mydomain)
41 mypde.setValue(A=C,X=sigma0,q=msk)
42 #... solve pde ...
43 u=mypde.getSolution()
44 #... calculate von-Misses
45 g=grad(u)
46 sigma=mu*(g+transpose(g))+lam*trace(g)*kronecker(mydomain)-sigma0
47 sigma_mises=sqrt(((sigma[0,0]-sigma[1,1])**2+(sigma[1,1]-sigma[2,2])**2+ \
48 (sigma[2,2]-sigma[0,0])**2)/6. \
49 +sigma[0,1]**2 + sigma[1,2]**2 + sigma[2,0]**2)
50
51 # Create a Scene.
52 s = Scene(renderer = JPG_RENDERER, x_size = X_SIZE, y_size = Y_SIZE)
53
54 # Create a DataCollector reading directly from an escript object.
55 dc = DataCollector(source = Source.ESCRIPT)
56 dc.setData(disp = u, stress = sigma_mises)
57
58 # Create a Velocity.
59 v = Velocity(scene = s, data_collector = dc, viewport = Viewport.SOUTH_WEST,
60 arrow = Arrow.THREE_D, color_mode = ColorMode.SCALAR,
61 lut = Lut.COLOR, cell_to_point = True, outline = True)
62 v.setScaleFactor(scale_factor = 0.3)
63
64 # Create a Camera.
65 c = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
66 c.isometricView()
67
68
69 # Render the object.
70 s.render(image_name = os.path.join(PYVISI_EXAMPLE_IMAGES_PATH,\
71 "heatedblock.jpg"))

  ViewVC Help
Powered by ViewVC 1.1.26