Changeset 9354
- Timestamp:
- Oct 21, 2014, 3:30:43 PM (11 years ago)
- Location:
- trunk/anuga_core
- Files:
-
- 7 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/utilities/plot_utils.py
r9347 r9354 1039 1039 1040 1040 1041 if (bounding_polygon is not None):1041 if ( (bounding_polygon is not None) and (len(cut_points)>0)): 1042 1042 # Cut the points outside the bounding polygon 1043 1043 gridq[cut_points]= numpy.nan … … 1060 1060 return 1061 1061 1062 def plot_triangles(p, adjustLowerLeft=False ):1062 def plot_triangles(p, adjustLowerLeft=False, values=None, color='k'): 1063 1063 """ Add mesh triangles to a pyplot plot 1064 """ 1064 1065 @param p = object holding sww vertex information (from util.get_output) 1066 @param adjustLowerLeft = if TRUE, use spatial coordinates, otherwise use ANUGA internal coordinates 1067 @param values = list or array of length(p.x), or None. All triangles are assigned this value (for face plotting colors). 1068 @param color = edge color for polygons (using matplotlib.colors notation) 1069 """ 1070 import matplotlib 1065 1071 from matplotlib import pyplot as pyplot 1072 from matplotlib.collections import PolyCollection 1066 1073 # 1067 1074 x0=p.xllcorner 1068 1075 x1=p.yllcorner 1069 # 1076 1077 # Get current figure information 1078 #ax = pyplot.axes() 1079 1080 ## 1081 vertices = [] 1070 1082 for i in range(len(p.vols)): 1071 1083 k1=p.vols[i][0] 1072 1084 k2=p.vols[i][1] 1073 1085 k3=p.vols[i][2] 1074 if (not adjustLowerLeft):1075 pyplot.plot([p.x[k1], p.x[k2], p.x[k3], p.x[k1]], [p.y[k1], p.y[k2], p.y[k3], p.y[k1]],'-',color='black')1086 if not adjustLowerLeft: 1087 vertices.append([ [p.x[k1], p.y[k1]], [p.x[k2], p.y[k2]], [p.x[k3], p.y[k3]] ]) 1076 1088 else: 1077 pyplot.plot([p.x[k1]+x0, p.x[k2]+x0, p.x[k3]+x0, p.x[k1]+x0], [p.y[k1]+x1, p.y[k2]+x1, p.y[k3]+x1, p.y[k1]+x1],'-',color='black') 1078 #pyplot.plot([p.x[k3], p.x[k2]], [p.y[k3], p.y[k2]],'-',color='black') 1079 #pyplot.plot([p.x[k3], p.x[k1]], [p.y[k3], p.y[k1]],'-',color='black') 1089 vertices.append([ [p.x[k1]+x0, p.y[k1]+y0], [p.x[k2]+x0, p.y[k2]+y0], [p.x[k3]+x0, p.y[k3]+y0] ]) 1090 1091 if values is None: 1092 all_poly = PolyCollection( vertices, array = numpy.zeros(len(p.vols)), 1093 edgecolors=color) 1094 all_poly.set_facecolor('none') 1095 else: 1096 assert len(values)==len(p.vols), 'len(values) must either be 1, or the same as len(p.vols)' 1097 all_poly = PolyCollection( vertices, array = values, cmap = matplotlib.cm.jet, edgecolors=color) 1098 1099 pyplot.gca().add_collection(all_poly) 1100 # if(not adjustLowerLeft): 1101 # pyplot.plot([p.x[k1], p.x[k2], p.x[k3], p.x[k1]], [p.y[k1], p.y[k2], p.y[k3], p.y[k1]],'-',color=color) 1102 # else: 1103 # pyplot.plot([p.x[k1]+x0, p.x[k2]+x0, p.x[k3]+x0, p.x[k1]+x0], [p.y[k1]+x1, p.y[k2]+x1, p.y[k3]+x1, p.y[k1]+x1],'-',color=color) 1104 # #pyplot.plot([p.x[k3], p.x[k2]], [p.y[k3], p.y[k2]],'-',color='black') 1105 # #pyplot.plot([p.x[k3], p.x[k1]], [p.y[k3], p.y[k1]],'-',color='black') 1080 1106 1081 1107 def find_neighbours(p,ind): -
trunk/anuga_core/validation_tests/case_studies/merewether/merewether.py
r8871 r9354 7 7 8 8 Water Research Laboratory, UNSW 9 10 Edits by Steve Roberts & Gareth Davies, 2014 9 11 """ 10 12 … … 22 24 # Related major packages 23 25 import anuga 24 from anuga_parallel import myid, distribute, finalize 26 from anuga_parallel import myid, distribute, finalize, barrier 25 27 26 28 from anuga_parallel.parallel_operator_factory import Inlet_operator 29 from anuga.utilities import quantity_setting_functions as qs 30 from anuga import plot_utils as util 27 31 28 32 # Application specific imports 29 33 import project # Definition of file names and polygons 30 34 31 verbose = project.verbose35 #verbose = project.verbose 32 36 use_cache = project.use_cache 33 37 … … 41 45 meshname = 'merewether.msh' 42 46 dem_name = 'topography1.dem' 47 48 args = anuga.get_args() 49 alg = args.alg 50 verbose = args.verbose 43 51 44 52 if myid == 0: … … 60 68 holes_res = 1.0 61 69 interior_regions = [[project.poly_merewether, merewether_res]] 62 holes = project.holes 70 71 # Either use houses as holes, or as part of the mesh (with breaklines) 72 houses_as_holes = False 73 if houses_as_holes: 74 holes = project.holes 75 breaklines = [] 76 else: 77 # Houses as elevation 78 house_height = 3.0 79 holes = [] 80 breaklines = project.holes 81 house_addition_poly_fun_pairs = [] 82 for i in range(len(breaklines)): 83 breaklines[i] = breaklines[i] + [breaklines[i][0]] 84 house_addition_poly_fun_pairs.append( 85 [ breaklines[i], house_height]) 86 house_addition_poly_fun_pairs.append(['All', 0.]) 87 88 #------------------------------------------------------------------------------ 89 # Make domain 90 #------------------------------------------------------------------------------ 63 91 64 92 if myid == 0: 65 domain = anuga.create_domain_from_regions(project.bounding_polygon, 66 boundary_tags={'bottom': [0], 67 'right': [1], 68 'top': [2], 69 'left': [3]}, 70 maximum_triangle_area=remainder_res, 71 interior_holes=holes, 72 mesh_filename=meshname, 73 interior_regions=interior_regions, 74 use_cache=use_cache, 75 verbose=verbose) 93 mesh = anuga.create_mesh_from_regions( 94 project.bounding_polygon, 95 boundary_tags={'bottom': [0], 96 'right': [1], 97 'top': [2], 98 'left': [3]}, 99 maximum_triangle_area=remainder_res, 100 interior_holes=holes, 101 breaklines=breaklines, 102 filename=meshname, 103 interior_regions=interior_regions, 104 use_cache=use_cache, 105 verbose=verbose) 106 107 domain = anuga.create_domain_from_file(meshname) 108 109 domain.set_flow_algorithm(alg) 76 110 77 111 #------------------------------------------------------------------------------ … … 79 113 #------------------------------------------------------------------------------ 80 114 domain.set_quantity('stage', 0.0) 81 domain.set_quantity('friction', 0.02) 82 domain.set_quantity('elevation', filename='topography1.pts', 83 use_cache=use_cache, 84 verbose=verbose) 85 115 116 # Friction -- 2 options 117 variable_friction = True 118 if not variable_friction: 119 # Constant friction 120 domain.set_quantity('friction', 0.02) 121 122 else: 123 # Set friction to 0.02 on roads, 0.04 elsewhere 124 road_polygon = anuga.read_polygon('Road/RoadPolygon.csv') 125 friction_function = qs.composite_quantity_setting_function( 126 [ [road_polygon, 0.02], ['All', 0.04] ], 127 domain) 128 domain.set_quantity('friction', friction_function) 129 130 # Elevation 131 if houses_as_holes: 132 domain.set_quantity('elevation', filename='topography1.pts', 133 use_cache=use_cache, 134 verbose=verbose) 135 136 else: 137 domain.set_quantity('elevation', filename='topography1.pts', 138 use_cache=use_cache, 139 verbose=verbose, location='vertices') 140 # Add house_height inside houses 141 house_addition_function = qs.composite_quantity_setting_function( 142 house_addition_poly_fun_pairs, domain) 143 domain.add_quantity('elevation', house_addition_function, 144 location='centroids') 86 145 else: 87 146 domain = None … … 93 152 domain = distribute(domain) 94 153 154 domain.set_store_vertices_uniquely() 155 95 156 #------------------------------------------------------------------------------ 96 157 # Setup computational domain … … 98 159 domain.set_name('merewether_1m') # Name of sww file 99 160 domain.set_datadir('.') # Store sww output here 100 domain.set_minimum_storable_height(0.001) # Store only depth > 1cm161 #domain.set_minimum_storable_height(0.001) # Store only depth > 1cm 101 162 102 163 … … 112 173 113 174 domain.set_boundary({'interior': Br, 114 175 'bottom': Br, 115 176 'right': Bt, # outflow 116 177 'top': Bt, # outflow … … 121 182 122 183 #fixed_inflow = anuga.Inflow(domain, 123 # 124 # 125 # 184 # center=(382300.0,6354290.0), 185 # radius=15.00, 186 # rate=19.7) 126 187 #domain.forcing_terms.append(fixed_inflow) 127 188 #hydrograph = anuga.Inflow(center=(382300.0,6354290.0),radius=30.0,rate=anuga.file_function('test_hydrograph2.tms', quantities=['hydrograph']) … … 132 193 #------------------------------------------------------------------------------ 133 194 134 for t in domain.evolve(yieldstep=10,finaltime= 2000):135 195 for t in domain.evolve(yieldstep=10,finaltime=1000): 196 if myid == 0: print domain.timestepping_statistics() 136 197 137 198 138 199 domain.sww_merge() 139 200 201 #------------------------------------------------------------------------------ 202 # Make geotif output 203 #------------------------------------------------------------------------------ 204 205 barrier() 206 if myid==0: 207 util.Make_Geotif('merewether_1m.sww', 208 output_quantities=['depth', 'velocity', 209 'friction', 'elevation'], 210 myTimeStep='last', 211 CellSize=1.0, 212 EPSG_CODE=32756, 213 bounding_polygon=project.bounding_polygon, 214 k_nearest_neighbours=1) 140 215 141 216 finalize() -
trunk/anuga_core/validation_tests/case_studies/merewether/project.py
r8833 r9354 19 19 # bounding polygon for study area 20 20 bounding_polygon = anuga.read_polygon('extent.csv') 21 print 'Area of bounding polygon ', anuga.polygon_area(bounding_polygon)/1000000.021 print 'Area of bounding polygon (km^2)', anuga.polygon_area(bounding_polygon)/1.0e+06 22 22 23 23
Note: See TracChangeset
for help on using the changeset viewer.