Changeset 4665


Ignore:
Timestamp:
Aug 8, 2007, 9:39:22 AM (17 years ago)
Author:
duncan
Message:

working on ticket#176

Location:
anuga_core/source/anuga
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/fit_interpolate/benchmark_least_squares.py

    r4658 r4665  
    2222import tempfile
    2323import profile , pstats
    24 import tempfile
    2524
    2625from anuga.fit_interpolate.interpolate import Interpolate
  • anuga_core/source/anuga/pmesh/mesh.py

    r4663 r4665  
    2828 
    2929#import load_mesh
    30 from anuga.coordinate_transforms.geo_reference import Geo_reference,DEFAULT_ZONE
     30from anuga.coordinate_transforms.geo_reference import Geo_reference, \
     31     DEFAULT_ZONE
    3132from anuga.utilities.polygon import point_in_polygon
    3233from  anuga.load_mesh.loadASCII import NOMAXAREA, export_mesh_file, \
     
    4041    import kinds 
    4142except ImportError: 
    42     # Hand-built mockup of the things we need from the kinds package, since it 
     43    # Hand-built mockup of the things we need from the kinds package, since it
    4344    # was recently removed from the standard Numeric distro.  Some users may 
    4445    # not have it by default. 
     
    8990        Returns the distance from this point to another
    9091        """
    91         SumOfSquares = ((self.x - OtherPoint.x)**2) + ((self.y - OtherPoint.y)**2)
     92        SumOfSquares = ((self.x - OtherPoint.x)**2) + \
     93                       ((self.y - OtherPoint.y)**2)
    9294        return math.sqrt(SumOfSquares)
    9395       
     
    154156       
    155157    VERTEXSQUARESIDELENGTH = 6
    156     def draw(self, canvas, tags, colour = 'black',scale = 1, xoffset = 0, yoffset =0, ):
     158    def draw(self, canvas, tags, colour = 'black',scale = 1, xoffset = 0,
     159             yoffset =0, ):
    157160        x =  scale*(self.x + xoffset)
    158161        y = -1*scale*(self.y + yoffset)  # - since for a canvas - is up
     
    189192    HOLECORNERLENGTH = 6
    190193   
    191     def draw(self, canvas, tags, colour = 'purple',scale = 1, xoffset = 0, yoffset =0, ):
     194    def draw(self, canvas, tags, colour = 'purple',scale = 1, xoffset = 0,
     195             yoffset =0, ):
    192196        x =  scale*(self.x + xoffset)
    193197        y = -1*scale*(self.y + yoffset)  # - since for a canvas - is up
     
    260264        return len(self.attributes)> 1
    261265   
    262     def draw(self, canvas, tags, scale=1, xoffset = 0, yoffset =0, colour = "black"):
     266    def draw(self, canvas, tags, scale=1, xoffset = 0, yoffset =0,
     267             colour = "black"):
    263268        """
    264269        Draw a black cross, returning the objectID
     
    301306    """
    302307
    303     def __init__(self, vertex1, vertex2, vertex3, attribute = None, neighbors = None ):
     308    def __init__(self, vertex1, vertex2, vertex3, attribute = None,
     309                 neighbors = None ):
    304310        """
    305311        Vertices, the initial arguments, are listed in counterclockwise order.
     
    347353        else:
    348354            if offset == 1:
    349                 self.vertices = [self.vertices[1],self.vertices[2],self.vertices[0]]
    350                 self.neighbors = [self.neighbors[1],self.neighbors[2],self.neighbors[0]]
     355                self.vertices = [self.vertices[1],self.vertices[2],
     356                                 self.vertices[0]]
     357                self.neighbors = [self.neighbors[1],self.neighbors[2],
     358                                  self.neighbors[0]]
    351359            if offset == 2:
    352                 self.vertices = [self.vertices[2],self.vertices[0],self.vertices[1]]
    353                 self.neighbors = [self.neighbors[2],self.neighbors[0],self.neighbors[1]]
     360                self.vertices = [self.vertices[2],self.vertices[0],
     361                                 self.vertices[1]]
     362                self.neighbors = [self.neighbors[2],self.neighbors[0],
     363                                  self.neighbors[1]]
    354364
    355365    def rotate_longest_side(self):
     
    395405        return a+b+c
    396406           
    397     def setNeighbors(self,neighbor1 = None, neighbor2 = None, neighbor3 = None):
     407    def setNeighbors(self,neighbor1=None, neighbor2=None, neighbor3=None):
    398408        """
    399409        neighbor1 is the triangle opposite vertex1 and so on.
     
    413423       
    414424
    415     def draw(self, canvas, tags, scale=1, xoffset = 0, yoffset =0, colour = "green"):
     425    def draw(self, canvas, tags, scale=1, xoffset=0, yoffset=0,
     426             colour="green"):
    416427        """
    417428        Draw a triangle, returning the objectID
     
    448459           
    449460       
    450     def draw(self, canvas, tags,scale=1 , xoffset=0 , yoffset=0,colour='blue' ):
     461    def draw(self, canvas, tags,scale=1, xoffset=0, yoffset=0,colour='blue'):
    451462        x=[]
    452463        y=[]
     
    529540    User attributes describe the mesh region/segments/vertices/attributes
    530541
    531     mesh attributes describe the mesh that is produced eg triangles and vertices.
     542    mesh attributes describe the mesh that is produced eg triangles and
     543    vertices.
    532544    All point information is relative to the geo_reference passed in
    533545   
     
    682694        return self._addRegion(x, y)
    683695
     696    def build_grid(self,  vert_rows, vert_columns):
     697        """
     698        Build a grid with vert_rows number of vertex rows and
     699        vert_columns number if vertex columns
     700
     701        Grid spacing of 1, the origin is the lower left hand corner.
     702
     703        FIXME(DSG-DSG) no test.
     704        """
     705
     706        for i in range(vert_rows):
     707            for j in range(vert_columns):
     708                self.addUserVertex(j,i)
     709        self.auto_segment()
     710        self.generateMesh(mode = "Q", minAngle=20.0)
     711       
    684712    # Depreciated
    685713    def addRegionEN(self, x,y):
     
    11411169                                  segconverter)
    11421170        #print "processed gen",generatedMesh['generatedsegmentmarkerlist']
    1143         #print "generatedtriangleattributelist",generatedMesh['generatedtriangleattributelist']
    11441171        generatedMesh['generatedtriangleattributelist'] = \
    11451172         region_ints2strings(generatedMesh['generatedtriangleattributelist'],
     
    16701697        for vertex in self.getUserVertices():
    16711698            points.append((vertex.x,vertex.y))
    1672         self.shape = anuga.alpha_shape.alpha_shape.Alpha_Shape(points, alpha = alpha)
     1699        self.shape = anuga.alpha_shape.alpha_shape.Alpha_Shape(points,
     1700                                                               alpha=alpha)
    16731701
    16741702
     
    26832711                            tag = parent_segment.tag
    26842712                            offspring = [line]
    2685                             offspring.extend(self.subtract_line(user_line,line))
     2713                            offspring.extend(self.subtract_line(user_line,
     2714                                                                line))
    26862715                            affine_lines.remove(user_line)
    26872716                            for newline in offspring:
     
    26952724                                        point_keys[point]=vert
    26962725                                    line_vertices.append(vert)
    2697                                 segment = Segment(line_vertices[0],line_vertices[1],tag)
     2726                                segment = Segment(line_vertices[0],
     2727                                                  line_vertices[1],tag)
    26982728                                userSegments[newline]=segment
    26992729                                affine_lines.append(newline)
     
    27142744                                point_keys[point]=vert
    27152745                            line_vertices.append(vert)
    2716                         segment = Segment(line_vertices[0],line_vertices[1],tag)
     2746                        segment = Segment(line_vertices[0],
     2747                                          line_vertices[1],tag)
    27172748                        userSegments[line]=segment
    27182749                        affine_lines.append(line)
     
    28192850        return ((x1-x0)**2-(y1-y0)**2)**0.5     
    28202851
    2821     def threshold(self,setName,min=None,max=None,attribute_name = 'elevation'):
     2852    def threshold(self,setName,min=None,max=None,attribute_name='elevation'):
    28222853        """
    28232854        threshold using  d
     
    33163347        """
    33173348
    3318         new_triangle1 = Triangle(new_point,triangle.vertices[0],triangle.vertices[1],attribute = triangle.attribute, neighbors = None)
    3319         new_triangle2 = Triangle(new_point,triangle.vertices[2],triangle.vertices[0],attribute = triangle.attribute, neighbors = None)
     3349        new_triangle1 = Triangle(new_point,triangle.vertices[0],
     3350                                 triangle.vertices[1],
     3351                                 attribute = triangle.attribute,
     3352                                 neighbors = None)
     3353        new_triangle2 = Triangle(new_point,triangle.vertices[2],
     3354                                 triangle.vertices[0],
     3355                                 attribute = triangle.attribute,
     3356                                 neighbors = None)
    33203357
    33213358        new_triangle1.setNeighbors(triangle.neighbors[2],None,new_triangle2)
     
    33583395            if not self.neighbour is None:
    33593396                self.neighbour.rotate_longest_side()
    3360             self.next_case = self.get_next_case(mesh,self.neighbour,self.current_triangle)
     3397            self.next_case = self.get_next_case(mesh,self.neighbour,
     3398                                                self.current_triangle)
    33613399        if self.case == 'vertex':
    33623400            self.new_point=self.old_point
     
    33933431            attributes.append(att)
    33943432        new_coordinate = [((a[0]-b[0])/2+b[0]),((a[1]-b[1])/2+b[1])]
    3395         newVertex = Vertex(new_coordinate[0],new_coordinate[1], attributes = attributes)
     3433        newVertex = Vertex(new_coordinate[0],new_coordinate[1],
     3434                           attributes = attributes)
    33963435        mesh.maxVertexIndex+=1
    33973436        newVertex.index = mesh.maxVertexIndex
  • anuga_core/source/anuga/shallow_water/data_manager.py

    r4663 r4665  
    21752175        ascid.close()
    21762176        fid.close()
    2177 
    21782177        return basename_out
    21792178
     
    49074906        If you get both, do a convertion from the old to the new.
    49084907       
    4909         If you only get new_origin, the points are absolute, convert to relative
     4908        If you only get new_origin, the points are absolute,
     4909        convert to relative
    49104910       
    49114911        if you only get the current_origin the points are relative, store
     
    49284928       
    49294929        number_of_points = len(points_utm)   
    4930         volumes = array(volumes)
     4930        volumes = array(volumes) 
     4931        points_utm = array(points_utm)
    49314932
    49324933        # given the two geo_refs and the points, do the stuff
     
    49514952   
    49524953        # This will put the geo ref in the middle
    4953         #geo_ref = Geo_reference(refzone,(max(x)+min(x))/2.0,(max(x)+min(y))/2.)
     4954        #geo_ref=Geo_reference(refzone,(max(x)+min(x))/2.0,(max(x)+min(y))/2.)
     4955       
    49544956        x =  points[:,0]
    49554957        y =  points[:,1]
     
    51225124        #Title
    51235125        fid.write('time' +d+ 'HA depth m'+d+ \
    5124                       'UA momentum East x m/sec' +d+ 'VA momentum North y m/sec' \
     5126                 'UA momentum East x m/sec' +d+ 'VA momentum North y m/sec' \
    51255127                      + "\n")
    51265128        for HA, UA, VA in map(None, mux['HA'], mux['UA'], mux['VA']):
     
    52315233    if extra_info <>'':
    52325234        extra_info = '_'+str(extra_info)
    5233     screen_output_name = dir_name + "screen_output%s%s%s.txt" %(myid,numprocs,extra_info)
    5234     screen_error_name = dir_name + "screen_error%s%s%s.txt" %(myid,numprocs,extra_info)
     5235    screen_output_name = dir_name + "screen_output%s%s%s.txt" %(myid,
     5236                                                                numprocs,
     5237                                                                extra_info)
     5238    screen_error_name = dir_name + "screen_error%s%s%s.txt" %(myid,
     5239                                                              numprocs,
     5240                                                              extra_info)
    52355241    print screen_output_name
    52365242    #used to catch screen output to file
     
    53235329    might be a better way to do this using CSV module Writer and writeDict
    53245330   
    5325     writes file to "output_dir" unless "completed" is in kwargs, then it writes to
    5326     "file_name" kwargs
     5331    writes file to "output_dir" unless "completed" is in kwargs, then
     5332    it writes to "file_name" kwargs
    53275333
    53285334    """
     
    54015407        fid.close()
    54025408    else:
    5403         #backup plan, if header is different and has completed will append info to
     5409        #backup plan,
     5410        # if header is different and has completed will append info to
    54045411        #end of details_temp.cvs file in output directory
    54055412        file = str(kwargs['output_dir'])+'detail_temp.csv'
     
    54315438                                                 verbose=False)
    54325439
    5433     filename is a NetCDF sww file containing ANUGA model output.                                                       
    5434     Optional arguments polygon and time_interval restricts the maximum runup calculation
     5440    filename is a NetCDF sww file containing ANUGA model output.   
     5441    Optional arguments polygon and time_interval restricts the maximum
     5442    runup calculation
    54355443    to a points that lie within the specified polygon and time interval.
    54365444
     
    54655473
    54665474    filename is a NetCDF sww file containing ANUGA model output.
    5467     Optional arguments polygon and time_interval restricts the maximum runup calculation
     5475    Optional arguments polygon and time_interval restricts the maximum
     5476    runup calculation
    54685477    to a points that lie within the specified polygon and time interval.
    54695478
     
    54955504   
    54965505
    5497     Algorithm is as in get_maximum_inundation_elevation from shallow_water_domain
     5506    Algorithm is as in get_maximum_inundation_elevation from
     5507    shallow_water_domain
    54985508    except that this function works with the sww file and computes the maximal
    54995509    runup height over multiple timesteps.
    55005510   
    5501     Optional arguments polygon and time_interval restricts the maximum runup calculation
    5502     to a points that lie within the specified polygon and time interval. Polygon is
     5511    Optional arguments polygon and time_interval restricts the
     5512    maximum runup calculation
     5513    to a points that lie within the specified polygon and time interval.
     5514    Polygon is
    55035515    assumed to be in (absolute) UTM coordinates in the same zone as domain.
    55045516
     
    55615573   
    55625574   
    5563         # Here's where one could convert nodal information to centroid information
     5575        # Here's where one could convert nodal information to centroid
     5576        # information
    55645577        # but is probably something we need to write in C.
    55655578        # Here's a Python thought which is NOT finished!!!
     
    55745587            msg = 'polygon must be a sequence of points.'
    55755588            assert len(polygon[0]) == 2, msg
    5576             # FIXME (Ole): Make a generic polygon input check in polygon.py and call it here
     5589            # FIXME (Ole): Make a generic polygon input check in polygon.py
     5590            # and call it here
    55775591           
    55785592            points = concatenate((x[:,NewAxis], y[:,NewAxis]), axis=1)
     
    56005614            msg = 'time_interval must be a sequence of length 2.'
    56015615            assert len(time_interval) == 2, msg
    5602             msg = 'time_interval %s must not be decreasing.' %(time_interval)       
     5616            msg = 'time_interval %s must not be decreasing.' %(time_interval)
    56035617            assert time_interval[1] >= time_interval[0], msg
    56045618           
     
    56335647        for i in timesteps:
    56345648            if use_centroid_values is True:
    5635                 stage_i = get_centroid_values(stage[i,:], volumes)                
     5649                stage_i = get_centroid_values(stage[i,:], volumes)   
    56365650            else:
    56375651                stage_i = stage[i,:]
Note: See TracChangeset for help on using the changeset viewer.