Changeset 8616


Ignore:
Timestamp:
Nov 13, 2012, 9:11:35 PM (11 years ago)
Author:
steve
Message:

Small changes to inlet operators

Location:
trunk/anuga_core
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/mesh_factory_ext.c

    r8551 r8616  
    118118                }
    119119
     120        free(vertices);
     121
    120122        return Py_BuildValue("O", pyobj_boundary);
    121123}
  • trunk/anuga_core/source/anuga/structures/inlet.py

    r8259 r8616  
    233233        summed_volume = num.zeros_like(areas)       
    234234        summed_volume[1:] = num.cumsum(summed_areas[:-1]*num.diff(stages[stages_order]))
    235        
    236         # find the number of cells which will be filled
    237         index = num.nonzero(summed_volume<=volume)[0][-1]
    238 
    239         # calculate stage needed to fill chosen cells with given volume of water
    240         depth = (volume - summed_volume[index])/summed_areas[index]
    241         stages[stages_order[0:index+1]] = stages[stages_order[index]]+depth
    242 
    243         self.set_stages(stages)
     235
     236
     237        if volume>= 0.0 :
     238            # find the number of cells which will be filled
     239            #print summed_volume
     240            #print summed_volume<=volume
     241
     242            #Test = summed_volume<=volume
     243
     244            #print num.any(Test)
     245            #print num.nonzero(summed_volume<=volume)
     246            #print num.nonzero(summed_volume<=volume)[0]
     247
     248            index = num.nonzero(summed_volume<=volume)[0][-1]
     249
     250            # calculate stage needed to fill chosen cells with given volume of water
     251            depth = (volume - summed_volume[index])/summed_areas[index]
     252            stages[stages_order[0:index+1]] = stages[stages_order[index]]+depth
     253
     254        else:
     255            if summed_volume[-1]>= -volume :
     256                depth = (summed_volume[-1] + volume)/summed_areas[-1]
     257                stages[:] = depth
     258            else:
     259                #assert summed_volume[-1] >= -volume
     260                import warnings
     261                warnings.warn('summed_volume < volume to be extracted')
     262                stages[:] = 0.0
     263
     264        self.set_stages(stages)
     265
     266
     267
     268
     269    def set_stages_evenly_new(self,volume):
     270        """ Distribute volume of water over
     271        inlet exchange region so that stage is level
     272        """
     273        # WARNING: requires synchronization, must be called by all procs associated
     274        # with this inlet
     275
     276        centroid_coordinates = self.domain.get_full_centroid_coordinates(absolute=True)
     277        areas = self.get_areas()
     278        stages = self.get_stages()
     279
     280        stages_order = stages.argsort()
     281
     282        # PETE: send stages and areas, apply merging procedure
     283
     284        total_stages = len(stages)
     285
     286
     287        s_areas = areas
     288        s_stages = stages
     289        s_stages_order = stages_order
     290
     291
     292        pos = 0
     293        summed_volume = 0.
     294        summed_areas = 0.
     295        prev_stage = 0.
     296        num_stages = 0.
     297        first = True
     298
     299        for i in self.procs:
     300            pos[i] = 0
     301
     302        while num_stages < total_stages:
     303            # Determine current minimum stage of all the processors in s_stages
     304            num_stages = num_stages + 1
     305            current_stage = num.finfo(num.float32).max
     306            index = -1
     307
     308
     309            if pos >= len(s_stages):
     310                continue
     311
     312            if s_stages[s_stages_order[pos]] < current_stage:
     313                current_stage = s_stages[i][s_stages_order[i][pos[i]]]
     314                index = i
     315
     316            # If first iteration, then only update summed_areas, position, and prev|current stage
     317
     318            if first:
     319                first = False
     320                summed_areas = s_areas[index][s_stages_order[index][pos[index]]]
     321                pos[index] = pos[index] + 1
     322                prev_stage = current_stage
     323                continue
     324
     325            assert index >= 0, "Index out of bounds"
     326
     327            # Update summed volume and summed areas
     328            tmp_volume = summed_volume + (summed_areas * (current_stage - prev_stage))
     329
     330            # Terminate if volume exceeded
     331            if tmp_volume >= volume:
     332                break
     333
     334            summed_areas = summed_areas + s_areas[index][s_stages_order[index][pos[index]]]
     335            pos[index] = pos[index] + 1
     336            summed_volume = tmp_volume
     337
     338        # Update position of index processor and current stage
     339        prev_stage = current_stage
     340
     341        # Calculate new stage
     342        new_stage = prev_stage + (volume - summed_volume) / summed_areas
     343
     344
     345        # Update own depth
     346        stages[stages_order[0:pos]] = new_stage
     347
     348
     349
     350        self.set_stages(stages)
     351
     352        stages = self.get_stages()
     353        stages_order = stages.argsort()
     354
    244355
    245356    def set_depths_evenly(self,volume):
  • trunk/anuga_core/source/anuga/structures/inlet_operator.py

    r8592 r8616  
    3636
    3737
     38        #print self.Q
     39
    3840        self.enquiry_point = 0.5*(self.line[0] + self.line[1])
    3941        self.outward_vector = self.line
     
    5961        Q2 = self.update_Q(t + timestep)
    6062
     63
     64        #print Q1,Q2
    6165        Q = 0.5*(Q1+Q2)
    6266        volume = Q*timestep
     67
     68        #print volume
    6369       
    6470        #print Q, volume
     71
     72        # store last discharge
     73        self.applied_Q = Q
    6574
    6675        msg =  'Requesting too much water to be removed from an inlet! \n'
    6776        msg += 'current_water_volume = %5.2e Increment volume = %5.2e' % (current_volume, volume)
    68         assert current_volume + volume >= 0.0, msg
    69 
    70         # store last discharge
    71         self.applied_Q = Q
    72 
     77        import warnings
     78        if current_volume + volume < 0.0:
     79            #warnings.warn(msg)
     80            volume = -current_volume
     81            self.applied_Q = volume/timestep
     82
     83
     84        #print 'applied_Q', self.applied_Q
     85       
    7386        # Distribute volume so as to obtain flat surface
    7487        self.inlet.set_stages_evenly(volume)
     
    7689        # Distribute volume evenly over all cells
    7790        #self.inlet.set_depths_evenly(volume)
    78        
     91
     92
     93
    7994    def update_Q(self, t):
    8095        """Allowing local modifications of Q
     
    8499        if callable(self.Q):
    85100            try:
    86                 Q = self.Q(t)[0]
     101                Q = self.Q(t)
    87102            except Modeltime_too_early, e:
    88103                raise Modeltime_too_early(e)
  • trunk/anuga_core/source/anuga_parallel/run_sequential_dist_distribute_merimbula.py

    r8606 r8616  
    3535
    3636
    37 from anuga_parallel.sequential_distribute import sequential_distribute
     37from anuga_parallel.sequential_distribute import sequential_distribute_dump
    3838
    3939
     
    9595
    9696if verbose: print 'DISTRIBUTING DOMAIN'
    97 sequential_distribute(domain, 4, verbose=True)
     97sequential_distribute_dump(domain, 4, verbose=True)
    9898
    9999
  • trunk/anuga_core/source/anuga_parallel/run_sequential_dist_evolve_merimbula.py

    r8606 r8616  
    3737from anuga_parallel import distribute, myid, numprocs, finalize, barrier
    3838
     39from anuga_parallel.sequential_distribute import sequential_distribute_load
    3940
    4041#--------------------------------------------------------------------------
    4142# Setup parameters
    4243#--------------------------------------------------------------------------
    43 
    44 #mesh_filename = "merimbula_10785_1.tsh" ; x0 = 756000.0 ; x1 = 756500.0
    45 mesh_filename = "merimbula_17156.tsh"   ; x0 = 756000.0 ; x1 = 756500.0
    46 #mesh_filename = "merimbula_43200_1.tsh"   ; x0 = 756000.0 ; x1 = 756500.0
    47 #mesh_filename = "test-100.tsh" ; x0 = 0.25 ; x1 = 0.5
    48 #mesh_filename = "test-20.tsh" ; x0 = 250.0 ; x1 = 350.0
    49 yieldstep = 50
     44yieldstep = 10
    5045finaltime = 1500
    5146verbose = True
    5247
    53 #--------------------------------------------------------------------------
    54 # Setup procedures
    55 #--------------------------------------------------------------------------
    56 class Set_Stage:
    57     """Set an initial condition with constant water height, for x0<x<x1
    58     """
    59 
    60     def __init__(self, x0=0.25, x1=0.5, h=1.0):
    61         self.x0 = x0
    62         self.x1 = x1
    63         self.h  = h
    64 
    65     def __call__(self, x, y):
    66         return self.h*((x>self.x0)&(x<self.x1))+1.0
    67 
    68 
    69 class Set_Elevation:
    70     """Set an elevation
    71     """
    72 
    73     def __init__(self, h=1.0):
    74         self.x0 = x0
    75         self.x1 = x1
    76         self.h  = h
    77 
    78     def __call__(self, x, y):
    79         return x/self.h
    80    
    81 
    82 ##--------------------------------------------------------------------------
    83 ## Setup Domain only on processor 0
    84 ##--------------------------------------------------------------------------
    85 #if myid == 0:
    86 #    domain = create_domain_from_file(mesh_filename)
    87 #    domain.set_quantity('stage', Set_Stage(x0, x1, 2.0))
    88 #    #domain.set_datadir('.')
    89 #    domain.set_name('merimbula_new')
    90 #    domain.set_store(True)
    91 #    #domain.set_quantity('elevation', Set_Elevation(500.0))
    92 #
    93 #    #print domain.statistics()
    94 #    #print domain.get_extent()
    95 #    #print domain.get_extent(absolute=True)
    96 #    #print domain.geo_reference
    97 #else:
    98 #    domain = None
    99 #
    100 ##--------------------------------------------------------------------------
    101 ## Distribute sequential domain on processor 0 to other processors
    102 ##--------------------------------------------------------------------------
    103 #
    104 #if myid == 0 and verbose: print 'DISTRIBUTING DOMAIN'
    105 #domain = distribute(domain)
    10648
    10749
    10850#-------------------------------------------------------------------------------
    109 # Read in cPickled parallel domains
     51# Read in cPickled distribute mesh data
    11052#-------------------------------------------------------------------------------
    111 
    112 
    113 import cPickle
    114 pickle_name = 'merimbula_new_P%g_%g.pickle'% (numprocs,myid)
    115 f = file(pickle_name, 'rb')
    116 domain = cPickle.load(f)
    117 f.close()
     53domain = sequential_distribute_load(filename='merimbula_new', verbose = True)
    11854
    11955#--------------------------------------------------------------------------
     
    12258#--------------------------------------------------------------------------
    12359
    124 domain.set_flow_algorithm('2_0')
     60domain.set_flow_algorithm('tsunami')
    12561
    126 #domain.smooth = False
    127 #domain.set_default_order(2)
    128 #domain.set_timestepping_method('rk2')
    129 #domain.set_CFL(0.7)
    130 #domain.set_beta(1.5)
    131 
    132 
    133 #for p in range(numprocs):
    134 #    if myid == p:
    135 #        print 'P%d'%p
    136 #        print domain.get_extent()
    137 #        print domain.get_extent(absolute=True)
    138 #        print domain.geo_reference
    139 #        print domain.s2p_map
    140 #        print domain.p2s_map
    141 #        print domain.tri_l2g
    142 #        print domain.node_l2g
    143 #    else:
    144 #        pass
    145 #
    146 #    barrier()
    14762
    14863
     
    185100# Merge the individual sww files into one file
    186101#--------------------------------------------------
    187 domain.sww_merge(delete_old=False)
     102
     103
     104
    188105
    189106finalize()
  • trunk/anuga_core/validation_tests/Tests/Benchmarks/Okushiri/create_okushiri.py

    r8529 r8616  
    2828
    2929
    30 base_resolution = 1 # Use this to coarsen or refine entire mesh.
     30base_resolution = 0.25 # Use this to coarsen or refine entire mesh.
    3131
    3232# Basic geometry and bounding polygon
     
    165165   
    166166    if elevation_in_mesh is True:
     167        from anuga.fit_interpolate.fit import fit_to_mesh_file
    167168        fit_to_mesh_file(project.mesh_filename, project.bathymetry_filename,
    168                          project.mesh_filename)
     169                         project.mesh_filename, verbose = True)
    169170
    170171
    171172#-------------------------------------------------------------
    172173if __name__ == "__main__":
    173     create_mesh()
     174    create_mesh(elevation_in_mesh=True)
    174175
    175176
  • trunk/anuga_core/validation_tests/Tests/Benchmarks/Okushiri/run_okushiri.py

    r8529 r8616  
    101101#-------------------------------------------------------------
    102102if __name__ == "__main__":
    103     main()
     103    main(elevation_in_mesh=True)
Note: See TracChangeset for help on using the changeset viewer.