/[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 6651 - (show annotations)
Wed Feb 7 02:12:08 2018 UTC (2 years, 3 months ago) by jfenwick
File MIME type: text/x-python
File size: 5578 byte(s)
Make everyone sad by touching all the files

Copyright dates update

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

  ViewVC Help
Powered by ViewVC 1.1.26