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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6651 - (hide annotations)
Wed Feb 7 02:12:08 2018 UTC (6 months ago) by jfenwick
File MIME type: text/x-python
File size: 5776 byte(s)
Make everyone sad by touching all the files

Copyright dates update

1 jfenwick 3981 ##############################################################################
2 gross 2948 #
3 jfenwick 6651 # Copyright (c) 2009-2018 by The University of Queensland
4 jfenwick 3981 # http://www.uq.edu.au
5 gross 2948 #
6     # Primary Business: Queensland, Australia
7 jfenwick 6112 # Licensed under the Apache License, version 2.0
8     # http://www.apache.org/licenses/LICENSE-2.0
9 gross 2948 #
10 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
12     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 jfenwick 3981 #
14     ##############################################################################
15 gross 2948
16 sshaw 5775 from __future__ import division, print_function
17 jfenwick 6651 __copyright__="""Copyright (c) 2009-2018 by The University of Queensland
18 jfenwick 3981 http://www.uq.edu.au
19 gross 2948 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 gross 2948 __url__="https://launchpad.net/escript-finley"
23    
24     """
25     Author: Antony Hallam antony.hallam@uqconnect.edu.au
26     """
27    
28     ############################################################FILE HEADER
29 gross 2952 # example05a.py
30 gross 2948 # Create either a 2D syncline or anticline model using pycad meshing
31 ahallam 2977 # tools. Then model steady state heat solution.
32 gross 2948
33     #######################################################EXTERNAL MODULES
34 caltinay 4087 import matplotlib
35     matplotlib.use('agg') #It's just here for automated testing
36 gross 2948 from esys.pycad import * #domain constructor
37     from esys.pycad.gmsh import Design #Finite Element meshing package
38     import os #file path tool
39     from math import * # math package
40     from esys.escript import *
41     from esys.escript.unitsSI import *
42     from esys.escript.linearPDEs import LinearPDE
43 sshaw 5775 from cblib import toRegGrid, HAVE_NATGRID
44 gross 2948 import pylab as pl #Plotting package
45    
46 sshaw 5288 try:
47     # This imports the rectangle domain function
48     from esys.finley import MakeDomain#Converter for escript
49     HAVE_FINLEY = True
50     except ImportError:
51     print("Finley module not available")
52     HAVE_FINLEY = False
53 gross 2948 ########################################################MPI WORLD CHECK
54     if getMPISizeWorld() > 1:
55 sshaw 4576 import sys
56     print("This example will not run in an MPI world.")
57     sys.exit(0)
58 gross 2948
59 sshaw 5775 if not HAVE_NATGRID:
60     print("This example requires that natgrid is available to matplotlib")
61 jfenwick 5417
62     if HAVE_FINLEY and HAVE_NATGRID:
63 sshaw 5288 #################################################ESTABLISHING VARIABLES
64     #set modal to 1 for a syncline or -1 for an anticline structural
65     #configuration
66     modal=-1
67 gross 2948
68 sshaw 5288 # the folder to put our outputs in, leave blank "" for script path -
69     # note this folder path must exist to work
70     save_path= os.path.join("data","example05")
71     mkDir(save_path)
72 gross 2948
73 sshaw 5288 ################################################ESTABLISHING PARAMETERS
74     #Model Parameters
75     width=5000.0*m #width of model
76     depth=-6000.0*m #depth of model
77     Ttop=20*K # top temperature
78     qin=70*Milli*W/(m*m) # bottom heat influx
79 gross 2948
80 sshaw 5288 sspl=51 #number of discrete points in spline
81     dsp=width/(sspl-1) #dx of spline steps for width
82     dep_sp=2500.0*m #avg depth of spline
83     h_sp=1500.0*m #heigh of spline
84     orit=-1.0 #orientation of spline 1.0=>up -1.0=>down
85 gross 2948
86 sshaw 5288 ####################################################DOMAIN CONSTRUCTION
87     # Domain Corners
88     p0=Point(0.0, 0.0, 0.0)
89     p1=Point(0.0, depth, 0.0)
90     p2=Point(width, depth, 0.0)
91     p3=Point(width, 0.0, 0.0)
92 gross 2948
93 sshaw 5288 # Generate Material Boundary
94     x=[ Point(i*dsp\
95     ,-dep_sp+modal*orit*h_sp*cos(pi*i*dsp/dep_sp+pi))\
96     for i in range(0,sspl)\
97     ]
98     mysp = Spline(*tuple(x))
99     # Start and end of material boundary.
100     x1=mysp.getStartPoint()
101     x2=mysp.getEndPoint()
102 sshaw 4576
103 sshaw 5288 # Create TOP BLOCK
104     # lines
105     tbl1=Line(p0,x1)
106     tbl2=mysp
107     tbl3=Line(x2,p3)
108     l30=Line(p3, p0)
109     # curve
110     tblockloop = CurveLoop(tbl1,tbl2,tbl3,l30)
111     # surface
112     tblock = PlaneSurface(tblockloop)
113 gross 2948
114    
115 sshaw 5288 # Create BOTTOM BLOCK
116     # lines
117     bbl1=Line(x1,p1)
118     bbl3=Line(p2,x2)
119     bbl4=-mysp
120     l12=Line(p1, p2)
121     # curve
122     bblockloop = CurveLoop(bbl1,l12,bbl3,bbl4)
123     # surface
124     bblock = PlaneSurface(bblockloop)
125 gross 2948
126 sshaw 5288 ################################################CREATE MESH FOR ESCRIPT
127     # Create a Design which can make the mesh
128     d=Design(dim=2, element_size=200)
129     # Add the subdomains and flux boundaries.
130     d.addItems(PropertySet("top",tblock),PropertySet("bottom",bblock),\
131     PropertySet("linebottom",l12))
132     # Create the geometry, mesh and Escript domain
133     d.setScriptFileName(os.path.join(save_path,"example05.geo"))
134     d.setMeshFileName(os.path.join(save_path,"example05.msh"))
135     domain=MakeDomain(d, optimizeLabeling=True)
136     print("Domain has been generated ...")
137     ##############################################################SOLVE PDE
138     mypde=LinearPDE(domain)
139     mypde.getSolverOptions().setVerbosityOn()
140     mypde.setSymmetryOn()
141     kappa=Scalar(0,Function(domain))
142     kappa.setTaggedValue("top",2.0*W/m/K)
143     kappa.setTaggedValue("bottom",4.0*W/m/K)
144     mypde.setValue(A=kappa*kronecker(domain))
145     x=Solution(domain).getX()
146     mypde.setValue(q=whereZero(x[1]-sup(x[1])),r=Ttop)
147     qS=Scalar(0,FunctionOnBoundary(domain))
148     qS.setTaggedValue("linebottom",qin)
149     mypde.setValue(y=qS)
150     print("PDE has been generated ...")
151     ###########################################################GET SOLUTION
152     T=mypde.getSolution()
153     print("PDE has been solved ...")
154 gross 2948
155 sshaw 5288 #######################################################################
156     xi, yi, zi = toRegGrid(T, nx=50, ny=50)
157     pl.matplotlib.pyplot.autumn()
158     pl.contourf(xi,yi,zi,10)
159     pl.xlabel("Horizontal Displacement (m)")
160     pl.ylabel("Depth (m)")
161     pl.savefig(os.path.join(save_path,"Tcontour.png"))
162     print("Solution has been plotted ...")

  ViewVC Help
Powered by ViewVC 1.1.26