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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 931 - (hide annotations)
Fri Jan 19 03:06:33 2007 UTC (13 years, 1 month ago) by gross
File MIME type: text/x-python
File size: 3820 byte(s)
pycad supports volumes now.
1 gross 899 # $Id:$
2    
3     """
4     Geometrical Elementries
5    
6     the concept is inspired by gmsh and very much focused on the fact that
7     the classes are used to wrk with gmsh.
8    
9     @var __author__: name of author
10     @var __copyright__: copyrights
11     @var __license__: licence agreement
12     @var __url__: url entry point on documentation
13     @var __version__: version
14     @var __date__: date of the version
15     """
16    
17    
18     __author__="Lutz Gross, l.gross@uq.edu.au"
19     __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
20     http://www.access.edu.au
21     Primary Business: Queensland, Australia"""
22     __license__="""Licensed under the Open Software License version 3.0
23     http://www.opensource.org/licenses/osl-3.0.php"""
24     __url__="http://www.iservo.edu.au/esys/escript"
25     __version__="$Revision:$"
26     __date__="$Date:$"
27    
28 gross 929 from primitives import Primitive #, PrimitiveStack
29 gross 899 from datetime import date
30     import tempfile
31     import os
32    
33 gross 931 class PrimitiveBaseStack(object):
34     def __init__(self,*items):
35     self.__prims=set()
36     for i in items:
37     self.__prims|=i.getPrimitives()
38     self.__prims=list(self.__prims)
39     self.__prims.sort()
40    
41     def getGmshCommands(self,scaling_factor=1.):
42     out=""
43     for i in self.__prims:
44     out+=i.getGmshCommand(scaling_factor)+"\n"
45     return out
46    
47 gross 899 class Design(object):
48     """
49     template for elementary geometrical object
50     """
51     def __init__(self,dim=3,scale=1.,element_order=1,keep_tmp_files=False):
52     """
53     """
54     self.__items=[]
55     self.setScale(scale)
56     self.setDim(dim)
57     self.setElementOrder(element_order)
58     self.setKeepTmpFiles(keep_tmp_files)
59     def addPrimitive(self,item):
60     self.addPrimitives(item)
61     def addPrimitives(self,*items):
62     for i in range(len(items)):
63     if not isinstance(items[i],Primitive):
64     raise TypeError("%s-th argument is not a Primitive object"%i)
65     for i in items:
66     self.__items.append(i)
67     def setKeepTmpFiles(self,flag=None):
68     if flag==None:
69     if self.__keep_tmp_files==True:
70     self.__keep_tmp_files=False
71     else:
72     self.__keep_tmp_files=True
73     else:
74     self.__keep_tmp_files=flag
75     def keepTmpFiles(self,scale=1.):
76     return self.__keep_tmp_files
77     def setScale(self,scale=1.):
78     self.__scale=scale
79     def getScale(self,scale=1.):
80     return self.__scale
81     def setDim(self,dim=3):
82     self.__dim=dim
83     def getDim(self,dim=3):
84     return self.__dim
85     def setElementOrder(self,order=1):
86     self.__order=order
87     def getElementOrder(self,order=1):
88     return self.__order
89     def getPrimitives(self):
90     return self.__items
91     def getGmshScript(self):
92     ps=PrimitiveStack(*tuple(self.getPrimitives()))
93     return "// generated by esys.pycad\nscale = %s;\n%s"%(self.getScale(),ps.getGmshCommands())
94     def writeGmshScript(self,file):
95     file.write(self.getGmshScript())
96     def writeGmshMesh(self,filename):
97     scriptname=tempfile.mkstemp(suffix=".geo")[1]
98     self.writeGmshScript(open(scriptname,"w"))
99     exe="gmsh -%s -smooth 2 -optimize -v 0 -order %s -o %s %s"%(self.getDim(),self.getElementOrder(),filename,scriptname)
100     os.system(exe)
101     if not self.keepTmpFiles(): os.unlink(scriptname)
102     return exe
103     def writeFinleyMesh(self,filename):
104     mshname=tempfile.mkstemp(suffix=".msh")[1]
105     exe=self.writeGmshMesh(mshname)
106 gross 901 convertGmshToFinley(open(mshname,"r"),open(filename,"w"),dim=self.getDim())
107     if not self.keepTmpFiles(): os.unlink(mshname)
108     return exe
109    
110     def convertGmshToFinley(gmsh_file,finley_file,dim=3):
111     line=gmsh_file.readline().split()
112 gross 899 while len(line)>0:
113     print line
114 gross 901 line=gmsh_file.readline().split()

  ViewVC Help
Powered by ViewVC 1.1.26