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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5775 - (show annotations)
Thu Jul 30 08:01:06 2015 UTC (3 years, 10 months ago) by sshaw
File MIME type: text/x-python
File size: 4600 byte(s)
pushing release to trunk
1 ##############################################################################
2 #
3 # Copyright (c) 2009-2015 by The University of Queensland
4 # http://www.uq.edu.au
5 #
6 # Primary Business: Queensland, Australia
7 # Licensed under the Open Software License version 3.0
8 # http://www.opensource.org/licenses/osl-3.0.php
9 #
10 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 # Development 2012-2013 by School of Earth Sciences
12 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 #
14 ##############################################################################
15
16 from __future__ import division, print_function
17 __copyright__="""Copyright (c) 2009-2015 by The 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 """
25 Author: Antony Hallam antony.hallam@uqconnect.edu.au
26 """
27
28 ############################################################FILE HEADER
29 # example04b.py
30 # Create either a 2D mesh for a rectangle model using pycad meshing
31 # tools.
32 #
33 #######################################################EXTERNAL MODULES
34 import matplotlib
35 matplotlib.use('agg') #It's just here for automated testing
36 from esys.pycad import * #domain constructor
37 from esys.pycad.gmsh import Design #Finite Element meshing package
38 from esys.escript import *
39 from esys.escript.unitsSI import *
40 from esys.escript.linearPDEs import LinearPDE
41 import pylab as pl #Plotting package
42 from cblib import toRegGrid, HAVE_NATGRID
43 import os
44 try:
45 # This imports the rectangle domain function
46 from esys.finley import MakeDomain#Converter for escript
47 HAVE_FINLEY = True
48 except ImportError:
49 print("Finley module not available")
50 HAVE_FINLEY = False
51
52 ########################################################MPI WORLD CHECK
53 if getMPISizeWorld() > 1:
54 import sys
55 print("This example will not run in an MPI world.")
56 sys.exit(0)
57
58 try:
59 from mpl_toolkits.natgrid import _natgrid
60 HAVE_NATGRID=True
61 except ImportError:
62 HAVE_NATGRID=False
63
64 if not HAVE_NATGRID:
65 print("This example requires that natgrid is available to matplotlib")
66
67 if HAVE_FINLEY and HAVE_NATGRID:
68 # make sure path exists
69 save_path= os.path.join("data","example04")
70 mkDir(save_path)
71
72 ################################################ESTABLISHING PARAMETERS
73 #Model Parameters
74 width=5000.0*m #width of model
75 depth=-6000.0*m #depth of model
76 kappa=2.0*W/m/K # watts/m.Kthermal conductivity
77 Ttop=20*K # top temperature
78 qin=70*Milli*W/(m*m) # bottom heat influx
79
80 ####################################################DOMAIN CONSTRUCTION
81 # Domain Corners
82 p0=Point(0.0, 0.0, 0.0)
83 p1=Point(0.0, depth, 0.0)
84 p2=Point(width, depth, 0.0)
85 p3=Point(width, 0.0, 0.0)
86 # Join corners in anti-clockwise manner.
87 l01=Line(p0, p1)
88 l12=Line(p1, p2)
89 l23=Line(p2, p3)
90 l30=Line(p3, p0)
91 # Join line segments to create domain boundary.
92 c=CurveLoop(l01, l12, l23, l30)
93 # surface
94 rec = PlaneSurface(c)
95
96 #############################################EXPORTING MESH FOR ESCRIPT
97 # Create a Design which can make the mesh
98 d=Design(dim=2, element_size=200*m)
99 # Add the subdomains and flux boundaries.
100 d.addItems(rec, PropertySet("linebottom",l12))
101 d.addItems(l01, l23, l30) # just in case we need them
102 #############################################MAKE THE DOMAIN
103 domain=MakeDomain(d, optimizeLabeling=True)
104 print("Domain has been generated ...")
105 ##############################################################SOLVE PDE
106 mypde=LinearPDE(domain)
107 mypde.getSolverOptions().setVerbosityOn()
108 mypde.setSymmetryOn()
109 mypde.setValue(A=kappa*kronecker(domain))
110 x=Solution(domain).getX()
111 mypde.setValue(q=whereZero(x[1]-sup(x[1])),r=Ttop)
112 qS=Scalar(0,FunctionOnBoundary(domain))
113 qS.setTaggedValue("linebottom",qin)
114 mypde.setValue(y=-qS)
115 print("PDE has been generated ...")
116 ###########################################################GET SOLUTION
117 T=mypde.getSolution()
118 print("PDE has been solved ...")
119 ###########################################################
120 xi, yi, zi = toRegGrid(T, nx=50, ny=50)
121 pl.matplotlib.pyplot.autumn()
122 pl.contourf(xi,yi,zi,10)
123 pl.xlabel("Horizontal Displacement (m)")
124 pl.ylabel("Depth (m)")
125 pl.savefig(os.path.join(save_path,"example04.png"))
126 print("Solution has been plotted ...")

  ViewVC Help
Powered by ViewVC 1.1.26