/[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 4154 - (show annotations)
Tue Jan 22 09:30:23 2013 UTC (6 years, 8 months ago) by jfenwick
File MIME type: text/x-python
File size: 5604 byte(s)
Round 1 of copyright fixes
1
2 ##############################################################################
3 #
4 # Copyright (c) 2009-2013 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 since 2012 by School of Earth Sciences
13 #
14 ##############################################################################
15
16 __copyright__="""Copyright (c) 2009-2013 by University of Queensland
17 http://www.uq.edu.au
18 Primary Business: Queensland, Australia"""
19 __license__="""Licensed under the Open Software License version 3.0
20 http://www.opensource.org/licenses/osl-3.0.php"""
21 __url__="https://launchpad.net/escript-finley"
22
23 """
24 Author: Antony Hallam antony.hallam@uqconnect.edu.au
25 """
26
27
28 ############################################################FILE HEADER
29 # example09m.py
30 # Create a simple 3D model for use in example09. This is the low res
31 # mesh for illustration purposes only.
32 #
33 #######################################################EXTERNAL MODULES
34 from esys.pycad import * #domain constructor
35 from esys.pycad.extras import layer_cake
36 from esys.pycad.gmsh import Design #Finite Element meshing package
37 from esys.finley import MakeDomain #Converter for escript
38 from esys.escript import mkDir, getMPISizeWorld
39 import os
40 import numpy as np
41 ########################################################MPI WORLD CHECK
42 if getMPISizeWorld() > 1:
43 import sys
44 print("This example will not run in an MPI world.")
45 sys.exit(0)
46
47 # make sure path exists
48 save_path= os.path.join("data","example09m")
49 mkDir(save_path)
50
51 ################################################ESTABLISHING PARAMETERS
52 # Time related variables.
53 testing=True
54 if testing:
55 print('This script is currently optioned for testing..')
56 print("Try changing the testing variable to False for more iterations.")
57 xwidth=40.
58 ywidth=40.
59 depth=20.
60 else:
61 #Model Parameters
62 xwidth=100.0 #x width of model
63 ywidth=100.0 #y width of model
64 depth=50.0 #depth of model
65
66 intf=depth/2. #Depth of the interface.
67 element_size=4.0
68
69 ####################################################DOMAIN CONSTRUCTION
70 # Domain Corners
71 p0=Point(0.0, 0.0, 0.0)
72 p1=Point(xwidth, 0.0, 0.0)
73 p2=Point(xwidth, ywidth, 0.0)
74 p3=Point(0.0, ywidth, 0.0)
75 p4=Point(0.0, ywidth, depth)
76 p5=Point(0.0, 0.0, depth)
77 p6=Point(xwidth, 0.0, depth)
78 p7=Point(xwidth, ywidth, depth)
79 # Join corners in anti-clockwise manner.
80 l01=Line(p0, p1)
81 l12=Line(p1, p2)
82 l23=Line(p2, p3)
83 l30=Line(p3, p0)
84 l56=Line(p5, p6)
85 l67=Line(p6, p7)
86 l74=Line(p7, p4)
87 l45=Line(p4, p5)
88
89 # Join line segments to create domain boundaries and then surfaces
90 ctop=CurveLoop(l01, l12, l23, l30); stop=PlaneSurface(ctop)
91 cbot=CurveLoop(-l67, -l56, -l45, -l74); sbot=PlaneSurface(cbot)
92
93 # for each side
94 ip0=Point(0.0, 0.0, intf)
95 ip1=Point(xwidth, 0.0, intf)
96 ip2=Point(xwidth, ywidth, intf)
97 ip3=Point(0.0, ywidth, intf)
98
99 linte_ar=[]; #lines for vertical edges
100 linhe_ar=[]; #lines for horizontal edges
101 linte_ar.append(Line(p0,ip0))
102 linte_ar.append(Line(ip0,p5))
103 linte_ar.append(Line(p1,ip1))
104 linte_ar.append(Line(ip1,p6))
105 linte_ar.append(Line(p2,ip2))
106 linte_ar.append(Line(ip2,p7))
107 linte_ar.append(Line(p3,ip3))
108 linte_ar.append(Line(ip3,p4))
109
110 linhe_ar.append(Line(ip0,ip1))
111 linhe_ar.append(Line(ip1,ip2))
112 linhe_ar.append(Line(ip2,ip3))
113 linhe_ar.append(Line(ip3,ip0))
114
115 cintfa_ar=[]; cintfb_ar=[] #curveloops for above and below interface on sides
116 cintfa_ar.append(CurveLoop(linte_ar[0],linhe_ar[0],-linte_ar[2],-l01))
117 cintfa_ar.append(CurveLoop(linte_ar[2],linhe_ar[1],-linte_ar[4],-l12))
118 cintfa_ar.append(CurveLoop(linte_ar[4],linhe_ar[2],-linte_ar[6],-l23))
119 cintfa_ar.append(CurveLoop(linte_ar[6],linhe_ar[3],-linte_ar[0],-l30))
120
121 cintfb_ar.append(CurveLoop(linte_ar[1],l56,-linte_ar[3],-linhe_ar[0]))
122 cintfb_ar.append(CurveLoop(linte_ar[3],l67,-linte_ar[5],-linhe_ar[1]))
123 cintfb_ar.append(CurveLoop(linte_ar[5],l74,-linte_ar[7],-linhe_ar[2]))
124 cintfb_ar.append(CurveLoop(linte_ar[7],l45,-linte_ar[1],-linhe_ar[3]))
125
126 sintfa_ar=[PlaneSurface(cintfa_ar[i]) for i in range(0,4)]
127 sintfb_ar=[PlaneSurface(cintfb_ar[i]) for i in range(0,4)]
128
129 sintf=PlaneSurface(CurveLoop(*tuple(linhe_ar)))
130
131 vintfa=Volume(SurfaceLoop(stop,-sintf,*tuple(sintfa_ar)))
132 vintfb=Volume(SurfaceLoop(sbot,sintf,*tuple(sintfb_ar)))
133
134 #############################################EXPORTING MESH FOR ESCRIPT
135 # Create a Design which can make the mesh
136 d=Design(dim=3, element_size=element_size, order=2)
137
138 d.addItems(PropertySet('vintfa',vintfa))
139 d.addItems(PropertySet('vintfb',vintfb))
140 d.addItems(PropertySet('stop',stop))
141 d.addItems(PropertySet('sbot',sbot))
142
143 d.setScriptFileName(os.path.join(save_path,"example09m.geo"))
144 d.setMeshFileName(os.path.join(save_path,"example09m.msh"))
145 #
146 # make the domain:
147 #
148 domain=MakeDomain(d)
149 # Create a file that can be read back in to python with
150 # mesh=ReadMesh(fileName)
151 domain.write(os.path.join(save_path,"example09m.fly"))
152
153 if testing:
154 intfaces=np.array([10,30,50,55,80,100,200,250,400])/100.
155 else:
156 intfaces=np.array([10,30,50,55,80,100,200,250,400])/10.
157
158 # Specify the domain.
159 domaindes=Design(dim=3,element_size=element_size,order=2)
160 cmplx_domain=layer_cake(domaindes,xwidth,ywidth,intfaces)
161 cmplx_domain.setScriptFileName(os.path.join(save_path,"example09lc.geo"))
162 cmplx_domain.setMeshFileName(os.path.join(save_path,"example09lc.msh"))
163 dcmplx=MakeDomain(cmplx_domain)
164 dcmplx.write(os.path.join(save_path,"example09lc.fly"))
165
166
167
168

  ViewVC Help
Powered by ViewVC 1.1.26