Changeset 3447


Ignore:
Timestamp:
Aug 2, 2006, 5:14:16 PM (19 years ago)
Author:
duncan
Message:

Making set_region easier to use.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • development/dam_2006/run_dam.py

    r3446 r3447  
    5656    create_mesh.generate(project.mesh_filename,
    5757                         gate_position,
    58                          #is_course=True) # this creates the mesh
    59                          is_course=False) # this creates the mesh
     58                         is_course=True) # this creates the mesh
     59                         #is_course=False) # this creates the mesh
    6060
    6161    head,tail = path.split(project.mesh_filename)
     
    9191
    9292    print 'Available boundary tags', domain.get_boundary_tags()
    93 
     93    domain.set_region('dam','stage',0.2,
     94                                 location = 'unique vertices')
    9495    domain.set_region(Set_region('dam','stage',0.2,
    9596                                 location = 'unique vertices'))
  • inundation/pyvolution/domain.py

    r3085 r3447  
    1515from pyvolution.generic_boundary_conditions import Transmissive_boundary
    1616from pyvolution.pmesh2domain import pmesh_to_domain
     17from pyvolution.region import Set_region as region_set_region
    1718
    1819import types
     
    424425
    425426
    426     def set_region(self, functions):
     427    def set_region(self, *args, **kwargs):
     428        """
     429        This method is used to set quantities based on a regional tag.
     430       
     431        It is most often called with the following parameters;
     432        (self, tag, quantity, X, location='vertices')
     433        tag: the name of the regional tag used to specify the region
     434        quantity: Name of quantity to change
     435        X: const or function - how the quantity is changed
     436        location: Where values are to be stored.
     437            Permissible options are: vertices, centroid and unique vertices
     438
     439        A callable region class or a list of callable region classes
     440        can also be passed into this function.
     441        """
     442        #print "*args", args
     443        #print "**kwargs", kwargs
     444        if len(args) == 1:
     445            self._set_region(*args, **kwargs)
     446        else:
     447            #Assume it is arguments for the region.set_region function
     448            func = region_set_region(*args, **kwargs)
     449            self._set_region(func)
     450           
     451       
     452    def _set_region(self, functions):
    427453        # The order of functions in the list is used.
    428454        if type(functions) not in [types.ListType,types.TupleType]:
     
    432458                function(tag, self.tagged_elements[tag], self)
    433459
    434                 #Do we need to do this sort of thing?
    435                 #self = function(tag, self.tagged_elements[tag], self)
    436460
    437461    #MISC
  • inundation/pyvolution/test_domain.py

    r2765 r3447  
    536536
    537537
     538    def test_region_tags2(self):
     539        """
     540        get values based on triangle lists.
     541        """
     542        from mesh_factory import rectangular
     543        from shallow_water import Domain
     544        from Numeric import zeros, Float
     545
     546        #Create basic mesh
     547        points, vertices, boundary = rectangular(1, 3)
     548
     549        #Create shallow water domain
     550        domain = Domain(points, vertices, boundary)
     551        domain.build_tagged_elements_dictionary({'bottom':[0,1],
     552                                                 'top':[4,5],
     553                                                 'all':[0,1,2,3,4,5]})
     554
     555
     556        #Set friction
     557        manning = 0.07
     558        domain.set_quantity('friction', manning)
     559
     560        domain.set_region('top', 'friction', 1.0)
     561        domain.set_region('bottom', 'friction', 0.09)
     562       
     563        #print domain.quantities['friction'].get_values()
     564        assert allclose(domain.quantities['friction'].get_values(),\
     565                        [[ 0.09,  0.09,  0.09],
     566                         [ 0.09,  0.09,  0.09],
     567                         [ 0.07,  0.07,  0.07],
     568                         [ 0.07,  0.07,  0.07],
     569                         [ 1.0,  1.0,  1.0],
     570                         [ 1.0,  1.0,  1.0]])
     571       
     572        domain.set_region([set_bottom_friction, set_top_friction])
     573        #print domain.quantities['friction'].get_values()
     574        assert allclose(domain.quantities['friction'].get_values(),\
     575                        [[ 0.09,  0.09,  0.09],
     576                         [ 0.09,  0.09,  0.09],
     577                         [ 0.07,  0.07,  0.07],
     578                         [ 0.07,  0.07,  0.07],
     579                         [ 1.0,  1.0,  1.0],
     580                         [ 1.0,  1.0,  1.0]])
     581
     582        domain.set_region([set_all_friction])
     583        #print domain.quantities['friction'].get_values()
     584        assert allclose(domain.quantities['friction'].get_values(),
     585                        [[ 10.09, 10.09, 10.09],
     586                         [ 10.09, 10.09, 10.09],
     587                         [ 10.07, 10.07, 10.07],
     588                         [ 10.07, 10.07, 10.07],
     589                         [ 11.0,  11.0,  11.0],
     590                         [ 11.0,  11.0,  11.0]])
    538591
    539592#-------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.