/[escript]/trunk/pycad/py_src/gmsh.py
ViewVC logotype

Contents of /trunk/pycad/py_src/gmsh.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 999 - (show annotations)
Tue Feb 27 08:12:37 2007 UTC (14 years, 6 months ago) by gross
File MIME type: text/x-python
File size: 4271 byte(s)
start to put some pycad documentation into the users guide
1 # $Id:$
2
3 """
4 mesh generation using gmsh
5
6 @var __author__: name of author
7 @var __copyright__: copyrights
8 @var __license__: licence agreement
9 @var __url__: url entry point on documentation
10 @var __version__: version
11 @var __date__: date of the version
12 """
13
14
15 __author__="Lutz Gross, l.gross@uq.edu.au"
16 __copyright__=""" Copyright (c) 2007 by ACcESS MNRF
17 http://www.access.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__="http://www.iservo.edu.au/esys/escript"
22 __version__="$Revision:$"
23 __date__="$Date:$"
24
25 import design
26 import tempfile
27 import os
28
29 class Design(design.Design):
30 """
31 design fo gmsh
32 """
33 DELAUNAY="iso"
34 NETGEN="netgen"
35 TETGEN="tetgen"
36 def __init__(self,dim=3,element_size=1.,order=1,keep_files=False):
37 """
38 initializes the gmsh design
39
40 @param dim: patial dimension
41 @param element_size: global element size
42 @param order: element order
43 @param keep_files: flag to keep work files.
44 """
45 design.Design.__init__(self,dim=dim,element_size=element_size,order=order,keep_files=keep_files)
46 self.setScriptFileName()
47 self.setMeshFileName()
48 self.setOptions()
49 def setScriptFileName(self,name=None):
50 """
51 set the filename for the gmsh input script. if no name is given a name with extension geo is generated.
52 """
53 if name == None:
54 self.__scriptname=tempfile.mkstemp(suffix=".geo")[1]
55 else:
56 self.__scriptname=name
57 self.setKeepFilesOn()
58 def getScriptFileName(self):
59 """
60 returns the name of the file for the gmsh script
61 """
62 return self.__scriptname
63 def setMeshFileName(self, name=None):
64 """
65 sets the name for the gmsh mesh file. if no name is given a name with extension msh is generated.
66 """
67 if name == None:
68 self.__mshname=tempfile.mkstemp(suffix=".msh")[1]
69 else:
70 self.__mshname=name
71 self.setKeepFilesOn()
72 def getMeshFileName(self):
73 """
74 returns the name of the file for the gmsh msh
75 """
76 return self.__mshname
77 def setOptions(self,algorithm=None,optimize_quality=True,smoothing=1):
78 """
79 sets options for the mesh generator
80 """
81 if algorithm==None: algorithm=self.DELAUNAY
82 self.__algo=algorithm
83 self.__optimize_quality=optimize_quality
84 self.__smoothing=smoothing
85 def __del__(self):
86 """
87 clean up
88 """
89 if not self.keepFiles():
90 os.unlink(self.getScriptFileName())
91 os.unlink(self.getMeshFileName())
92 def getScriptString(self):
93 """
94 returns the gmsh script to generate the mesh
95 """
96 prim=self.getAllPrimitives()
97 out="// generated by esys.pycad\n"
98 for p in prim:
99 out+=p.getGmshCommand(self.getElementSize())+"\n"
100 return out
101 def getCommandString(self):
102 """
103 returns the gmsh comand
104 """
105 if self.__optimize_quality:
106 opt="-optimize "
107 else:
108 opt=""
109 exe="gmsh -%s -algo %s -clcurv -smooth %s %s -v 0 -order %s -o %s %s"%(self.getDim(),
110 self.__algo,
111 self.__smoothing,
112 opt,
113 self.getElementOrder(),
114 self.getMeshFileName(),
115 self.getScriptFileName())
116 return exe
117 def getMeshHandler(self):
118 """
119 returns a handle to a mesh meshing the design. In the current implementation
120 a mesh file name in gmsh format is returned.
121 """
122 open(self.getScriptFileName(),"w").write(self.getScriptString())
123 os.system(self.getCommandString())
124 return self.getMeshFileName()

  ViewVC Help
Powered by ViewVC 1.1.26