/[escript]/trunk/doc/examples/usersguide/wave.py
ViewVC logotype

Contents of /trunk/doc/examples/usersguide/wave.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4821 - (show annotations)
Tue Apr 1 04:58:33 2014 UTC (5 years, 4 months ago) by sshaw
File MIME type: text/x-python
File size: 4441 byte(s)
moved SolverOptions to c++, split into SolverOptions for the options and SolverBuddy as the state as a precursor to per-pde solving... does break some use cases (e.g. pde.getSolverOptions().DIRECT will now fail, new value access is with SolverOptions.DIRECT), examples and documentation updated to match
1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2014 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22 __url__="https://launchpad.net/escript-finley"
23
24 import matplotlib
25 matplotlib.use('agg') #For interactive use, you can comment out this line
26 #It's just here to make testing easier
27
28 import matplotlib.pyplot as plt
29 from numpy import zeros,ones
30 from esys.escript import *
31 from esys.escript.linearPDEs import LinearPDE, SolverOptions
32 from esys.escript.pdetools import Locator
33 from esys.dudley import Brick
34 from esys.weipa import saveVTK
35
36
37 ne=32 # number of cells in x_0 and x_1 directions
38 width=10000. # length in x_0 and x_1 directions
39 lam=3.462e9
40 mu=3.462e9
41 rho=1154.
42 tend=10. # to ran a full simulation change tend to 60.
43 alpha=0.7
44 t0=3.
45
46
47 U0=1. # maximum displacement
48 mkDir("data") # create directory data if it does not exist already.
49
50 def wavePropagation(domain,h,tend,lam,mu,rho, xc, src_radius, U0):
51 # lists to collect displacement at point source
52 ts, u_pc0,u_pc1,u_pc2=[], [], [], []
53 x=domain.getX()
54 # ... open new PDE ...
55 mypde=LinearPDE(domain)
56 mypde.getSolverOptions().setSolverMethod(SolverOptions.HRZ_LUMPING)
57 kron=kronecker(mypde.getDim())
58
59 dunit=numpy.array([1.,0.,0.]) # defines direction of point source
60
61 mypde.setValue(D=kron*rho, q=whereNegative(length(x-xc)-src_radius)*dunit)
62 # ... set initial values ....
63 n=0
64 # for first two time steps
65 u=Vector(0.,Solution(domain))
66 u_last=Vector(0.,Solution(domain))
67 t=0
68
69 # define the location of the point source
70 L=Locator(domain,xc)
71 # find potential at point source
72 u_pc=L.getValue(u)
73 print("u at point charge = %s"%u_pc)
74 ts.append(t); u_pc0.append(u_pc[0]), u_pc1.append(u_pc[1]), u_pc2.append(u_pc[2])
75
76 while t<tend:
77 t+=h
78 # ... get current stress ....
79 g=grad(u)
80 stress=lam*trace(g)*kron+mu*(g+transpose(g))
81 # ... get new acceleration ....
82 amplitude=U0*(4*(t-t0)**3/alpha**3-6*(t-t0)/alpha)*sqrt(2.)/alpha**2*exp(1./2.-(t-t0)**2/alpha**2)
83 mypde.setValue(X=-stress, r=dunit*amplitude)
84 a=mypde.getSolution()
85 # ... get new displacement ...
86 u_new=2*u-u_last+h**2*a
87 # ... shift displacements ....
88 u_last=u
89 u=u_new
90 n+=1
91 print("time step %d, t = %s"%(n,t))
92 u_pc=L.getValue(u)
93 print("u at point charge = %s"%u_pc)
94 ts.append(t); u_pc0.append(u_pc[0]), u_pc1.append(u_pc[1]), u_pc2.append(u_pc[2])
95
96 # ... save current acceleration in units of gravity and displacements
97 if n==1 or n%10==0: saveVTK("./data/usoln.%i.vtu"%(n/10),acceleration=length(a)/9.81,
98 displacement = length(u), tensor = stress, Ux = u[0] )
99 return ts, u_pc0,u_pc1,u_pc2
100
101 #
102 # create domain:
103 #
104 mydomain=Brick(ne,ne,10,l0=width,l1=width,l2=10.*width/ne)
105 #
106 # sety time step size:
107 #
108 h=inf(1./5.)*inf(sqrt(rho/(lam+2*mu))*mydomain.getSize())
109 print("time step size = %s"%h)
110 #
111 # spherical source at middle of bottom face
112 #
113 xc=[width/2.,width/2.,0.]
114 # define small radius around point xc
115 src_radius = 0.03*width
116 print("src_radius = %s"%src_radius)
117 #
118 # run it
119 #
120 ts, u_pc0,u_pc1,u_pc2 = wavePropagation(mydomain,h,tend,lam,mu,rho, xc, src_radius, U0)
121 #
122 # create a plot:
123 #
124 if getMPIRankWorld() == 0:
125 plt.title("Displacement at Point Source")
126 plt.plot(ts, u_pc0, '-', label="x_0", linewidth=1)
127 plt.plot(ts, u_pc1, '-', label="x_1", linewidth=1)
128 plt.plot(ts, u_pc2, '-', label="x_2", linewidth=1)
129 plt.xlabel('time')
130 plt.ylabel('displacement')
131 plt.legend()
132 plt.savefig('u_pc.png', format='png')
133 # or save displacement
134 u_pc_data=FileWriter('./data/U_pc.out')
135 for i in range(len(ts)) :
136 u_pc_data.write("%f %f %f %f\n"%(ts[i],u_pc0[i],u_pc1[i],u_pc2[i]))
137 u_pc_data.close()
138

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision
svn:mergeinfo /branches/lapack2681/doc/examples/usersguide/wave.py:2682-2741 /branches/pasowrap/doc/examples/usersguide/wave.py:3661-3674 /branches/py3_attempt2/doc/examples/usersguide/wave.py:3871-3891 /branches/restext/doc/examples/usersguide/wave.py:2610-2624 /branches/ripleygmg_from_3668/doc/examples/usersguide/wave.py:3669-3791 /branches/symbolic_from_3470/doc/examples/usersguide/wave.py:3471-3974 /branches/symbolic_from_3470/ripley/test/python/doc/examples/usersguide/wave.py:3517-3974 /trunk/doc/examples/usersguide/wave.py:1388-2483 /trunk/ripley/test/python/doc/examples/usersguide/wave.py:3480-3515

  ViewVC Help
Powered by ViewVC 1.1.26