source: anuga_core/source/anuga/pyvolution/tsh2sww.py @ 3514

Last change on this file since 3514 was 3514, checked in by duncan, 18 years ago

Hi all,
I'm doing a change in the anuga structure, moving the code to

\anuga_core\source\anuga

After you have done an svn update, the PYTHONPATH has to be changed to;
PYTHONPATH = anuga_core/source/

This is part of changes required to make installation of anuga quicker and reducing the size of our sandpits.

If any imports are broken, try fixing them. With adding anuga. to them for example. If this seems to have really broken things, email/phone me.

Cheers
Duncan

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 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.filename = 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.filename + "." + 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.