revision 911 by gross, Thu Nov 16 07:22:08 2006 UTC revision 912 by gross, Wed Dec 6 03:29:49 2006 UTC
# Line 26  __version__="\$Revision:\$" Line 26  __version__="\$Revision:\$"
26  __date__="\$Date:\$"  __date__="\$Date:\$"
27
28  import numarray  import numarray
29    from transformations import _TYPE
30
31  global global_primitive_id_counter  global global_primitive_id_counter
32  global_primitive_id_counter=0  global_primitive_id_counter=1
33
34  class Primitive(object):  class Primitive(object):
35      """      """
# Line 46  class Primitive(object): Line 47  class Primitive(object):
47         return "%s(%s)"%(self.__class__.__name__,self.getID())         return "%s(%s)"%(self.__class__.__name__,self.getID())
48      def __cmp__(self,other):      def __cmp__(self,other):
49         return cmp(self.getID(),other.getID())         return cmp(self.getID(),other.getID())
50        def getPoints(self):
51            """
52            returns the C{set} of points used to construct the primitive
53            """
54            out=set()
55            for i in self.getHistory():
57            return out
58
59        def setLocalScale(self,factor=1.):
60            """
61            sets the local refinement factor
62            """
63            for p in self.getPoints(): p.setLocalScale(factor)
64
65      def isPoint(self):      def isPoint(self):
66            """
67            returns C{True} is the primitive is a L{Point}
68            """
69          return False          return False
70      def isCurve(self):      def isCurve(self):
71            """
72            returns C{True} is the primitive is a L{Curve}
73            """
74          return False          return False
75      def isSurface(self):      def isSurface(self):
76            """
77            returns C{True} is the primitive is a L{Surface}
78            """
79          return False          return False
80      def isCurveLoop(self):      def isCurveLoop(self):
81            """
82            returns C{True} is the primitive is a L{CurveLoop}
83            """
84          return False          return False
85      def isSurfaceLoop(self):      def isSurfaceLoop(self):
86            """
87            returns C{True} is the primitive is a L{SurfaceLoop}
88            """
89          return False          return False
90        def getHistory(self):
91            """
92            returns C{set} of primitive used to construct the primitive
93            """
94            return set()
95
96
97        #==================================================
98      def __neg__(self):      def __neg__(self):
99          return ReversedPrimitive(self)          return ReversedPrimitive(self)
100      def __pos__(self):      def __pos__(self):
# Line 66  class Primitive(object): Line 105  class Primitive(object):
105         return out         return out
107         self.shift()         self.shift()
def setLocalLength(self,factor=1.):
for p in self.getPoints(): p.setLocalLength(factor)
108      def shift(self,shift):      def shift(self,shift):
109          for p in self.getPoints(): p+=shift          for p in self.getPoints(): p+=shift
110      def copy(self):      def copy(self):
111          return Primitive()          return Primitive()
112      def getGmshCommand(self):      def getGmshCommand(self):
113          raise NotImplementedError("getGmshCommand is not implemented for this class %s."%self.__class__.__name__)          raise NotImplementedError("getGmshCommand is not implemented for this class %s."%self.__class__.__name__)
def getHistory(self):
return set()
def getPoints(self):
return set()
114      def translate(self,shift):      def translate(self,shift):
115          raise NotImplementedError("translate is not implemented for this class %s."%self.__class__.__name__)          raise NotImplementedError("translate is not implemented for this class %s."%self.__class__.__name__)
116
class ReversedPrimitive(object):
def __init__(self,prim):
self.__prim=prim
def __getattr__(self,name):
if name == "getID":
return self.getReverseID
else:
return getattr(self.__prim,name)
def getReverseID(self):
return -self.__prim.getID()

