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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1003 - (hide annotations)
Thu Mar 1 01:53:37 2007 UTC (15 years, 5 months ago) by gross
File MIME type: text/x-python
File size: 4573 byte(s)
small fix on the finley gmsh reader for the case of no face elements.
1 gross 932 # $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 gross 999 DELAUNAY="iso"
34 gross 932 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 ksteube 990 @param element_size: global element size
42     @param order: element order
43     @param keep_files: flag to keep work files.
44 gross 932 """
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 gross 1003 def setOptions(self,algorithm=None,optimize_quality=True,smoothing=1, curvature_based_element_size=False):
78 gross 932 """
79     sets options for the mesh generator
80     """
81 gross 999 if algorithm==None: algorithm=self.DELAUNAY
82 gross 1003 self.__curvature_based_element_size=curvature_based_element_size
83 gross 932 self.__algo=algorithm
84     self.__optimize_quality=optimize_quality
85     self.__smoothing=smoothing
86     def __del__(self):
87     """
88     clean up
89     """
90     if not self.keepFiles():
91     os.unlink(self.getScriptFileName())
92     os.unlink(self.getMeshFileName())
93     def getScriptString(self):
94     """
95     returns the gmsh script to generate the mesh
96     """
97     prim=self.getAllPrimitives()
98     out="// generated by esys.pycad\n"
99     for p in prim:
100     out+=p.getGmshCommand(self.getElementSize())+"\n"
101     return out
102     def getCommandString(self):
103     """
104     returns the gmsh comand
105     """
106     if self.__optimize_quality:
107     opt="-optimize "
108     else:
109     opt=""
110 gross 1003 if self.__curvature_based_element_size:
111     clcurv="-clcurv "
112     else:
113     clcurv=""
114    
115     exe="gmsh -%s -algo %s %s-smooth %s %s-v 0 -order %s -o %s %s"%(self.getDim(),
116 gross 932 self.__algo,
117 gross 1003 clcurv,
118 gross 932 self.__smoothing,
119     opt,
120     self.getElementOrder(),
121     self.getMeshFileName(),
122     self.getScriptFileName())
123     return exe
124     def getMeshHandler(self):
125     """
126     returns a handle to a mesh meshing the design. In the current implementation
127     a mesh file name in gmsh format is returned.
128     """
129     open(self.getScriptFileName(),"w").write(self.getScriptString())
130     os.system(self.getCommandString())
131     return self.getMeshFileName()

  ViewVC Help
Powered by ViewVC 1.1.26