Changeset 8945
- Timestamp:
- Jul 17, 2013, 11:11:19 PM (11 years ago)
- Location:
- trunk/anuga_core/source/anuga
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/__init__.py
r8757 r8945 34 34 35 35 from anuga.abstract_2d_finite_volumes.quantity import Quantity 36 37 from anuga.operators.region import Region 36 38 37 39 from anuga.abstract_2d_finite_volumes.util import file_function, \ -
trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py
r8944 r8945 1065 1065 1066 1066 Usage: 1067 i = get_extreme_index()1067 i = Q.get_extreme_index() 1068 1068 1069 1069 Notes: … … 1520 1520 self.y_gradient[:] = 0.0 1521 1521 1522 def get_integral(self, full_only=True): 1523 1524 """Compute the integral of quantity across entire domain.""" 1522 def get_integral(self, full_only=True, region=None, indices=None): 1523 1524 """Compute the integral of quantity across entire domain, 1525 or over a region. Eg 1526 my_region = anuga.Region(polygon = user_polygon) 1527 1528 Q.get_integral(region = my_region)""" 1529 1530 assert region is None or indices is None 1525 1531 1526 1532 1527 1533 areas = self.domain.get_areas() 1528 1534 1529 if full_only: 1530 indices = num.where(self.domain.tri_full_flag ==1)[0] 1535 if region is None and indices is None: 1536 if full_only: 1537 indices = num.where(self.domain.tri_full_flag ==1)[0] 1538 return num.sum(areas[indices]*self.centroid_values[indices]) 1539 else: 1540 return num.sum(areas*self.centroid_values) 1541 1542 if indices is None: 1543 indices = region.get_indices(full_only) 1544 1545 if indices == []: 1546 return 0.0 1547 elif indices is None: 1548 return num.sum(areas*self.centroid_values) 1549 else: 1531 1550 return num.sum(areas[indices]*self.centroid_values[indices]) 1532 else:1533 return num.sum(areas*self.centroid_values)1534 1551 1535 1552 -
trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py
r8930 r8945 425 425 assert num.allclose (quantity.get_integral(), ref_integral) 426 426 427 427 def test_integral_with_region(self): 428 quantity = Quantity(self.mesh4) 429 430 # Try constants first 431 const = 5 432 quantity.set_values(const, location = 'vertices') 433 #print 'Q', quantity.get_integral() 434 435 assert num.allclose(quantity.get_integral(), self.mesh4.get_area() * const) 436 437 # Try with a linear function 438 def f(x, y): 439 return x+y 440 441 quantity.set_values(f, location = 'vertices') 442 443 444 from anuga import Region 445 446 reg1 = Region(self.mesh4, indices=[2]) 447 ref_integral = (10.0/3) * 2 448 449 assert num.allclose (quantity.get_integral(region=reg1), ref_integral) 450 451 reg2 = Region(self.mesh4, indices=[2,3]) 452 ref_integral = (10.0/3 + 10.0/3) * 2 453 454 assert num.allclose (quantity.get_integral(region=reg2), ref_integral) 455 456 id=[2,3] 457 ref_integral = (10.0/3 + 10.0/3) * 2 458 459 assert num.allclose (quantity.get_integral(indices=id), ref_integral) 428 460 429 461 def test_set_vertex_values(self): … … 2540 2572 if __name__ == "__main__": 2541 2573 suite = unittest.makeSuite(Test_Quantity, 'test') 2542 runner = unittest.TextTestRunner(verbosity= 2)2574 runner = unittest.TextTestRunner(verbosity=1) 2543 2575 runner.run(suite) -
trunk/anuga_core/source/anuga/operators/erosion_operators.py
r8944 r8945 11 11 12 12 import numpy as num 13 from anuga.geometry.polygon import inside_polygon 14 from anuga import indent 13 15 14 16 15 from anuga import Domain -
trunk/anuga_core/source/anuga/operators/rate_operators.py
r8944 r8945 13 13 from anuga import indent 14 14 import numpy as num 15 from warnings import warn16 15 import anuga.utilities.log as log 17 from anuga.geometry.polygon import inside_polygon18 19 20 from anuga.fit_interpolate.interpolate import Modeltime_too_early, \21 Modeltime_too_late22 16 from anuga.utilities.function_utils import evaluate_temporal_function 23 17 24 from anuga import Domain 25 from anuga import Quantity 18 26 19 from anuga.operators.base_operator import Operator 27 20 from anuga.operators.region import Region … … 102 95 103 96 if self.rate_spatial: 104 if self.indices is None:97 if indices is None: 105 98 x = self.coord_c[:,0] 106 99 y = self.coord_c[:,1] 107 100 else: 108 x = self.coord_c[self.indices,0] 109 y = self.coord_c[self.indices,1] 101 x = self.coord_c[indices,0] 102 y = self.coord_c[indices,1] 103 110 104 rate = self.get_spatial_rate(x,y,t) 111 105 else: … … 117 111 118 112 if num.all(rate >= 0.0): 119 if self.indices is None:113 if indices is None: 120 114 self.stage_c[:] = self.stage_c[:] \ 121 115 + factor*rate*timestep … … 124 118 + factor*rate*timestep 125 119 else: # Be more careful if rate < 0 126 if self.indices is None:120 if indices is None: 127 121 self.stage_c[:] = num.maximun(self.stage_c \ 128 122 + factor*rate*timestep, self.elev_c ) -
trunk/anuga_core/source/anuga/operators/region.py
r8938 r8945 10 10 from anuga import Quantity 11 11 import numpy as num 12 import anuga.utilities.log as log 12 13 13 14 14 from anuga.geometry.polygon import inside_polygon … … 16 16 from anuga.utilities.function_utils import determine_function_type 17 17 18 from anuga import indent18 #from anuga import indent 19 19 20 20 … … 56 56 if self.indices is not None: 57 57 # This overrides polygon, center and radius 58 pass 58 self.indices = num.asarray(self.indices) 59 60 if self.indices.size == 0: 61 self.indices = [] 62 59 63 elif (self.center is not None) and (self.radius is not None): 60 64 … … 71 75 else: 72 76 assert self.indices is None or self.indices is [] 77 78 79 80 if self.indices == []: 81 self.full_indices = [] 82 elif self.indices is None: 83 self.full_indices = num.where(self.domain.tri_full_flag ==1)[0] 84 else: 85 self.full_indices = self.indices[self.domain.tri_full_flag[self.indices]==1] 73 86 74 87 … … 93 106 indices.append(k) 94 107 95 self.indices = indices 108 if indices is []: 109 self.indices = indices 110 else: 111 self.indices = num.asarray(indices) 96 112 97 113 msg = 'No centroids intersect circle center'+str(c)+' radius '+str(r) … … 104 120 points = self.domain.get_centroid_coordinates(absolute=True) 105 121 122 indices = num.asarray(inside_polygon(points, self.polygon)) 106 123 107 self.indices = inside_polygon(points, self.polygon) 124 if indices is []: 125 self.indices = indices 126 else: 127 self.indices = num.asarray(indices) 108 128 109 129 130 def get_indices(self, full_only=True): 131 132 if full_only: 133 return self.full_indices 134 else: 135 return self.indices 136 137 110 138 111 139 112 -
trunk/anuga_core/source/anuga/operators/run_collect_max_stage_operator.py
r8944 r8945 62 62 Br = anuga.Reflective_boundary(domain) # Solid reflective wall 63 63 Bt = anuga.Transmissive_boundary(domain) # Continue all values on boundary 64 Bd = anuga.Dirichlet_boundary([1,0.,0.]) # Constant boundary values64 Bd = anuga.Dirichlet_boundary([1,0.,0.]) # Constant boundary values 65 65 66 66 67 67 # Associate boundary tags with boundary objects 68 68 domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br}) 69 70 71 69 72 70 #----------------------------------------------------------------------------- … … 85 83 86 84 87 88 85 # save the max_stage centroid data to a text file 89 86 max_operator.save_centroid_data_to_csv() 90 87 88 # Let's have a look at the max_stage 91 89 max_operator.plot_quantity() 92 90 -
trunk/anuga_core/source/anuga/operators/run_polygon_erosion.py
r8944 r8945 27 27 z = -x/100 28 28 29 N = len(x) 30 for i in range(N): 31 # Step 32 if 2 < x[i] < 4: 33 z[i] += 0.4 - 0.05*y[i] 29 # Step 30 id = (2 < x) & (x < 4) 31 z[id] += 0.4 - 0.05*y[id] 34 32 35 36 if (x[i] - 8)**2 + (y[i] - 2)**2 < 0.4**2:37 z[i] += 133 # Permanent pole 34 id = (x - 8)**2 + (y - 2)**2 < 0.4**2 35 z[id] += 1 38 36 39 # Dam 40 if 12 < x[i] < 13: 41 z[i] += 0.4 42 37 # Dam 38 id = (12 < x) & (x < 13) 39 z[id] += 0.4 43 40 44 41 return z … … 74 71 t = self.get_time() 75 72 dt = self.get_timestep() 76 77 73 78 74 updated = True -
trunk/anuga_core/source/anuga/operators/run_set_depth_friction.py
r8480 r8945 12 12 from anuga import Dirichlet_boundary 13 13 from anuga import Time_boundary 14 from anuga import Region 15 from anuga import indent 14 16 15 17 #------------------------------------------------------------------------------ … … 23 25 len1=length, len2=width) 24 26 domain = Domain(points, vertices, boundary) 25 domain.set_name( 'set_depth_friction') # Output name27 domain.set_name() # Output name 26 28 print domain.statistics() 27 29 … … 35 37 z = -x/100 36 38 37 N = len(x) 38 for i in range(N): 39 # Step 40 if 2 < x[i] < 4: 41 z[i] += 0.4 - 0.05*y[i] 39 # Step 40 id = ( 2 < x ) & (x < 4) 41 z[id] += 0.4 - 0.05*y[id] 42 42 43 # Permanent pole 44 if (x[i] - 8)**2 + (y[i] - 2)**2 < 0.4**2: 45 z[i] += 1 46 47 # # Pole 2 48 # if (x[i] - 14)**2 + (y[i] - 3.5)**2 < 0.4**2: 49 # z[i] += 1.0 43 # Permanent pole 44 id = (x - 8)**2 + (y - 2)**2 < 0.4**2 45 z[id] += 1 46 47 # Pole 2 48 #id = (x - 14)**2 + (y - 3.5)**2 < 0.4**2 49 #z[id] += 1.0 50 50 51 51 52 return z 52 53 53 54 54 … … 68 68 69 69 #------------------------------------------------------------------------------ 70 # Setup operators which are applied each inner step 71 #------------------------------------------------------------------------------ 72 from anuga.operators.set_friction_operators import Depth_friction_operator 73 74 op1 = Depth_friction_operator(domain) 75 76 p1 = [ [12.0, 2.5], [13.5, 2.5], [13.5, 4.0], [12.0, 4.0] ] 77 op2 = Depth_friction_operator(domain, 78 friction_max = 10, 79 friction_min = 0.0, 80 polygon=p1) 81 82 # Setup region for integrating quantities 83 p2 = [ [8.0, 2.5], [9.5, 2.5], [9.5, 4.0], [8.0, 4.0] ] 84 reg = Region(domain, polygon=p2) 85 86 # Some useful aliases 87 stage = domain.quantities['stage'] 88 elev = domain.quantities['elevation'] 89 90 #------------------------------------------------------------------------------ 70 91 # Evolve system through time 71 92 #------------------------------------------------------------------------------ 72 73 from anuga.operators.set_friction_operators import Set_depth_friction_operator 74 from anuga.operators.set_friction_operators import Polygonal_depth_friction_operator 75 76 #op1 = Set_depth_friction_operator(domain) 77 78 polygon1 = [ [12.0, 2.5], [13.5, 2.5], [13.5, 4.0], [12.0, 4.0] ] 79 op2 = Polygonal_depth_friction_operator(domain, friction_max = 10000, friction_min = 0.0, polygon=polygon1) 80 81 82 83 for t in domain.evolve(yieldstep=0.1, finaltime=30.0): 93 for t in domain.evolve(yieldstep=0.1, finaltime=10.0): 84 94 domain.print_timestepping_statistics() 85 95 domain.print_operator_timestepping_statistics() 96 97 # let calculate the integral of height over a region 98 height = stage-elev 99 print indent+'Int_p2(h) = '+str(height.get_integral(region=reg)) 86 100 87 101 -
trunk/anuga_core/source/anuga/operators/set_elevation_operator.py
r8929 r8945 9 9 10 10 11 from anuga import Domain12 from anuga import Quantity13 import numpy as num14 import anuga.utilities.log as log15 16 from anuga.geometry.polygon import inside_polygon17 11 18 12 from anuga.operators.base_operator import Operator -
trunk/anuga_core/source/anuga/operators/set_friction_operators.py
r8480 r8945 10 10 11 11 12 from anuga import Domain13 from anuga import Quantity14 import numpy as num15 import anuga.utilities.log as log16 12 17 from anuga.geometry.polygon import inside_polygon18 13 19 14 from anuga.operators.base_operator import Operator 20 from anuga.fit_interpolate.interpolate import Modeltime_too_early, \ 21 Modeltime_too_late 15 from anuga.operators.region import Region 16 17 22 18 from anuga import indent 23 19 … … 26 22 default_friction_max = 0.035 27 23 28 class Set_depth_friction_operator(Operator):24 class Depth_friction_operator(Operator, Region): 29 25 """ 30 26 Set the friction in a region 31 32 indices: None == all triangles, Empty list [] no triangles33 34 rate can be a function of time.35 36 27 """ 37 28 … … 40 31 friction_min=default_friction_min, 41 32 friction_max=default_friction_max, 42 indices = None, 33 indices=None, 34 polygon=None, 35 center=None, 36 radius=None, 43 37 description = None, 44 38 label = None, … … 48 42 49 43 Operator.__init__(self, domain, description, label, logging, verbose) 44 45 Region.__init__(self, domain, 46 indices=indices, 47 polygon=polygon, 48 center=center, 49 radius=radius, 50 verbose=verbose) 50 51 51 52 #------------------------------------------ … … 59 60 self.friction_max = friction_max 60 61 self.friction_c = self.domain.get_quantity('friction').centroid_values 61 self.indices = indices 62 62 63 63 64 … … 106 107 107 108 #=============================================================================== 108 # Specific Bed Operatorsfor circular region.109 # Specific Operator for circular region. 109 110 #=============================================================================== 110 class Circular_ set_depth_friction_operator(Set_depth_friction_operator):111 class Circular_depth_friction_operator(Depth_friction_operator): 111 112 """ 112 Set elevation over a circular region113 Set friction over a circular region 113 114 114 115 """ … … 121 122 verbose=False): 122 123 123 assert center is not None124 assert radius is not None125 126 127 # Determine indices in update region128 N = domain.get_number_of_triangles()129 points = domain.get_centroid_coordinates(absolute=True)130 131 132 indices = []133 134 c = center135 r = radius136 137 self.center = center138 self.radius = radius139 140 intersect = False141 for k in range(N):142 x, y = points[k,:] # Centroid143 144 if ((x-c[0])**2+(y-c[1])**2) < r**2:145 intersect = True146 indices.append(k)147 148 149 msg = 'No centroids intersect circle center'+str(center)+' radius '+str(radius)150 assert intersect, msg151 124 152 125 153 126 154 155 # It is possible that circle doesn't intersect with mesh (as can happen 156 # for parallel runs 157 158 159 Set_depth_friction_operator.__init__(self, 127 Dpth_friction_operator.__init__(self, 160 128 domain, 161 129 friction_min=friction_min, 162 130 friction_max=friction_max, 163 indices=indices, 131 center=center, 132 radius=radius, 164 133 verbose=verbose) 165 134 166 135 167 168 169 170 136 #=============================================================================== 171 # Specific Bed Operatorsfor polygonal region.137 # Specific Operator for polygonal region. 172 138 #=============================================================================== 173 class Polygonal_depth_friction_operator( Set_depth_friction_operator):139 class Polygonal_depth_friction_operator(Depth_friction_operator): 174 140 """ 175 Add water at certain rate (ms^{-1} = vol/Area/sec) over a 176 polygonal region 177 178 rate can be a function of time. 141 Set Friction over a polygon 179 142 180 143 """ … … 187 150 188 151 189 # Determine indices in update region190 N = domain.get_number_of_triangles()191 points = domain.get_centroid_coordinates(absolute=True)192 152 193 194 indices = inside_polygon(points, polygon) 195 self.polygon = polygon 196 197 # It is possible that circle doesn't intersect with mesh (as can happen 198 # for parallel runs 199 200 201 Set_depth_friction_operator.__init__(self, 153 Depth_friction_operator.__init__(self, 202 154 domain, 203 155 friction_min=friction_min, 204 156 friction_max=friction_max, 205 indices=indices,157 polygon=polygon, 206 158 verbose=verbose) 207 159 -
trunk/anuga_core/source/anuga/operators/set_quantity_operator.py
r8931 r8945 9 9 10 10 11 from anuga import Domain12 from anuga import Quantity13 import numpy as num14 import anuga.utilities.log as log15 11 16 from anuga.geometry.polygon import inside_polygon17 12 18 13 from anuga.operators.base_operator import Operator -
trunk/anuga_core/source/anuga/operators/set_stage_operator.py
r8930 r8945 26 26 class Set_stage_operator(Set_quantity_operator): 27 27 """ 28 Set the stage in a region 29 30 indices: None == all triangles, Empty list [] no triangles 31 32 rate can be a function of time. 33 28 Set the stage over a region 34 29 """ 35 30 … … 92 87 """ 93 88 Set stage over a circular region 94 95 89 """ 96 90 … … 116 110 class Polygonal_set_stage_operator(Set_stage_operator): 117 111 """ 118 Add water at certain rate (ms^{-1} = vol/Area/sec) over a 119 polygonal region 120 121 rate can be a function of time. 122 112 Set stage over a polygonal region 123 113 """ 124 114 -
trunk/anuga_core/source/anuga/operators/test_rate_operators.py
r8854 r8945 14 14 from anuga.file_conversion.file_conversion import timefile2netcdf 15 15 from anuga.config import time_format 16 17 from anuga.fit_interpolate.interpolate import Modeltime_too_early 18 from anuga.fit_interpolate.interpolate import Modeltime_too_late 16 19 17 20 from rate_operators import *
Note: See TracChangeset
for help on using the changeset viewer.