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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3099 - (show annotations)
Sun Aug 22 04:35:15 2010 UTC (8 years, 9 months ago) by ahallam
File MIME type: text/x-python
File size: 5187 byte(s)
Gravitational Potential Example- Needs some tuning.
1
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
27 ############################################################FILE HEADER
28 # example09m.py
29 # Create a simple 3D model for use in example09. This is the low res
30 # mesh for illustration purposes only.
31 #
32 #######################################################EXTERNAL MODULES
33 from esys.pycad import * #domain constructor
34 from esys.pycad.extras import layer_cake
35 from esys.pycad.gmsh import Design #Finite Element meshing package
36 from esys.finley import MakeDomain #Converter for escript
37 from esys.escript import mkDir, getMPISizeWorld
38 import os
39 ########################################################MPI WORLD CHECK
40 if getMPISizeWorld() > 1:
41 import sys
42 print "This example will not run in an MPI world."
43 sys.exit(0)
44
45 # make sure path exists
46 save_path= os.path.join("data","example09m")
47 mkDir(save_path)
48
49 ################################################ESTABLISHING PARAMETERS
50 #Model Parameters
51 xwidth=200.0 #x width of model
52 ywidth=200.0 #y width of model
53 depth=100.0 #depth of model
54 intf=depth/2. #Depth of the interface.
55 element_size=4.0
56
57 ####################################################DOMAIN CONSTRUCTION
58 # Domain Corners
59 p0=Point(0.0, 0.0, 0.0)
60 p1=Point(xwidth, 0.0, 0.0)
61 p2=Point(xwidth, ywidth, 0.0)
62 p3=Point(0.0, ywidth, 0.0)
63 p4=Point(0.0, ywidth, depth)
64 p5=Point(0.0, 0.0, depth)
65 p6=Point(xwidth, 0.0, depth)
66 p7=Point(xwidth, ywidth, depth)
67 # Join corners in anti-clockwise manner.
68 l01=Line(p0, p1)
69 l12=Line(p1, p2)
70 l23=Line(p2, p3)
71 l30=Line(p3, p0)
72 l56=Line(p5, p6)
73 l67=Line(p6, p7)
74 l74=Line(p7, p4)
75 l45=Line(p4, p5)
76
77 # Join line segments to create domain boundaries and then surfaces
78 ctop=CurveLoop(l01, l12, l23, l30); stop=PlaneSurface(ctop)
79 cbot=CurveLoop(-l67, -l56, -l45, -l74); sbot=PlaneSurface(cbot)
80
81 # for each side
82 ip0=Point(0.0, 0.0, intf)
83 ip1=Point(xwidth, 0.0, intf)
84 ip2=Point(xwidth, ywidth, intf)
85 ip3=Point(0.0, ywidth, intf)
86
87 linte_ar=[]; #lines for vertical edges
88 linhe_ar=[]; #lines for horizontal edges
89 linte_ar.append(Line(p0,ip0))
90 linte_ar.append(Line(ip0,p5))
91 linte_ar.append(Line(p1,ip1))
92 linte_ar.append(Line(ip1,p6))
93 linte_ar.append(Line(p2,ip2))
94 linte_ar.append(Line(ip2,p7))
95 linte_ar.append(Line(p3,ip3))
96 linte_ar.append(Line(ip3,p4))
97
98 linhe_ar.append(Line(ip0,ip1))
99 linhe_ar.append(Line(ip1,ip2))
100 linhe_ar.append(Line(ip2,ip3))
101 linhe_ar.append(Line(ip3,ip0))
102
103 cintfa_ar=[]; cintfb_ar=[] #curveloops for above and below interface on sides
104 cintfa_ar.append(CurveLoop(linte_ar[0],linhe_ar[0],-linte_ar[2],-l01))
105 cintfa_ar.append(CurveLoop(linte_ar[2],linhe_ar[1],-linte_ar[4],-l12))
106 cintfa_ar.append(CurveLoop(linte_ar[4],linhe_ar[2],-linte_ar[6],-l23))
107 cintfa_ar.append(CurveLoop(linte_ar[6],linhe_ar[3],-linte_ar[0],-l30))
108
109 cintfb_ar.append(CurveLoop(linte_ar[1],l56,-linte_ar[3],-linhe_ar[0]))
110 cintfb_ar.append(CurveLoop(linte_ar[3],l67,-linte_ar[5],-linhe_ar[1]))
111 cintfb_ar.append(CurveLoop(linte_ar[5],l74,-linte_ar[7],-linhe_ar[2]))
112 cintfb_ar.append(CurveLoop(linte_ar[7],l45,-linte_ar[1],-linhe_ar[3]))
113
114 sintfa_ar=[PlaneSurface(cintfa_ar[i]) for i in range(0,4)]
115 sintfb_ar=[PlaneSurface(cintfb_ar[i]) for i in range(0,4)]
116
117 sintf=PlaneSurface(CurveLoop(*tuple(linhe_ar)))
118
119 vintfa=Volume(SurfaceLoop(stop,-sintf,*tuple(sintfa_ar)))
120 vintfb=Volume(SurfaceLoop(sbot,sintf,*tuple(sintfb_ar)))
121
122 #############################################EXPORTING MESH FOR ESCRIPT
123 # Create a Design which can make the mesh
124 d=Design(dim=3, element_size=element_size, order=2)
125
126 d.addItems(PropertySet('vintfa',vintfa))
127 d.addItems(PropertySet('vintfb',vintfb))
128 d.addItems(PropertySet('stop',stop))
129 d.addItems(PropertySet('sbot',sbot))
130
131 d.setScriptFileName(os.path.join(save_path,"example09m.geo"))
132 d.setMeshFileName(os.path.join(save_path,"example09m.msh"))
133 #
134 # make the finley domain:
135 #
136 domain=MakeDomain(d)
137 # Create a file that can be read back in to python with
138 # mesh=ReadMesh(fileName)
139 domain.write(os.path.join(save_path,"example09m.fly"))
140
141 intfaces=[10,30,50,55,80,100,200,250,400,500]
142
143 # Specify the domain.
144 #domaindes=Design(dim=3,element_size=element_size,order=2)
145 #cmplx_domain=layer_cake(domaindes,xwidth,ywidth,intfaces)
146 #cmplx_domain.setScriptFileName(os.path.join(save_path,"example09lc.geo"))
147 #cmplx_domain.setMeshFileName(os.path.join(save_path,"example09lc.msh"))
148 #dcmplx=MakeDomain(cmplx_domain)
149 #dcmplx.write(os.path.join(save_path,"example09lc.fly"))
150
151
152
153

  ViewVC Help
Powered by ViewVC 1.1.26