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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1095 - (show annotations)
Mon Apr 16 06:32:24 2007 UTC (13 years, 7 months ago) by jongui
File MIME type: text/x-python
File size: 1628 byte(s)
Added some example scripts reading directly from escript objects.
1 # $Id$
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, Map
6 from esys.pyvisi.constant import *
7 #... set some parameters ...
8 lam=1.
9 mu=0.1
10 alpha=1.e-6
11 xc=[0.3,0.3,1.]
12 beta=8.
13 T_ref=0.
14 T_0=1.
15 #... generate domain ...
16 mydomain = Brick(l0=1.,l1=1., l2=1.,n0=10, n1=10, n2=10)
17 x=mydomain.getX()
18 #... set temperature ...
19 T=T_0*exp(-beta*length(x-xc))
20 #... open symmetric PDE ...
21 mypde=LinearPDE(mydomain)
22 mypde.setSymmetryOn()
23 #... set coefficients ...
24 C=Tensor4(0.,Function(mydomain))
25 for i in range(mydomain.getDim()):
26 for j in range(mydomain.getDim()):
27 C[i,i,j,j]+=lam
28 C[j,i,j,i]+=mu
29 C[j,i,i,j]+=mu
30 msk=whereZero(x[0])*[1.,0.,0.] \
31 +whereZero(x[1])*[0.,1.,0.] \
32 +whereZero(x[2])*[0.,0.,1.]
33 sigma0=(lam+2./3.*mu)*alpha*(T-T_ref)*kronecker(mydomain)
34 mypde.setValue(A=C,X=sigma0,q=msk)
35 #... solve pde ...
36 u=mypde.getSolution()
37 #... calculate von-Misses
38 g=grad(u)
39 sigma=mu*(g+transpose(g))+lam*trace(g)*kronecker(mydomain)-sigma0
40 sigma_mises=sqrt(((sigma[0,0]-sigma[1,1])**2+(sigma[1,1]-sigma[2,2])**2+ \
41 (sigma[2,2]-sigma[0,0])**2)/6. \
42 +sigma[0,1]**2 + sigma[1,2]**2 + sigma[2,0]**2)
43 #... output ...
44 #saveVTK("deform.xml",disp=u,stress=sigma_mises)
45
46 s = Scene(renderer = Renderer.ONLINE, x_size = 800, y_size = 600)
47 dc = DataCollector(source = Source.ESCRIPT)
48
49 dc.setData(disp = u,stress = sigma_mises)
50 Map(scene = s, data_collector = dc, viewport = Viewport.SOUTH_WEST,
51 lut = Lut.COLOR, cell_to_point = True, outline = True)
52
53 s.render(image_name = "heatedblock.jpg")

  ViewVC Help
Powered by ViewVC 1.1.26