/[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 1100 - (show annotations)
Tue Apr 17 05:36:24 2007 UTC (13 years, 7 months ago) by jongui
File MIME type: text/x-python
File size: 2101 byte(s)
Fixed the problem related to the use of point and cell data. Both point and cell data should now be able to work properly together. i.e. plotting a velocity field using 'vector point data' but coloring the arrows using 'scalar cell data'.
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
8 PYVISI_EXAMPLE_IMAGES_PATH = "data_sample_images/"
9 X_SIZE = 400
10 Y_SIZE = 400
11 JPG_RENDERER = Renderer.ONLINE_JPG
12
13 #... set some parameters ...
14 lam=1.
15 mu=0.1
16 alpha=1.e-6
17 xc=[0.3,0.3,1.]
18 beta=8.
19 T_ref=0.
20 T_0=1.
21 #... generate domain ...
22 mydomain = Brick(l0=1.,l1=1., l2=1.,n0=10, n1=10, n2=10)
23 x=mydomain.getX()
24 #... set temperature ...
25 T=T_0*exp(-beta*length(x-xc))
26 #... open symmetric PDE ...
27 mypde=LinearPDE(mydomain)
28 mypde.setSymmetryOn()
29 #... set coefficients ...
30 C=Tensor4(0.,Function(mydomain))
31 for i in range(mydomain.getDim()):
32 for j in range(mydomain.getDim()):
33 C[i,i,j,j]+=lam
34 C[j,i,j,i]+=mu
35 C[j,i,i,j]+=mu
36 msk=whereZero(x[0])*[1.,0.,0.] \
37 +whereZero(x[1])*[0.,1.,0.] \
38 +whereZero(x[2])*[0.,0.,1.]
39 sigma0=(lam+2./3.*mu)*alpha*(T-T_ref)*kronecker(mydomain)
40 mypde.setValue(A=C,X=sigma0,q=msk)
41 #... solve pde ...
42 u=mypde.getSolution()
43 #... calculate von-Misses
44 g=grad(u)
45 sigma=mu*(g+transpose(g))+lam*trace(g)*kronecker(mydomain)-sigma0
46 sigma_mises=sqrt(((sigma[0,0]-sigma[1,1])**2+(sigma[1,1]-sigma[2,2])**2+ \
47 (sigma[2,2]-sigma[0,0])**2)/6. \
48 +sigma[0,1]**2 + sigma[1,2]**2 + sigma[2,0]**2)
49
50 # Create a Scene.
51 s = Scene(renderer = JPG_RENDERER, x_size = X_SIZE, y_size = Y_SIZE)
52
53 # Create a DataCollector reading directly from an escript object.
54 dc = DataCollector(source = Source.ESCRIPT)
55 dc.setData(disp = u,stress = sigma_mises)
56
57 # Create a Velocity.
58 v = Velocity(scene = s, data_collector = dc, viewport = Viewport.SOUTH_WEST,
59 arrow = Arrow.THREE_D, color_mode = ColorMode.SCALAR,
60 lut = Lut.COLOR, cell_to_point = True, outline = True)
61 v.setScaleFactor(scale_factor = 0.3)
62
63 # Create a Camera.
64 c = Camera(scene = s, data_collector = dc, viewport = Viewport.SOUTH_WEST)
65 c.isometricView()
66
67 # Render the object.
68 s.render(image_name = PYVISI_EXAMPLE_IMAGES_PATH + "heatedblock.jpg")
69

  ViewVC Help
Powered by ViewVC 1.1.26