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



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 import numpy as np
40 ########################################################MPI WORLD CHECK
41 if getMPISizeWorld() > 1:
42 import sys
43 print("This example will not run in an MPI world.")
44 sys.exit(0)
45
46 # make sure path exists
47 save_path= os.path.join("data","example09m")
48 mkDir(save_path)
49
50 ################################################ESTABLISHING PARAMETERS
51 # Time related variables.
52 testing=True
53 if testing:
54 print('This script is currently optioned for testing..')
55 print("Try changing the testing variable to False for more iterations.")
56 xwidth=40.
57 ywidth=40.
58 depth=20.
59 else:
60 #Model Parameters
61 xwidth=100.0 #x width of model
62 ywidth=100.0 #y width of model
63 depth=50.0 #depth of model
64
65 intf=depth/2. #Depth of the interface.
66 element_size=4.0
67
68 ####################################################DOMAIN CONSTRUCTION
69 # Domain Corners
70 p0=Point(0.0, 0.0, 0.0)
71 p1=Point(xwidth, 0.0, 0.0)
72 p2=Point(xwidth, ywidth, 0.0)
73 p3=Point(0.0, ywidth, 0.0)
74 p4=Point(0.0, ywidth, depth)
75 p5=Point(0.0, 0.0, depth)
76 p6=Point(xwidth, 0.0, depth)
77 p7=Point(xwidth, ywidth, depth)
78 # Join corners in anti-clockwise manner.
79 l01=Line(p0, p1)
80 l12=Line(p1, p2)
81 l23=Line(p2, p3)
82 l30=Line(p3, p0)
83 l56=Line(p5, p6)
84 l67=Line(p6, p7)
85 l74=Line(p7, p4)
86 l45=Line(p4, p5)
87
88 # Join line segments to create domain boundaries and then surfaces
89 ctop=CurveLoop(l01, l12, l23, l30); stop=PlaneSurface(ctop)
90 cbot=CurveLoop(-l67, -l56, -l45, -l74); sbot=PlaneSurface(cbot)
91
92 # for each side
93 ip0=Point(0.0, 0.0, intf)
94 ip1=Point(xwidth, 0.0, intf)
95 ip2=Point(xwidth, ywidth, intf)
96 ip3=Point(0.0, ywidth, intf)
97
98 linte_ar=[]; #lines for vertical edges
99 linhe_ar=[]; #lines for horizontal edges
100 linte_ar.append(Line(p0,ip0))
101 linte_ar.append(Line(ip0,p5))
102 linte_ar.append(Line(p1,ip1))
103 linte_ar.append(Line(ip1,p6))
104 linte_ar.append(Line(p2,ip2))
105 linte_ar.append(Line(ip2,p7))
106 linte_ar.append(Line(p3,ip3))
107 linte_ar.append(Line(ip3,p4))
108
109 linhe_ar.append(Line(ip0,ip1))
110 linhe_ar.append(Line(ip1,ip2))
111 linhe_ar.append(Line(ip2,ip3))
112 linhe_ar.append(Line(ip3,ip0))
113
114 cintfa_ar=[]; cintfb_ar=[] #curveloops for above and below interface on sides
115 cintfa_ar.append(CurveLoop(linte_ar[0],linhe_ar[0],-linte_ar[2],-l01))
116 cintfa_ar.append(CurveLoop(linte_ar[2],linhe_ar[1],-linte_ar[4],-l12))
117 cintfa_ar.append(CurveLoop(linte_ar[4],linhe_ar[2],-linte_ar[6],-l23))
118 cintfa_ar.append(CurveLoop(linte_ar[6],linhe_ar[3],-linte_ar[0],-l30))
119
120 cintfb_ar.append(CurveLoop(linte_ar[1],l56,-linte_ar[3],-linhe_ar[0]))
121 cintfb_ar.append(CurveLoop(linte_ar[3],l67,-linte_ar[5],-linhe_ar[1]))
122 cintfb_ar.append(CurveLoop(linte_ar[5],l74,-linte_ar[7],-linhe_ar[2]))
123 cintfb_ar.append(CurveLoop(linte_ar[7],l45,-linte_ar[1],-linhe_ar[3]))
124
125 sintfa_ar=[PlaneSurface(cintfa_ar[i]) for i in range(0,4)]
126 sintfb_ar=[PlaneSurface(cintfb_ar[i]) for i in range(0,4)]
127
128 sintf=PlaneSurface(CurveLoop(*tuple(linhe_ar)))
129
130 vintfa=Volume(SurfaceLoop(stop,-sintf,*tuple(sintfa_ar)))
131 vintfb=Volume(SurfaceLoop(sbot,sintf,*tuple(sintfb_ar)))
132
133 #############################################EXPORTING MESH FOR ESCRIPT
134 # Create a Design which can make the mesh
135 d=Design(dim=3, element_size=element_size, order=2)
136
137 d.addItems(PropertySet('vintfa',vintfa))
138 d.addItems(PropertySet('vintfb',vintfb))
139 d.addItems(PropertySet('stop',stop))
140 d.addItems(PropertySet('sbot',sbot))
141
142 d.setScriptFileName(os.path.join(save_path,"example09m.geo"))
143 d.setMeshFileName(os.path.join(save_path,"example09m.msh"))
144 #
145 # make the domain:
146 #
147 domain=MakeDomain(d)
148 # Create a file that can be read back in to python with
149 # mesh=ReadMesh(fileName)
150 domain.write(os.path.join(save_path,"example09m.fly"))
151
152 if testing:
153 intfaces=np.array([10,30,50,55,80,100,200,250,400])/100.
154 else:
155 intfaces=np.array([10,30,50,55,80,100,200,250,400])/10.
156
157 # Specify the domain.
158 domaindes=Design(dim=3,element_size=element_size,order=2)
159 cmplx_domain=layer_cake(domaindes,xwidth,ywidth,intfaces)
160 cmplx_domain.setScriptFileName(os.path.join(save_path,"example09lc.geo"))
161 cmplx_domain.setMeshFileName(os.path.join(save_path,"example09lc.msh"))
162 dcmplx=MakeDomain(cmplx_domain)
163 dcmplx.write(os.path.join(save_path,"example09lc.fly"))
164
165
166
167

  ViewVC Help
Powered by ViewVC 1.1.26