source: anuga_core/source/anuga/shallow_water/tsh2sww.py @ 5224

Last change on this file since 5224 was 3846, checked in by ole, 18 years ago

Refactored references to domain.filename away.
Use

domain.set_name()
domain.get_name()

instead.

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