Changeset 1995
- Timestamp:
- Nov 3, 2005, 3:07:06 PM (19 years ago)
- Location:
- inundation
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/analytical solutions/Analytical_solution_circular_hydraulic_jump.py
r1929 r1995 141 141 import time 142 142 143 f = open("output.txt","w") 144 143 145 t0 = time.time() 144 for t in domain.evolve(yieldstep = .01, finaltime = 10):146 for t in domain.evolve(yieldstep = .01, finaltime = 0.1): 145 147 domain.write_time() 146 148 … … 158 160 print ' radial mom ', \ 159 161 radial_momentum.get_values(location='centroids', 160 indices=[typical_inner[0]]) 161 162 indices=[typical_inner[0]]) 162 163 163 164 164 165 166 165 f.write('time = %25.15e wall clock time %g \n' % (domain.time, time.time())) 166 f.write('%g \n' % w.get_values(location='centroids', 167 indices=[typical_outer[0]])[0]) 168 169 170 f.close() 171 172 167 173 #vxmom.update_quantity('xmomentum') 168 174 #vymom.update_quantity('ymomentum') -
inundation/pyvolution/quantity.py
r1928 r1995 56 56 57 57 58 #Methods for operator overloading 58 #Methods for operator overloading 59 59 def __len__(self): 60 60 return self.centroid_values.shape[0] … … 69 69 Q.set_values(-self.vertex_values) 70 70 return Q 71 71 72 72 73 73 def __add__(self, other): 74 74 """Add to self anything that could populate a quantity 75 75 76 76 E.g other can be a constant, an array, a function, another quantity 77 77 (except for a filename or points, attributes (for now)) … … 80 80 81 81 Q = Quantity(self.domain) 82 Q.set_values(other) 82 Q.set_values(other) 83 83 84 84 result = Quantity(self.domain) … … 90 90 """ 91 91 return self + other 92 93 94 def __sub__(self, other): 92 93 94 def __sub__(self, other): 95 95 return self + -other #Invoke __neg__ 96 96 97 97 def __mul__(self, other): 98 98 """Multiply self with anything that could populate a quantity 99 99 100 100 E.g other can be a constant, an array, a function, another quantity 101 101 (except for a filename or points, attributes (for now)) … … 111 111 Q = Quantity(self.domain) 112 112 Q.set_values(other) 113 113 114 114 result = Quantity(self.domain) 115 115 result.set_values(self.vertex_values * Q.vertex_values) 116 116 return result 117 117 118 118 def __rmul__(self, other): 119 119 """Handle cases like 3*Q, where Q is an instance of class Quantity … … 135 135 result.set_values(self.vertex_values**other) 136 136 return result 137 138 137 138 139 139 140 140 def interpolate(self): … … 166 166 numeric = None, # List, numeric array or constant 167 167 quantity = None, # Another quantity 168 function = None, # Callable object: f(x,y) 168 function = None, # Callable object: f(x,y) 169 169 points = None, values = None, #Input for least squares 170 170 filename = None, attribute_name = None, #Input from file 171 171 alpha = None, 172 location = 'vertices', 172 location = 'vertices', 173 173 indices = None, 174 174 verbose = None, 175 175 use_cache = False): 176 176 177 177 """Set values for quantity based on different sources. 178 178 179 179 numeric: 180 180 Compatible list, Numeric array (see below) or constant. 181 If callable it will treated as a function 181 If callable it will treated as a function 182 182 If instance of another Quantity it will be treated as such. 183 183 … … 209 209 Alpha will only be used with points, values or filename. 210 210 Otherwise it will be ignored. 211 212 211 212 213 213 location: Where values are to be stored. 214 214 Permissible options are: vertices, edges, centroids … … 239 239 use_cache: True means that caching of intermediate results is 240 240 attempted for least squares fit. 241 242 243 241 242 243 244 244 245 245 Exactly one of the arguments … … 252 252 253 253 #General input checks 254 L = [numeric, quantity, function, points, filename] 254 L = [numeric, quantity, function, points, filename] 255 255 msg = 'Exactly one of the arguments '+\ 256 256 'numeric, quantity, function, points, or filename '+\ … … 267 267 msg = 'Indices must be a list or None' 268 268 assert type(indices) in [ListType, NoneType, ArrayType], msg 269 270 271 269 270 271 272 272 #Determine which 'set_values_from_...' to use 273 273 … … 288 288 msg = 'Illegal type for argument numeric: %s' %str(numeric) 289 289 raise msg 290 290 291 291 elif quantity is not None: 292 292 self.set_values_from_quantity(quantity, … … 294 294 elif function is not None: 295 295 msg = 'Argument function must be callable' 296 assert callable(function), msg 296 assert callable(function), msg 297 297 self.set_values_from_function(function, 298 298 location, indices, verbose) … … 320 320 self.extrapolate_first_order() 321 321 322 322 323 323 324 324 #Specific functions for setting values … … 372 372 self.vertex_values[i_vertex,:] = X 373 373 374 375 376 374 375 376 377 377 378 378 … … 479 479 """Set quantity values from specified quantity instance q 480 480 481 Location is ignored 482 """ 483 484 481 Location is ignored 482 """ 483 484 485 485 A = q.vertex_values 486 486 … … 517 517 else: 518 518 is_subset = True 519 519 520 520 if location == 'centroids': 521 521 P = take(self.domain.centroid_coordinates, indices) … … 546 546 """ 547 547 548 from Numeric import Float 548 from Numeric import Float 549 549 from util import ensure_numeric 550 550 from least_squares import fit_to_mesh 551 551 552 552 points = ensure_numeric(points, Float) 553 553 values = ensure_numeric(values, Float) … … 568 568 'could not be imported' 569 569 raise msg 570 570 571 571 args = (coordinates, triangles, points, values) 572 572 kwargs = {'alpha': alpha, 'verbose': verbose} … … 574 574 args, kwargs, 575 575 verbose = verbose) 576 else: 576 else: 577 577 vertex_attributes = fit_to_mesh(coordinates, 578 578 triangles, … … 581 581 alpha = alpha, 582 582 verbose = verbose) 583 584 583 584 585 585 self.set_values_from_array(vertex_attributes, 586 location, indices, verbose) 587 588 589 590 591 586 location, indices, verbose) 587 588 589 590 591 592 592 def set_values_from_file(self, filename, attribute_name, alpha, 593 593 location, indices, verbose, use_cache): 594 594 """Set quantity based on arbitrary points in .pts file 595 595 using least_squares attribute_name selects name of attribute 596 present in file. 596 present in file. 597 597 If not specified try to use whatever is available in file. 598 598 """ … … 609 609 points = points_dict['pointlist'] 610 610 attributes = points_dict['attributelist'] 611 611 612 612 if attribute_name is None: 613 613 names = attributes.keys() … … 615 615 616 616 msg = 'Attribute_name must be a text string' 617 assert type(attribute_name) == StringType, msg 617 assert type(attribute_name) == StringType, msg 618 618 619 619 … … 629 629 raise msg 630 630 631 632 #Call least squares method 631 632 #Call least squares method 633 633 self.set_values_from_points(points, z, alpha, 634 634 location, indices, verbose, use_cache) … … 896 896 def get_integral(self): 897 897 """Compute the integral of quantity across entire domain 898 899 900 898 """ 899 integral = 0 900 for k in range(self.domain.number_of_elements): 901 901 area = self.domain.areas[k] 902 902 qc = self.centroid_values[k] 903 903 integral += qc*area 904 904 905 906 907 908 905 return integral 906 907 908 909 909 910 910 class Conserved_quantity(Quantity): -
inundation/zeus/anuga-workspace.zwi
r1967 r1995 2 2 <workspace name="anuga-workspace"> 3 3 <mode>Debug</mode> 4 <active> steve</active>4 <active>analytic_solutions</active> 5 5 <project name="analytic_solutions">analytic_solutions.zpi</project> 6 6 <project name="euler">euler.zpi</project>
Note: See TracChangeset
for help on using the changeset viewer.