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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2548 by jfenwick, Mon Jul 20 06:20:06 2009 UTC revision 2700 by gross, Wed Sep 30 08:28:55 2009 UTC
# Line 11  Line 11 
11  #  #
12  ########################################################  ########################################################
13    
14  __copyright__="""Copyright (c) 2003-2008 by University of Queensland  __copyright__="""Copyright (c) 2003-2009 by University of Queensland
15  Earth Systems Science Computational Center (ESSCC)  Earth Systems Science Computational Center (ESSCC)
16  http://www.uq.edu.au/esscc  http://www.uq.edu.au/esscc
17  Primary Business: Queensland, Australia"""  Primary Business: Queensland, Australia"""
# Line 22  __url__="https://launchpad.net/escript-f Line 22  __url__="https://launchpad.net/escript-f
22  """  """
23  mesh generation using gmsh  mesh generation using gmsh
24    
25  @var __author__: name of author  :var __author__: name of author
26  @var __copyright__: copyrights  :var __copyright__: copyrights
27  @var __license__: licence agreement  :var __license__: licence agreement
28  @var __url__: url entry point on documentation  :var __url__: url entry point on documentation
29  @var __version__: version  :var __version__: version
30  @var __date__: date of the version  :var __date__: date of the version
31  """  """
32    
33  __author__="Lutz Gross, l.gross@uq.edu.au"  __author__="Lutz Gross, l.gross@uq.edu.au"
# Line 51  class Design(design.Design): Line 51  class Design(design.Design):
51         """         """
52         Initializes the gmsh design.         Initializes the gmsh design.
53    
54         @param dim: spatial dimension         :param dim: spatial dimension
55         @param element_size: global element size         :param element_size: global element size
56         @param order: element order         :param order: element order
57         @param keep_files: flag to keep work files         :param keep_files: flag to keep work files
58         """         """
59         design.Design.__init__(self,dim=dim,element_size=element_size,order=order,keep_files=keep_files)         design.Design.__init__(self,dim=dim,element_size=element_size,order=order,keep_files=keep_files)
60         self.setScriptFileName()         self.setScriptFileName()
# Line 127  class Design(design.Design): Line 127  class Design(design.Design):
127          else:          else:
128                opt=""                opt=""
129    
130          exe="gmsh -format msh -%s -algo %s -smooth %s %s-v 0 -order %s -o %s %s" % (          exe="gmsh -format msh -%s -algo %s -smooth %s %s-v 3 -order %s -o %s %%s" % (
131                  self.getDim(), self.__algo, self.__smoothing, opt,                  self.getDim(), self.__algo, self.__smoothing, opt,
132                  self.getElementOrder(), self.getMeshFileName(),                  self.getElementOrder(), self.getMeshFileName())
                 self.getScriptFileName())  
133          return exe          return exe
134        def getScriptHandler(self):
135            """
136            Returns a handler to the script file to generate the geometry.
137            In the current implementation a script file name is returned.
138            """
139            if getMPIRankWorld() == 0:
140                open(self.getScriptFileName(),"w").write(self.getScriptString())
141            return self.getScriptFileName()
142    
143    
144      def getMeshHandler(self):      def getMeshHandler(self):
145          """          """
146          Returns a handle to a mesh meshing the design. In the current          Returns a handle to a mesh meshing the design. In the current
147          implementation a mesh file name in gmsh format is returned.          implementation a mesh file name in gmsh format is returned.
148          """          """
149          cmd = self.getCommandString()          cmd = self.getCommandString()%self.getScriptHandler()
150          if getMPIRankWorld() == 0:          if getMPIRankWorld() == 0:
             open(self.getScriptFileName(),"w").write(self.getScriptString())  
151              ret = os.system(cmd) / 256              ret = os.system(cmd) / 256
152          else:          else:
153              ret=0              ret=0
# Line 156  class Design(design.Design): Line 163  class Design(design.Design):
163          Returns the gmsh script to generate the mesh.          Returns the gmsh script to generate the mesh.
164          """          """
165          h=self.getElementSize()          h=self.getElementSize()
166          out="// generated by esys.pycad\n"          out='// generated by esys.pycad\nGeneral.Terminal = 1;\n'
167          for prim in self.getAllPrimitives():          for prim in self.getAllPrimitives():
168             p=prim.getUnderlyingPrimitive()             p=prim.getUnderlyingPrimitive()
169             if isinstance(p, Point):             if isinstance(p, Point):
# Line 216  class Design(design.Design): Line 223  class Design(design.Design):
223                        line+="Surface"                        line+="Surface"
224                    else:                    else:
225                        line+="Volume"                        line+="Volume"
226                    out+=line+"(" + str(p.getID()) + ") = {"+self.__mkArgs(p.getItems())+"};\n"                    out+=line+"(" + str(p.getID()) + ") = {"+self.__mkArgs(p.getItems(),useAbs=True)+"};\n"
227    
228             else:             else:
229                 raise TypeError("unable to pass %s object to gmsh."%str(type(p)))                 raise TypeError("unable to pass %s object to gmsh."%str(type(p)))
230          return out          return out
231    
232    
233      def __mkArgs(self,args):      def __mkArgs(self,args, useAbs=False):
234          line=""          line=""
235          for i in args:          for i in args:
236                id = i.getDirectedID()
237                if useAbs: id=abs(id)
238              if len(line)>0:              if len(line)>0:
239                  line+=", %s"%i.getDirectedID()                  line+=", %s"%id
240              else:              else:
241                  line="%s"%i.getDirectedID()                  line="%s"%id
242          return line          return line
243    
244      def __mkTransfiniteLine(self,p):      def __mkTransfiniteLine(self,p):

Legend:
Removed from v.2548  
changed lines
  Added in v.2700

  ViewVC Help
Powered by ViewVC 1.1.26