Changeset 7751
- Timestamp:
- May 28, 2010, 1:24:10 PM (15 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 1 added
- 10 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/__init__.py
r3518 r7751 7 7 import sys 8 8 sys.path += __path__ 9 10 11 # Make selected classes available directly 12 13 # Boundaries specific to shallow water domain. 14 from anuga.shallow_water.boundaries import Reflective_boundary,\ 15 Transmissive_momentum_set_stage_boundary,\ 16 Dirichlet_discharge_boundary,\ 17 Field_boundary,\ 18 Transmissive_stage_zero_momentum_boundary,\ 19 Transmissive_n_momentum_zero_t_momentum_set_stage_boundary 20 21 # Boundaries generic across all forms of domain. 22 from anuga.abstract_2d_finite_volumes.generic_boundary_conditions\ 23 import Transmissive_boundary, Dirichlet_boundary, \ 24 Time_boundary, File_boundary, AWI_boundary 25 26 # Shallow water domain is the standard 27 from anuga.shallow_water.shallow_water_domain import Domain -
anuga_core/source/anuga/abstract_2d_finite_volumes/util.py
r7745 r7751 308 308 return degrees(angle([uh, vh], [0, -1])) 309 309 310 311 def copy_code_files(dir_name, filename1, filename2, verbose=False):312 """Copies "filename1" and "filename2" to "dir_name".313 314 Each 'filename' may be a string or list of filename strings.315 316 Filenames must be absolute pathnames317 """318 319 ##320 # @brief copies a file or sequence to destination directory.321 # @param dest The destination directory to copy to.322 # @param file A filename string or sequence of filename strings.323 def copy_file_or_sequence(dest, file):324 if hasattr(file, '__iter__'):325 for f in file:326 shutil.copy(f, dir_name)327 if verbose:328 log.critical('File %s copied' % f)329 else:330 shutil.copy(file, dir_name)331 if verbose:332 log.critical('File %s copied' % file)333 334 # check we have a destination directory, create if necessary335 if not os.path.isdir(dir_name):336 if verbose:337 log.critical('Make directory %s' % dir_name)338 mkdir(dir_name, 0777)339 340 if verbose:341 log.critical('Output directory: %s' % dir_name)342 343 copy_file_or_sequence(dir_name, filename1)344 345 if not filename2 is None:346 copy_file_or_sequence(dir_name, filename2)347 310 348 311 ## -
anuga_core/source/anuga/file_conversion/__init__.py
r7742 r7751 6 6 sys.path += __path__ 7 7 8 # Make selected classes available directly9 from boundaries import Reflective_boundary,\10 Transmissive_momentum_set_stage_boundary,\11 Dirichlet_discharge_boundary,\12 Field_boundary,\13 Transmissive_stage_zero_momentum_boundary,\14 Transmissive_n_momentum_zero_t_momentum_set_stage_boundary15 16 from anuga.abstract_2d_finite_volumes.generic_boundary_conditions\17 import Transmissive_boundary, Dirichlet_boundary, \18 Time_boundary, File_boundary, AWI_boundary19 20 from shallow_water_domain import Domain21 22 8 23 9 #from shallow_water_balanced_domain import Swb_domain -
anuga_core/source/anuga/fit_interpolate/fit.py
r7717 r7751 35 35 from anuga.utilities.sparse import Sparse, Sparse_CSR 36 36 from anuga.geometry.polygon import inside_polygon, is_inside_polygon 37 from anuga. geometry.mesh_quadtree import MeshQuadtree37 from anuga.pmesh.mesh_quadtree import MeshQuadtree 38 38 39 39 from anuga.utilities.cg_solve import conjugate_gradient -
anuga_core/source/anuga/fit_interpolate/general_fit_interpolate.py
r7717 r7751 31 31 from anuga.geospatial_data.geospatial_data import Geospatial_data, \ 32 32 ensure_absolute 33 from anuga. geometry.mesh_quadtree import MeshQuadtree33 from anuga.pmesh.mesh_quadtree import MeshQuadtree 34 34 import anuga.utilities.log as log 35 35 -
anuga_core/source/anuga/geometry/aabb.py
r7721 r7751 1 # Allow children to be slightly bigger than their parents to prevent straddling of a boundary 1 """ 2 Axially aligned bounding box. 3 Contains a class describing a bounding box. It contains methods 4 to split itself and return child boxes. 5 """ 6 7 # Allow children to be slightly bigger than their parents to prevent 8 # straddling of a boundary 2 9 SPLIT_BORDER_RATIO = 0.55 3 10 … … 23 30 def __repr__(self): 24 31 return 'AABB(xmin:%f, xmax:%f, ymin:%f, ymax:%f)' \ 25 % (round(self.xmin,1), round(self.xmax,1), round(self.ymin,1), round(self.ymax, 1)) 32 % (round(self.xmin,1), round(self.xmax,1), \ 33 round(self.ymin,1), round(self.ymax, 1)) 26 34 27 35 … … 56 64 if (width > height): 57 65 # split vertically 58 return AABB(self.xmin, self.xmin+width*border, self.ymin, self.ymax), \ 59 AABB(self.xmax-width*border, self.xmax, self.ymin, self.ymax) 66 split1 = self.xmin+width*border 67 split2 = self.xmax-width*border 68 return AABB(self.xmin, split1, self.ymin, self.ymax), \ 69 AABB(split2, self.xmax, self.ymin, self.ymax) 60 70 else: 61 71 # split horizontally 62 return AABB(self.xmin, self.xmax, self.ymin, self.ymin+height*border), \ 63 AABB(self.xmin, self.xmax, self.ymax-height*border, self.ymax) 72 split1 = self.ymin+height*border 73 split2 = self.ymax-height*border 74 return AABB(self.xmin, self.xmax, self.ymin, split1), \ 75 AABB(self.xmin, self.xmax, split2, self.ymax) 64 76 65 77 … … 76 88 return True 77 89 78 def contains(self, x):90 def contains(self, point): 79 91 """ is point within box 80 xis a test point92 point is a test point 81 93 return True if the point is contained within the box. 82 94 """ 83 return (self.xmin <= x[0] <= self.xmax) and (self.ymin <= x[1] <= self.ymax) 95 return (self.xmin <= point[0] <= self.xmax) \ 96 and (self.ymin <= point[1] <= self.ymax) 84 97 -
anuga_core/source/anuga/geometry/quad.py
r7721 r7751 1 1 """quad.py - quad tree data structure for fast indexing of regions in the plane. 2 2 3 This is a generic structure that can be used to store any geometry in a quadtree. 4 It is naive, and does not exploit any coherency - it merely tests a bounding 5 box against all other bounding boxes in its heirarchy. 6 7 It returns a list of bounding boxes which intersect with the test box, which 8 must then be iterated over to detect actual intersections. 3 This generic structure can be used to store any geometry in a quadtree. 4 It is naive, and does not exploit any coherency - it merely tests a point 5 against all bounding boxes in its heirarchy. 6 7 It returns a list of bounding boxes which intersect with the test point, which 8 may then be iterated over with a proper intersection test to detect actual 9 geometry intersections. 9 10 10 11 """ 11 12 12 13 from anuga.utilities.treenode import TreeNode 13 import string, types, sys14 14 import anuga.utilities.log as log 15 from aabb import AABB16 15 17 16 … … 30 29 31 30 # Initialise base classes 32 TreeNode.__init__(self, string.lower(name))31 TreeNode.__init__(self, name) 33 32 34 33 self.extents = extents … … 41 40 42 41 def __repr__(self): 43 str = '%s: leaves: %d' \42 ret_str = '%s: leaves: %d' \ 44 43 % (self.name , len(self.leaves)) 45 44 if self.children: 46 str += ', children: %d' % (len(self.children))47 return str45 ret_str += ', children: %d' % (len(self.children)) 46 return ret_str 48 47 49 48 50 49 51 50 def clear(self): 51 """ Remove all leaves from this node. 52 """ 52 53 self.Prune() # TreeNode method 53 54 54 55 55 56 def clear_leaf_node(self): 56 """ Clears storage in leaf node.57 Called from Treenode.58 Must exist.59 """57 """ Clears storage in leaf node. 58 Called from Treenode. 59 Must exist. 60 """ 60 61 self.leaves = [] 61 62 … … 75 76 if type(new_leaf)==type(list()): 76 77 for leaf in new_leaf: 77 self. _insert(leaf)78 self.insert_item(leaf) 78 79 else: 79 self. _insert(new_leaf)80 81 82 def _insert(self, new_leaf):83 """ Internal recursive insert .80 self.insert_item(new_leaf) 81 82 83 def insert_item(self, new_leaf): 84 """ Internal recursive insert a single item. 84 85 new_leaf is a tuple of (AABB extents, data), where data can 85 86 be any user data (geometry, triangle index, etc.). 86 87 """ 87 new_region, data= new_leaf88 new_region, _ = new_leaf 88 89 89 90 # recurse down to any children until we get an intersection … … 91 92 for child in self.children: 92 93 if child.extents.is_trivial_in(new_region): 93 child. _insert(new_leaf)94 child.insert_item(new_leaf) 94 95 return 95 96 else: … … 98 99 99 100 # option 1 - try splitting 4 ways 100 #subregion11, subregion12 = subregion1.split() 101 #subregion11, subregion12 = subregion1.split() 101 102 #subregion21, subregion22 = subregion2.split() 102 103 #regions = [subregion11, subregion12, subregion21, subregion22] … … 104 105 #if region.is_trivial_in(new_region): 105 106 #self.children = [Cell(x, parent=self) for x in regions] 106 #self. _insert(new_leaf)107 #self.insert_item(new_leaf) 107 108 #return 108 109 109 110 # option 2 - try splitting 2 ways - no diff noticed in practise 110 111 if subregion1.is_trivial_in(new_region): 111 self.children = [Cell(subregion1, self), Cell(subregion2, self)] 112 self.children[0]._insert(new_leaf) 112 self.children = [Cell(subregion1, self), \ 113 Cell(subregion2, self)] 114 self.children[0].insert_item(new_leaf) 113 115 return 114 116 elif subregion2.is_trivial_in(new_region): 115 self.children = [Cell(subregion1, self), Cell(subregion2, self)] 116 self.children[1]._insert(new_leaf) 117 self.children = [Cell(subregion1, self), \ 118 Cell(subregion2, self)] 119 self.children[1].insert_item(new_leaf) 117 120 return 118 121 … … 156 159 if depth == 0: 157 160 log.critical() 158 print '%s%s' % (' '*depth, self.name), self.extents,' [', self.leaves, ']' 161 print '%s%s' % (' '*depth, self.name), self.extents, ' [', \ 162 self.leaves, ']' 159 163 if self.children: 160 164 log.critical() … … 162 166 child.show(depth+1) 163 167 164 def search(self, x): 165 """return a list of possible intersections with geometry""" 166 167 intersecting_regions = self.test_leaves(x) 168 def search(self, point): 169 """ 170 Search the tree for intersection with leaves 171 point is a test point. 172 return a list of possible intersections with geometry. 173 """ 174 intersecting_regions = self.test_leaves(point) 168 175 169 176 # recurse down into nodes that the point passes through 170 177 if self.children: 171 178 for child in self.children: 172 if child.extents.contains( x):173 intersecting_regions.extend(child.search( x))179 if child.extents.contains(point): 180 intersecting_regions.extend(child.search(point)) 174 181 175 182 return intersecting_regions 176 183 177 184 178 def test_leaves(self, x):185 def test_leaves(self, point): 179 186 """ Test all leaves to see if they intersect x. 180 187 x is a point to test … … 186 193 for leaf in self.leaves: 187 194 aabb, data = leaf 188 if aabb.contains( x):195 if aabb.contains(point): 189 196 intersecting_regions.append([data, self]) 190 197 -
anuga_core/source/anuga/pmesh/mesh_quadtree.py
r7743 r7751 71 71 72 72 # insert a tuple with an AABB, and the triangle index as data 73 self. _insert((AABB(min([x0, x1, x2]), max([x0, x1, x2]), \73 self.insert_item((AABB(min([x0, x1, x2]), max([x0, x1, x2]), \ 74 74 min([y0, y1, y2]), max([y0, y1, y2])), \ 75 75 node_data)) … … 146 146 147 147 for node_data in triangles: 148 if bool(_is_inside_triangle(x, node_data[0][1], int(True), 1.0e-12, 1.0e-12)): 148 if bool(_is_inside_triangle(x, node_data[0][1], \ 149 int(True), 1.0e-12, 1.0e-12)): 149 150 normals = node_data[0][2] 150 151 n0 = normals[0:2] … … 155 156 sigma0 = num.dot((x-xi1), n0)/num.dot((xi0-xi1), n0) 156 157 sigma1 = num.dot((x-xi2), n1)/num.dot((xi1-xi2), n1) 157 sigma2 = num.dot((x-xi0), n2)/num.dot((xi2-xi0), n2) 158 sigma2 = num.dot((x-xi0), n2)/num.dot((xi2-xi0), n2) 158 159 159 160 # Don't look for any other triangles in the triangle list 160 161 self.last_triangle = [node_data] 161 return True, sigma0, sigma1, sigma2, node_data[0][0] # tri index 162 return True, sigma0, sigma1, sigma2, node_data[0][0] # tri index 162 163 return False, -1, -1, -1, -10 163 164 -
anuga_core/source/anuga/shallow_water/data_manager.py
r7744 r7751 79 79 from anuga.utilities.numerical_tools import ensure_numeric, mean 80 80 from anuga.caching.caching import myhash 81 from anuga.shallow_water import Domain81 from anuga.shallow_water.shallow_water_domain import Domain 82 82 from anuga.abstract_2d_finite_volumes.pmesh2domain import \ 83 83 pmesh_to_domain_instance -
anuga_core/source/anuga/utilities/file_utils.py
r7745 r7751 393 393 394 394 395 396 def copy_code_files(dir_name, filename1, filename2, verbose=False): 397 """Copies "filename1" and "filename2" to "dir_name". 398 399 Each 'filename' may be a string or list of filename strings. 400 401 Filenames must be absolute pathnames 402 """ 403 404 ## 405 # @brief copies a file or sequence to destination directory. 406 # @param dest The destination directory to copy to. 407 # @param file A filename string or sequence of filename strings. 408 def copy_file_or_sequence(dest, file): 409 if hasattr(file, '__iter__'): 410 for f in file: 411 shutil.copy(f, dir_name) 412 if verbose: 413 log.critical('File %s copied' % f) 414 else: 415 shutil.copy(file, dir_name) 416 if verbose: 417 log.critical('File %s copied' % file) 418 419 # check we have a destination directory, create if necessary 420 if not os.path.isdir(dir_name): 421 if verbose: 422 log.critical('Make directory %s' % dir_name) 423 mkdir(dir_name, 0777) 424 425 if verbose: 426 log.critical('Output directory: %s' % dir_name) 427 428 copy_file_or_sequence(dir_name, filename1) 429 430 if not filename2 is None: 431 copy_file_or_sequence(dir_name, filename2) -
anuga_core/source/anuga/utilities/interp.py
r7276 r7751 138 138 """ 139 139 import arrayfns 140 import numpy.ma MA140 import numpy.ma as MA 141 141 import numpy as N 142 142 from where_close import where_close
Note: See TracChangeset
for help on using the changeset viewer.