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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6651 - (hide annotations)
Wed Feb 7 02:12:08 2018 UTC (2 years, 4 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 sshaw 5288 from __future__ import division, print_function
2 jfenwick 3981 ##############################################################################
3 ahallam 3025 #
4 jfenwick 6651 # Copyright (c) 2009-2018 by The University of Queensland
5 jfenwick 3981 # http://www.uq.edu.au
6 ahallam 3025 #
7     # Primary Business: Queensland, Australia
8 jfenwick 6112 # Licensed under the Apache License, version 2.0
9     # http://www.apache.org/licenses/LICENSE-2.0
10 ahallam 3025 #
11 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
13     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 jfenwick 3981 #
15     ##############################################################################
16 ahallam 3025
17 jfenwick 6651 __copyright__="""Copyright (c) 2009-2018 by The University of Queensland
18 jfenwick 3981 http://www.uq.edu.au
19 ahallam 3025 Primary Business: Queensland, Australia"""
20 jfenwick 6112 __license__="""Licensed under the Apache License, version 2.0
21     http://www.apache.org/licenses/LICENSE-2.0"""
22 ahallam 3025 __url__="https://launchpad.net/escript-finley"
23    
24     ############################################################FILE HEADER
25 ahallam 3029 # example08a.py
26 ahallam 3025 # Antony Hallam
27     # Seismic Wave Equation Simulation using acceleration solution.
28    
29     #######################################################EXTERNAL MODULES
30     from esys.escript import *
31 caltinay 3346 from esys.weipa import saveVTK
32 ahallam 3025 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 sshaw 4821 from esys.escript.linearPDEs import LinearPDE, SolverOptions
39 sshaw 5288 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 ahallam 3195 ########################################################MPI WORLD CHECK
47     if getMPISizeWorld() > 1:
48 sshaw 4576 import sys
49     print("This example will not run in an MPI world.")
50     sys.exit(0)
51 ahallam 3195
52 sshaw 5288 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 ahallam 3195
76 sshaw 5288 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 ahallam 3025
83 sshaw 5288 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 ahallam 3025
87 sshaw 5288 ####################################################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 ahallam 3025
91 sshaw 5288 ##########################################################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 ahallam 3025
99 sshaw 5288 ############################################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 jfenwick 6095 src_dir=np.array([0.,-1.]) # defines direction of point source as down
105 sshaw 5288 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 ahallam 3025
112 sshaw 5288 ####################################################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