/[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 3892 - (hide annotations)
Tue Apr 10 08:57:23 2012 UTC (6 years, 2 months ago) by jfenwick
File MIME type: text/x-python
File size: 4922 byte(s)
Merged changes across from the attempt2 branch.
This version builds and passes python2 tests.
It also passes most python3 tests.



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

  ViewVC Help
Powered by ViewVC 1.1.26