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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6651 - (show annotations)
Wed Feb 7 02:12:08 2018 UTC (2 years, 5 months ago) by jfenwick
File MIME type: text/x-python
File size: 5349 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 # example08a.py
26 # Antony Hallam
27 # Seismic Wave Equation Simulation using acceleration solution.
28
29 #######################################################EXTERNAL MODULES
30 from esys.escript import *
31 from esys.weipa import saveVTK
32 import sys
33 import os
34 # smoothing operator
35 from esys.escript.pdetools import Projector, Locator
36 from esys.escript.unitsSI import *
37 import numpy as np
38 from esys.escript.linearPDEs import LinearPDE, SolverOptions
39 try:
40 # This imports the rectangle domain function
41 from esys.finley import Rectangle
42 HAVE_FINLEY = True
43 except ImportError:
44 print("Finley module not available")
45 HAVE_FINLEY = False
46 ########################################################MPI WORLD CHECK
47 if getMPISizeWorld() > 1:
48 import sys
49 print("This example will not run in an MPI world.")
50 sys.exit(0)
51
52 if HAVE_FINLEY:
53 #################################################ESTABLISHING VARIABLES
54 # where to save output data
55 savepath = "data/example08a"
56 mkDir(savepath)
57 #Geometric and material property related variables.
58 mx = 1000. # model lenght
59 my = -1000. # model width
60 ndx = 500 # steps in x direction
61 ndy = 500 # steps in y direction
62 xstep=mx/ndx # calculate the size of delta x
63 ystep=abs(my/ndy) # calculate the size of delta y
64 lam=3.462e9 #lames constant
65 mu=3.462e9 #bulk modulus
66 rho=1154. #density
67 # Time related variables.
68 testing=True
69 if testing:
70 print('The testing end time is currently selected. This severely limits the number of time iterations.')
71 print("Try changing testing to False for more iterations.")
72 tend=0.001
73 else:
74 tend=0.5 # end time
75
76 h=0.0005 # time step
77 # data recording times
78 rtime=0.0 # first time to record
79 rtime_inc=tend/20.0 # time increment to record
80 #Check to make sure number of time steps is not too large.
81 print("Time step size= ",h, "Expected number of outputs= ",tend/h)
82
83 U0=0.01 # amplitude of point source
84 # will introduce a spherical source at middle left of bottom face
85 xc=[mx/2,0]
86
87 ####################################################DOMAIN CONSTRUCTION
88 domain=Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy) # create the domain
89 x=domain.getX() # get the locations of the nodes in the domani
90
91 ##########################################################ESTABLISH PDE
92 mypde=LinearPDE(domain) # create pde
93 mypde.setSymmetryOn() # turn symmetry on
94 # turn lumping on for more efficient solving
95 mypde.getSolverOptions().setSolverMethod(SolverOptions.HRZ_LUMPING)
96 kmat = kronecker(domain) # create the kronecker delta function of the domain
97 mypde.setValue(D=kmat*rho) #set the general form value D
98
99 ############################################FIRST TIME STEPS AND SOURCE
100 # define small radius around point xc
101 src_length = 20; print("src_length = ",src_length)
102 # set initial values for first two time steps with source terms
103 y=U0*(cos(length(x-xc)*3.1415/src_length)+1)*whereNegative(length(x-xc)-src_length)
104 src_dir=np.array([0.,-1.]) # defines direction of point source as down
105 y=y*src_dir
106 mypde.setValue(y=y) #set the source as a function on the boundary
107 # initial value of displacement at point source is constant (U0=0.01)
108 # for first two time steps
109 u=[0.0,0.0]*whereNegative(x)
110 u_m1=u
111
112 ####################################################ITERATION VARIABLES
113 n=0 # iteration counter
114 t=0 # time counter
115 ##############################################################ITERATION
116 while t<tend:
117 # get current stress
118 g=grad(u); stress=lam*trace(g)*kmat+mu*(g+transpose(g))
119 mypde.setValue(X=-stress) # set PDE values
120 accel = mypde.getSolution() #get PDE solution for accelleration
121 u_p1=(2.*u-u_m1)+h*h*accel #calculate displacement
122 u_m1=u; u=u_p1 # shift values by 1
123 # save current displacement, acceleration and pressure
124 if (t >= rtime):
125 saveVTK(os.path.join(savepath,"ex08a.%05d.vtu"%n),displacement=length(u),\
126 acceleration=length(accel),tensor=stress)
127 rtime=rtime+rtime_inc #increment data save time
128 # increment loop values
129 t=t+h; n=n+1
130 print("time step %d, t=%s"%(n,t))

  ViewVC Help
Powered by ViewVC 1.1.26