117  class Point(Primitive):  class Point(Primitive):
118      """      """
119      a three dimensional point      a three dimensional point
120      """      """
121      def __init__(self,x=0.,y=0.,z=0.,local_scale=1.):      def __init__(self,x=0.,y=0.,z=0.,local_scale=1.):
122         """         """
123         creates a point with coorinates x,y,z with a relative refinement factor         creates a point with coorinates x,y,z with the local refinement factor local_scale
124         """         """
125         super(Point, self).__init__()         super(Point, self).__init__()
126         if not local_scale > 0.:         self.setCoordinates(x,y,z)
raise ValueError("local_scale needs to be positive.")
self._x=numarray.array([x,y,z],numarray.Float64)
127         self.setLocalScale(local_scale)         self.setLocalScale(local_scale)
128      def setLocalScale(self,factor=1.):      def setLocalScale(self,factor=1.):
129         """         """
130         sets the local relative length scale         sets the local refinement factor
131         """         """
132           if factor<=0.:
133              raise ValueError("scaling factor must be positive.")
134         self.__local_scale=factor         self.__local_scale=factor
135      def getLocalScale(self):      def getLocalScale(self):
136           """
137           returns the local refinement factor
138           """
139         return self.__local_scale         return self.__local_scale
140        def getCoordinates(self):
141           """
142           returns the coodinates of the point as L{numarray.NumArray} object
143           """
144           return self._x
145        def setCoordinates(self,x,y,z):
146           """
147           returns the coodinates of the point as L{numarray.NumArray} object
148           """
149           self._x=numarray.array([x,y,z],_TYPE)
150        def getHistory(self):
151           """
152           returns C{set} of primitive used to construct the primitive
153           """
154           return set([self])
155
156        def isColocated(self,point,tol=1.e-11):
157           """
158           returns True if L{Point} point is colocation (same coordinates)
159           that means if |self-point| <= tol * max(|self|,|point|)
160           """
161           if isinstance(point,Point):
162              point=point.getCoordinates()
163           c=self.getCoordinates()
164           d=c-point
165           return numarray.dot(d,d)<=tol**2*max(numarray.dot(c,c),numarray.dot(point,point))
166
167
168        #=============================================================
169      def copy(self):      def copy(self):
170         c=self.getCoordinates()         c=self.getCoordinates()
171         return Point(c[0],c[1],c[2],local_scale=self.getLocalScale())         return Point(c[0],c[1],c[2],local_scale=self.getLocalScale())
172      def isPoint(self):      def isPoint(self):
173          return True          return True
def getCoordinates(self):
return self._x
174      def getGmshCommand(self):      def getGmshCommand(self):
175          c=self.getCoordinates()          c=self.getCoordinates()
176          return "Point(%s) = {%e , %e, %e , %e * scale};"%(self.getID(),c[0],c[1],c[2], self.getLocalScale())          return "Point(%s) = {%e , %e, %e , %e * scale};"%(self.getID(),c[0],c[1],c[2], self.getLocalScale())
def getHistory(self):
return set([self])
def getPoints(self):
return set([self])
177      def shift(self,shift):      def shift(self,shift):
178         """         """
179         shifts the point by a given shift         shifts the point by a given shift
# Line 507  class Volume(Primitive): Line 555  class Volume(Primitive):
555          else:          else:
556            return "Volume(%s) = {%s};"%(self.getID(),self.getSurfaceLoop().getID())            return "Volume(%s) = {%s};"%(self.getID(),self.getSurfaceLoop().getID())
557
558    class ReversedPrimitive(object):
559        def __init__(self,prim):
560           self.__prim=prim
561        def __getattr__(self,name):
562           if name == "getID":
563              return self.getReverseID
564           else:
565              return getattr(self.__prim,name)
566        def getReverseID(self):
567            return -self.__prim.getID()
568
569  class PropertySet(Primitive):  class PropertySet(Primitive):
570      """      """
571      defines a group L{Primitive} objects.      defines a group L{Primitive} objects.

Legend:
 Removed from v.911 changed lines Added in v.912