/[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 5288 - (show annotations)
Tue Dec 2 23:18:40 2014 UTC (4 years, 9 months ago) by sshaw
File MIME type: text/x-python
File size: 4338 byte(s)
fixing tests for cases where required domains not built
1 from __future__ import division, print_function
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 """
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
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 if HAVE_FINLEY:
59 # make sure path exists
60 save_path= os.path.join("data","example04")
61 mkDir(save_path)
62
63 ################################################ESTABLISHING PARAMETERS
64 #Model Parameters
65 width=5000.0*m #width of model
66 depth=-6000.0*m #depth of model
67 kappa=2.0*W/m/K # watts/m.Kthermal conductivity
68 Ttop=20*K # top temperature
69 qin=70*Milli*W/(m*m) # bottom heat influx
70
71 ####################################################DOMAIN CONSTRUCTION
72 # Domain Corners
73 p0=Point(0.0, 0.0, 0.0)
74 p1=Point(0.0, depth, 0.0)
75 p2=Point(width, depth, 0.0)
76 p3=Point(width, 0.0, 0.0)
77 # Join corners in anti-clockwise manner.
78 l01=Line(p0, p1)
79 l12=Line(p1, p2)
80 l23=Line(p2, p3)
81 l30=Line(p3, p0)
82 # Join line segments to create domain boundary.
83 c=CurveLoop(l01, l12, l23, l30)
84 # surface
85 rec = PlaneSurface(c)
86
87 #############################################EXPORTING MESH FOR ESCRIPT
88 # Create a Design which can make the mesh
89 d=Design(dim=2, element_size=200*m)
90 # Add the subdomains and flux boundaries.
91 d.addItems(rec, PropertySet("linebottom",l12))
92 d.addItems(l01, l23, l30) # just in case we need them
93 #############################################MAKE THE DOMAIN
94 domain=MakeDomain(d, optimizeLabeling=True)
95 print("Domain has been generated ...")
96 ##############################################################SOLVE PDE
97 mypde=LinearPDE(domain)
98 mypde.getSolverOptions().setVerbosityOn()
99 mypde.setSymmetryOn()
100 mypde.setValue(A=kappa*kronecker(domain))
101 x=Solution(domain).getX()
102 mypde.setValue(q=whereZero(x[1]-sup(x[1])),r=Ttop)
103 qS=Scalar(0,FunctionOnBoundary(domain))
104 qS.setTaggedValue("linebottom",qin)
105 mypde.setValue(y=-qS)
106 print("PDE has been generated ...")
107 ###########################################################GET SOLUTION
108 T=mypde.getSolution()
109 print("PDE has been solved ...")
110 ###########################################################
111 xi, yi, zi = toRegGrid(T, nx=50, ny=50)
112 pl.matplotlib.pyplot.autumn()
113 pl.contourf(xi,yi,zi,10)
114 pl.xlabel("Horizontal Displacement (m)")
115 pl.ylabel("Depth (m)")
116 pl.savefig(os.path.join(save_path,"example04.png"))
117 print("Solution has been plotted ...")

  ViewVC Help
Powered by ViewVC 1.1.26