/[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 932 - (show annotations)
Fri Jan 19 09:27:15 2007 UTC (12 years, 7 months ago) by gross
File MIME type: text/x-python
File size: 4752 byte(s)
Design added. The loops tests are switched off to allow faults.
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 ISO="iso"
34 TRI="tri"
35 ANISO="aniso"
36 NETGEN="netgen"
37 TETGEN="tetgen"
38 def __init__(self,dim=3,element_size=1.,order=1,keep_files=False):
39 """
40 initializes the gmsh design
41
42 @param dim: patial dimension
43 @element_size: global element size
44 @order: element order
45 @keep_files: flag to keep work files.
46 """
47 design.Design.__init__(self,dim=dim,element_size=element_size,order=order,keep_files=keep_files)
48 self.setScriptFileName()
49 self.setMeshFileName()
50 self.setOptions()
51 def setScriptFileName(self,name=None):
52 """
53 set the filename for the gmsh input script. if no name is given a name with extension geo is generated.
54 """
55 if name == None:
56 self.__scriptname=tempfile.mkstemp(suffix=".geo")[1]
57 else:
58 self.__scriptname=name
59 self.setKeepFilesOn()
60 def getScriptFileName(self):
61 """
62 returns the name of the file for the gmsh script
63 """
64 return self.__scriptname
65 def setMeshFileName(self, name=None):
66 """
67 sets the name for the gmsh mesh file. if no name is given a name with extension msh is generated.
68 """
69 if name == None:
70 self.__mshname=tempfile.mkstemp(suffix=".msh")[1]
71 else:
72 self.__mshname=name
73 self.setKeepFilesOn()
74 def getMeshFileName(self):
75 """
76 returns the name of the file for the gmsh msh
77 """
78 return self.__mshname
79 def setOptions(self,algorithm=None,optimize_quality=True,smoothing=3):
80 """
81 sets options for the mesh generator
82 """
83 if algorithm==None: algorithm=self.ISO
84 self.__algo=algorithm
85 self.__optimize_quality=optimize_quality
86 self.__smoothing=smoothing
87 def __del__(self):
88 """
89 clean up
90 """
91 if not self.keepFiles():
92 os.unlink(self.getScriptFileName())
93 os.unlink(self.getMeshFileName())
94 def getScriptString(self):
95 """
96 returns the gmsh script to generate the mesh
97 """
98 prim=self.getAllPrimitives()
99 out="// generated by esys.pycad\n"
100 for p in prim:
101 out+=p.getGmshCommand(self.getElementSize())+"\n"
102 return out
103 def getCommandString(self):
104 """
105 returns the gmsh comand
106 """
107 if self.__optimize_quality:
108 opt="-optimize "
109 else:
110 opt=""
111 exe="gmsh -%s -algo %s -smooth %s %s -v 0 -order %s -o %s %s"%(self.getDim(),
112 self.__algo,
113 self.__smoothing,
114 opt,
115 self.getElementOrder(),
116 self.getMeshFileName(),
117 self.getScriptFileName())
118 return exe
119 def getMeshHandler(self):
120 """
121 returns a handle to a mesh meshing the design. In the current implementation
122 a mesh file name in gmsh format is returned.
123 """
124 open(self.getScriptFileName(),"w").write(self.getScriptString())
125 os.system(self.getCommandString())
126 return self.getMeshFileName()
127 # to finley
128 def MakeDomain(design,integrationOrder=-1,optimizeLabeling=True, richFaceElements=False):
129 mshname=design.getMeshHandler()
130 print "MakeDomain :",mshname
131 1/0
132 convertGmshToFinley(open(mshname,"r"),open(filename,"w"),dim=self.getDim())
133 if not self.keepTmpFiles(): os.unlink(mshname)
134 return exe
135 line=gmsh_file.readline().split()
136 while len(line)>0:
137 print line
138 line=gmsh_file.readline().split()

  ViewVC Help
Powered by ViewVC 1.1.26