Changeset 829
- Timestamp:
- Feb 2, 2005, 12:10:28 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pmesh
- Files:
-
- 9 added
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pmesh/mesh.py
r824 r829 30 30 SET_COLOUR='red' 31 31 32 33 34 35 def gradient_python(x0, y0, x1, y1, x2, y2, q0, q1, q2): 36 """ 37 """ 38 39 det = (y2-y0)*(x1-x0) - (y1-y0)*(x2-x0) 40 a = (y2-y0)*(q1-q0) - (y1-y0)*(q2-q0) 41 a /= det 42 43 b = (x1-x0)*(q2-q0) - (x2-x0)*(q1-q0) 44 b /= det 45 46 return a, b 47 48 ############################################## 49 #Initialise module 50 51 import compile 52 if compile.can_use_C_extension('util_ext.c'): 53 from util_ext import gradient, point_on_line 54 else: 55 gradient = gradient_python 32 56 33 57 # 1st and third values must be the same … … 1737 1761 return userVertices, userSegments 1738 1762 1739 def threshold(self,setName,min=None,max=None ):1740 """ 1741 threshold using d/A, notd1763 def threshold(self,setName,min=None,max=None,attribute_name = 'elevation'): 1764 """ 1765 threshold using d 1742 1766 """ 1743 1767 triangles = self.sets[self.setID[setName]] 1744 1768 A = [] 1769 1770 if attribute_name in self.attributeTitles: 1771 i = self.attributeTitles.index(attribute_name) 1745 1772 if not max == None: 1746 1773 for t in triangles: 1747 if (min<self.av_att(t )<max):1774 if (min<self.av_att(t,i)<max): 1748 1775 A.append(t) 1749 1776 else: 1750 1777 for t in triangles: 1751 if (min<self.av_att(t )):1778 if (min<self.av_att(t,i)): 1752 1779 A.append(t) 1753 1780 self.sets[self.setID[setName]] = A 1754 1781 1755 1756 def av_att(self,triangle): 1782 def general_threshold(self,setName,min=None,max=None,attribute_name = 'elevation',function = None): 1783 """ 1784 threshold using d 1785 """ 1786 triangles = self.sets[self.setID[setName]] 1787 A = [] 1788 1789 if attribute_name in self.attributeTitles: 1790 i = self.attributeTitles.index(attribute_name) 1791 if not max == None: 1792 for t in triangles: 1793 if (min<function(t,i)<max): 1794 A.append(t) 1795 else: 1796 for t in triangles: 1797 if (min<self.function(t,i)): 1798 A.append(t) 1799 self.sets[self.setID[setName]] = A 1800 1801 def av_att(self,triangle,i): 1757 1802 #evaluates the average attribute of the vertices of a triangle. 1758 1803 V = triangle.getVertices() 1759 a0 = (V[0].attributes[ 0])1760 a1 = (V[1].attributes[ 0])1761 a2 = (V[2].attributes[ 0])1804 a0 = (V[0].attributes[i]) 1805 a1 = (V[1].attributes[i]) 1806 a2 = (V[2].attributes[i]) 1762 1807 return (a0+a1+a2)/3 1763 1808 1764 def Courant_threshold(self,setName,min=None,max=None): 1765 """ 1766 threshold using d/A, not d 1767 """ 1768 triangles = self.sets[self.setID[setName]] 1769 A = [] 1770 if not max == None: 1771 for t in triangles: 1772 if (min<self.Courant_ratio(t)<max): 1773 A.append(t) 1774 else: 1775 for t in triangles: 1776 if (min<self.av_att(t)): 1777 A.append(t) 1778 self.sets[self.setID[setName]] = A 1779 1780 1781 1782 def Courant_ratio(self,triangle): 1809 def Courant_ratio(self,triangle,index): 1783 1810 """ 1784 1811 Not the true Courant ratio, just elevation on area 1785 1812 """ 1786 e = self.av_att(triangle )1813 e = self.av_att(triangle,index) 1787 1814 A = triangle.calcArea() 1788 1815 return e/A 1816 1817 def Gradient(self,triangle,index): 1818 V = triangle.vertices 1819 x0, y0, x1, y1, x2, y2, q0, q1, q2 = V[0].x,V[0].y,V[1].x,V[1].y,V[2].x,V[2].y,V[0].attributes[index],V[1].attributes[index],V[2].attributes[index] 1820 grad_x,grad_y = gradient(x0, y0, x1, y1, x2, y2, q0, q1, q2) 1821 if ((grad_x**2)+(grad_y**2))**(0.5)<0: 1822 print ((grad_x**2)+(grad_y**2))**(0.5) 1823 return ((grad_x**2)+(grad_y**2))**(0.5) 1824 1789 1825 1790 1826 def append_triangle(self,triangle): -
inundation/ga/storm_surge/pmesh/pmesh.py
r828 r829 234 234 statushelp='' ) 235 235 236 def createVisualiseIcons(self): 237 """ 238 Add Edit buttons to the top of the GUI 239 """ 240 ToolBarButton(self, self.toolbar, 'sep', 'sep.gif', width=10, 241 state='disabled') 242 for key, func, balloon in [ 243 ('visualise', self.visualise, 'Visualise mesh triangles'), 244 ('unvisualise', self.unvisualise, 'Do not visualise mesh triangles (for large meshes)')]: 245 ToolBarButton(self, self.toolbar, key, '%s.gif' %key, 246 command=func, balloonhelp=balloon, 247 statushelp='' ) 236 248 237 249 … … 351 363 self.visualiseMesh(self.mesh) 352 364 365 def visualise(self,parent): 366 self.Visualise = True 367 self.visualiseMesh(self.mesh) 368 369 def unvisualise(self,parent): 370 self.Visualise = False 353 371 354 372 def createMesh(self): … … 874 892 visualise vertices, segments, triangulation, holes 875 893 """ 876 for triangle in mesh.getTriangulation(): 877 self.serial +=1 878 self.uniqueID = 'M*%d' % self.serial 879 self.Triangles.visualise(triangle, 880 self.uniqueID, 881 self.canvas, 882 self.SCALE) 883 884 Triangles = mesh.sets[mesh.setID[self.selSet]] 885 for triangle in Triangles: 886 triangle.draw(self.canvas,1, 887 scale = self.SCALE, 888 colour = SET_COLOUR) 894 if self.Visualise: 895 for triangle in mesh.getTriangulation(): 896 self.serial +=1 897 self.uniqueID = 'M*%d' % self.serial 898 self.Triangles.visualise(triangle, 899 self.uniqueID, 900 self.canvas, 901 self.SCALE) 902 903 if self.Visualise: 904 Triangles = mesh.sets[mesh.setID[self.selSet]] 905 for triangle in Triangles: 906 triangle.draw(self.canvas,1, 907 scale = self.SCALE, 908 colour = SET_COLOUR) 889 909 890 910 for segment in mesh.getUserSegments(): … … 1259 1279 self.createSetTools() 1260 1280 self.createSetIcons() 1281 self.createVisualiseIcons() 1261 1282 #self.addVertsAndSegs() # !!!DSG start pmesh with a triangle 1262 1283 self.selectFunc('pointer') 1263 1284 self.currentPath = os.getcwd() 1285 1286 self.Visualise = True 1264 1287 1265 1288 def loadtestmesh(self,ofile):
Note: See TracChangeset
for help on using the changeset viewer.