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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3892 - (show annotations)
Tue Apr 10 08:57:23 2012 UTC (6 years, 11 months ago) by jfenwick
File MIME type: text/x-python
File size: 2982 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 # example04a.py
29 # Create either a 2D mesh for a rectangle model using pycad meshing
30 # tools.
31 #
32 #######################################################EXTERNAL MODULES
33 from esys.pycad import * #domain constructor
34 from esys.pycad.gmsh import Design #Finite Element meshing package
35 from esys.finley import MakeDomain #Converter for escript
36 from esys.escript import mkDir, getMPISizeWorld
37 from esys.escript.unitsSI import *
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","example04")
47 mkDir(save_path)
48
49 ################################################ESTABLISHING PARAMETERS
50 #Model Parameters
51 width=5000.0*m #width of model
52 depth=-6000.0*m #depth of model
53
54 ####################################################DOMAIN CONSTRUCTION
55 # Domain Corners
56 p0=Point(0.0, 0.0, 0.0)
57 p1=Point(0.0, depth, 0.0)
58 p2=Point(width, depth, 0.0)
59 p3=Point(width, 0.0, 0.0)
60 # Join corners in anti-clockwise manner.
61 l01=Line(p0, p1)
62 l12=Line(p1, p2)
63 l23=Line(p2, p3)
64 l30=Line(p3, p0)
65 # Join line segments to create domain boundary.
66 c=CurveLoop(l01, l12, l23, l30)
67 # surface
68 rec = PlaneSurface(c)
69
70 #############################################EXPORTING MESH FOR ESCRIPT
71 # Create a Design which can make the mesh
72 d=Design(dim=2, element_size=200*m)
73 # Add the subdomains and flux boundaries.
74 d.addItems(rec, PropertySet("linebottom",l12) )
75 d.addItems(l23, l30, l01) # just in case we need them.
76
77 # this is the name of gmsh input file generated by pycad
78 #
79 # >> gmsh example04.geo
80 #
81 # to show the mesh.
82 #
83 d.setScriptFileName(os.path.join(save_path,"example04.geo"))
84
85 # this is the name of mesh file generated gmsh. Use
86 #
87 # >> gmsh example04.msh
88 #
89 # to show the mesh.
90 #
91 d.setMeshFileName(os.path.join(save_path,"example04.msh"))
92 #
93 # make the domain:
94 #
95 domain=MakeDomain(d)
96 # Create a file that can be read back in to python with
97 # mesh=ReadMesh(fileName)
98 domain.write(os.path.join(save_path,"example04.fly"))
99
100

  ViewVC Help
Powered by ViewVC 1.1.26