/[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 929 - (hide annotations)
Wed Jan 17 07:41:13 2007 UTC (12 years, 6 months ago) by gross
File MIME type: text/x-python
File size: 3418 byte(s)
reverse orientation added but does not work for 2D yet.
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     class Design(object):
34     """
35     template for elementary geometrical object
36     """
37     def __init__(self,dim=3,scale=1.,element_order=1,keep_tmp_files=False):
38     """
39     """
40     self.__items=[]
41     self.setScale(scale)
42     self.setDim(dim)
43     self.setElementOrder(element_order)
44     self.setKeepTmpFiles(keep_tmp_files)
45     def addPrimitive(self,item):
46     self.addPrimitives(item)
47     def addPrimitives(self,*items):
48     for i in range(len(items)):
49     if not isinstance(items[i],Primitive):
50     raise TypeError("%s-th argument is not a Primitive object"%i)
51     for i in items:
52     self.__items.append(i)
53     def setKeepTmpFiles(self,flag=None):
54     if flag==None:
55     if self.__keep_tmp_files==True:
56     self.__keep_tmp_files=False
57     else:
58     self.__keep_tmp_files=True
59     else:
60     self.__keep_tmp_files=flag
61     def keepTmpFiles(self,scale=1.):
62     return self.__keep_tmp_files
63     def setScale(self,scale=1.):
64     self.__scale=scale
65     def getScale(self,scale=1.):
66     return self.__scale
67     def setDim(self,dim=3):
68     self.__dim=dim
69     def getDim(self,dim=3):
70     return self.__dim
71     def setElementOrder(self,order=1):
72     self.__order=order
73     def getElementOrder(self,order=1):
74     return self.__order
75     def getPrimitives(self):
76     return self.__items
77     def getGmshScript(self):
78     ps=PrimitiveStack(*tuple(self.getPrimitives()))
79     return "// generated by esys.pycad\nscale = %s;\n%s"%(self.getScale(),ps.getGmshCommands())
80     def writeGmshScript(self,file):
81     file.write(self.getGmshScript())
82     def writeGmshMesh(self,filename):
83     scriptname=tempfile.mkstemp(suffix=".geo")[1]
84     self.writeGmshScript(open(scriptname,"w"))
85     exe="gmsh -%s -smooth 2 -optimize -v 0 -order %s -o %s %s"%(self.getDim(),self.getElementOrder(),filename,scriptname)
86     os.system(exe)
87     if not self.keepTmpFiles(): os.unlink(scriptname)
88     return exe
89     def writeFinleyMesh(self,filename):
90     mshname=tempfile.mkstemp(suffix=".msh")[1]
91     exe=self.writeGmshMesh(mshname)
92 gross 901 convertGmshToFinley(open(mshname,"r"),open(filename,"w"),dim=self.getDim())
93     if not self.keepTmpFiles(): os.unlink(mshname)
94     return exe
95    
96     def convertGmshToFinley(gmsh_file,finley_file,dim=3):
97     line=gmsh_file.readline().split()
98 gross 899 while len(line)>0:
99     print line
100 gross 901 line=gmsh_file.readline().split()

  ViewVC Help
Powered by ViewVC 1.1.26