/[escript]/trunk/doc/examples/cookbook/example07a.py
ViewVC logotype

Contents of /trunk/doc/examples/cookbook/example07a.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4005 - (show annotations)
Fri Sep 28 06:09:03 2012 UTC (6 years, 10 months ago) by caltinay
File MIME type: text/x-python
File size: 4951 byte(s)
test fixes, doco updates, annoyance removals.

1
2 from __future__ import print_function
3 ##############################################################################
4 #
5 # Copyright (c) 2009-2012 by University of Queensland
6 # http://www.uq.edu.au
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
13 # Development since 2012 by School of Earth Sciences
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2009-2012 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 ############################################################FILE HEADER
25 # example07a.py
26 # Antony Hallam
27 # Acoustic Wave Equation Simulation using displacement solution
28
29 #######################################################EXTERNAL MODULES
30 from esys.escript import *
31 from esys.finley import Rectangle
32 from esys.weipa import saveVTK
33 import sys
34 import os
35 # smoothing operator
36 from esys.escript.pdetools import Projector, Locator
37 from esys.escript.unitsSI import *
38 import numpy as np
39 import matplotlib
40 matplotlib.use('agg') #It's just here for automated testing
41 import pylab as pl
42 import matplotlib.cm as cm
43 from esys.escript.linearPDEs import LinearPDE
44
45 ########################################################MPI WORLD CHECK
46 if getMPISizeWorld() > 1:
47 import sys
48 print("This example will not run in an MPI world.")
49 sys.exit(0)
50
51 #################################################ESTABLISHING VARIABLES
52 # where to save output data
53 savepath = "data/example07a"
54 mkDir(savepath)
55 #Geometric and material property related variables.
56 mx = 1000. # model lenght
57 my = 1000. # model width
58 ndx = 400 # steps in x direction
59 ndy = 400 # steps in y direction
60 xstep=mx/ndx # calculate the size of delta x
61 ystep=my/ndy # calculate the size of delta y
62
63 c=380.0*m/sec # velocity of sound in air
64 csq=c*c #square of c
65 # Time related variables.
66 testing=True
67 if testing:
68 print('The testing end time is currently selected. This severely limits the number of time iterations.')
69 print("Try changing testing to False for more iterations.")
70 tend=0.004
71 else:
72 tend=1.5 # end time
73
74 h=0.001 # time step
75 # data recording times
76 rtime=0.0 # first time to record
77 rtime_inc=tend/20.0 # time increment to record
78 #Check to make sure number of time steps is not too large.
79 print("Time step size= ",h, "Expected number of outputs= ",tend/h)
80
81 U0=0.005 # amplitude of point source
82 # want a spherical source in the middle of area
83 xc=[500,500] # with reference to mx,my this is the source location
84
85 ####################################################DOMAIN CONSTRUCTION
86 mydomain=Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy) # create the domain
87 x=mydomain.getX() # get the node locations of the domain
88
89 ##########################################################ESTABLISH PDE
90 mypde=LinearPDE(mydomain) # create pde
91 mypde.setSymmetryOn() # turn symmetry on
92 mypde.setValue(D=1.) # set the value of D in the general form to 1.
93
94 ############################################FIRST TIME STEPS AND SOURCE
95 # define small radius around point xc
96 src_radius = 30
97 print("src_radius = ",src_radius)
98 # set initial values for first two time steps with source terms
99 u=U0*(cos(length(x-xc)*3.1415/src_radius)+1)*whereNegative(length(x-xc)-src_radius)
100 u_m1=u
101 #plot source shape
102 cut_loc=[] #where the cross section of the source along x will be
103 src_cut=[] #where the cross section of the source will be
104 # create locations for source cross section
105 for i in range(ndx//2-ndx//10,ndx//2+ndx//10):
106 cut_loc.append(xstep*i)
107 src_cut.append([xstep*i,xc[1]])
108 # locate the nearest nodes to the points in src_cut
109 src=Locator(mydomain,src_cut)
110 src_cut=src.getValue(u) #retrieve the values from the nodes
111 # plot the x locations vs value and save the figure
112 pl.plot(cut_loc,src_cut)
113 pl.axis([xc[0]-src_radius*3,xc[0]+src_radius*3,0.,2.*U0])
114 pl.savefig(os.path.join(savepath,"source_line.png"))
115
116 ####################################################ITERATION VARIABLES
117 n=0 # iteration counter
118 t=0 # time counter
119 ##############################################################ITERATION
120 while t<tend:
121 g=grad(u); pres=csq*h*h*g # get current pressure
122 mypde.setValue(X=-pres,Y=(2.*u-u_m1)) # set values in pde
123 u_p1 = mypde.getSolution() # get the new displacement
124 u_m1=u; u=u_p1 # shift values back one time step for next iteration
125 # save current displacement, acceleration and pressure
126 if (t >= rtime):
127 saveVTK(os.path.join(savepath,"ex07a.%i.vtu"%n),displacement=length(u),tensor=pres)
128 rtime=rtime+rtime_inc #increment data save time
129 # increment loop values
130 t=t+h; n=n+1
131 print("time step %d, t=%s"%(n,t))

  ViewVC Help
Powered by ViewVC 1.1.26