Changeset 9596


Ignore:
Timestamp:
Feb 4, 2015, 12:21:03 PM (9 years ago)
Author:
davies
Message:

Working on structures / hecras bridge

Location:
trunk
Files:
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/anuga/structures/riverwall.py

    r9501 r9596  
    578578        """
    579579
    580         domain=self.domain
     580        domain = self.domain
    581581
    582582        # Preliminary definitions
    583         isConnected=True
    584         printInfo=''
     583        isConnected = True
     584        printInfo = ''
    585585
    586586        if(len(self.names)==0):
    587587            if(verbose):
    588                 printInfo=printInfo+'  There are no riverwalls (P'+str(myid)+')\n'
     588                printInfo = printInfo+'  There are no riverwalls (P'+str(myid)+')\n'
    589589            return [printInfo, isConnected]
    590590
    591591        # Shorthand notation
    592         rwd=self
     592        rwd = self
    593593
    594594        for i, name in enumerate(rwd.names):
    595595            # Get indices of edges on this riverwall
    596             riverwalledgeInds=rwd.riverwall_edges[(rwd.hydraulic_properties_rowIndex==i).nonzero()[0]]
     596            riverwalledgeInds = rwd.riverwall_edges[(rwd.hydraulic_properties_rowIndex==i).nonzero()[0]]
    597597
    598598            if(len(riverwalledgeInds)==0):
    599                 printInfo=printInfo+'Riverwall '+name+' was not found on this mesh (if this is wrong, adjust tol in create_riverwalls)\n'
     599                printInfo = printInfo+'Riverwall '+name+' was not found on this mesh (if this is wrong, adjust tol in create_riverwalls)\n'
    600600                continue
    601601            # Get their corresponding vertices
     
    604604            # Flag telling us if vertex points are on the boundary of the model
    605605            # Used to help detect disconnected riverwalls (due to round-off)
    606             v1_on_boundary=rwd.is_vertex_on_boundary(riverwallV1Inds)
    607             v2_on_boundary=rwd.is_vertex_on_boundary(riverwallV2Inds)
     606            v1_on_boundary = rwd.is_vertex_on_boundary(riverwallV1Inds)
     607            v2_on_boundary = rwd.is_vertex_on_boundary(riverwallV2Inds)
    608608
    609609            # With discontinuous triangles, we expect edges to occur twice
    610610            # Let's remove duplicates to simplify the analysis
    611             repeat=riverwalledgeInds*0
    612             lre=len(riverwalledgeInds)
     611            repeat = riverwalledgeInds*0
     612            lre = len(riverwalledgeInds)
    613613            # edge coordinates as a complex number, for easy equality checking
    614             complex_edge_coordinates=domain.edge_coordinates[riverwalledgeInds,0]+\
    615                                      1j*domain.edge_coordinates[riverwalledgeInds,1]
     614            complex_edge_coordinates = domain.edge_coordinates[riverwalledgeInds,0]+\
     615                                       1j*domain.edge_coordinates[riverwalledgeInds,1]
    616616            for j in range(lre-1):
    617617                # Ignore if already checked
     
    619619                    continue
    620620                # Check for a dupulicate 
    621                 dups=(complex_edge_coordinates[(j+1):lre]==complex_edge_coordinates[j]).nonzero()[0]
     621                dups = (complex_edge_coordinates[(j+1):lre]==complex_edge_coordinates[j]).nonzero()[0]
    622622                if(len(dups)>0):
    623                     repeat[dups+j+1]=1
     623                    repeat[dups+j+1] = 1
    624624           
    625             unique_riverwall_edge_indices=(repeat==0).nonzero()[0]
     625            unique_riverwall_edge_indices = (repeat==0).nonzero()[0]
    626626
    627627            # Finally, get 'unqiue' edges in the riverwall
    628             uEdges=riverwalledgeInds[unique_riverwall_edge_indices]
    629             uV1=riverwallV1Inds[unique_riverwall_edge_indices]
    630             uV2=riverwallV2Inds[unique_riverwall_edge_indices]
    631             uV1_boundary=v1_on_boundary[unique_riverwall_edge_indices]
    632             uV2_boundary=v2_on_boundary[unique_riverwall_edge_indices]
     628            uEdges = riverwalledgeInds[unique_riverwall_edge_indices]
     629            uV1 = riverwallV1Inds[unique_riverwall_edge_indices]
     630            uV2 = riverwallV2Inds[unique_riverwall_edge_indices]
     631            uV1_boundary = v1_on_boundary[unique_riverwall_edge_indices]
     632            uV2_boundary = v2_on_boundary[unique_riverwall_edge_indices]
    633633
    634634            # Next, count how many times each vertex value occurs.
    635635            # For a 'connected' riverwall, we only want 2 edges where a vertex occurs only once,
    636636            #   unless the vertex is on the boundary of the domain
    637             lure=len(uEdges)
    638             complex_v1_coordinates=domain.vertex_coordinates[uV1,0]+\
    639                                    1j*domain.vertex_coordinates[uV1,1]
    640             complex_v2_coordinates=domain.vertex_coordinates[uV2,0]+\
    641                                    1j*domain.vertex_coordinates[uV2,1]
    642             v1Counter=uEdges*0
    643             v2Counter=uEdges*0
     637            lure = len(uEdges)
     638            complex_v1_coordinates = domain.vertex_coordinates[uV1,0]+\
     639                                     1j*domain.vertex_coordinates[uV1,1]
     640            complex_v2_coordinates = domain.vertex_coordinates[uV2,0]+\
     641                                     1j*domain.vertex_coordinates[uV2,1]
     642            v1Counter = uEdges*0
     643            v2Counter = uEdges*0
    644644            for j in range(lure):
    645                 v1Counter[j]=(complex_v1_coordinates==complex_v1_coordinates[j]).sum()+\
    646                              (complex_v2_coordinates==complex_v1_coordinates[j]).sum()
    647                 v2Counter[j]=(complex_v1_coordinates==complex_v2_coordinates[j]).sum()+\
    648                              (complex_v2_coordinates==complex_v2_coordinates[j]).sum()
    649 
    650             num_disconnected_edges=((v1Counter==1)*(1-uV1_boundary)).sum()+\
    651                                    ((v2Counter==1)*(1-uV2_boundary)).sum()
     645                v1Counter[j] = (complex_v1_coordinates==complex_v1_coordinates[j]).sum()+\
     646                               (complex_v2_coordinates==complex_v1_coordinates[j]).sum()
     647                v2Counter[j] = (complex_v1_coordinates==complex_v2_coordinates[j]).sum()+\
     648                               (complex_v2_coordinates==complex_v2_coordinates[j]).sum()
     649
     650            num_disconnected_edges = ((v1Counter==1)*(1-uV1_boundary)).sum()+\
     651                                     ((v2Counter==1)*(1-uV2_boundary)).sum()
    652652         
    653653            if(verbose):   
    654                 printInfo=printInfo+ '  On riverwall '+ str(name) +' there are '+ str(num_disconnected_edges)+\
     654                printInfo = printInfo+ '  On riverwall '+ str(name) +' there are '+ str(num_disconnected_edges)+\
    655655                         ' endpoints inside the domain [ignoring points on the boundary polygon] (P'+str(myid)+')\n'
    656656
    657             if(num_disconnected_edges<=2):
     657            if(num_disconnected_edges <= 2):
    658658                if(verbose):
    659659                    pass
    660660                    #printInfo=printInfo+ "  This is consistent with a continuous wall \n"
    661661            else:
    662                 isConnected=False
    663                 printInfo=printInfo+'  Riverwall ' + name +' appears to be discontinuous. (P'+str(myid)+')\n'+\
     662                isConnected = False
     663                printInfo = printInfo + '  Riverwall ' + name +' appears to be discontinuous. (P'+str(myid)+')\n'+\
    664664                    '  This suggests there is a gap in the wall, which should not occur\n'
    665665       
     
    683683            return
    684684   
    685         if(myid==0):
     685        if(myid == 0):
    686686            # Make output directory
    687687            try:
     
    691691            # Make output files with empty contents
    692692            for i, riverWallFile in enumerate(self.names):
    693                 newFile=open(output_dir+'/'+os.path.splitext(os.path.basename(riverWallFile))[0]+'.txt','w')
     693                newFile=open(output_dir + '/' + os.path.splitext(os.path.basename(riverWallFile))[0] + '.txt','w')
    694694                # Write hydraulic variable information
    695695                hydraulicVars=self.hydraulic_properties[i,:]
    696696                newFile.write('## Hydraulic Variable values below ## \n')
    697                 newFile.write(str(self.hydraulic_variable_names)+'\n')
    698                 newFile.write(str(hydraulicVars)+'\n')
     697                newFile.write(str(self.hydraulic_variable_names) + '\n')
     698                newFile.write(str(hydraulicVars) + '\n')
    699699                newFile.write('\n')
    700700                newFile.write('## xyElevation at edges below. Order may be erratic for parallel runs ##\n')
     
    716716        for i in range(numprocs):
    717717            # Write 1 processor at a time
    718             if(myid==i):
     718            if(myid == i):
    719719                for j, riverWallname in enumerate(self.names):
    720720                    # Get xyz data for riverwall j
    721                     riverWallInds=(self.hydraulic_properties_rowIndex==j).nonzero()[0].tolist()
    722                     riverWallDomainInds=self.riverwall_edges[riverWallInds].tolist()
    723                     myXCoords=domain.edge_coordinates[riverWallDomainInds,0]+domain.geo_reference.xllcorner
    724                     myYCoords=domain.edge_coordinates[riverWallDomainInds,1]+domain.geo_reference.yllcorner
    725                     myElev=self.riverwall_elevation[riverWallInds]
     721                    riverWallInds = (self.hydraulic_properties_rowIndex==j).nonzero()[0].tolist()
     722                    riverWallDomainInds = self.riverwall_edges[riverWallInds].tolist()
     723                    myXCoords = domain.edge_coordinates[riverWallDomainInds,0] + domain.geo_reference.xllcorner
     724                    myYCoords = domain.edge_coordinates[riverWallDomainInds,1] + domain.geo_reference.yllcorner
     725                    myElev = self.riverwall_elevation[riverWallInds]
    726726               
    727727                    # Open file for appending data
    728                     theFile=open(output_dir+'/'+os.path.splitext(os.path.basename(riverWallname))[0]+'.txt','a')
     728                    theFile = open(output_dir + '/' + os.path.splitext(os.path.basename(riverWallname))[0] + '.txt','a')
    729729                    for k in range(len(myElev)):
    730                         theFile.write(str(myXCoords[k])+','+str(myYCoords[k])+','+str(myElev[k])+'\n')
     730                        theFile.write(str(myXCoords[k]) + ',' + str(myYCoords[k]) + ',' + str(myElev[k]) + '\n')
    731731                    theFile.close()
    732732                       
  • trunk/anuga_core/anuga/structures/structure_operator.py

    r9130 r9596  
    3636                 manning=None,
    3737                 enquiry_gap=None,
     38                 use_momentum_jet=False,
     39                 zero_outflow_momentum=True,
    3840                 description=None,
    3941                 label=None,
     
    8486        self.manning = manning
    8587        self.enquiry_gap = enquiry_gap
     88        self.use_momentum_jet = use_momentum_jet
     89        self.zero_outflow_momentum = zero_outflow_momentum
     90
     91        if use_momentum_jet and zero_outflow_momentum:
     92            msg = "Can't have use_momentum_jet and zero_outflow_momentum both True"
     93            raise Exception(msg)
    8694
    8795        if description == None:
     
    222230   
    223231            loss = (old_inflow_depth - new_inflow_depth)*self.inflow.get_area()
     232            xmom_loss = (old_inflow_xmom - new_inflow_xmom)*self.inflow.get_area()
     233            ymom_loss = (old_inflow_ymom - new_inflow_ymom)*self.inflow.get_area()
    224234   
    225235            # set outflow
     
    229239                timestep_star = 0.0
    230240   
    231    
    232    
    233    
    234241            outflow_extra_depth = Q*timestep_star/self.outflow.get_area()
    235242            outflow_direction = - self.outflow.outward_culvert_vector
    236             outflow_extra_momentum = outflow_extra_depth*barrel_speed*outflow_direction
     243            #outflow_extra_momentum = outflow_extra_depth*barrel_speed*outflow_direction
    237244               
    238245            gain = outflow_extra_depth*self.outflow.get_area()
     
    262269            outflow_extra_depth = Q*timestep/self.outflow.get_area()
    263270            outflow_direction = - self.outflow.outward_culvert_vector
    264             outflow_extra_momentum = outflow_extra_depth*barrel_speed*outflow_direction
     271            #outflow_extra_momentum = outflow_extra_depth*barrel_speed*outflow_direction
    265272               
    266273            gain = outflow_extra_depth*self.outflow.get_area()
     
    275282       
    276283        self.accumulated_flow += gain
    277         self.discharge  = outflow_extra_depth*self.outflow.get_area()/timestep #Q
     284        self.discharge  = Q*timestep_star/timestep # outflow_extra_depth*self.outflow.get_area()/timestep #Q
    278285        self.velocity =   barrel_speed # self.discharge/outlet_depth/self.width
    279286        self.outlet_depth = outlet_depth
     
    281288        new_outflow_depth = self.outflow.get_average_depth() + outflow_extra_depth
    282289
    283         if self.use_momentum_jet :
     290        self.outflow.set_depths(new_outflow_depth)
     291
     292        if self.use_momentum_jet:
    284293            # FIXME (SR) Review momentum to account for possible hydraulic jumps at outlet
     294            # FIXME (GD) Depending on barrel speed I think this will be either
     295            # a source or sink of momentum (considering the momentum losses
     296            # above). Might not always be reasonable.
    285297            #new_outflow_xmom = self.outflow.get_average_xmom() + outflow_extra_momentum[0]
    286298            #new_outflow_ymom = self.outflow.get_average_ymom() + outflow_extra_momentum[1]
    287299            new_outflow_xmom = barrel_speed*new_outflow_depth*outflow_direction[0]
    288300            new_outflow_ymom = barrel_speed*new_outflow_depth*outflow_direction[1]
    289 
    290         else:
     301           
     302        elif self.zero_outflow_momentum:
     303            # Default case (FIXME: Should this be default? We lose all the
     304            # momentum, often not physically reasonable)
     305            new_outflow_xmom = 0.0
     306            new_outflow_ymom = 0.0
    291307            #new_outflow_xmom = outflow.get_average_xmom()
    292308            #new_outflow_ymom = outflow.get_average_ymom()
    293309
    294             new_outflow_xmom = 0.0
    295             new_outflow_ymom = 0.0
    296 
    297         self.outflow.set_depths(new_outflow_depth)
     310        else:
     311            # Add the momentum lost from the inflow to the outflow. For
     312            # structures where barrel_speed is unknown + direction doesn't
     313            # change from inflow to outflow
     314            new_outflow_xmom = self.outflow.get_average_xmom() + xmom_loss/self.outflow.get_area()
     315            new_outflow_ymom = self.outflow.get_average_ymom() + ymom_loss/self.outflow.get_area()
     316
    298317        self.outflow.set_xmoms(new_outflow_xmom)
    299318        self.outflow.set_ymoms(new_outflow_ymom)
     
    514533            self.log_filename = self.label + '.log'
    515534            log_to_file(self.log_filename, self.statistics(), mode='w')
    516             log_to_file(self.log_filename, 'time,discharge,velocity,driving_energy,delta_total_energy')
     535            log_to_file(self.log_filename, 'time, discharge, velocity, accumulated_flow, driving_energy, delta_total_energy')
    517536
    518537            #log_to_file(self.log_filename, self.culvert_type)
Note: See TracChangeset for help on using the changeset viewer.