Changeset 1909
- Timestamp:
- Oct 13, 2005, 6:10:41 PM (19 years ago)
- Location:
- inundation
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/mesh_factory.py
r1762 r1909 676 676 677 677 return points, elements, boundary 678 679 680 681 682 def oblique_cross(m, n, lenx = 1.0, leny = 1.0, theta = 8.95, origin = (0.0, 0.0)): 683 """Setup a oblique grid of triangles 684 with m segments in the x-direction and n segments in the y-direction 685 686 """ 687 688 from Numeric import array 689 import math 690 691 from config import epsilon 692 693 694 deltax = lenx/float(m) 695 deltay = leny/float(n) 696 a = 0.75*lenx*math.tan(theta/180.*math.pi) 697 x1 = lenx 698 y1 = 0 699 x2 = lenx 700 y2 = leny 701 x3 = 0.25*lenx 702 y3 = leny 703 x4 = x3 704 y4 = 0 705 a2 = a/(x1-x4) 706 a1 = -a2*x4 707 a4 = ((a1 + a2*x3)/y3-(a1 + a2*x2)/y2)/(x2-x3) 708 a3 = 1. - (a1 + a2*x3)/y3 - a4*x3 709 710 # Dictionary of vertex objects 711 vertices = {} 712 points = [] 713 714 for i in range(m+1): 715 x = deltax*i 716 for j in range(n+1): 717 y = deltay*j 718 if x > 0.25*lenx: 719 y = a1 + a2*x + a3*y + a4*x*y 720 721 vertices[i,j] = len(points) 722 points.append([x + origin[0], y + origin[1]]) 723 724 # Construct 4 triangles per element 725 elements = [] 726 boundary = {} 727 for i in range(m): 728 for j in range(n): 729 v1 = vertices[i,j+1] 730 v2 = vertices[i,j] 731 v3 = vertices[i+1,j+1] 732 v4 = vertices[i+1,j] 733 x = (points[v1][0]+points[v2][0]+points[v3][0]+points[v4][0])*0.25 734 y = (points[v1][1]+points[v2][1]+points[v3][1]+points[v4][1])*0.25 735 v5 = len(points) 736 points.append([x, y]) 737 738 #Update boundary dictionary and create elements 739 #Create left triangle 740 if i == 0: 741 boundary[(len(elements), 1)] = 'left' 742 elements.append([v2,v5,v1]) 743 744 #Create bottom triangle 745 if j == 0: 746 boundary[(len(elements), 1)] = 'bottom' 747 elements.append([v4,v5,v2]) 748 749 #Create right triangle 750 if i == m-1: 751 boundary[(len(elements), 1)] = 'right' 752 elements.append([v3,v5,v4]) 753 754 #Create top triangle 755 if j == n-1: 756 boundary[(len(elements), 1)] = 'top' 757 elements.append([v1,v5,v3]) 758 759 760 return points, elements, boundary
Note: See TracChangeset
for help on using the changeset viewer.