}, maximum_triangle_area=1.0e+06, #0.5*l0*l0, minimum_triangle_angle=28.0, filename='channel_floodplain1.msh', interior_regions=[], breaklines=breakLines.values(), regionPtArea=regionPtAreas, verbose=True) domain = anuga.create_domain_from_file('channel_floodplain1.msh') domain.set_name('channel_floodplain1') # Output name domain.set_flow_algorithm(alg) else: domain = None barrier() domain = distribute(domain) barrier() domain.set_store_vertices_uniquely(True) #------------------------------------------------------------------------------ # # Setup initial conditions # #------------------------------------------------------------------------------ # Function for topography def topography(x, y): # Longitudinally sloping floodplain with channel in centre elev1= -y*floodplain_slope - chan_bankfull_depth*\
'bottom2': [7] }, maximum_triangle_area = 1.0e+06, #0.5*l0*l0, minimum_triangle_angle = 28.0, filename = 'channel_floodplain1.msh', interior_regions = [ ], breaklines=breakLines.values(), regionPtArea=regionPtAreas, verbose=True) domain=anuga.create_domain_from_file('channel_floodplain1.msh') domain.set_name('channel_floodplain1') # Output name domain.set_flow_algorithm(alg) else: domain=None barrier() domain=distribute(domain) barrier() domain.set_store_vertices_uniquely(True) #------------------------------------------------------------------------------ # # Setup initial conditions # #------------------------------------------------------------------------------ # Function for topography def topography(x, y): # Longitudinally sloping floodplain with channel in centre elev1= -y*floodplain_slope - chan_bankfull_depth*\ (x>(floodplain_width/2. - chan_width/2.))*\
def run_simulation(parallel = False, control_data = None, test_points = None, verbose = False): success = True ##----------------------------------------------------------------------- ## Setup domain ##----------------------------------------------------------------------- points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), len1=length, len2=width) domain = anuga.Domain(points, vertices, boundary) #domain.set_name('output_parallel_boyd_pipe_op') # Output name domain.set_store(False) domain.set_default_order(2) ##----------------------------------------------------------------------- ## Distribute domain ##----------------------------------------------------------------------- if parallel: domain = distribute(domain) #domain.dump_triangulation("boyd_pipe_domain.png") ##----------------------------------------------------------------------- ## Setup boundary conditions ##----------------------------------------------------------------------- domain.set_quantity('elevation', topography) domain.set_quantity('friction', 0.01) # Constant friction domain.set_quantity('stage', expression='elevation') # Dry initial condition Bi = anuga.Dirichlet_boundary([5.0, 0.0, 0.0]) Br = anuga.Reflective_boundary(domain) # Solid reflective wall domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br}) ##----------------------------------------------------------------------- ## Determine triangle index coinciding with test points ##----------------------------------------------------------------------- assert(test_points is not None) assert(len(test_points) == samples) tri_ids = [] for point in test_points: try: k = domain.get_triangle_containing_point(point) if domain.tri_full_flag[k] == 1: tri_ids.append(k) else: tri_ids.append(-1) except: tri_ids.append(-2) if verbose: print 'P%d has points = %s' %(myid, tri_ids) if not parallel: control_data = [] ################ Define Fractional Operators ########################## inlet0 = None inlet1 = None boyd_pipe0 = None inlet0 = Inlet_operator(domain, line0, Q0, verbose = False) inlet1 = Inlet_operator(domain, line1, Q1, verbose = False) # Enquiry point [ 19. 2.5] is contained in two domains in 4 proc case boyd_pipe0 = Boyd_pipe_operator(domain, end_points=[[9.0, 2.5],[19.0, 2.5]], losses=1.5, diameter=5.0, apron=5.0, use_momentum_jet=True, use_velocity_head=False, manning=0.013, verbose=False) if inlet0 is not None and verbose: inlet0.print_statistics() if inlet1 is not None and verbose: inlet1.print_statistics() if boyd_pipe0 is not None and verbose: boyd_pipe0.print_statistics() # if parallel: # factory = Parallel_operator_factory(domain, verbose = True) # # inlet0 = factory.inlet_operator_factory(line0, Q0) # inlet1 = factory.inlet_operator_factory(line1, Q1) # # boyd_box0 = factory.boyd_box_operator_factory(end_points=[[9.0, 2.5],[19.0, 2.5]], # losses=1.5, # width=1.5, # apron=5.0, # use_momentum_jet=True, # use_velocity_head=False, # manning=0.013, # verbose=False) # # else: # inlet0 = Inlet_operator(domain, line0, Q0) # inlet1 = Inlet_operator(domain, line1, Q1) # # # Enquiry point [ 19. 2.5] is contained in two domains in 4 proc case # boyd_box0 = Boyd_box_operator(domain, # end_points=[[9.0, 2.5],[19.0, 2.5]], # losses=1.5, # width=1.5, # apron=5.0, # use_momentum_jet=True, # use_velocity_head=False, # manning=0.013, # verbose=False) ####################################################################### ##----------------------------------------------------------------------- ## Evolve system through time ##----------------------------------------------------------------------- for t in domain.evolve(yieldstep = 2.0, finaltime = 20.0): if myid == 0 and verbose: domain.write_time() #print domain.volumetric_balance_statistics() stage = domain.get_quantity('stage') if boyd_pipe0 is not None and verbose : boyd_pipe0.print_timestepping_statistics() #for i in range(samples): # if tri_ids[i] >= 0: # if verbose: print 'P%d tri %d, value = %s' %(myid, i, stage.centroid_values[tri_ids[i]]) sys.stdout.flush() pass success = True ##----------------------------------------------------------------------- ## Assign/Test Control data ##----------------------------------------------------------------------- if not parallel: stage = domain.get_quantity('stage') for i in range(samples): assert(tri_ids[i] >= 0) control_data.append(stage.centroid_values[tri_ids[i]]) if inlet0 is not None: control_data.append(inlet0.inlet.get_average_stage()) control_data.append(inlet0.inlet.get_average_xmom()) control_data.append(inlet0.inlet.get_average_ymom()) control_data.append(inlet0.inlet.get_total_water_volume()) control_data.append(inlet0.inlet.get_average_depth()) if verbose: print 'P%d control_data = %s' %(myid, control_data) else: stage = domain.get_quantity('stage') for i in range(samples): if tri_ids[i] >= 0: local_success = num.allclose(control_data[i], stage.centroid_values[tri_ids[i]]) success = success and local_success if verbose: print 'P%d tri %d, control = %s, actual = %s, Success = %s' %(myid, i, control_data[i], stage.centroid_values[tri_ids[i]], local_success) if inlet0 is not None: inlet_master_proc = inlet0.inlet.get_master_proc() average_stage = inlet0.inlet.get_global_average_stage() average_xmom = inlet0.inlet.get_global_average_xmom() average_ymom = inlet0.inlet.get_global_average_ymom() average_volume = inlet0.inlet.get_global_total_water_volume() average_depth = inlet0.inlet.get_global_average_depth() if myid == inlet_master_proc: if verbose: print 'P%d average stage, control = %s, actual = %s' %(myid, control_data[samples], average_stage) print 'P%d average xmom, control = %s, actual = %s' %(myid, control_data[samples+1], average_xmom) print 'P%d average ymom, control = %s, actual = %s' %(myid, control_data[samples+2], average_ymom) print 'P%d average volume, control = %s, actual = %s' %(myid, control_data[samples+3], average_volume) print 'P%d average depth, control = %s, actual = %s' %(myid, control_data[samples+4], average_depth) assert(success) if parallel: finalize() return control_data
def run_simulation(parallel=False, control_data=None, test_points=None, verbose=False): success = True ##----------------------------------------------------------------------- ## Setup domain ##----------------------------------------------------------------------- points, vertices, boundary = rectangular_cross(int(old_div(length, dx)), int(old_div(width, dy)), len1=length, len2=width) domain = anuga.Domain(points, vertices, boundary) #domain.set_name() # Output name domain.set_store(False) domain.set_default_order(2) ##----------------------------------------------------------------------- ## Distribute domain ##----------------------------------------------------------------------- if parallel: domain = distribute(domain) #domain.dump_triangulation("frac_op_domain.png") ##----------------------------------------------------------------------- ## Setup boundary conditions ##----------------------------------------------------------------------- domain.set_quantity('elevation', topography) domain.set_quantity('friction', 0.01) # Constant friction domain.set_quantity('stage', expression='elevation') # Dry initial condition Bi = anuga.Dirichlet_boundary([5.0, 0.0, 0.0]) Br = anuga.Reflective_boundary(domain) # Solid reflective wall domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br}) ##----------------------------------------------------------------------- ## Determine triangle index coinciding with test points ##----------------------------------------------------------------------- assert (test_points is not None) assert (len(test_points) == samples) tri_ids = [] for point in test_points: try: k = domain.get_triangle_containing_point(point) if domain.tri_full_flag[k] == 1: tri_ids.append(k) else: tri_ids.append(-1) except: tri_ids.append(-2) if verbose: print('P%d has points = %s' % (myid, tri_ids)) if not parallel: control_data = [] ################ Define Fractional Operators ########################## inlet0 = None inlet1 = None boyd_box0 = None inlet0 = Inlet_operator(domain, line0, Q0, verbose=False, label='Inlet_0') inlet1 = Inlet_operator(domain, line1, Q1, verbose=False, label='Inlet_1') # Enquiry point [ 19. 2.5] is contained in two domains in 4 proc case boyd_box0 = Boyd_box_operator(domain, end_points=[[9.0, 2.5], [19.0, 2.5]], losses=1.5, width=5.0, apron=5.0, use_momentum_jet=True, use_velocity_head=False, manning=0.013, label='Boyd_Box_0', verbose=False) #if inlet0 is not None and verbose: inlet0.print_statistics() #if inlet1 is not None and verbose: inlet1.print_statistics() if boyd_box0 is not None and verbose: print("++++", myid) boyd_box0.print_statistics() # if parallel: # factory = Parallel_operator_factory(domain, verbose = True) # # inlet0 = factory.inlet_operator_factory(line0, Q0) # inlet1 = factory.inlet_operator_factory(line1, Q1) # # boyd_box0 = factory.boyd_box_operator_factory(end_points=[[9.0, 2.5],[19.0, 2.5]], # losses=1.5, # width=1.5, # apron=5.0, # use_momentum_jet=True, # use_velocity_head=False, # manning=0.013, # verbose=False) # # else: # inlet0 = Inlet_operator(domain, line0, Q0) # inlet1 = Inlet_operator(domain, line1, Q1) # # # Enquiry point [ 19. 2.5] is contained in two domains in 4 proc case # boyd_box0 = Boyd_box_operator(domain, # end_points=[[9.0, 2.5],[19.0, 2.5]], # losses=1.5, # width=1.5, # apron=5.0, # use_momentum_jet=True, # use_velocity_head=False, # manning=0.013, # verbose=False) ####################################################################### ##----------------------------------------------------------------------- ## Evolve system through time ##----------------------------------------------------------------------- for t in domain.evolve(yieldstep=2.0, finaltime=20.0): if myid == 0 and verbose: domain.write_time() #print domain.volumetric_balance_statistics() stage = domain.get_quantity('stage') if boyd_box0 is not None and verbose: if myid == boyd_box0.master_proc: print('master_proc ', myid) boyd_box0.print_timestepping_statistics() #for i in range(samples): # if tri_ids[i] >= 0: # if verbose: print 'P%d tri %d, value = %s' %(myid, i, stage.centroid_values[tri_ids[i]]) sys.stdout.flush() pass domain.sww_merge(delete_old=True) success = True ##----------------------------------------------------------------------- ## Assign/Test Control data ##----------------------------------------------------------------------- if not parallel: stage = domain.get_quantity('stage') for i in range(samples): assert (tri_ids[i] >= 0) control_data.append(stage.centroid_values[tri_ids[i]]) if inlet0 is not None: control_data.append(inlet0.inlet.get_average_stage()) control_data.append(inlet0.inlet.get_average_xmom()) control_data.append(inlet0.inlet.get_average_ymom()) control_data.append(inlet0.inlet.get_total_water_volume()) control_data.append(inlet0.inlet.get_average_depth()) if verbose: print('P%d control_data = %s' % (myid, control_data)) else: stage = domain.get_quantity('stage') for i in range(samples): if tri_ids[i] >= 0: local_success = num.allclose(control_data[i], stage.centroid_values[tri_ids[i]]) success = success and local_success if verbose: print( 'P%d tri %d, control = %s, actual = %s, Success = %s' % (myid, i, control_data[i], stage.centroid_values[tri_ids[i]], local_success)) if inlet0 is not None: inlet_master_proc = inlet0.inlet.get_master_proc() average_stage = inlet0.inlet.get_global_average_stage() average_xmom = inlet0.inlet.get_global_average_xmom() average_ymom = inlet0.inlet.get_global_average_ymom() average_volume = inlet0.inlet.get_global_total_water_volume() average_depth = inlet0.inlet.get_global_average_depth() if myid == inlet_master_proc: if verbose: print('P%d average stage, control = %s, actual = %s' % (myid, control_data[samples], average_stage)) print('P%d average xmom, control = %s, actual = %s' % (myid, control_data[samples + 1], average_xmom)) print('P%d average ymom, control = %s, actual = %s' % (myid, control_data[samples + 2], average_ymom)) print('P%d average volume, control = %s, actual = %s' % (myid, control_data[samples + 3], average_volume)) print('P%d average depth, control = %s, actual = %s' % (myid, control_data[samples + 4], average_depth)) return control_data, success
def run_simulation(parallel=False, control_data=None, test_points=None, verbose=False): success = True ##----------------------------------------------------------------------- ## Setup domain ##----------------------------------------------------------------------- points, vertices, boundary = rectangular_cross(int(length / dx), int(width / dy), len1=length, len2=width) domain = anuga.Domain(points, vertices, boundary) #rm *.swwdomain.set_name('output_parallel_inlet_operator') # Output name domain.set_store(False) domain.set_default_order(2) ##----------------------------------------------------------------------- ## Distribute domain ##----------------------------------------------------------------------- if parallel: domain = distribute(domain) #domain.dump_triangulation("frac_op_domain.png") ##----------------------------------------------------------------------- ## Setup boundary conditions ##----------------------------------------------------------------------- domain.set_quantity('elevation', topography) domain.set_quantity('friction', 0.01) # Constant friction domain.set_quantity('stage', expression='elevation') # Dry initial condition Bi = anuga.Dirichlet_boundary([5.0, 0.0, 0.0]) Br = anuga.Reflective_boundary(domain) # Solid reflective wall domain.set_boundary({'left': Br, 'right': Br, 'top': Br, 'bottom': Br}) ##----------------------------------------------------------------------- ## Determine triangle index coinciding with test points ##----------------------------------------------------------------------- assert (test_points is not None) assert (len(test_points) == samples) tri_ids = [] for point in test_points: try: k = domain.get_triangle_containing_point(point) if domain.tri_full_flag[k] == 1: tri_ids.append(k) else: tri_ids.append(-1) except: tri_ids.append(-2) if verbose: print 'P%d has points = %s' % (myid, tri_ids) if not parallel: control_data = [] ################ Define Fractional Operators ########################## inlet0 = None inlet1 = None boyd_box0 = None inlet0 = Inlet_operator(domain, line0, Q0, verbose=False, default=0.0) inlet1 = Inlet_operator(domain, line1, Q1, verbose=False) if inlet0 is not None and verbose: inlet0.print_statistics() if inlet1 is not None and verbose: inlet1.print_statistics() #if boyd_box0 is not None and verbose: boyd_box0.print_statistics() ##----------------------------------------------------------------------- ## Evolve system through time ##----------------------------------------------------------------------- for t in domain.evolve(yieldstep=2.0, finaltime=40.0): if myid == 0 and verbose: domain.write_time() #print domain.volumetric_balance_statistics() stage = domain.get_quantity('stage') #if boyd_box0 is not None and verbose : boyd_box0.print_timestepping_statistics() #for i in range(samples): # if tri_ids[i] >= 0: # if verbose: print 'P%d tri %d, value = %s' %(myid, i, stage.centroid_values[tri_ids[i]]) sys.stdout.flush() pass domain.sww_merge(delete_old=True) success = True ##----------------------------------------------------------------------- ## Assign/Test Control data ##----------------------------------------------------------------------- if not parallel: stage = domain.get_quantity('stage') for i in range(samples): assert (tri_ids[i] >= 0) control_data.append(stage.centroid_values[tri_ids[i]]) if inlet0 is not None: control_data.append(inlet0.inlet.get_average_stage()) control_data.append(inlet0.inlet.get_average_xmom()) control_data.append(inlet0.inlet.get_average_ymom()) control_data.append(inlet0.inlet.get_total_water_volume()) control_data.append(inlet0.inlet.get_average_depth()) if verbose: print 'P%d control_data = %s' % (myid, control_data) else: stage = domain.get_quantity('stage') for i in range(samples): if tri_ids[i] >= 0: local_success = num.allclose(control_data[i], stage.centroid_values[tri_ids[i]]) success = success and local_success if verbose: print 'P%d tri %d, control = %s, actual = %s, Success = %s' % ( myid, i, control_data[i], stage.centroid_values[tri_ids[i]], local_success) if inlet0 is not None: inlet_master_proc = inlet0.inlet.get_master_proc() average_stage = inlet0.inlet.get_global_average_stage() average_xmom = inlet0.inlet.get_global_average_xmom() average_ymom = inlet0.inlet.get_global_average_ymom() average_volume = inlet0.inlet.get_global_total_water_volume() average_depth = inlet0.inlet.get_global_average_depth() if myid == inlet_master_proc: if verbose: print 'P%d average stage, control = %s, actual = %s' % ( myid, control_data[samples], average_stage) print 'P%d average xmom, control = %s, actual = %s' % ( myid, control_data[samples + 1], average_xmom) print 'P%d average ymom, control = %s, actual = %s' % ( myid, control_data[samples + 2], average_ymom) print 'P%d average volume, control = %s, actual = %s' % ( myid, control_data[samples + 3], average_volume) print 'P%d average depth, control = %s, actual = %s' % ( myid, control_data[samples + 4], average_depth) assert (success) return control_data
def parallel_time_varying_file_boundary_sts(self): """ parallel_test_time_varying_file_boundary_sts_sequential(self): Read correct points from ordering file and apply sts to boundary. The boundary is time varying. Compares sequential result with distributed result found using anuga_parallel """ #------------------------------------------------------------ # Define test variables #------------------------------------------------------------ lat_long_points = [[6.01, 97.0], [6.02, 97.0], [6.05, 96.9], [6.0, 97.0]] bounding_polygon = [[6.0, 97.0], [6.01, 97.0], [6.02, 97.0], [6.02, 97.02], [6.00, 97.02]] tide = 3.0 time_step_count = 65 time_step = 2 n = len(lat_long_points) first_tstep = num.ones(n, num.int) last_tstep = (time_step_count) * num.ones(n, num.int) finaltime = num.float(time_step * (time_step_count - 1)) yieldstep = num.float(time_step) gauge_depth = 20 * num.ones(n, num.float) ha = 2 * num.ones((n, time_step_count), num.float) ua = 10 * num.ones((n, time_step_count), num.float) va = -10 * num.ones((n, time_step_count), num.float) times = num.arange(0, time_step_count * time_step, time_step) for i in range(n): #ha[i]+=num.sin(times) ha[i] += times / finaltime #------------------------------------------------------------ # Write mux data to file then convert to sts format #------------------------------------------------------------ sts_file = "test" if myid == 0: base_name, files = self.write_mux2(lat_long_points, time_step_count, time_step, first_tstep, last_tstep, depth=gauge_depth, ha=ha, ua=ua, va=va) # base name will not exist, but 3 other files are created # Write order file file_handle, order_base_name = tempfile.mkstemp("") os.close(file_handle) os.remove(order_base_name) d = "," order_file = order_base_name + 'order.txt' fid = open(order_file, 'w') # Write Header header = 'index, longitude, latitude\n' fid.write(header) indices = [3, 0, 1] for i in indices: line=str(i)+d+str(lat_long_points[i][1])+d+\ str(lat_long_points[i][0])+"\n" fid.write(line) fid.close() urs2sts(base_name, basename_out=sts_file, ordering_filename=order_file, mean_stage=tide, verbose=verbose) self.delete_mux(files) assert (os.access(sts_file + '.sts', os.F_OK)) os.remove(order_file) barrier() #------------------------------------------------------------ # Define boundary_polygon on each processor. This polygon defines the # urs boundary and lies on a portion of the bounding_polygon #------------------------------------------------------------ boundary_polygon = create_sts_boundary(sts_file) # Append the remaining part of the boundary polygon to be defined by # the user bounding_polygon_utm = [] for point in bounding_polygon: zone, easting, northing = redfearn(point[0], point[1]) bounding_polygon_utm.append([easting, northing]) boundary_polygon.append(bounding_polygon_utm[3]) boundary_polygon.append(bounding_polygon_utm[4]) assert num.allclose(bounding_polygon_utm, boundary_polygon) extent_res = 10000 meshname = 'urs_test_mesh' + '.tsh' interior_regions = None boundary_tags = {'ocean': [0, 1], 'otherocean': [2, 3, 4]} #------------------------------------------------------------ # Create mesh on the master processor and store in file. This file # is read in by each slave processor when needed #------------------------------------------------------------ if myid == 0: create_mesh_from_regions(boundary_polygon, boundary_tags=boundary_tags, maximum_triangle_area=extent_res, filename=meshname, interior_regions=interior_regions, verbose=verbose) # barrier() domain_fbound = Domain(meshname) domain_fbound.set_quantities_to_be_stored(None) domain_fbound.set_quantity('stage', tide) # print domain_fbound.mesh.get_boundary_polygon() else: domain_fbound = None barrier() if (verbose and myid == 0): print 'DISTRIBUTING PARALLEL DOMAIN' domain_fbound = distribute(domain_fbound) #-------------------------------------------------------------------- # Find which sub_domain in which the interpolation points are located # # Sometimes the interpolation points sit exactly # between two centroids, so in the parallel run we # reset the interpolation points to the centroids # found in the sequential run #-------------------------------------------------------------------- interpolation_points = [[279000, 664000], [280250, 664130], [279280, 665400], [280500, 665000]] interpolation_points = num.array(interpolation_points) #if myid==0: # import pylab as P # boundary_polygon=num.array(boundary_polygon) # P.plot(boundary_polygon[:,0],boundary_polygon[:,1]) # P.plot(interpolation_points[:,0],interpolation_points[:,1],'ko') # P.show() fbound_gauge_values = [] fbound_proc_tri_ids = [] for i, point in enumerate(interpolation_points): fbound_gauge_values.append([]) # Empty list for timeseries try: k = domain_fbound.get_triangle_containing_point(point) if domain_fbound.tri_full_flag[k] == 1: fbound_proc_tri_ids.append(k) else: fbound_proc_tri_ids.append(-1) except: fbound_proc_tri_ids.append(-2) if verbose: print 'P%d has points = %s' % (myid, fbound_proc_tri_ids) #------------------------------------------------------------ # Set boundary conditions #------------------------------------------------------------ Bf = File_boundary(sts_file + '.sts', domain_fbound, boundary_polygon=boundary_polygon) Br = Reflective_boundary(domain_fbound) domain_fbound.set_boundary({'ocean': Bf, 'otherocean': Br}) #------------------------------------------------------------ # Evolve the domain on each processor #------------------------------------------------------------ for i, t in enumerate( domain_fbound.evolve(yieldstep=yieldstep, finaltime=finaltime, skip_initial_step=False)): stage = domain_fbound.get_quantity('stage') for i in range(4): if fbound_proc_tri_ids[i] > -1: fbound_gauge_values[i].append( stage.centroid_values[fbound_proc_tri_ids[i]]) #------------------------------------------------------------ # Create domain to be run sequntially on each processor #------------------------------------------------------------ domain_drchlt = Domain(meshname) domain_drchlt.set_quantities_to_be_stored(None) domain_drchlt.set_starttime(time_step) domain_drchlt.set_quantity('stage', tide) Br = Reflective_boundary(domain_drchlt) #Bd = Dirichlet_boundary([2.0+tide,220+10*tide,-220-10*tide]) Bd = Time_boundary( domain=domain_drchlt, function=lambda t: [ 2.0 + t / finaltime + tide, 220. + 10. * tide + 10. * t / finaltime, -220. - 10. * tide - 10. * t / finaltime ]) #Bd = Time_boundary(domain=domain_drchlt,function=lambda t: [2.0+num.sin(t)+tide,10.*(2+20.+num.sin(t)+tide),-10.*(2+20.+num.sin(t)+tide)]) domain_drchlt.set_boundary({'ocean': Bd, 'otherocean': Br}) drchlt_gauge_values = [] drchlt_proc_tri_ids = [] for i, point in enumerate(interpolation_points): drchlt_gauge_values.append([]) # Empty list for timeseries try: k = domain_drchlt.get_triangle_containing_point(point) if domain_drchlt.tri_full_flag[k] == 1: drchlt_proc_tri_ids.append(k) else: drchlt_proc_tri_ids.append(-1) except: drchlt_proc_tri_ids.append(-2) if verbose: print 'P%d has points = %s' % (myid, drchlt_proc_tri_ids) #------------------------------------------------------------ # Evolve entire domain on each processor #------------------------------------------------------------ for i, t in enumerate( domain_drchlt.evolve(yieldstep=yieldstep, finaltime=finaltime, skip_initial_step=False)): stage = domain_drchlt.get_quantity('stage') for i in range(4): drchlt_gauge_values[i].append( stage.centroid_values[drchlt_proc_tri_ids[i]]) #------------------------------------------------------------ # Compare sequential values with parallel values #------------------------------------------------------------ barrier() success = True for i in range(4): if fbound_proc_tri_ids[i] > -1: fbound_gauge_values[i] = num.array(fbound_gauge_values[i]) drchlt_gauge_values[i] = num.array(drchlt_gauge_values[i]) #print i,fbound_gauge_values[i][4] #print i,drchlt_gauge_values[i][4] success = success and num.allclose(fbound_gauge_values[i], drchlt_gauge_values[i]) assert success #, (fbound_gauge_values[i]-drchlt_gauge_values[i]) #assert_(success) if not sys.platform == 'win32': if myid == 0: os.remove(sts_file + '.sts') if myid == 0: os.remove(meshname)
def run_simulation(parallel=False): domain = create_domain_from_file(mesh_filename) domain.set_quantity('stage', Set_Stage(756000.0, 756500.0, 2.0)) #-------------------------------------------------------------------------- # Create parallel domain if requested #-------------------------------------------------------------------------- if parallel: if myid == 0 and verbose: print('DISTRIBUTING PARALLEL DOMAIN') domain = distribute(domain) #------------------------------------------------------------------------------ # Setup boundary conditions # This must currently happen *after* domain has been distributed #------------------------------------------------------------------------------ domain.store = False Br = Reflective_boundary(domain) # Solid reflective wall domain.set_boundary({'outflow' :Br, 'inflow' :Br, 'inner' :Br, 'exterior' :Br, 'open' :Br}) #------------------------------------------------------------------------------ # Setup diagnostic arrays #------------------------------------------------------------------------------ l1list = [] l2list = [] linflist = [] l1norm = num.zeros(3, num.float) l2norm = num.zeros(3, num.float) linfnorm = num.zeros(3, num.float) recv_norm = num.zeros(3, num.float) #------------------------------------------------------------------------------ # Evolution #------------------------------------------------------------------------------ if parallel: if myid == 0 and verbose: print('PARALLEL EVOLVE') else: if verbose: print('SEQUENTIAL EVOLVE') for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): edges = domain.quantities[quantity].edge_values.take(num.flatnonzero(domain.tri_full_flag),axis=0) l1norm[0] = l1_norm(edges[:,0]) l1norm[1] = l1_norm(edges[:,1]) l1norm[2] = l1_norm(edges[:,2]) l2norm[0] = l2_norm(edges[:,0]) l2norm[1] = l2_norm(edges[:,1]) l2norm[2] = l2_norm(edges[:,2]) linfnorm[0] = linf_norm(edges[:,0]) linfnorm[1] = linf_norm(edges[:,1]) linfnorm[2] = linf_norm(edges[:,2]) if parallel: l2norm[0] = pow(l2norm[0], 2) l2norm[1] = pow(l2norm[1], 2) l2norm[2] = pow(l2norm[2], 2) if myid == 0: #domain.write_time() #print edges[:,1] for p in range(1, numprocs): recv_norm = pypar.receive(p) l1norm += recv_norm recv_norm = pypar.receive(p) l2norm += recv_norm recv_norm = pypar.receive(p) linfnorm[0] = max(linfnorm[0], recv_norm[0]) linfnorm[1] = max(linfnorm[1], recv_norm[1]) linfnorm[2] = max(linfnorm[2], recv_norm[2]) l2norm[0] = pow(l2norm[0], 0.5) l2norm[1] = pow(l2norm[1], 0.5) l2norm[2] = pow(l2norm[2], 0.5) l1list.append(l1norm) l2list.append(l2norm) linflist.append(linfnorm) else: pypar.send(l1norm, 0) pypar.send(l2norm, 0) pypar.send(linfnorm, 0) else: #domain.write_time() l1list.append(l1norm) l2list.append(l2norm) linflist.append(linfnorm) return (l1list, l2list, linflist)
def parallel_time_varying_file_boundary_sts(self): """ parallel_test_time_varying_file_boundary_sts_sequential(self): Read correct points from ordering file and apply sts to boundary. The boundary is time varying. Compares sequential result with distributed result found using anuga_parallel """ #------------------------------------------------------------ # Define test variables #------------------------------------------------------------ lat_long_points=[[6.01,97.0],[6.02,97.0],[6.05,96.9],[6.0,97.0]] bounding_polygon=[[6.0,97.0],[6.01,97.0],[6.02,97.0], [6.02,97.02],[6.00,97.02]] tide = 3.0 time_step_count = 65 time_step = 2 n=len(lat_long_points) first_tstep=num.ones(n,num.int) last_tstep=(time_step_count)*num.ones(n,num.int) finaltime=num.float(time_step*(time_step_count-1)) yieldstep=num.float(time_step) gauge_depth=20*num.ones(n,num.float) ha=2*num.ones((n,time_step_count),num.float) ua=10*num.ones((n,time_step_count),num.float) va=-10*num.ones((n,time_step_count),num.float) times=num.arange(0, time_step_count*time_step, time_step) for i in range(n): #ha[i]+=num.sin(times) ha[i]+=times/finaltime #------------------------------------------------------------ # Write mux data to file then convert to sts format #------------------------------------------------------------ sts_file="test" if myid==0: base_name, files = self.write_mux2(lat_long_points, time_step_count, time_step, first_tstep, last_tstep, depth=gauge_depth, ha=ha, ua=ua, va=va) # base name will not exist, but 3 other files are created # Write order file file_handle, order_base_name = tempfile.mkstemp("") os.close(file_handle) os.remove(order_base_name) d="," order_file=order_base_name+'order.txt' fid=open(order_file,'w') # Write Header header='index, longitude, latitude\n' fid.write(header) indices=[3,0,1] for i in indices: line=str(i)+d+str(lat_long_points[i][1])+d+\ str(lat_long_points[i][0])+"\n" fid.write(line) fid.close() urs2sts(base_name, basename_out=sts_file, ordering_filename=order_file, mean_stage=tide, verbose=verbose) self.delete_mux(files) assert(os.access(sts_file+'.sts', os.F_OK)) os.remove(order_file) barrier() #------------------------------------------------------------ # Define boundary_polygon on each processor. This polygon defines the # urs boundary and lies on a portion of the bounding_polygon #------------------------------------------------------------ boundary_polygon = create_sts_boundary(sts_file) # Append the remaining part of the boundary polygon to be defined by # the user bounding_polygon_utm=[] for point in bounding_polygon: zone,easting,northing=redfearn(point[0],point[1]) bounding_polygon_utm.append([easting,northing]) boundary_polygon.append(bounding_polygon_utm[3]) boundary_polygon.append(bounding_polygon_utm[4]) assert num.allclose(bounding_polygon_utm,boundary_polygon) extent_res=10000 meshname = 'urs_test_mesh' + '.tsh' interior_regions=None boundary_tags={'ocean': [0,1], 'otherocean': [2,3,4]} #------------------------------------------------------------ # Create mesh on the master processor and store in file. This file # is read in by each slave processor when needed #------------------------------------------------------------ if myid==0: create_mesh_from_regions(boundary_polygon, boundary_tags=boundary_tags, maximum_triangle_area=extent_res, filename=meshname, interior_regions=interior_regions, verbose=verbose) # barrier() domain_fbound = Domain(meshname) domain_fbound.set_quantities_to_be_stored(None) domain_fbound.set_quantity('stage', tide) # print domain_fbound.mesh.get_boundary_polygon() else: domain_fbound=None barrier() if ( verbose and myid == 0 ): print 'DISTRIBUTING PARALLEL DOMAIN' domain_fbound = distribute(domain_fbound) #-------------------------------------------------------------------- # Find which sub_domain in which the interpolation points are located # # Sometimes the interpolation points sit exactly # between two centroids, so in the parallel run we # reset the interpolation points to the centroids # found in the sequential run #-------------------------------------------------------------------- interpolation_points = [[279000,664000], [280250,664130], [279280,665400], [280500,665000]] interpolation_points=num.array(interpolation_points) #if myid==0: # import pylab as P # boundary_polygon=num.array(boundary_polygon) # P.plot(boundary_polygon[:,0],boundary_polygon[:,1]) # P.plot(interpolation_points[:,0],interpolation_points[:,1],'ko') # P.show() fbound_gauge_values = [] fbound_proc_tri_ids = [] for i, point in enumerate(interpolation_points): fbound_gauge_values.append([]) # Empty list for timeseries try: k = domain_fbound.get_triangle_containing_point(point) if domain_fbound.tri_full_flag[k] == 1: fbound_proc_tri_ids.append(k) else: fbound_proc_tri_ids.append(-1) except: fbound_proc_tri_ids.append(-2) if verbose: print 'P%d has points = %s' %(myid, fbound_proc_tri_ids) #------------------------------------------------------------ # Set boundary conditions #------------------------------------------------------------ Bf = File_boundary(sts_file+'.sts', domain_fbound, boundary_polygon=boundary_polygon) Br = Reflective_boundary(domain_fbound) domain_fbound.set_boundary({'ocean': Bf,'otherocean': Br}) #------------------------------------------------------------ # Evolve the domain on each processor #------------------------------------------------------------ for i, t in enumerate(domain_fbound.evolve(yieldstep=yieldstep, finaltime=finaltime, skip_initial_step = False)): stage = domain_fbound.get_quantity('stage') for i in range(4): if fbound_proc_tri_ids[i] > -1: fbound_gauge_values[i].append(stage.centroid_values[fbound_proc_tri_ids[i]]) #------------------------------------------------------------ # Create domain to be run sequntially on each processor #------------------------------------------------------------ domain_drchlt = Domain(meshname) domain_drchlt.set_quantities_to_be_stored(None) domain_drchlt.set_starttime(time_step) domain_drchlt.set_quantity('stage', tide) Br = Reflective_boundary(domain_drchlt) #Bd = Dirichlet_boundary([2.0+tide,220+10*tide,-220-10*tide]) Bd = Time_boundary(domain=domain_drchlt, function=lambda t: [2.0+t/finaltime+tide,220.+10.*tide+10.*t/finaltime,-220.-10.*tide-10.*t/finaltime]) #Bd = Time_boundary(domain=domain_drchlt,function=lambda t: [2.0+num.sin(t)+tide,10.*(2+20.+num.sin(t)+tide),-10.*(2+20.+num.sin(t)+tide)]) domain_drchlt.set_boundary({'ocean': Bd,'otherocean': Br}) drchlt_gauge_values = [] drchlt_proc_tri_ids = [] for i, point in enumerate(interpolation_points): drchlt_gauge_values.append([]) # Empty list for timeseries try: k = domain_drchlt.get_triangle_containing_point(point) if domain_drchlt.tri_full_flag[k] == 1: drchlt_proc_tri_ids.append(k) else: drchlt_proc_tri_ids.append(-1) except: drchlt_proc_tri_ids.append(-2) if verbose: print 'P%d has points = %s' %(myid, drchlt_proc_tri_ids) #------------------------------------------------------------ # Evolve entire domain on each processor #------------------------------------------------------------ for i, t in enumerate(domain_drchlt.evolve(yieldstep=yieldstep, finaltime=finaltime, skip_initial_step = False)): stage = domain_drchlt.get_quantity('stage') for i in range(4): drchlt_gauge_values[i].append(stage.centroid_values[drchlt_proc_tri_ids[i]]) #------------------------------------------------------------ # Compare sequential values with parallel values #------------------------------------------------------------ barrier() success = True for i in range(4): if fbound_proc_tri_ids[i] > -1: fbound_gauge_values[i]=num.array(fbound_gauge_values[i]) drchlt_gauge_values[i]=num.array(drchlt_gauge_values[i]) #print i,fbound_gauge_values[i][4] #print i,drchlt_gauge_values[i][4] success = success and num.allclose(fbound_gauge_values[i], drchlt_gauge_values[i]) assert success#, (fbound_gauge_values[i]-drchlt_gauge_values[i]) #assert_(success) if not sys.platform == 'win32': if myid==0: os.remove(sts_file+'.sts') if myid==0: os.remove(meshname)
def run_simulation(parallel=False): domain = create_domain_from_file(mesh_filename) domain.set_quantity('stage', Set_Stage(756000.0, 756500.0, 2.0)) #-------------------------------------------------------------------------- # Create parallel domain if requested #-------------------------------------------------------------------------- if parallel: if myid == 0 and verbose: print 'DISTRIBUTING PARALLEL DOMAIN' domain = distribute(domain) #------------------------------------------------------------------------------ # Setup boundary conditions # This must currently happen *after* domain has been distributed #------------------------------------------------------------------------------ domain.store = False Br = Reflective_boundary(domain) # Solid reflective wall domain.set_boundary({'outflow' :Br, 'inflow' :Br, 'inner' :Br, 'exterior' :Br, 'open' :Br}) #------------------------------------------------------------------------------ # Setup diagnostic arrays #------------------------------------------------------------------------------ l1list = [] l2list = [] linflist = [] l1norm = num.zeros(3, num.float) l2norm = num.zeros(3, num.float) linfnorm = num.zeros(3, num.float) recv_norm = num.zeros(3, num.float) #------------------------------------------------------------------------------ # Evolution #------------------------------------------------------------------------------ if parallel: if myid == 0 and verbose: print 'PARALLEL EVOLVE' else: if verbose: print 'SEQUENTIAL EVOLVE' for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): edges = domain.quantities[quantity].edge_values.take(num.flatnonzero(domain.tri_full_flag),axis=0) l1norm[0] = l1_norm(edges[:,0]) l1norm[1] = l1_norm(edges[:,1]) l1norm[2] = l1_norm(edges[:,2]) l2norm[0] = l2_norm(edges[:,0]) l2norm[1] = l2_norm(edges[:,1]) l2norm[2] = l2_norm(edges[:,2]) linfnorm[0] = linf_norm(edges[:,0]) linfnorm[1] = linf_norm(edges[:,1]) linfnorm[2] = linf_norm(edges[:,2]) if parallel: l2norm[0] = pow(l2norm[0], 2) l2norm[1] = pow(l2norm[1], 2) l2norm[2] = pow(l2norm[2], 2) if myid == 0: #domain.write_time() #print edges[:,1] for p in range(1, numprocs): recv_norm = pypar.receive(p) l1norm += recv_norm recv_norm = pypar.receive(p) l2norm += recv_norm recv_norm = pypar.receive(p) linfnorm[0] = max(linfnorm[0], recv_norm[0]) linfnorm[1] = max(linfnorm[1], recv_norm[1]) linfnorm[2] = max(linfnorm[2], recv_norm[2]) l2norm[0] = pow(l2norm[0], 0.5) l2norm[1] = pow(l2norm[1], 0.5) l2norm[2] = pow(l2norm[2], 0.5) l1list.append(l1norm) l2list.append(l2norm) linflist.append(linfnorm) else: pypar.send(l1norm, 0) pypar.send(l2norm, 0) pypar.send(linfnorm, 0) else: #domain.write_time() l1list.append(l1norm) l2list.append(l2norm) linflist.append(linfnorm) return (l1list, l2list, linflist)