def __init__(self, coordinates, vertices, boundary = None, full_send_dict = None, ghost_recv_dict = None, velocity = None): Domain.__init__(self, coordinates, vertices, boundary, velocity = velocity, full_send_dict=full_send_dict, ghost_recv_dict=ghost_recv_dict, processor=pypar.rank(), numproc=pypar.size() ) N = self.number_of_elements self.communication_time = 0.0 self.communication_reduce_time = 0.0 print 'processor',self.processor print 'numproc',self.numproc
def update_timestep(self, yieldstep, finaltime): """Calculate local timestep """ generic_comms.communicate_flux_timestep(self, yieldstep, finaltime) Domain.update_timestep(self, yieldstep, finaltime)
def test_create_operator(self): points = num.array([[0.0,0.0],[1.0,0.0],[0.0,1.0]]) elements = num.array([[0,1,2]]) boundary_map = {} boundary_map[(0,0)] = 'edge0' boundary_map[(0,1)] = 'edge1' boundary_map[(0,2)] = 'edge2' domain = Domain(points, elements, boundary_map) operator = Operator(domain) message = operator.statistics() assert message == 'You need to implement operator statistics for your operator' message = operator.timestepping_statistics() assert message == 'You need to implement timestepping statistics for your operator' domain.timestep = 3.0 assert operator.get_timestep() == domain.get_timestep() try: operator() except: pass else: raise Exception('should have raised an exception')
def __init__(self, coordinates=None, vertices=None, boundary=None, source=None, triangular=None, conserved_quantities=None, evolved_quantities=None, other_quantities=None, tagged_elements=None, geo_reference=None, use_inscribed_circle=False, mesh_fulename=None, use_cache=False, verbose=False, full_send_dict=None, ghost_recv_dict=None, starttime=0.0, processor=0, numproc=1, number_of_full_nodes=None, number_of_full_triangles=None, ghost_layer_width=2 ): """The init routain of the ANUGA to create the mesh.""" Domain.__init__(self, coordinates, vertices, boundary, full_send_dict=full_send_dict, ghost_recv_dict=ghost_recv_dict, number_of_full_nodes=number_of_full_nodes, number_of_full_triangles=number_of_full_triangles, geo_reference=geo_reference) #jj added this
def __init__(self, coordinates, vertices, boundary=None, full_send_dict=None, ghost_recv_dict=None, velocity=None): Domain.__init__(self, coordinates, vertices, boundary, velocity=velocity, full_send_dict=full_send_dict, ghost_recv_dict=ghost_recv_dict, processor=pypar.rank(), numproc=pypar.size()) N = self.number_of_elements self.communication_time = 0.0 self.communication_reduce_time = 0.0 print 'processor', self.processor print 'numproc', self.numproc
def test_set_stage_operator_negative(self): from anuga.config import rho_a, rho_w, eta_w from math import pi, cos, sin a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] # bac, bce, ecf, dbe vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] domain = Domain(points, vertices) #Flat surface with 1m of water domain.set_quantity('elevation', lambda x,y : -2*x) domain.set_quantity('stage', 1.0) domain.set_quantity('friction', 0) Br = Reflective_boundary(domain) domain.set_boundary({'exterior': Br}) # print domain.quantities['elevation'].centroid_values # print domain.quantities['stage'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values # Apply operator to these triangles indices = [0,1,3] #Catchment_Rain_Polygon = read_polygon(join('CatchmentBdy.csv')) #rainfall = file_function(join('1y120m.tms'), quantities=['rainfall']) stage = -5.0 operator = Set_stage_operator(domain, stage=stage, indices=indices) # Apply Operator domain.timestep = 2.0 operator() stage_ex = [ -5., -5., 1., -5.] #print domain.quantities['elevation'].centroid_values #print domain.quantities['stage'].centroid_values #print domain.quantities['xmomentum'].centroid_values #print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
def test_set_quantity_simple(self): from anuga.config import rho_a, rho_w, eta_w from math import pi, cos, sin a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] # bac, bce, ecf, dbe vertices = [[1, 0, 2], [1, 2, 4], [4, 2, 5], [3, 1, 4]] domain = Domain(points, vertices) #Flat surface with 1m of water domain.set_quantity('elevation', 0) domain.set_quantity('stage', 1.0) domain.set_quantity('friction', 0) Br = Reflective_boundary(domain) domain.set_boundary({'exterior': Br}) # print domain.quantities['stage'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values # Apply operator to these triangles indices = [0, 1, 3] stage = 3.0 update_stage = Set_quantity(domain, "stage", value=stage, indices=indices, test_stage=False) # Apply Operator update_stage() stage_ex = [3., 3., 1., 3.] #print domain.quantities['stage'].centroid_values #print domain.quantities['xmomentum'].centroid_values #print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
def test_rate_operator_simple(self): from anuga.config import rho_a, rho_w, eta_w from math import pi, cos, sin a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] # bac, bce, ecf, dbe vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] domain = Domain(points, vertices) #Flat surface with 1m of water domain.set_quantity('elevation', 0) domain.set_quantity('stage', 1.0) domain.set_quantity('friction', 0) Br = Reflective_boundary(domain) domain.set_boundary({'exterior': Br}) # print domain.quantities['stage'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values # Apply operator to these triangles indices = [0,1,3] rate = 1.0 factor = 10.0 default_rate= 0.0 operator = Rate_operator(domain, rate=rate, factor=factor, \ indices=indices, default_rate = default_rate) # Apply Operator domain.timestep = 2.0 operator() stage_ex = [ 21., 21., 1., 21.] # print domain.quantities['stage'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0) assert num.allclose(domain.fractional_step_volume_integral, factor*domain.timestep*(rate*domain.areas[indices]).sum())
def set_name(self, name): """Assign name based on processor number """ if name.endswith('.sww'): name = name[:-4] self.global_name = name # Call parents method with processor number attached. Domain.set_name(self, name + '_P%d_%d' %(self.numproc, self.processor))
def set_name(self, name): """Assign name based on processor number """ if name.endswith('.sww'): name = name[:-4] self.global_name = name # Call parents method with processor number attached. Domain.set_name(self, name + '_P%d_%d' % (self.numproc, self.processor))
def test_set_stage_operator_simple(self): from anuga.config import rho_a, rho_w, eta_w from math import pi, cos, sin a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] # bac, bce, ecf, dbe vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] domain = Domain(points, vertices) #Flat surface with 1m of water domain.set_quantity('elevation', 0) domain.set_quantity('stage', 1.0) domain.set_quantity('friction', 0) Br = Reflective_boundary(domain) domain.set_boundary({'exterior': Br}) # print domain.quantities['stage'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values # Apply operator to these triangles indices = [0,1,3] stage = 3.0 operator = Set_stage_operator(domain, stage=stage, indices=indices) # Apply Operator domain.timestep = 2.0 operator() stage_ex = [ 3., 3., 1., 3.] #print domain.quantities['stage'].centroid_values #print domain.quantities['xmomentum'].centroid_values #print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
def test_slide_tsunami_domain(self): if anuga_installed: pass else: print 'Note: test_slide_tsunami_domain not tested as ANUGA '\ 'is not installed' return length = 600.0 dep = 150.0 th = 9.0 thk = 15.0 wid = 340.0 kappa = 3.0 kappad = 0.8 x0 = 100000. y0 = x0 from anuga.pmesh.mesh_interface import create_mesh_from_regions polygon = [[0,0],[200000,0],[200000,200000],[0,200000]] create_mesh_from_regions(polygon, {'e0': [0], 'e1': [1], 'e2': [2], 'e3': [3]}, maximum_triangle_area=5000000000, filename='test.msh', verbose = False) domain = Domain('test.msh', use_cache = True, verbose = False) slide = slide_tsunami(length, dep, th, x0, y0, \ wid, thk, kappa, kappad, \ domain=domain,verbose=False) domain.set_quantity('stage', slide) stage = domain.get_quantity('stage') w = stage.get_values() ## check = [[-0.0 -0.0 -0.0], ## [-.189709745 -517.877716 -0.0], ## [-0.0 -0.0 -2.7695931e-08], ## [-0.0 -2.7695931e-08 -1.897097e-01] ## [-0.0 -517.877716 -0.0], ## [-0.0 -0.0 -0.0], ## [-0.0 -0.0 -0.0], ## [-0.0 -0.0 -0.0]] assert num.allclose(num.min(w), -517.877771593) assert num.allclose(num.max(w), 0.0) assert num.allclose(slide.a3D, 518.38797486)
def test_rate_operator_negative_rate_full(self): from anuga.config import rho_a, rho_w, eta_w from math import pi, cos, sin a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] # bac, bce, ecf, dbe vertices = [[1, 0, 2], [1, 2, 4], [4, 2, 5], [3, 1, 4]] domain = Domain(points, vertices) # Flat surface with 1m of water domain.set_quantity("elevation", 0) domain.set_quantity("stage", 10.0) domain.set_quantity("friction", 0) Br = Reflective_boundary(domain) domain.set_boundary({"exterior": Br}) # print domain.quantities['elevation'].centroid_values # print domain.quantities['stage'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values # Apply operator to these triangles indices = [0, 1, 3] # Catchment_Rain_Polygon = read_polygon(join('CatchmentBdy.csv')) # rainfall = file_function(join('1y120m.tms'), quantities=['rainfall']) rate = -1.0 factor = 10.0 default_rate = 0.0 operator = Rate_operator(domain, rate=rate, factor=factor, indices=None, default_rate=default_rate) # Apply Operator domain.timestep = 2.0 operator() stage_ex = [0.0, 0.0, 0.0, 0.0] step_integral = -80.0 # print domain.quantities['elevation'].centroid_values # print domain.quantities['stage'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values # print domain.fractional_step_volume_integral assert num.allclose(domain.quantities["stage"].centroid_values, stage_ex) assert num.allclose(domain.quantities["xmomentum"].centroid_values, 0.0) assert num.allclose(domain.quantities["ymomentum"].centroid_values, 0.0) assert num.allclose(domain.fractional_step_volume_integral, step_integral)
def sequential_distribute_load_pickle_file(pickle_name, np=1, verbose = False): """ Open pickle files """ f = open(pickle_name, 'rb') import pickle kwargs, points, vertices, boundary, quantities, boundary_map, \ domain_name, domain_dir, domain_store, domain_store_centroids, \ domain_minimum_storable_height, domain_minimum_allowed_height, \ domain_flow_algorithm, domain_georef, \ domain_quantities_to_be_stored, domain_smooth, \ domain_low_froude = pickle.load(f) f.close() for k in quantities: quantities[k] = num.load(quantities[k]) points = num.load(points) vertices = num.load(vertices) #--------------------------------------------------------------------------- # Create domain (parallel if np>1) #--------------------------------------------------------------------------- if np>1: domain = Parallel_domain(points, vertices, boundary, **kwargs) else: domain = Domain(points, vertices, boundary, **kwargs) #------------------------------------------------------------------------ # Copy in quantity data #------------------------------------------------------------------------ for q in quantities: domain.set_quantity(q, quantities[q]) #------------------------------------------------------------------------ # Transfer boundary conditions to each subdomain #------------------------------------------------------------------------ boundary_map['ghost'] = None # Add binding to ghost boundary domain.set_boundary(boundary_map) #------------------------------------------------------------------------ # Transfer other attributes to each subdomain #------------------------------------------------------------------------ domain.set_name(domain_name) domain.set_datadir(domain_dir) domain.set_flow_algorithm(domain_flow_algorithm) domain.set_low_froude(domain_low_froude) domain.set_store(domain_store) domain.set_store_centroids(domain_store_centroids) domain.set_minimum_storable_height(domain_minimum_storable_height) domain.set_minimum_allowed_height(domain_minimum_allowed_height) domain.geo_reference = domain_georef domain.set_quantities_to_be_stored(domain_quantities_to_be_stored) domain.smooth = domain_smooth return domain
def test_slide_tsunami_domain(self): length = 600.0 dep = 150.0 th = 9.0 thk = 15.0 wid = 340.0 kappa = 3.0 kappad = 0.8 x0 = 100000. y0 = x0 from anuga.pmesh.mesh_interface import create_mesh_from_regions polygon = [[0, 0], [200000, 0], [200000, 200000], [0, 200000]] create_mesh_from_regions(polygon, { 'e0': [0], 'e1': [1], 'e2': [2], 'e3': [3] }, maximum_triangle_area=5000000000, filename='test.msh', verbose=False) domain = Domain('test.msh', use_cache=True, verbose=False) slide = slide_tsunami(length, dep, th, x0, y0, \ wid, thk, kappa, kappad, \ domain=domain,verbose=False) domain.set_quantity('stage', slide) stage = domain.get_quantity('stage') w = stage.get_values() ## check = [[-0.0 -0.0 -0.0], ## [-.189709745 -517.877716 -0.0], ## [-0.0 -0.0 -2.7695931e-08], ## [-0.0 -2.7695931e-08 -1.897097e-01] ## [-0.0 -517.877716 -0.0], ## [-0.0 -0.0 -0.0], ## [-0.0 -0.0 -0.0], ## [-0.0 -0.0 -0.0]] assert num.allclose(num.min(w), -517.877771593) assert num.allclose(num.max(w), 0.0) assert num.allclose(slide.a3D, 518.38797486)
def __init__(self, coordinates, vertices, boundary=None, full_send_dict=None, ghost_recv_dict=None, number_of_full_nodes=None, number_of_full_triangles=None, geo_reference=None): #jj added this Domain.__init__(self, coordinates, vertices, boundary, full_send_dict=full_send_dict, ghost_recv_dict=ghost_recv_dict, number_of_full_nodes=number_of_full_nodes, number_of_full_triangles=number_of_full_triangles, geo_reference=geo_reference) #jj added this
def update_timestep(self, yieldstep, finaltime): #LINDA: # moved the calculation so that it is done after timestep # has been broadcast # # Calculate local timestep # Domain.update_timestep(self, yieldstep, finaltime) import time t0 = time.time() # For some reason it looks like pypar only reduces numeric arrays # hence we need to create some dummy arrays for communication ltimestep = num.ones(1, num.float) ltimestep[0] = self.flux_timestep gtimestep = num.zeros(1, num.float) # Buffer for results #ltimestep = self.flux_timeste #print self.processor, ltimestep, gtimestep gtimestep = pypar.reduce(ltimestep, pypar.MIN, 0, buffer=gtimestep) #print self.processor, ltimestep, gtimestep pypar.broadcast(gtimestep, 0) #print self.processor, ltimestep, gtimestep self.flux_timestep = gtimestep[0] self.communication_reduce_time += time.time() - t0 # LINDA: # Now update time stats # Calculate local timestep Domain.update_timestep(self, yieldstep, finaltime)
def update_timestep(self, yieldstep, finaltime): #LINDA: # moved the calculation so that it is done after timestep # has been broadcast # # Calculate local timestep # Domain.update_timestep(self, yieldstep, finaltime) import time t0 = time.time() # For some reason it looks like pypar only reduces numeric arrays # hence we need to create some dummy arrays for communication ltimestep = num.ones( 1, num.float ) ltimestep[0] = self.flux_timestep gtimestep = num.zeros( 1, num.float ) # Buffer for results #ltimestep = self.flux_timeste #print self.processor, ltimestep, gtimestep gtimestep = pypar.reduce(ltimestep, pypar.MIN, 0, buffer=gtimestep) #print self.processor, ltimestep, gtimestep pypar.broadcast(gtimestep,0) #print self.processor, ltimestep, gtimestep self.flux_timestep = gtimestep[0] self.communication_reduce_time += time.time()-t0 # LINDA: # Now update time stats # Calculate local timestep Domain.update_timestep(self, yieldstep, finaltime)
def concept_ungenerateIII(self): from anuga import Domain, Reflective_boundary, \ Dirichlet_boundary from anuga.pmesh.mesh_interface import create_mesh_from_regions # These are the absolute values polygon = [[0, 0], [100, 0], [100, 100], [0, 100]] boundary_tags = {'wall': [0, 1, 3], 'wave': [2]} inner1_polygon = [[10, 10], [20, 10], [20, 20], [10, 20]] inner2_polygon = [[30, 30], [40, 30], [40, 40], [30, 40]] max_area = 1 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)] m = create_mesh_from_regions(polygon, boundary_tags, max_area, interior_regions=interior_regions) fileName = tempfile.mktemp('.txt') file = open(fileName, 'w') file.write(' 1 ?? ??\n\ 90.0 90.0\n\ 81.0 90.0\n\ 81.0 81.0\n\ 90.0 81.0\n\ 90.0 90.0\n\ END\n\ 2 ?? ??\n\ 10.0 80.0\n\ 10.0 90.0\n\ 20.0 90.0\n\ 10.0 80.0\n\ END\n\ END\n') file.close() m.import_ungenerate_file(fileName) os.remove(fileName) m.generate_mesh(maximum_triangle_area=max_area, verbose=False) mesh_filename = 'mesh.tsh' m.export_mesh_file(mesh_filename) domain = Domain(mesh_filename, use_cache=False) Br = Reflective_boundary(domain) Bd = Dirichlet_boundary([3, 0, 0]) domain.set_boundary({'wall': Br, 'wave': Bd}) yieldstep = 0.1 finaltime = 10 for t in domain.evolve(yieldstep, finaltime): domain.write_time()
def concept_ungenerateIII(self): from anuga import Domain, Reflective_boundary, \ Dirichlet_boundary from anuga.pmesh.mesh_interface import create_mesh_from_regions # These are the absolute values polygon = [[0,0], [100,0], [100,100], [0,100]] boundary_tags = {'wall': [0,1,3], 'wave': [2]} inner1_polygon = [[10,10], [20,10], [20,20], [10,20]] inner2_polygon = [[30,30], [40,30], [40,40], [30,40]] max_area = 1 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)] m = create_mesh_from_regions(polygon, boundary_tags, max_area, interior_regions=interior_regions) fileName = tempfile.mktemp('.txt') file = open(fileName, 'w') file.write(' 1 ?? ??\n\ 90.0 90.0\n\ 81.0 90.0\n\ 81.0 81.0\n\ 90.0 81.0\n\ 90.0 90.0\n\ END\n\ 2 ?? ??\n\ 10.0 80.0\n\ 10.0 90.0\n\ 20.0 90.0\n\ 10.0 80.0\n\ END\n\ END\n') file.close() m.import_ungenerate_file(fileName) os.remove(fileName) m.generate_mesh(maximum_triangle_area=max_area, verbose=False) mesh_filename = 'mesh.tsh' m.export_mesh_file(mesh_filename) domain = Domain(mesh_filename, use_cache=False) Br = Reflective_boundary(domain) Bd = Dirichlet_boundary([3, 0, 0]) domain.set_boundary({'wall': Br, 'wave': Bd}) yieldstep = 0.1 finaltime = 10 for t in domain.evolve(yieldstep, finaltime): domain.write_time()
def test_runup_sinusoid(self): """ Run a version of the validation test runup_sinusoid to ensure limiting solution has small velocity """ points, vertices, boundary = anuga.rectangular_cross(20,20, len1=1., len2=1.) domain=Domain(points,vertices,boundary) # Create Domain domain.set_flow_algorithm('DE0') domain.set_name('runup_sinusoid_v2') # Output to file runup.sww domain.set_datadir('.') # Use current folder domain.set_quantities_to_be_stored({'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 1}) #domain.set_store_vertices_uniquely(True) #------------------ # Define topography #------------------ scale_me=1.0 def topography(x,y): return (-x/2.0 +0.05*num.sin((x+y)*50.0))*scale_me def stagefun(x,y): stge=-0.2*scale_me #+0.01*(x>0.9) return stge domain.set_quantity('elevation',topography) # Use function for elevation domain.get_quantity('elevation').smooth_vertex_values() domain.set_quantity('friction',0.03) # Constant friction domain.set_quantity('stage', stagefun) # Constant negative initial stage domain.get_quantity('stage').smooth_vertex_values() #-------------------------- # Setup boundary conditions #-------------------------- Br=anuga.Reflective_boundary(domain) # Solid reflective wall Bd=anuga.Dirichlet_boundary([-0.1*scale_me,0.,0.]) # Constant boundary values -- not used in this example #---------------------------------------------- # Associate boundary tags with boundary objects #---------------------------------------------- domain.set_boundary({'left': Br, 'right': Bd, 'top': Br, 'bottom':Br}) #------------------------------ #Evolve the system through time #------------------------------ for t in domain.evolve(yieldstep=7.0,finaltime=7.0): #print domain.timestepping_statistics() xx = domain.quantities['xmomentum'].centroid_values yy = domain.quantities['ymomentum'].centroid_values dd = domain.quantities['stage'].centroid_values - domain.quantities['elevation'].centroid_values #dd_raw=1.0*dd dd = (dd)*(dd>1.0e-03)+1.0e-03 vv = ( (xx/dd)**2 + (yy/dd)**2)**0.5 vv = vv*(dd>1.0e-03) #print 'Peak velocity is: ', vv.max(), vv.argmax() #print 'Volume is', sum(dd_raw*domain.areas) #print vv.max() assert num.all(vv<1.01e-01)
#------------------------------------------------------------------------------ dx = 1. dy = dx L = 1500. W = 60. #=============================================================================== # Create sequential domain #=============================================================================== if myid == 0: # structured mesh points, vertices, boundary = anuga.rectangular_cross( int(L / dx), int(W / dy), L, W, (0., -W / 2.)) #domain = anuga.Domain(points, vertices, boundary) domain = Domain(points, vertices, boundary) domain.set_name(output_file) domain.set_datadir(output_dir) #------------------------------------------------------------------------------ # Setup Algorithm, either using command line arguments # or override manually yourself #------------------------------------------------------------------------------ domain.set_flow_algorithm(alg) #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ domain.set_quantity('friction', 0.0) domain.set_quantity('stage', 12.0)
from anuga import rectangular_cross from anuga import Domain from anuga import Reflective_boundary from anuga import Dirichlet_boundary from anuga import Time_boundary #------------------------------------------------------------------------------ # Setup computational domain #------------------------------------------------------------------------------ length = 24. width = 5. dx = dy = 0.2 #.1 # Resolution: Length of subdivisions on both axes points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), len1=length, len2=width) domain = Domain(points, vertices, boundary) domain.set_name('channel_variable_bed_0.2_newviewer') # Output name print domain.statistics() domain.set_quantities_to_be_stored({'elevation': 2, 'stage': 2}) #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ def topography(x,y): """Complex topography defined by a function of vectors x and y.""" z = -x/100 N = len(x) for i in range(N):
from anuga import rectangular_cross from anuga import Domain from anuga import Reflective_boundary from anuga import Dirichlet_boundary from anuga import Time_boundary #------------------------------------------------------------------------------ # Setup computational domain #------------------------------------------------------------------------------ length = 24. width = 5. dx = dy = 0.2 #.1 # Resolution: Length of subdivisions on both axes points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), len1=length, len2=width) domain = Domain(points, vertices, boundary) domain.set_name('set_elevation') # Output name print domain.statistics() domain.set_quantities_to_be_stored({'elevation': 2, 'stage': 2}) #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ def topography_dam(x,y): """Complex topography defined by a function of vectors x and y.""" z = -x/100 N = len(x) for i in range(N):
def write_time(self): if self.processor == 0: Domain.write_time(self)
def test_rate_operator_functions_empty_indices(self): from anuga.config import rho_a, rho_w, eta_w from math import pi, cos, sin a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] # bac, bce, ecf, dbe vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] domain = Domain(points, vertices) #Flat surface with 1m of water domain.set_quantity('elevation', 0.0) domain.set_quantity('stage', 1.0) domain.set_quantity('friction', 0.0) Br = Reflective_boundary(domain) domain.set_boundary({'exterior': Br}) verbose = False if verbose: print domain.quantities['elevation'].centroid_values print domain.quantities['stage'].centroid_values print domain.quantities['xmomentum'].centroid_values print domain.quantities['ymomentum'].centroid_values # Apply operator to these triangles indices = [] factor = 10.0 def main_spatial_rate(x,y,t): # x and y should be an n by 1 array return x + y default_rate = 0.0 domain.tri_full_flag[0] = 0 operator = Rate_operator(domain, rate=main_spatial_rate, factor=factor, \ indices=indices, default_rate = default_rate) # Apply Operator domain.timestep = 2.0 operator() t = operator.get_time() Q = operator.get_Q() x = operator.coord_c[indices,0] y = operator.coord_c[indices,1] rate = main_spatial_rate(x,y,t)*factor Q_ex = num.sum(domain.areas[indices]*rate) d = operator.get_timestep()*rate + 1 #print Q_ex, Q #print indices #print "d" #print d stage_ex = num.array([ 1.0, 1.0, 1.0, 1.0]) stage_ex[indices] = d if verbose: print domain.quantities['elevation'].centroid_values print domain.quantities['stage'].centroid_values print domain.quantities['xmomentum'].centroid_values print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0) assert num.allclose(Q_ex, Q) assert num.allclose(domain.fractional_step_volume_integral, ((d-1.)*domain.areas[indices]).sum())
def test_rate_operator_negative_rate_full(self): from anuga.config import rho_a, rho_w, eta_w from math import pi, cos, sin a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] # bac, bce, ecf, dbe vertices = [[1, 0, 2], [1, 2, 4], [4, 2, 5], [3, 1, 4]] domain = Domain(points, vertices) #Flat surface with 1m of water domain.set_quantity('elevation', 0) domain.set_quantity('stage', 10.0) domain.set_quantity('friction', 0) Br = Reflective_boundary(domain) domain.set_boundary({'exterior': Br}) # print domain.quantities['elevation'].centroid_values # print domain.quantities['stage'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values # Apply operator to these triangles indices = [0, 1, 3] #Catchment_Rain_Polygon = read_polygon(join('CatchmentBdy.csv')) #rainfall = file_function(join('1y120m.tms'), quantities=['rainfall']) rate = -1.0 factor = 10.0 default_rate = 0.0 operator = Rate_operator(domain, rate=rate, factor=factor, \ indices=None, default_rate = default_rate) # Apply Operator domain.timestep = 2.0 operator() stage_ex = [0., 0., 0., 0.] step_integral = -80.0 #print domain.quantities['elevation'].centroid_values #print domain.quantities['stage'].centroid_values #print domain.quantities['xmomentum'].centroid_values #print domain.quantities['ymomentum'].centroid_values #print domain.fractional_step_volume_integral assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0) assert num.allclose(domain.fractional_step_volume_integral, step_integral)
def test_rate_operator_rate_from_file(self): from anuga.config import rho_a, rho_w, eta_w from math import pi, cos, sin a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] # bac, bce, ecf, dbe vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] #--------------------------------- #Typical ASCII file #--------------------------------- finaltime = 1200 filename = 'test_file_function' fid = open(filename + '.txt', 'w') start = time.mktime(time.strptime('2000', '%Y')) dt = 60 #One minute intervals t = 0.0 while t <= finaltime: t_string = time.strftime(time_format, time.gmtime(t+start)) fid.write('%s, %f %f %f\n' %(t_string, 2*t, t**2, sin(t*pi/600))) t += dt fid.close() #Convert ASCII file to NetCDF (Which is what we really like!) timefile2netcdf(filename+'.txt') #Create file function from time series F = file_function(filename + '.tms', quantities = ['Attribute0', 'Attribute1', 'Attribute2']) #Now try interpolation for i in range(20): t = i*10 q = F(t) #Exact linear intpolation assert num.allclose(q[0], 2*t) if i%6 == 0: assert num.allclose(q[1], t**2) assert num.allclose(q[2], sin(t*pi/600)) #Check non-exact t = 90 #Halfway between 60 and 120 q = F(t) assert num.allclose( (120**2 + 60**2)/2, q[1] ) assert num.allclose( (sin(120*pi/600) + sin(60*pi/600))/2, q[2] ) t = 100 #Two thirds of the way between between 60 and 120 q = F(t) assert num.allclose( 2*120**2/3 + 60**2/3, q[1] ) assert num.allclose( 2*sin(120*pi/600)/3 + sin(60*pi/600)/3, q[2] ) #os.remove(filename + '.txt') #os.remove(filename + '.tms') domain = Domain(points, vertices) #Flat surface with 1m of water domain.set_quantity('elevation', 0) domain.set_quantity('stage', 1.0) domain.set_quantity('friction', 0) Br = Reflective_boundary(domain) domain.set_boundary({'exterior': Br}) # print domain.quantities['elevation'].centroid_values # print domain.quantities['stage'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values # Apply operator to these triangles indices = [0,1,3] rate = file_function(filename + '.tms', quantities=['Attribute1']) # Make starttime of domain consistent with tms file starttime domain.set_starttime(rate.starttime) factor = 1000.0 default_rate= 17.7 operator = Rate_operator(domain, rate=rate, factor=factor, \ indices=indices, default_rate = default_rate) # Apply Operator domain.set_time(360.0) domain.timestep = 1.0 operator() d = domain.get_time()**2 * factor + 1.0 stage_ex0 = [ d, d, 1., d] # print d, domain.get_time(), F(360.0) # print domain.quantities['elevation'].centroid_values # print domain.quantities['stage'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex0) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0) assert num.allclose(domain.fractional_step_volume_integral, ((d-1.)*domain.areas[indices]).sum()) domain.set_time(-10.0) domain.timestep = 1.0 try: operator() except: pass else: raise Exception('Should have raised an exception, time too early') domain.set_time(1300.0) domain.timestep = 1.0 operator() d = default_rate*factor + d stage_ex1 = [ d, d, 1., d] # print domain.quantities['elevation'].centroid_values # print domain.quantities['stage'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex1) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0) assert num.allclose(domain.fractional_step_volume_integral, ((d-1.)*domain.areas[indices]).sum())
def test_rate_operator_functions_rate_default_rate(self): from anuga.config import rho_a, rho_w, eta_w from math import pi, cos, sin a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] # bac, bce, ecf, dbe vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] domain = Domain(points, vertices) #Flat surface with 1m of water domain.set_quantity('elevation', 0) domain.set_quantity('stage', 1.0) domain.set_quantity('friction', 0) Br = Reflective_boundary(domain) domain.set_boundary({'exterior': Br}) verbose = False if verbose: print domain.quantities['elevation'].centroid_values print domain.quantities['stage'].centroid_values print domain.quantities['xmomentum'].centroid_values print domain.quantities['ymomentum'].centroid_values # Apply operator to these triangles indices = [0,1,3] factor = 10.0 def main_rate(t): if t > 20: msg = 'Model time exceeded.' raise Modeltime_too_late, msg else: return 3.0 * t + 7.0 default_rate = lambda t: 3*t + 7 operator = Rate_operator(domain, rate=main_rate, factor=factor, \ indices=indices, default_rate = default_rate) # Apply Operator domain.timestep = 2.0 operator() t = operator.get_time() d = operator.get_timestep()*main_rate(t)*factor + 1 stage_ex = [ d, d, 1., d] if verbose: print domain.quantities['elevation'].centroid_values print domain.quantities['stage'].centroid_values print domain.quantities['xmomentum'].centroid_values print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0) assert num.allclose(domain.fractional_step_volume_integral, ((d-1.)*domain.areas[indices]).sum()) domain.set_starttime(30.0) domain.timestep = 1.0 operator() t = operator.get_time() d = operator.get_timestep()*default_rate(t)*factor + d stage_ex = [ d, d, 1., d] if verbose: print domain.quantities['elevation'].centroid_values print domain.quantities['stage'].centroid_values print domain.quantities['xmomentum'].centroid_values print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
def test_set_w_uh_vh_operator_time(self): from anuga.config import rho_a, rho_w, eta_w from math import pi, cos, sin a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] # bac, bce, ecf, dbe vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] domain = Domain(points, vertices) #Flat surface with 1m of water domain.set_quantity('elevation', 0) domain.set_quantity('stage', 1.0) domain.set_quantity('xmomentum', 7.0) domain.set_quantity('ymomentum', 8.0) domain.set_quantity('friction', 0) Br = Reflective_boundary(domain) domain.set_boundary({'exterior': Br}) # print domain.quantities['w_uh_vh'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values # Apply operator to these triangles indices = [0,1,3] w_uh_vh = lambda t : [t, t+1, t+2] operator = Set_w_uh_vh_operator(domain, w_uh_vh=w_uh_vh, indices=indices) # Apply Operator domain.timestep = 2.0 domain.time = 1.0 operator() t = domain.time stage_ex = [ t, t, 1., t] xmom_ex = [ t+1, t+1, 7., t+1] ymom_ex = [ t+2, t+2, 8., t+2] #print domain.quantities['stage'].centroid_values #print domain.quantities['xmomentum'].centroid_values #print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) assert num.allclose(domain.quantities['xmomentum'].centroid_values, xmom_ex) assert num.allclose(domain.quantities['ymomentum'].centroid_values, ymom_ex)
z[id] += 1 # Pole 2 #id = (x - 14)**2 + (y - 3.5)**2 < 0.4**2 #z[id] += 1.0 return z #---------------------------------------------------------------------------- # Setup initial domain #---------------------------------------------------------------------------- if anuga.myid == 0: points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), len1=length, len2=width) domain = Domain(points, vertices, boundary) domain.set_name() # Output name print domain.statistics() domain.set_quantity('elevation', topography) # elevation is a function domain.set_quantity('friction', 0.01) # Constant friction domain.set_quantity('stage', expression='elevation') # Dry initial condition else: domain = None domain = anuga.distribute(domain) #------------------------------------------------------------------------------ # Setup boundary conditions
# ------------------------------------------------------------------------------ # Setup Algorithm, either using command line arguments # or override manually yourself # ------------------------------------------------------------------------------ args = anuga.get_args() alg = args.alg verbose = args.verbose if myid == 0: # structured mesh points, vertices, boundary = anuga.rectangular_cross(int(L / dx), int(W / dy), L, W, (-L / 2.0, -W / 2.0)) # domain = anuga.Domain(points, vertices, boundary) domain = Domain(points, vertices, boundary) domain.set_name(output_file) domain.set_datadir(output_dir) domain.set_flow_algorithm(alg) # ------------------------------------------------------------------------------ # Setup initial conditions # ------------------------------------------------------------------------------ # No Mannings friction, but we introduce Coulomb friction below. domain.set_quantity("friction", 0.0) domain.set_quantity("stage", stage) domain.set_quantity("elevation", elevation)
#=============================================================================== #------------------------------------------------------------------------------ # Setup computational domain #------------------------------------------------------------------------------ length = 15. width = 4. dx = dy = 0.25 #.1 # Resolution: Length of subdivisions on both axes points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), len1=length, len2=width) evolved_quantities = ['stage', 'xmomentum', 'ymomentum', 'elevation'] domain = Domain(points, vertices, boundary, evolved_quantities=evolved_quantities) domain.set_flow_algorithm('DE0') domain.set_name('veg') # Output name # domain.set_store_vertices_uniquely(True) # print domain.statistics() domain.set_quantities_to_be_stored({'elevation': 2, 'stage': 2, 'xmomentum': 2, 'ymomentum': 2}) domain.set_quantity('elevation', topography) # elevation is a function domain.set_quantity('friction', 0.01) # Constant friction domain.set_quantity('stage', topography) # Dry initial condition
#start_screen_catcher(output_dir+'_') #------------------------------------------------------------------------------ # Setup domain #------------------------------------------------------------------------------ dx = 0.25 dy = dx L = 20. W = 5. # structured mesh points, vertices, boundary = anuga.rectangular_cross(int(L/dx), int(W/dy), L, W, (-L/2.0, -W/2.0)) #domain = anuga.Domain(points, vertices, boundary) domain = Domain(points, vertices, boundary) domain.set_name(output_file) domain.set_datadir(output_dir) #------------------------------------------------------------------------------ # Setup Algorithm, either using command line arguments # or override manually yourself #------------------------------------------------------------------------------ from anuga.utilities.argparsing import parse_standard_args alg = parse_standard_args() domain.set_flow_algorithm(alg) #------------------------------------------------------------------------------ # Setup initial conditions
def test_rate_operator_functions_rate_default_rate(self): from anuga.config import rho_a, rho_w, eta_w from math import pi, cos, sin a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] # bac, bce, ecf, dbe vertices = [[1, 0, 2], [1, 2, 4], [4, 2, 5], [3, 1, 4]] domain = Domain(points, vertices) #Flat surface with 1m of water domain.set_quantity('elevation', 0) domain.set_quantity('stage', 1.0) domain.set_quantity('friction', 0) Br = Reflective_boundary(domain) domain.set_boundary({'exterior': Br}) verbose = False if verbose: print domain.quantities['elevation'].centroid_values print domain.quantities['stage'].centroid_values print domain.quantities['xmomentum'].centroid_values print domain.quantities['ymomentum'].centroid_values # Apply operator to these triangles indices = [0, 1, 3] factor = 10.0 def main_rate(t): if t > 20: msg = 'Model time exceeded.' raise Modeltime_too_late, msg else: return 3.0 * t + 7.0 default_rate = lambda t: 3 * t + 7 operator = Rate_operator(domain, rate=main_rate, factor=factor, \ indices=indices, default_rate = default_rate) # Apply Operator domain.timestep = 2.0 operator() t = operator.get_time() d = operator.get_timestep() * main_rate(t) * factor + 1 stage_ex = [d, d, 1., d] if verbose: print domain.quantities['elevation'].centroid_values print domain.quantities['stage'].centroid_values print domain.quantities['xmomentum'].centroid_values print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0) assert num.allclose(domain.fractional_step_volume_integral, ((d - 1.) * domain.areas[indices]).sum()) domain.set_starttime(30.0) domain.timestep = 1.0 operator() t = operator.get_time() d = operator.get_timestep() * default_rate(t) * factor + d stage_ex = [d, d, 1., d] if verbose: print domain.quantities['elevation'].centroid_values print domain.quantities['stage'].centroid_values print domain.quantities['xmomentum'].centroid_values print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0)
def concept_ungenerateII(self): from anuga import Domain, Reflective_boundary, Dirichlet_boundary x = 0 y = 0 mesh_geo = geo_reference = Geo_reference(56, x, y) # These are the absolute values polygon_absolute = [[0, 0], [100, 0], [100, 100], [0, 100]] x_p = -10 y_p = -40 geo_ref_poly = Geo_reference(56, x_p, y_p) polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) boundary_tags = {'wall': [0, 1, 3], 'wave': [2]} inner1_polygon_absolute = [[10, 10], [20, 10], [20, 20], [10, 20]] inner1_polygon = geo_ref_poly.\ change_points_geo_ref(inner1_polygon_absolute) inner2_polygon_absolute = [[30, 30], [40, 30], [40, 40], [30, 40]] inner2_polygon = geo_ref_poly.\ change_points_geo_ref(inner2_polygon_absolute) max_area = 1 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)] m = create_mesh_from_regions(polygon, boundary_tags, max_area, interior_regions=interior_regions, poly_geo_reference=geo_ref_poly, mesh_geo_reference=mesh_geo) m.export_mesh_file('a_test_mesh_iknterface.tsh') fileName = tempfile.mktemp('.txt') file = open(fileName, 'w') file.write(' 1 ?? ??\n\ 90.0 90.0\n\ 81.0 90.0\n\ 81.0 81.0\n\ 90.0 81.0\n\ 90.0 90.0\n\ END\n\ 2 ?? ??\n\ 10.0 80.0\n\ 10.0 90.0\n\ 20.0 90.0\n\ 10.0 80.0\n\ END\n\ END\n') file.close() m.import_ungenerate_file(fileName) #, tag='wall') os.remove(fileName) m.generate_mesh(maximum_triangle_area=max_area, verbose=False) mesh_filename = 'bento_b.tsh' m.export_mesh_file(mesh_filename) domain = Domain(mesh_filename, use_cache=False) Br = Reflective_boundary(domain) Bd = Dirichlet_boundary([3, 0, 0]) domain.set_boundary({'wall': Br, 'wave': Bd}) yieldstep = 0.1 finaltime = 10 for t in domain.evolve(yieldstep, finaltime): domain.write_time()
def test_rate_operator_simple(self): from anuga.config import rho_a, rho_w, eta_w from math import pi, cos, sin a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] # bac, bce, ecf, dbe vertices = [[1, 0, 2], [1, 2, 4], [4, 2, 5], [3, 1, 4]] domain = Domain(points, vertices) #Flat surface with 1m of water domain.set_quantity('elevation', 0) domain.set_quantity('stage', 1.0) domain.set_quantity('friction', 0) Br = Reflective_boundary(domain) domain.set_boundary({'exterior': Br}) # print domain.quantities['stage'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values # Apply operator to these triangles indices = [0, 1, 3] rate = 1.0 factor = 10.0 default_rate = 0.0 operator = Rate_operator(domain, rate=rate, factor=factor, \ indices=indices, default_rate = default_rate) # Apply Operator domain.timestep = 2.0 operator() stage_ex = [21., 21., 1., 21.] # print domain.quantities['stage'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0) assert num.allclose( domain.fractional_step_volume_integral, factor * domain.timestep * (rate * domain.areas[indices]).sum())
else: return z + 1.0 #------------------------------------------------------------------------------ # Setup computational domain #------------------------------------------------------------------------------ length = 24. width = 5. dx = dy = 0.2 #.1 # Resolution: Length of subdivisions on both axes points, vertices, boundary = rectangular_cross(int(length / dx), int(width / dy), len1=length, len2=width) domain = Domain(points, vertices, boundary) domain.set_name() # Output name based on script name print domain.statistics() domain.set_quantities_to_be_stored({'elevation': 2, 'stage': 2}) #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ domain.set_quantity('elevation', topography) # elevation is a function domain.set_quantity('friction', 0.01) # Constant friction domain.set_quantity('stage', expression='elevation') # Dry initial condition #------------------------------------------------------------------------------ # Setup boundary conditions #------------------------------------------------------------------------------
def test_rate_operator_rate_quantity(self): from anuga.config import rho_a, rho_w, eta_w from math import pi, cos, sin a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] # bac, bce, ecf, dbe vertices = [[1, 0, 2], [1, 2, 4], [4, 2, 5], [3, 1, 4]] domain = Domain(points, vertices) #Flat surface with 1m of water domain.set_quantity('elevation', 0.0) domain.set_quantity('stage', 1.0) domain.set_quantity('friction', 0.0) Br = Reflective_boundary(domain) domain.set_boundary({'exterior': Br}) verbose = False if verbose: print domain.quantities['elevation'].centroid_values print domain.quantities['stage'].centroid_values print domain.quantities['xmomentum'].centroid_values print domain.quantities['ymomentum'].centroid_values # Apply operator to these triangles indices = [0, 1, 3] factor = 10.0 from anuga import Quantity rate_Q = Quantity(domain) rate_Q.set_values(1.0) operator = Rate_operator(domain, rate=rate_Q, factor=factor, \ indices=indices) # Apply Operator domain.timestep = 2.0 operator() rate = rate_Q.centroid_values[indices] t = operator.get_time() Q = operator.get_Q() rate = rate * factor Q_ex = num.sum(domain.areas[indices] * rate) d = operator.get_timestep() * rate + 1 #print "d" #print d #print Q_ex #print Q stage_ex = num.array([1.0, 1.0, 1.0, 1.0]) stage_ex[indices] = d verbose = False if verbose: print domain.quantities['elevation'].centroid_values print domain.quantities['stage'].centroid_values print domain.quantities['xmomentum'].centroid_values print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0) assert num.allclose(Q_ex, Q) assert num.allclose(domain.fractional_step_volume_integral, ((d - 1.) * domain.areas[indices]).sum())
def concept_ungenerateII(self): from anuga import Domain, Reflective_boundary, Dirichlet_boundary x=0 y=0 mesh_geo = geo_reference=Geo_reference(56, x, y) # These are the absolute values polygon_absolute = [[0,0], [100,0], [100,100], [0,100]] x_p = -10 y_p = -40 geo_ref_poly = Geo_reference(56, x_p, y_p) polygon = geo_ref_poly.change_points_geo_ref(polygon_absolute) boundary_tags = {'wall': [0,1,3], 'wave': [2]} inner1_polygon_absolute = [[10,10], [20,10], [20,20], [10,20]] inner1_polygon = geo_ref_poly.\ change_points_geo_ref(inner1_polygon_absolute) inner2_polygon_absolute = [[30,30], [40,30], [40,40], [30,40]] inner2_polygon = geo_ref_poly.\ change_points_geo_ref(inner2_polygon_absolute) max_area = 1 interior_regions = [(inner1_polygon, 5), (inner2_polygon, 10)] m = create_mesh_from_regions(polygon, boundary_tags, max_area, interior_regions=interior_regions, poly_geo_reference=geo_ref_poly, mesh_geo_reference=mesh_geo) m.export_mesh_file('a_test_mesh_iknterface.tsh') fileName = tempfile.mktemp('.txt') file = open(fileName, 'w') file.write(' 1 ?? ??\n\ 90.0 90.0\n\ 81.0 90.0\n\ 81.0 81.0\n\ 90.0 81.0\n\ 90.0 90.0\n\ END\n\ 2 ?? ??\n\ 10.0 80.0\n\ 10.0 90.0\n\ 20.0 90.0\n\ 10.0 80.0\n\ END\n\ END\n') file.close() m.import_ungenerate_file(fileName) #, tag='wall') os.remove(fileName) m.generate_mesh(maximum_triangle_area=max_area, verbose=False) mesh_filename = 'bento_b.tsh' m.export_mesh_file(mesh_filename) domain = Domain(mesh_filename, use_cache = False) Br = Reflective_boundary(domain) Bd = Dirichlet_boundary([3, 0, 0]) domain.set_boundary({'wall': Br, 'wave': Bd}) yieldstep = 0.1 finaltime = 10 for t in domain.evolve(yieldstep, finaltime): domain.write_time()
def test_rate_operator_functions_empty_indices(self): from anuga.config import rho_a, rho_w, eta_w from math import pi, cos, sin a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] # bac, bce, ecf, dbe vertices = [[1, 0, 2], [1, 2, 4], [4, 2, 5], [3, 1, 4]] domain = Domain(points, vertices) #Flat surface with 1m of water domain.set_quantity('elevation', 0.0) domain.set_quantity('stage', 1.0) domain.set_quantity('friction', 0.0) Br = Reflective_boundary(domain) domain.set_boundary({'exterior': Br}) verbose = False if verbose: print domain.quantities['elevation'].centroid_values print domain.quantities['stage'].centroid_values print domain.quantities['xmomentum'].centroid_values print domain.quantities['ymomentum'].centroid_values # Apply operator to these triangles indices = [] factor = 10.0 def main_spatial_rate(x, y, t): # x and y should be an n by 1 array return x + y default_rate = 0.0 domain.tri_full_flag[0] = 0 operator = Rate_operator(domain, rate=main_spatial_rate, factor=factor, \ indices=indices, default_rate = default_rate) # Apply Operator domain.timestep = 2.0 operator() t = operator.get_time() Q = operator.get_Q() x = operator.coord_c[indices, 0] y = operator.coord_c[indices, 1] rate = main_spatial_rate(x, y, t) * factor Q_ex = num.sum(domain.areas[indices] * rate) d = operator.get_timestep() * rate + 1 #print Q_ex, Q #print indices #print "d" #print d stage_ex = num.array([1.0, 1.0, 1.0, 1.0]) stage_ex[indices] = d if verbose: print domain.quantities['elevation'].centroid_values print domain.quantities['stage'].centroid_values print domain.quantities['xmomentum'].centroid_values print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0) assert num.allclose(Q_ex, Q) assert num.allclose(domain.fractional_step_volume_integral, ((d - 1.) * domain.areas[indices]).sum())
def __init__( self, coordinates, vertices, boundary=None, full_send_dict=None, ghost_recv_dict=None, number_of_full_nodes=None, number_of_full_triangles=None, geo_reference=None, processor=None, numproc=None, number_of_global_triangles=None, ## SR added this number_of_global_nodes=None, ## SR added this s2p_map=None, p2s_map=None, #jj added this tri_l2g=None, ## SR added this node_l2g=None, #): ## SR added this ghost_layer_width=2): ## SR added this #----------------------------------------- # Sometimes we want to manually # create instances of the parallel_domain # otherwise ... #---------------------------------------- if processor is None: processor = pypar.rank() if numproc is None: numproc = pypar.size() Domain.__init__( self, coordinates, vertices, boundary, full_send_dict=full_send_dict, ghost_recv_dict=ghost_recv_dict, processor=processor, numproc=numproc, number_of_full_nodes=number_of_full_nodes, number_of_full_triangles=number_of_full_triangles, geo_reference=geo_reference, #) #jj added this ghost_layer_width=ghost_layer_width) self.parallel = True # PETE: Find the number of full nodes and full triangles, this is a temporary fix # until the bug with get_number_of_full_[nodes|triangles]() is fixed. if number_of_full_nodes is not None: self.number_of_full_nodes_tmp = number_of_full_nodes else: self.number_of_full_nodes_tmp = self.get_number_of_nodes() if number_of_full_triangles is not None: self.number_of_full_triangles_tmp = number_of_full_triangles else: self.number_of_full_triangles_tmp = self.get_number_of_triangles() generic_comms.setup_buffers(self) self.global_name = 'domain' self.number_of_global_triangles = number_of_global_triangles self.number_of_global_nodes = number_of_global_nodes self.s2p_map = s2p_map self.p2s_map = p2s_map self.s2p_map = None self.p2s_map = None self.tri_l2g = tri_l2g self.node_l2g = node_l2g self.ghost_counter = 0
interactive_visualisation = False if myid == 0: #------------------------------------------------------------------------------ # Setup sequential domain #------------------------------------------------------------------------------ dx = 500. dy = dx L = 100000. W = 10*dx # structured mesh points, vertices, boundary = anuga.rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, -W/2)) domain = Domain(points, vertices, boundary) domain.set_name(output_file) domain.set_datadir(output_dir) #------------------------------------------------------------------------------ # Setup Algorithm, either using command line arguments # or override manually yourself #------------------------------------------------------------------------------ domain.set_flow_algorithm(alg) #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ domain.set_quantity('elevation',-100.0) domain.set_quantity('friction', 0.00)
args = anuga.get_args() alg = args.alg verbose = args.verbose #================================================================================ # create sequential domain #================================================================================ if myid == 0: # structured mesh points, vertices, boundary = anuga.rectangular_cross( int(L / dx), int(W / dy), L, W, (-L / 2.0, -W / 2.0)) #domain = anuga.Domain(points, vertices, boundary) domain = Domain(points, vertices, boundary) domain.set_name(output_file) domain.set_datadir(output_dir) #------------------------------------------------------------------------------ # Setup Algorithm, either using command line arguments # or override manually yourself #------------------------------------------------------------------------------ domain.set_flow_algorithm(alg) #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ domain.set_quantity('elevation', 0.0) domain.set_quantity('friction', 0.0)
from anuga import rectangular_cross from anuga import Domain from anuga import Reflective_boundary from anuga import Dirichlet_boundary from anuga import Time_boundary #------------------------------------------------------------------------------ # Setup computational domain #------------------------------------------------------------------------------ length = 24. width = 5. dx = dy = 0.2 #.1 # Resolution: Length of subdivisions on both axes points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), len1=length, len2=width) domain = Domain(points, vertices, boundary) domain.set_name() print domain.statistics() domain.set_quantities_to_be_stored({'elevation': 2, 'stage': 2, 'xmomentum': 2, 'ymomentum': 2}) #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ def topography_dam(x,y): """Complex topography defined by a function of vectors x and y.""" z = -x/100
# Setup and Run Model #=============================================================================== #------------------------------------------------------------------------------ # Setup computational domain #------------------------------------------------------------------------------ print ' Set up Domain first...' length = 24. width = 5. dx = dy = 0.2 #.1 # Resolution: Length of subdivisions on both axes points, vertices, boundary = rectangular_cross(int(length / dx), int(width / dy), len1=length, len2=width) domain = Domain(points, vertices, boundary) domain.set_flow_algorithm('DE0') domain.set_name() # Output name domain.set_store_vertices_uniquely(True) print domain.statistics() domain.set_quantities_to_be_stored({ 'elevation': 2, 'stage': 2, 'xmomentum': 2, 'ymomentum': 2 }) domain.set_quantity('elevation', topography) # elevation is a function domain.set_quantity('friction', 0.01) # Constant friction
from anuga import Reflective_boundary from anuga import Dirichlet_boundary from anuga import Time_boundary import os #------------------------------------------------------------------------------ # Setup computational domain #------------------------------------------------------------------------------ length = 24. width = 5. dx = dy = 0.2 #.1 # Resolution: Length of subdivisions on both axes points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), len1=length, len2=width) domain = Domain(points, vertices, boundary) domain.set_name() # Output name based on script name. You can add timestamp=True print domain.statistics() #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ def topography(x,y): """Complex topography defined by a function of vectors x and y.""" z = -x/100 # Step id = (2 < x) & (x < 4) z[id] += 0.4 - 0.05*y[id]
from anuga import Domain from anuga import myid, finalize, distribute args = anuga.get_args() alg = args.alg verbose = args.verbose if myid == 0: #--------- #Setup computational domain #--------- points, vertices, boundary = anuga.rectangular_cross(100, 3, len1=1.0, len2=0.03) domain = Domain(points, vertices, boundary) # Create Domain domain.set_name('runup') # Output to file runup.sww domain.set_datadir('.') # Use current folder domain.set_quantities_to_be_stored({ 'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 1 }) domain.set_flow_algorithm(alg) #------------------ # Define topography #------------------ def topography(x, y): return -x / 2 #Linear bed slope
#------------------------------------------------------------------------------ # Setup domain #------------------------------------------------------------------------------ dx = 0.1 dy = dx L = 25. W = 3*dx if myid == 0: # structured mesh points, vertices, boundary = anuga.rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, 0.0)) #domain = anuga.Domain(points, vertices, boundary) domain = Domain(points, vertices, boundary) domain.set_name(output_file) domain.set_datadir(output_dir) domain.set_flow_algorithm(alg) #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ domain.set_quantity('elevation',0.0) domain.set_quantity('friction', 0.0) domain.set_quantity('stage', 1.5) domain.set_quantity('xmomentum', 0.0) domain.set_quantity('ymomentum', 0.0)
#=============================================================================== # Setup and Run Model #=============================================================================== #------------------------------------------------------------------------------ # Setup computational domain #------------------------------------------------------------------------------ print ' Set up Domain first...' length = 24. width = 5. dx = dy = 0.2 #.1 # Resolution: Length of subdivisions on both axes points, vertices, boundary = rectangular_cross(int(length/dx), int(width/dy), len1=length, len2=width) domain = Domain(points, vertices, boundary) domain.set_flow_algorithm('DE1') domain.set_name('flat_fill_slice_erosion') # Output name print domain.statistics() domain.set_quantities_to_be_stored({'elevation': 2, 'stage': 2, 'xmomentum': 2, 'ymomentum': 2}) domain.set_quantity('elevation', topography) # elevation is a function domain.set_quantity('friction', 0.01) # Constant friction domain.set_quantity('stage', expression='elevation') # Dry initial condition
) # Velocity dana = fluxin / uana # Depth args = anuga.get_args() alg = args.alg verbose = args.verbose #------------------------------------------------------------------------------ # Setup sequential computational domain #------------------------------------------------------------------------------ if myid == 0: points, vertices, boundary = rectangular_cross(40, 10, len1=400.0, len2=100.0) domain = Domain(points, vertices, boundary) # Create domain domain.set_name('channel') # Output name domain.set_flow_algorithm(alg) #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ def topography(x, y): return -x / 10. # linear bed slope def init_stage(x, y): stg = -x / 10. + 0.004 # Constant depth: 10 cm. return stg
elif 1500.0 <= x[i] < 1700.0: z[i] = 3.0 elif 1700.0 <= x[i] < 1800.0: z[i] = -0.03*(x[i]-1700) + 3.0 else: z[i] = (4.5/40000)*(x[i]-1800)*(x[i]-1800) + 2.0 return z #------------------------------------------------------------------------------ # Setup sequential domain #------------------------------------------------------------------------------ if myid == 0: # structured mesh points, vertices, boundary = anuga.rectangular_cross(int(L/dx), int(W/dy), L, W, (0.0, 0.0)) domain = Domain(points, vertices, boundary) domain.set_name(output_file) domain.set_datadir(output_dir) domain.set_flow_algorithm(alg) #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ domain.set_quantity('friction', 0.0) domain.set_quantity('stage', stage_flat) domain.set_quantity('elevation', bed_elevation) else: domain = None
from anuga import Reflective_boundary from anuga import Dirichlet_boundary from anuga import Time_boundary #------------------------------------------------------------------------------ # Setup computational domain #------------------------------------------------------------------------------ length = 24. width = 5. dx = dy = 0.1 # Resolution: Length of subdivisions on both axes points, vertices, boundary = rectangular_cross(int(length / dx), int(width / dy), len1=length, len2=width) domain = Domain(points, vertices, boundary) domain.set_name('channel_variable_bed_dx=%.2f_dy=%.2f' % (dx, dy)) # Output name print(domain.statistics()) domain.set_quantities_to_be_stored({'elevation': 2, 'stage': 2}) #------------------------------------------------------------------------------ # Setup initial conditions #------------------------------------------------------------------------------ def topography(x, y): """Complex topography defined by a function of vectors x and y.""" z = -x / 100
def test_rate_operator_rate_from_file(self): from anuga.config import rho_a, rho_w, eta_w from math import pi, cos, sin a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] # bac, bce, ecf, dbe vertices = [[1, 0, 2], [1, 2, 4], [4, 2, 5], [3, 1, 4]] #--------------------------------- #Typical ASCII file #--------------------------------- finaltime = 1200 filename = 'test_file_function' fid = open(filename + '.txt', 'w') start = time.mktime(time.strptime('2000', '%Y')) dt = 60 #One minute intervals t = 0.0 while t <= finaltime: t_string = time.strftime(time_format, time.gmtime(t + start)) fid.write('%s, %f %f %f\n' % (t_string, 2 * t, t**2, sin(t * pi / 600))) t += dt fid.close() #Convert ASCII file to NetCDF (Which is what we really like!) timefile2netcdf(filename + '.txt') #Create file function from time series F = file_function( filename + '.tms', quantities=['Attribute0', 'Attribute1', 'Attribute2']) #Now try interpolation for i in range(20): t = i * 10 q = F(t) #Exact linear intpolation assert num.allclose(q[0], 2 * t) if i % 6 == 0: assert num.allclose(q[1], t**2) assert num.allclose(q[2], sin(t * pi / 600)) #Check non-exact t = 90 #Halfway between 60 and 120 q = F(t) assert num.allclose((120**2 + 60**2) / 2, q[1]) assert num.allclose((sin(120 * pi / 600) + sin(60 * pi / 600)) / 2, q[2]) t = 100 #Two thirds of the way between between 60 and 120 q = F(t) assert num.allclose(2 * 120**2 / 3 + 60**2 / 3, q[1]) assert num.allclose( 2 * sin(120 * pi / 600) / 3 + sin(60 * pi / 600) / 3, q[2]) #os.remove(filename + '.txt') #os.remove(filename + '.tms') domain = Domain(points, vertices) #Flat surface with 1m of water domain.set_quantity('elevation', 0) domain.set_quantity('stage', 1.0) domain.set_quantity('friction', 0) Br = Reflective_boundary(domain) domain.set_boundary({'exterior': Br}) # print domain.quantities['elevation'].centroid_values # print domain.quantities['stage'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values # Apply operator to these triangles indices = [0, 1, 3] rate = file_function('test_file_function.tms', quantities=['Attribute1']) factor = 1000.0 default_rate = 17.7 operator = Rate_operator(domain, rate=rate, factor=factor, \ indices=indices, default_rate = default_rate) # Apply Operator domain.set_starttime(360.0) domain.timestep = 1.0 operator() d = domain.get_time()**2 * factor + 1.0 stage_ex0 = [d, d, 1., d] # print d, domain.get_time(), F(360.0) # print domain.quantities['elevation'].centroid_values # print domain.quantities['stage'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex0) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0) assert num.allclose(domain.fractional_step_volume_integral, ((d - 1.) * domain.areas[indices]).sum()) domain.set_starttime(-10.0) domain.timestep = 1.0 try: operator() except: pass else: raise Exception('Should have raised an exception, time too early') domain.set_starttime(1300.0) domain.timestep = 1.0 operator() d = default_rate * factor + d stage_ex1 = [d, d, 1., d] # print domain.quantities['elevation'].centroid_values # print domain.quantities['stage'].centroid_values # print domain.quantities['xmomentum'].centroid_values # print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex1) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0) assert num.allclose(domain.fractional_step_volume_integral, ((d - 1.) * domain.areas[indices]).sum())
def test_rate_operator_rate_quantity(self): from anuga.config import rho_a, rho_w, eta_w from math import pi, cos, sin a = [0.0, 0.0] b = [0.0, 2.0] c = [2.0, 0.0] d = [0.0, 4.0] e = [2.0, 2.0] f = [4.0, 0.0] points = [a, b, c, d, e, f] # bac, bce, ecf, dbe vertices = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] domain = Domain(points, vertices) #Flat surface with 1m of water domain.set_quantity('elevation', 0.0) domain.set_quantity('stage', 1.0) domain.set_quantity('friction', 0.0) Br = Reflective_boundary(domain) domain.set_boundary({'exterior': Br}) verbose = False if verbose: print domain.quantities['elevation'].centroid_values print domain.quantities['stage'].centroid_values print domain.quantities['xmomentum'].centroid_values print domain.quantities['ymomentum'].centroid_values # Apply operator to these triangles indices = [0,1,3] factor = 10.0 from anuga import Quantity rate_Q = Quantity(domain) rate_Q.set_values(1.0) operator = Rate_operator(domain, rate=rate_Q, factor=factor, \ indices=indices) # Apply Operator domain.timestep = 2.0 operator() rate = rate_Q.centroid_values[indices] t = operator.get_time() Q = operator.get_Q() rate = rate*factor Q_ex = num.sum(domain.areas[indices]*rate) d = operator.get_timestep()*rate + 1 #print "d" #print d #print Q_ex #print Q stage_ex = num.array([ 1.0, 1.0, 1.0, 1.0]) stage_ex[indices] = d verbose = False if verbose: print domain.quantities['elevation'].centroid_values print domain.quantities['stage'].centroid_values print domain.quantities['xmomentum'].centroid_values print domain.quantities['ymomentum'].centroid_values assert num.allclose(domain.quantities['stage'].centroid_values, stage_ex) assert num.allclose(domain.quantities['xmomentum'].centroid_values, 0.0) assert num.allclose(domain.quantities['ymomentum'].centroid_values, 0.0) assert num.allclose(Q_ex, Q) assert num.allclose(domain.fractional_step_volume_integral, ((d-1.)*domain.areas[indices]).sum())