def tsh2sww(filename, verbose=False): """ to check if a tsh/msh file 'looks' good. """ if filename[-4:] != '.tsh' and filename[-4:] != '.msh': raise IOError('Input file %s should be .tsh or .msh.' % name_out) if verbose == True: log.critical('Creating domain from %s' % filename) domain = pmesh_to_domain_instance(filename, Domain) if verbose == True: log.critical("Number of triangles = %s" % len(domain)) domain.smooth = True domain.format = 'sww' #Native netcdf visualisation format file_path, filename = path.split(filename) filename, ext = path.splitext(filename) domain.set_name(filename) domain.reduction = mean if verbose == True: log.critical("file_path = %s" % file_path) if file_path == "": file_path = "." domain.set_datadir(file_path) if verbose == True: log.critical("Output written to %s%s%s.%s" % (domain.get_datadir(), sep, domain.get_name(), domain.format)) sww = SWW_file(domain) sww.store_connectivity() sww.store_timestep()
def tsh2sww(infilename, sww_file_name = None, verbose = False): """ This converts a mesh file (.tsh/.msh) to an .sww file. This is usefull to visualise the mesh. Note: This currently just writes the output file in the input file dir. """ if verbose == True: log.critical('Creating domain from %s' % infilename) domain = pmesh_to_domain_instance(infilename, Domain) if verbose == True: log.critical("Number of triangles = %d" % len(domain)) domain.smooth = True domain.format = 'sww' #Native netcdf visualisation format file_path, filename = path.split(infilename) filename, ext = path.splitext(filename) if not (sww_file_name is None): file_path, filename = path.split(sww_file_name) filename, ext = path.splitext(filename) domain.set_name(filename) domain.reduction = mean if verbose == True: log.critical("file_path %s" % file_path) if file_path == "":file_path = "." domain.set_datadir(file_path) if verbose == True: log.critical("Output written to %s%s%s.%s" % (domain.get_datadir(), sep, domain.get_name(), domain.format)) sww = SWW_file(domain) sww.store_connectivity() sww.store_timestep('stage')
def tsh2sww(infilename, sww_file_name=None, verbose=False): """ This converts a mesh file (.tsh/.msh) to an .sww file. This is usefull to visualise the mesh. Note: This currently just writes the output file in the input file dir. """ if verbose == True: log.critical('Creating domain from %s' % infilename) domain = pmesh_to_domain_instance(infilename, Domain) if verbose == True: log.critical("Number of triangles = %d" % len(domain)) domain.smooth = True domain.format = 'sww' #Native netcdf visualisation format file_path, filename = path.split(infilename) filename, ext = path.splitext(filename) if not (sww_file_name is None): file_path, filename = path.split(sww_file_name) filename, ext = path.splitext(filename) domain.set_name(filename) domain.reduction = mean if verbose == True: log.critical("file_path %s" % file_path) if file_path == "": file_path = "." domain.set_datadir(file_path) if verbose == True: log.critical( "Output written to %s%s%s.%s" % (domain.get_datadir(), sep, domain.get_name(), domain.format)) sww = SWW_file(domain) sww.store_connectivity() sww.store_timestep('stage')
def tsh2sww(filename, verbose=False): """ to check if a tsh/msh file 'looks' good. """ if filename[-4:] != '.tsh' and filename[-4:] != '.msh': raise IOError('Input file %s should be .tsh or .msh.' % name_out) if verbose == True: log.critical('Creating domain from %s' % filename) domain = pmesh_to_domain_instance(filename, Domain) if verbose == True: log.critical("Number of triangles = %s" % len(domain)) domain.smooth = True domain.format = 'sww' #Native netcdf visualisation format file_path, filename = path.split(filename) filename, ext = path.splitext(filename) domain.set_name(filename) domain.reduction = mean if verbose == True: log.critical("file_path = %s" % file_path) if file_path == "": file_path = "." domain.set_datadir(file_path) if verbose == True: log.critical( "Output written to %s%s%s.%s" % (domain.get_datadir(), sep, domain.get_name(), domain.format)) sww = SWW_file(domain) sww.store_connectivity() sww.store_timestep()
def test_boundary_timeII(self): """ test_boundary_timeII(self): Test that starttime can be set in the middle of a boundary condition """ boundary_starttime = 0 boundary_filename = self.create_sww_boundary(boundary_starttime) #print "boundary_filename",boundary_filename filename = tempfile.mktemp(".sww") #print "filename",filename dir, base = os.path.split(filename) senario_name = base[:-4] mesh = Mesh() mesh.add_region_from_polygon([[10, 10], [90, 10], [90, 90], [10, 90]]) mesh.generate_mesh(verbose=False) domain = pmesh_to_domain_instance(mesh, anuga.Domain) domain.set_name(senario_name) domain.set_datadir(dir) new_starttime = 0. domain.set_starttime(new_starttime) # Setup initial conditions domain.set_quantity('elevation', 0.0) domain.set_quantity('stage', 0.0) Bf = anuga.File_boundary(boundary_filename, domain, use_cache=False, verbose=False) # Setup boundary conditions domain.set_boundary({'exterior': Bf}) for t in domain.evolve(yieldstep=5, finaltime=9.0): pass #print domain.boundary_statistics() #domain.write_time() #print "domain.time", domain.time # do an assertion on the time of the produced sww file fid = NetCDFFile(filename, netcdf_mode_r) #Open existing file for read times = fid.variables['time'][:] stage = fid.variables['stage'][:] #print stage #print "times", times #print "fid.starttime", fid.starttime assert num.allclose(fid.starttime, new_starttime) fid.close() #print "stage[2,0]", stage[2,0] msg = "This test is a bit hand crafted, based on the output file. " msg += "Not logic. " msg += "It's testing that starttime is working" assert num.allclose(stage[2, 0], 4.85825), msg # clean up os.remove(boundary_filename) os.remove(filename)
def test_boundary_timeII_1_5(self): """ test_boundary_timeII(self): Test that starttime can be set in the middle of a boundary condition """ boundary_starttime = 0 boundary_filename = self.create_sww_boundary(boundary_starttime) # print "boundary_filename",boundary_filename filename = tempfile.mktemp(".sww") # print "filename",filename dir, base = os.path.split(filename) senario_name = base[:-4] mesh = Mesh() mesh.add_region_from_polygon([[10, 10], [90, 10], [90, 90], [10, 90]]) mesh.generate_mesh(verbose=False) domain = pmesh_to_domain_instance(mesh, anuga.Domain) domain.set_name(senario_name) domain.set_datadir(dir) domain.set_flow_algorithm("1_5") new_starttime = 0.0 domain.set_starttime(new_starttime) # Setup initial conditions domain.set_quantity("elevation", 0.0) domain.set_quantity("stage", 0.0) Bf = anuga.File_boundary(boundary_filename, domain, use_cache=False, verbose=False) # Setup boundary conditions domain.set_boundary({"exterior": Bf}) for t in domain.evolve(yieldstep=5, finaltime=9.0): pass # print domain.boundary_statistics() # domain.write_time() # print "domain.time", domain.time # do an assertion on the time of the produced sww file fid = NetCDFFile(filename, netcdf_mode_r) # Open existing file for read times = fid.variables["time"][:] stage = fid.variables["stage"][:] # print stage # print "times", times # print "fid.starttime", fid.starttime assert num.allclose(fid.starttime, new_starttime) fid.close() # print "stage[2,0]", stage[2,0] msg = "This test is a bit hand crafted, based on the output file. " msg += "Not logic. " msg += "It's testing that starttime is working" assert num.allclose(stage[2, 0], 4.88601), msg # clean up os.remove(boundary_filename) os.remove(filename)
def create_sww_boundary(self, boundary_starttime): """ This creates a boundary file with ; time stage 0 5 10 2.15268 20 13.9773 """ tide = 5 boundary_filename = tempfile.mktemp(".sww") dir, base = os.path.split(boundary_filename) boundary_name = base[:-4] # Setup computational domain mesh = Mesh() mesh.add_region_from_polygon([[0, 0], [100, 0], [100, 100], [0, 100]]) mesh.generate_mesh(verbose=False) domain = pmesh_to_domain_instance(mesh, anuga.Domain) domain.set_name(boundary_name) domain.set_datadir(dir) domain.set_starttime(boundary_starttime) domain.set_low_froude(0) # Setup initial conditions domain.set_quantity('elevation', 0.0) domain.set_quantity('stage', tide) # Setup boundary conditions Bd = anuga.Dirichlet_boundary([tide, 0., 0.]) # Constant boundary values Bd = anuga.Time_boundary( domain=domain, # Time dependent boundary function=lambda t: [t, 0.0, 0.0]) domain.set_boundary({'exterior': Bd}) for t in domain.evolve(yieldstep=10, finaltime=20.0): pass #print domain.boundary_statistics('stage') q = Bd.evaluate() # FIXME (Ole): This test would not have passed in # changeset:5846. msg = 'Time boundary not evaluated correctly' assert num.allclose(t, q[0]), msg #print domain.get_quantity('stage').get_values() #domain.write_time() #print "domain.time", domain.time return boundary_filename
def test_boundary_time(self): """ test_boundary_time(self): test that the starttime of a boundary condition is carried thru to the output sww file. """ boundary_starttime = 0 boundary_filename = self.create_sww_boundary(boundary_starttime) filename = tempfile.mktemp(".sww") dir, base = os.path.split(filename) senario_name = base[:-4] mesh = Mesh() ###mesh.add_region_from_polygon([[10,10], [90,10], [90,90], [10,90]]) mesh.add_region_from_polygon([[0, 0], [100, 0], [100, 100], [0, 100]]) mesh.generate_mesh(verbose=False) domain = pmesh_to_domain_instance(mesh, anuga.Domain) domain.set_name(senario_name) domain.set_datadir(dir) # Setup initial conditions domain.set_quantity('elevation', 0.0) domain.set_quantity('stage', 0.0) Bf = anuga.File_boundary(boundary_filename, domain, use_cache=False, verbose=False) # Setup boundary conditions domain.set_boundary({'exterior': Bf}) for t in domain.evolve(yieldstep=5.0, finaltime=10.0): pass #print domain.write_time() #print "domain.time", domain.time # do an assertion on the time of the produced sww file fid = NetCDFFile(filename, netcdf_mode_r) #Open existing file for read times = fid.variables['time'][:] #print "times", times #print "fid.starttime", fid.starttime assert num.allclose(fid.starttime, boundary_starttime) fid.close() # clean up os.remove(boundary_filename) os.remove(filename)
def test_boundary_time(self): """ test_boundary_time(self): test that the starttime of a boundary condition is carried thru to the output sww file. """ boundary_starttime = 0 boundary_filename = self.create_sww_boundary(boundary_starttime) filename = tempfile.mktemp(".sww") dir, base = os.path.split(filename) senario_name = base[:-4] mesh = Mesh() ###mesh.add_region_from_polygon([[10,10], [90,10], [90,90], [10,90]]) mesh.add_region_from_polygon([[0, 0], [100, 0], [100, 100], [0, 100]]) mesh.generate_mesh(verbose=False) domain = pmesh_to_domain_instance(mesh, anuga.Domain) domain.set_name(senario_name) domain.set_datadir(dir) # Setup initial conditions domain.set_quantity("elevation", 0.0) domain.set_quantity("stage", 0.0) Bf = anuga.File_boundary(boundary_filename, domain, use_cache=False, verbose=False) # Setup boundary conditions domain.set_boundary({"exterior": Bf}) for t in domain.evolve(yieldstep=5.0, finaltime=10.0): pass # print domain.write_time() # print "domain.time", domain.time # do an assertion on the time of the produced sww file fid = NetCDFFile(filename, netcdf_mode_r) # Open existing file for read times = fid.variables["time"][:] # print "times", times # print "fid.starttime", fid.starttime assert num.allclose(fid.starttime, boundary_starttime) fid.close() # clean up os.remove(boundary_filename) os.remove(filename)
def create_sww_boundary(self, boundary_starttime): """ This creates a boundary file with ; time stage 0 5 10 2.15268 20 13.9773 """ tide = 5 boundary_filename = tempfile.mktemp(".sww") dir, base = os.path.split(boundary_filename) boundary_name = base[:-4] # Setup computational domain mesh = Mesh() mesh.add_region_from_polygon([[0, 0], [100, 0], [100, 100], [0, 100]]) mesh.generate_mesh(verbose=False) domain = pmesh_to_domain_instance(mesh, anuga.Domain) domain.set_name(boundary_name) domain.set_datadir(dir) domain.set_starttime(boundary_starttime) # Setup initial conditions domain.set_quantity("elevation", 0.0) domain.set_quantity("stage", tide) # Setup boundary conditions Bd = anuga.Dirichlet_boundary([tide, 0.0, 0.0]) # Constant boundary values Bd = anuga.Time_boundary(domain=domain, function=lambda t: [t, 0.0, 0.0]) # Time dependent boundary domain.set_boundary({"exterior": Bd}) for t in domain.evolve(yieldstep=10, finaltime=20.0): pass # print domain.boundary_statistics('stage') q = Bd.evaluate() # FIXME (Ole): This test would not have passed in # changeset:5846. msg = "Time boundary not evaluated correctly" assert num.allclose(t, q[0]), msg # print domain.get_quantity('stage').get_values() # domain.write_time() # print "domain.time", domain.time return boundary_filename
self.x1 = x1 self.h = h def __call__(self, x, y): return self.h*((x>self.x0)&(x<self.x1)) # read in the test files filename = 'test-100.tsh' nx = 1 ny = 1 domain = pmesh_to_domain_instance(filename, Domain) domain.set_quantity('stage', Set_Stage(200.0,300.0,5.0)) rect = array(domain.xy_extent, Float) try: domain.initialise_visualiser(rect=rect) #domain.visualiser.coloring['stage'] = True domain.visualiser.scale_z['stage'] = 0.2 domain.visualiser.scale_z['elevation'] = 0.05 except: print 'No visualiser' domain.default_order = 2
self.x0 = x0 self.x1 = x1 self.h = h def __call__(self, x, y): return self.h * ((x > self.x0) & (x < self.x1)) # read in the test files filename = 'test-100.tsh' nx = 1 ny = 1 domain = pmesh_to_domain_instance(filename, Domain) domain.set_quantity('stage', Set_Stage(200.0, 300.0, 5.0)) rect = array(domain.xy_extent, Float) try: domain.initialise_visualiser(rect=rect) #domain.visualiser.coloring['stage'] = True domain.visualiser.scale_z['stage'] = 0.2 domain.visualiser.scale_z['elevation'] = 0.05 except: print 'No visualiser' domain.default_order = 2 #Boundaries
def create_domain_from_file(filename, DomainClass=Domain): """ Create a domain from a file """ return pmesh_to_domain_instance(filename, DomainClass=DomainClass)
#------- # Domain rect = zeros(4, Float) # Buffer for results if myid == 0: # read in the test files filename = 'test-100.tsh' # filename = 'merimbula_10785.tsh' nx = numprocs ny = 1 if nx * ny != numprocs: print "WARNING: number of subboxes is not equal to the number of proc" domain_full = pmesh_to_domain_instance(filename, Advection_Domain) domain_full.set_quantity('stage', Set_Stage(200.0, 300.0, 1.0)) # domain_full.set_quantity('stage', Set_Stage(756000.0,756500.0,4.0)) nodes, triangles, boundary, triangles_per_proc, quantities =\ pmesh_divide_metis(domain_full, numprocs) # subdivide the mesh rect = array(domain_full.xy_extent, Float) # rect = array(rect, Float) submesh = build_submesh(nodes, triangles, boundary, quantities, \ triangles_per_proc) # send the mesh partition to the appropriate processor
def create_domain_from_file(filename, DomainClass=Domain): """ Create a domain from a file """ return pmesh_to_domain_instance(filename,DomainClass=DomainClass)
#------- # Domain rect = zeros( 4, Float) # Buffer for results if myid == 0: # read in the test files filename = 'test-100.tsh' # filename = 'merimbula_10785.tsh' nx = numprocs ny = 1 if nx*ny != numprocs: print "WARNING: number of subboxes is not equal to the number of proc" domain_full = pmesh_to_domain_instance(filename, Advection_Domain) domain_full.set_quantity('stage', Set_Stage(200.0,300.0,1.0)) # domain_full.set_quantity('stage', Set_Stage(756000.0,756500.0,4.0)) nodes, triangles, boundary, triangles_per_proc, quantities =\ pmesh_divide_metis(domain_full, numprocs) # subdivide the mesh rect = array(domain_full.xy_extent, Float) # rect = array(rect, Float) submesh = build_submesh(nodes, triangles, boundary, quantities, \ triangles_per_proc) # send the mesh partition to the appropriate processor