Changeset 8361
- Timestamp:
- Mar 18, 2012, 9:07:07 PM (13 years ago)
- Location:
- trunk/anuga_core/source/anuga
- Files:
-
- 5 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/geometry/polygon.py
r8257 r8361 229 229 230 230 def line_intersect(triangles, line, verbose=False): 231 """Determine if a polygon and triangle overlap231 """Determine which of a list of trianglee intersect a line 232 232 233 233 """ … … 242 242 243 243 if verbose: 244 log.critical('Found %d triangles (out of %d) that overlap the polygon' % (count, M))244 log.critical('Found %d triangles (out of %d) that intersect line' % (count, M)) 245 245 246 246 return indices[:count] -
trunk/anuga_core/source/anuga/geometry/polygon_ext.c
r8247 r8361 514 514 if (A >= 1 && B >= 1) 515 515 { 516 return 1; // polygonsits completely inside a triangle516 return 1; //line sits completely inside a triangle 517 517 } 518 518 -
trunk/anuga_core/source/anuga/operators/base_operator.py
r8357 r8361 6 6 """ 7 7 8 def __init__(self, domain): 8 counter = 0 9 10 def __init__(self, 11 domain, 12 description = None, 13 label = None, 14 logging = False, 15 verbose = False): 9 16 10 17 self.domain = domain … … 15 22 assert self.__parallel_safe(), msg 16 23 17 self.logging = False 18 self.logging_file = '' 24 if description == None: 25 self.description = ' ' 26 else: 27 self.description = description 28 29 30 if label == None: 31 self.label = "inlet_%g" % Operator.counter 32 else: 33 self.label = label + '_%g' % Operator.counter 34 35 36 self.verbose = verbose 37 38 # Keep count of inlet operator 39 Operator.counter += 1 40 41 self.set_logging(logging) 42 19 43 20 44 def __call__(self): … … 37 61 return message 38 62 63 def timestepping_statistics(self): 64 65 message = 'You need to implement timestepping statistics for your operator' 66 return message 67 39 68 40 69 def print_statistics(self): 41 70 42 71 print self.statistics() 43 44 45 def timestepping_statistics(self):46 47 message = 'You need to implement timestepping statistics for your operator'48 return message49 72 50 73 def print_timestepping_statistics(self): … … 58 81 if self.logging: 59 82 log_to_file(self.log_filename, self.timestepping_statistics()) 60 83 84 85 86 def set_logging(self, flag=True): 87 88 self.logging = flag 89 90 # If flag is true open file with mode = "w" to form a clean file for logging 91 if self.logging: 92 self.log_filename = self.label + '.log' 93 log_to_file(self.log_filename, self.statistics(), mode='w') 94 log_to_file(self.log_filename, 'time,Q') 95 96 #log_to_file(self.log_filename, self.culvert_type) 97 98 -
trunk/anuga_core/source/anuga/operators/rate_operators.py
r8360 r8361 14 14 import numpy as num 15 15 import anuga.utilities.log as log 16 17 from anuga.geometry.polygon import inside_polygon 16 18 17 19 from anuga.operators.base_operator import Operator … … 36 38 indices=None, 37 39 default_rate=None, 38 verbose=False): 39 40 Operator.__init__(self,domain) 40 description = None, 41 label = None, 42 logging = False, 43 verbose = False): 44 45 46 anuga.Operator.__init__(self, domain, description, label, logging, verbose) 41 47 42 48 #------------------------------------------ … … 81 87 82 88 def __call__(self): 89 """ 90 Apply rate to those triangles defined in indices 91 92 indices == [] don't apply anywhere 93 indices == None apply everywhere 94 otherwise applyfor the specific indices 95 """ 83 96 84 97 if self.indices is []: … … 103 116 104 117 def update_rate(self, t): 105 """Virtual method allowing local modifications by writing an 106 overriding version in descendant 118 """Provide a rate to calculate added volume 107 119 """ 108 120 … … 146 158 147 159 def __parallel_safe(self): 148 """Operator is justapplied independently to each cell and160 """Operator is applied independently to each cell and 149 161 so is parallel safe. 150 162 """ … … 166 178 167 179 #=============================================================================== 168 # Specific Rate Operators for special regions.180 # Specific Rate Operators for circular region. 169 181 #=============================================================================== 170 182 class Circular_rate_operator(Rate_operator): … … 179 191 def __init__(self, domain, 180 192 rate=0.0, 181 center =None,182 radius =None,193 center=None, 194 radius=None, 183 195 default_rate=None, 184 196 verbose=False): 185 186 if verbose: log.critical(self.__name__+': Beginning Initialisation')187 188 197 189 198 assert center is not None … … 205 214 206 215 if ((x-c[0])**2+(y-c[1])**2) < r**2: 207 self.indices.append(k)216 indices.append(k) 208 217 209 218 … … 224 233 225 234 235 #=============================================================================== 236 # Specific Rate Operators for polygonal region. 237 #=============================================================================== 238 class Polygonal_rate_operator(Rate_operator): 239 """ 240 Add water at certain rate (ms^{-1} = vol/Area/sec) over a 241 polygonal region 242 243 rate can be a function of time. 244 245 """ 246 247 def __init__(self, domain, 248 rate=0.0, 249 polygon=None, 250 default_rate=None, 251 verbose=False): 252 253 assert center is not None 254 assert radius is not None 255 256 257 # Determine indices in update region 258 N = domain.get_number_of_triangles() 259 points = domain.get_centroid_coordinates(absolute=True) 260 261 262 indices = inside_polygon(points, polygon) 263 264 265 # It is possible that circle doesn't intersect with mesh (as can happen 266 # for parallel runs 267 268 269 Rate_operator.__init__(self, 270 domain, 271 rate=rate, 272 indices=indices, 273 default_rate=default_rate, 274 verbose=verbose) 275 276 277 self.polygon = polygon 278 279 280 281 282 -
trunk/anuga_core/source/anuga/structures/inlet_operator.py
r8228 r8361 1 1 import anuga 2 2 import numpy 3 import math4 3 import inlet 5 4 6 from anuga.utilities.system_tools import log_to_file7 5 8 9 class Inlet_operator: 6 class Inlet_operator(anuga.Operator): 10 7 """Inlet Operator - add water to an inlet. 11 8 Sets up the geometry of problem … … 17 14 """ 18 15 19 counter = 020 16 21 17 def __init__(self, … … 27 23 logging = False, 28 24 verbose = False): 25 26 27 anuga.Operator.__init__(self, domain, description, label, logging, verbose) 28 29 29 30 self.domain = domain31 self.domain.set_fractional_step_operator(self)32 30 self.line = numpy.array(line, dtype='d') 33 31 … … 35 33 self.Q = Q 36 34 37 if description == None:38 self.description = ' '39 else:40 self.description = description41 42 43 if label == None:44 self.label = "inlet_%g" % Inlet_operator.counter45 else:46 self.label = label + '_%g' % Inlet_operator.counter47 48 49 self.verbose = verbose50 51 # Keep count of inlet operator52 Inlet_operator.counter += 153 35 54 36 self.enquiry_point = 0.5*(self.line[0] + self.line[1]) … … 56 38 self.inlet = inlet.Inlet(self.domain, self.line, verbose= verbose) 57 39 58 self. set_logging(logging)40 self.applied_Q = 0.0 59 41 60 42 def __call__(self): … … 63 45 64 46 t = self.domain.get_time() 47 65 48 Q1 = self.update_Q(t) 66 49 Q2 = self.update_Q(t + timestep) 50 51 Q = 0.5*(Q1+Q2) 52 volume = Q*timestep 67 53 68 volume = 0.5*(Q1+Q2)*timestep 69 70 assert 0.5*(Q1+Q2) >= 0.0, 'Q < 0: Water to be removed from an inlet!' 71 54 assert volume >= 0.0, 'Q < 0: Water to be removed from an inlet!' 55 56 # store last discharge 57 self.applied_Q = Q 58 72 59 # Distribute volume so as to obtain flat surface 73 60 self.inlet.set_stages_evenly(volume) … … 77 64 78 65 def update_Q(self, t): 79 """Virtual method allowing local modifications by writing an 80 overriding version in descendant 66 """Allowing local modifications of Q 81 67 """ 82 68 … … 121 107 122 108 123 def print_statistics(self): 124 125 print self.statistics() 126 127 128 def print_timestepping_statistics(self): 109 def timestepping_statistics(self): 129 110 130 111 message = '---------------------------\n' 131 112 message += 'Inlet report for %s:\n' % self.label 132 113 message += '--------------------------\n' 133 message += 'Q [m^3/s]: %.2f\n' % self.Q 134 135 136 print message 137 138 139 def set_logging(self, flag=True): 140 141 self.logging = flag 142 143 # If flag is true open file with mode = "w" to form a clean file for logging 144 if self.logging: 145 self.log_filename = self.label + '.log' 146 log_to_file(self.log_filename, self.statistics(), mode='w') 147 log_to_file(self.log_filename, 'time,Q') 148 149 #log_to_file(self.log_filename, self.culvert_type) 150 151 152 def timestepping_statistics(self): 153 154 message = '%.5f, ' % self.domain.get_time() 155 message += '%.5f, ' % self.Q 114 message += 'Q [m^3/s]: %.2f\n' % self.applied_Q 156 115 157 116 return message 158 159 def log_timestepping_statistics(self):160 161 if self.logging:162 log_to_file(self.log_filename, self.timestepping_statistics())163 164 117 165 118 -
trunk/anuga_core/source/anuga/structures/run_inlet_operator.py
r8360 r8361 102 102 103 103 104 line = [[0.0, 5.0], [0.0, 10.0]]104 line0 = [[0.0, 5.0], [0.0, 10.0]] 105 105 106 106 Q = file_function('test_hydrograph.tms', quantities=['hydrograph']) 107 107 108 Inlet_operator(domain, line, Q)108 inlet0 = Inlet_operator(domain, line0, Q, label='first inlet') 109 109 110 111 line1 = [[1.0, 5.0], [2.0, 10.0]] 112 inlet1 = Inlet_operator(domain, line1, 2.0) 110 113 111 114 … … 150 153 151 154 print domain.volumetric_balance_statistics() 152 155 156 inlet0.print_timestepping_statistics() 157 print inlet1.timestepping_statistics() 153 158 pass 154 159
Note: See TracChangeset
for help on using the changeset viewer.