/[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 1005 by ksteube, Fri Mar 2 06:50:48 2007 UTC revision 1045 by gross, Tue Mar 20 01:30:58 2007 UTC
# Line 25  __date__="$Date:$" Line 25  __date__="$Date:$"
25  import design  import design
26  import tempfile  import tempfile
27  import os  import os
28    from primitives import Point, Spline, BezierCurve, BSpline, Line, Arc, CurveLoop, RuledSurface, PlaneSurface, SurfaceLoop, Volume, PropertySet
29    
30  class Design(design.Design):  class Design(design.Design):
31      """      """
# Line 90  class Design(design.Design): Line 91  class Design(design.Design):
91          if not self.keepFiles():          if not self.keepFiles():
92                 os.unlink(self.getScriptFileName())                 os.unlink(self.getScriptFileName())
93                 os.unlink(self.getMeshFileName())                 os.unlink(self.getMeshFileName())
     def getScriptString(self):  
         """  
         returns the gmsh script to generate the mesh  
         """  
         prim=self.getAllPrimitives()  
         out="// generated by esys.pycad\n"  
         for p in prim:  
            out+=p.getGmshCommand(self.getElementSize())+"\n"  
         return out  
94      def getCommandString(self):      def getCommandString(self):
95          """          """
96          returns the gmsh comand          returns the gmsh comand
# Line 133  class Design(design.Design): Line 125  class Design(design.Design):
125        raise RuntimeError, "Could not build mesh: %s"%cmd        raise RuntimeError, "Could not build mesh: %s"%cmd
126      else:      else:
127            return self.getMeshFileName()            return self.getMeshFileName()
128    
129        def getScriptString(self):
130            """
131            returns the gmsh script to generate the mesh
132            """
133            h=self.getElementSize()
134            out="// generated by esys.pycad\n"
135            for prim in self.getAllPrimitives():
136               p=prim.getUnderlyingPrimitive()
137               if isinstance(p, Point):
138                   c=p.getCoordinates()
139                   out+="Point(%s) = {%s , %s, %s , %s };\n"%(p.getID(),c[0],c[1],c[2], p.getLocalScale()*h)
140            
141               elif isinstance(p, Spline):
142                   out+="Spline(%s) = {%s};\n"%(p.getID(),self.__mkArgs(p.getControlPoints()))
143        
144               elif isinstance(p, BezierCurve):
145                   out+="Bezier(%s) = {%s};\n"%(p.getID(),self.__mkArgs(p.getControlPoints()))
146    
147               elif isinstance(p, BSpline):
148                   out+="BSpline(%s) = {%s};\n"%(p.getID(),self.__mkArgs(p.getControlPoints()))
149    
150               elif isinstance(p, Line):
151                   out+="Line(%s) = {%s, %s};\n"%(p.getID(),p.getStartPoint().getDirectedID(),p.getEndPoint().getDirectedID())
152    
153               elif isinstance(p, Arc):
154                  out+="Circle(%s) = {%s, %s, %s};\n"%(p.getID(),p.getStartPoint().getDirectedID(),p.getCenterPoint().getDirectedID(),p.getEndPoint().getDirectedID())
155          
156               elif isinstance(p, CurveLoop):
157                   out+="Line Loop(%s) = {%s};\n"%(p.getID(),self.__mkArgs(p.getCurves()))
158          
159               elif isinstance(p, RuledSurface):
160                   out+="Ruled Surface(%s) = {%s};\n"%(p.getID(),p.getBoundaryLoop().getDirectedID())
161          
162               elif isinstance(p, PlaneSurface):
163                   line=self.__mkArgs(p.getHoles())
164                   if len(line)>0:
165                     out+="Plane Surface(%s) = {%s, %s};\n"%(p.getID(),p.getBoundaryLoop().getDirectedID(), line)
166                   else:
167                     out+="Plane Surface(%s) = {%s};\n"%(p.getID(),p.getBoundaryLoop().getDirectedID())
168          
169               elif isinstance(p, SurfaceLoop):
170                   out+="Surface Loop(%s) = {%s};\n"%(p.getID(),self.__mkArgs(p.getSurfaces()))
171          
172               elif isinstance(p, Volume):
173                   line=self.__mkArgs(p.getHoles())
174                   if len(line)>0:
175                     out+="Volume(%s) = {%s, %s};\n"%(p.getID(),p.getSurfaceLoop().getDirectedID(), line)
176                   else:
177                     out+="Volume(%s) = {%s};\n"%(p.getID(),p.getSurfaceLoop().getDirectedID())
178    
179               elif isinstance(p, PropertySet):
180               dim=p.getDim()
181                   line="Physical "
182                   if dim==0:
183                       line+="Point"
184                   elif dim==1:
185                       line+="Line"
186                   elif dim==2:
187                       line+="Surface"
188                   else:
189                       line+="Volume"
190                   out+=line+"(" + str(p.getID()) + ") = {"+self.__mkArgs(p.getItems())+"};\n"
191    
192               else:
193                   raise TypeError("unable to pass %s object to gmsh."%str(type(p)))
194            return out
195    
196    
197        def __mkArgs(self,args):
198            line=""
199            for i in args:
200                if len(line)>0:
201                    line+=", %s"%i.getDirectedID()
202                else:
203                    line="%s"%i.getDirectedID()
204            return line

Legend:
Removed from v.1005  
changed lines
  Added in v.1045

  ViewVC Help
Powered by ViewVC 1.1.26