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

Annotation of /trunk/doc/examples/cookbook/heatrefraction_mesher001.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2706 - (hide annotations)
Fri Oct 2 02:15:04 2009 UTC (9 years, 9 months ago) by jfenwick
File MIME type: text/x-python
File size: 4372 byte(s)
Perhaps this will stop the cookbook from hating me.


1 ahallam 2588
2     ########################################################
3     #
4 jfenwick 2667 # Copyright (c) 2009 by University of Queensland
5 ahallam 2588 # 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 jfenwick 2667 __copyright__="""Copyright (c) 2009 by University of Queensland
15 ahallam 2588 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 ahallam 2658 ############################################################FILE HEADER
27     # heatrefraction_mesher001.py
28     # Create either a 2D syncline or anticline model using pycad meshing
29     # tools.
30    
31     #######################################################EXTERNAL MODULES
32 ahallam 2597 from esys.pycad import * #domain constructor
33     from esys.pycad.gmsh import Design #Finite Element meshing package
34     from esys.finley import MakeDomain #Converter for escript
35     import os #file path tool
36     import numpy as np #numerial python for arrays
37     from math import * # math package
38 jfenwick 2667
39 ahallam 2597 #used to construct polygons for plotting from pycad
40 jfenwick 2706 from cblib1 import getLoopCoords, needdirs
41 ahallam 2588
42 jfenwick 2667
43    
44 ahallam 2658 #################################################ESTABLISHING VARIABLES
45 ahallam 2597 #set modal to 1 for a syncline or -1 for an anticline structural
46     #configuration
47 ahallam 2672 modal=-1
48 ahallam 2588
49 ahallam 2597 # the folder to put our outputs in, leave blank "" for script path -
50     # note this folder path must exist to work
51 ahallam 2658 save_path= os.path.join("data","heatrefrac001")
52 jfenwick 2648 needdirs([save_path])
53 ahallam 2597
54 ahallam 2658 ################################################ESTABLISHING PARAMETERS
55 ahallam 2634 #Model Parameters
56     width=5000.0 #width of model
57     depth=-6000.0 #depth of model
58     sspl=51 #number of discrete points in spline
59     dsp=width/(sspl-1) #dx of spline steps for width
60     dep_sp=2500.0 #avg depth of spline
61     h_sp=1500.0 #heigh of spline
62     orit=-1.0 #orientation of spline 1.0=>up -1.0=>down
63    
64 ahallam 2658 ####################################################DOMAIN CONSTRUCTION
65     # Domain Corners
66 ahallam 2634 p0=Point(0.0, 0.0, 0.0)
67     p1=Point(0.0, depth, 0.0)
68     p2=Point(width, depth, 0.0)
69     p3=Point(width, 0.0, 0.0)
70 ahallam 2658 # Join corners in anti-clockwise manner.
71 ahallam 2588 l01=Line(p0, p1)
72     l12=Line(p1, p2)
73     l23=Line(p2, p3)
74     l30=Line(p3, p0)
75 ahallam 2658 # Join line segments to create domain boundary.
76 ahallam 2588 c=CurveLoop(l01, l12, l23, l30)
77 ahallam 2658 # Generate Material Boundary
78 ahallam 2634 x=[ Point(i*dsp\
79     ,-dep_sp+modal*orit*h_sp*cos(pi*i*dsp/dep_sp+pi))\
80     for i in range(0,sspl)\
81     ]
82 ahallam 2588 mysp = Spline(*tuple(x))
83 ahallam 2658 # Start and end of material boundary.
84 ahallam 2588 x1=Spline.getStartPoint(mysp)
85     x2=Spline.getEndPoint(mysp)
86    
87 ahallam 2658 # Create TOP BLOCK
88     # lines
89 ahallam 2588 tbl1=Line(p0,x1)
90     tbl2=mysp
91     tbl3=Line(x2,p3)
92 ahallam 2658 # curve
93 ahallam 2588 tblockloop = CurveLoop(tbl1,tbl2,tbl3,l30)
94 ahallam 2658 # surface
95 ahallam 2588 tblock = PlaneSurface(tblockloop)
96 ahallam 2658 # polygon for python plotting
97 ahallam 2597 tpg = getLoopCoords(tblockloop)
98     np.savetxt(os.path.join(save_path,"toppg"),tpg,delimiter=" ")
99 ahallam 2588
100 ahallam 2658 # Create BOTTOM BLOCK
101     # lines
102 ahallam 2588 bbl1=Line(x1,p1)
103     bbl3=Line(p2,x2)
104     bbl4=-mysp
105 ahallam 2658 # curve
106 ahallam 2588 bblockloop = CurveLoop(bbl1,l12,bbl3,bbl4)
107 ahallam 2658 # surface
108 ahallam 2588 bblock = PlaneSurface(bblockloop)
109    
110 ahallam 2597 #clockwise check as splines must be set as polygons in the point order
111     #they were created. Otherwise get a line across plot.
112 ahallam 2588 bblockloop2=CurveLoop(mysp,Line(x2,p2),Line(p2,p1),Line(p1,x1))
113 ahallam 2597 bpg = getLoopCoords(bblockloop2)
114     np.savetxt(os.path.join(save_path,"botpg"),bpg,delimiter=" ")
115 ahallam 2588
116 ahallam 2658 #############################################EXPORTING MESH FOR ESCRIPT
117 ahallam 2588 # Create a Design which can make the mesh
118     d=Design(dim=2, element_size=200)
119 ahallam 2597 # Add the subdomains and flux boundaries.
120 ahallam 2658 d.addItems(PropertySet("top",tblock),PropertySet("bottom",bblock),\
121     PropertySet("linebottom",l12))
122 ahallam 2588 # Create the geometry, mesh and Escript domain
123 ahallam 2658 d.setScriptFileName(os.path.join(save_path,\
124     "heatrefraction_mesh001.geo"))
125 ahallam 2588
126 ahallam 2597 d.setMeshFileName(os.path.join(save_path,"heatrefraction_mesh001.msh"))
127 ahallam 2658 domain=MakeDomain(d, integrationOrder=-1, reducedIntegrationOrder=-1,\
128     optimizeLabeling=True)
129     # Create a file that can be read back in to python with
130     # mesh=ReadMesh(fileName)
131 ahallam 2597 domain.write(os.path.join(save_path,"heatrefraction_mesh001.fly"))
132 ahallam 2588
133    

  ViewVC Help
Powered by ViewVC 1.1.26