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

  ViewVC Help
Powered by ViewVC 1.1.26