source: trunk/anuga_core/source/anuga/shallow_water/tsh2sww.py @ 9558

Last change on this file since 9558 was 9552, checked in by steve, 10 years ago

Picked up error in tsh2sww when installing

File size: 2.1 KB
Line 
1"""Given a .tsh, print an sww
2"""
3
4######################
5# Module imports
6#
7
8import sys
9from os import sep, path
10sys.path.append('..'+sep+'pyvolution')
11
12from anuga import Domain
13from anuga.abstract_2d_finite_volumes.pmesh2domain import pmesh_to_domain_instance
14import time, os 
15from anuga.file.sww import SWW_file
16from anuga.utilities.numerical_tools import mean
17import anuga.utilities.log as log
18
19
20def tsh2sww(infilename, sww_file_name = None, verbose = False):
21    """
22    This converts a mesh file (.tsh/.msh) to an .sww file.
23    This is usefull to visualise the mesh.
24   
25    Note: This currently just writes the output file in the input file dir.
26    """
27    if verbose == True: log.critical('Creating domain from %s' % infilename)
28    domain = pmesh_to_domain_instance(infilename, Domain)
29    if verbose == True: log.critical("Number of triangles = %d" % len(domain))
30
31    domain.smooth = True
32    domain.format = 'sww'   #Native netcdf visualisation format
33       
34    file_path, filename = path.split(infilename)
35    filename, ext = path.splitext(filename)
36   
37    if not (sww_file_name == None):
38        file_path, filename = path.split(sww_file_name)
39        filename, ext = path.splitext(filename)
40    domain.set_name(filename)
41       
42    domain.reduction = mean
43    if verbose == True: log.critical("file_path %s" % file_path)
44    if file_path == "":file_path = "."
45    domain.set_datadir(file_path)
46
47    if verbose == True:
48        log.critical("Output written to %s%s%s.%s" % (domain.get_datadir(), sep, domain.get_name(), domain.format))
49   
50    sww = SWW_file(domain)
51    sww.store_connectivity()
52    sww.store_timestep('stage')
53
54if __name__ == "__main__":
55    usage = "usage:python %s pmesh_file_name [verbose|non_verbose]" %         path.basename(sys.argv[0])
56    if len(sys.argv) < 2:
57        print usage
58    else:
59        filename = sys.argv[1]
60        verbose = False
61    if len(sys.argv) > 2:
62        if sys.argv[2][0] == "v" or sys.argv[2][0] == "V":
63            verbose = True
64        tsh2sww(filename, verbose = verbose)
65   
Note: See TracBrowser for help on using the repository browser.