Changeset 4100


Ignore:
Timestamp:
Dec 19, 2006, 6:20:47 PM (17 years ago)
Author:
ole
Message:

Compliance with style guide, cleanup and change of the way create_mesh_from_regions uses caching.

Location:
anuga_core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/documentation/user_manual/demos/cairns/project.py

    r4063 r4100  
    1515
    1616# bounding polygon for study area
    17 polyAll = read_polygon('extent.csv')
     17bounding_polygon = read_polygon('extent.csv')
    1818
    19 print 'Area of bounding polygon', polygon_area(polyAll)/1000000.0
     19print 'Area of bounding polygon', polygon_area(bounding_polygon)/1000000.0
    2020
    2121###############################
     
    3131poly_shallow = read_polygon('shallow.csv')
    3232
    33 #plot_polygons([polyAll,poly_cairns,poly_island0,poly_island1,\
     33#plot_polygons([bounding_polygon,poly_cairns,poly_island0,poly_island1,\
    3434#               poly_island2,poly_island3,poly_shallow],\
    3535#              'boundingpoly',verbose=False)
  • anuga_core/documentation/user_manual/demos/cairns/runcairns.py

    r4087 r4100  
    99the elevation data and a tsunami wave generated by a submarine mass failure.
    1010
    11 Ole Nielsen and Duncan Gray, GA - 2005 and Jane Sexton and Nick Bartzis, GA - 2006
     11Ole Nielsen and Duncan Gray, GA - 2005 and Jane Sexton and
     12Nick Bartzis, GA - 2006
    1213"""
    1314
    14 #-------------------------------------------------------------------------------
     15#------------------------------------------------------------------------------
    1516# Import necessary modules
    16 #-------------------------------------------------------------------------------
     17#------------------------------------------------------------------------------
    1718
    1819# Standard modules
    1920import os
    2021import time
    21 from shutil import copy
    22 from os import mkdir, access, F_OK
    2322import sys
    2423
    2524# Related major packages
    26 from anuga.shallow_water import Domain, Reflective_boundary, \
    27                             Dirichlet_boundary, Time_boundary, File_boundary
    28 from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts
    29 from anuga.abstract_2d_finite_volumes.combine_pts import combine_rectangular_points_files
    30 from anuga.geospatial_data.geospatial_data import *
     25from anuga.shallow_water import Domain
     26from anuga.shallow_water import Reflective_boundary
     27from anuga.shallow_water import Dirichlet_boundary
     28from anuga.shallow_water import Time_boundary
     29from anuga.shallow_water import File_boundary
     30from anuga.pmesh.mesh_interface import create_mesh_from_regions
     31from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf
     32from anuga.shallow_water.data_manager import dem2pts
    3133
    3234# Application specific imports
    3335import project                 # Definition of file names and polygons
    3436
    35 #-------------------------------------------------------------------------------
     37
     38#------------------------------------------------------------------------------
    3639# Define scenario as either slide or fixed_wave.
    37 #-------------------------------------------------------------------------------
     40#------------------------------------------------------------------------------
    3841scenario = 'slide'
    3942#scenario = 'fixed_wave'
    40 if access(scenario,F_OK) == 0:
    41     mkdir (scenario)
     43
     44if os.access(scenario, os.F_OK) == 0:
     45    os.mkdir(scenario)
    4246basename = scenario + 'source'
    4347
    44 #-------------------------------------------------------------------------------
     48
     49#------------------------------------------------------------------------------
    4550# Preparation of topographic data
    46 #
    4751# Convert ASC 2 DEM 2 PTS using source data and store result in source data
    48 #-------------------------------------------------------------------------------
    49 
    50 # filenames
     52#------------------------------------------------------------------------------
     53
     54# Filenames
    5155dem_name = 'cairns'
    5256meshname = 'cairns.msh'
    5357
    54 # creates DEM from asc data
     58# Create DEM from asc data
    5559convert_dem_from_ascii2netcdf(dem_name, use_cache=True, verbose=True)
    5660
    57 #creates pts file for onshore DEM
     61# Create pts file for onshore DEM
    5862dem2pts(dem_name, use_cache=True, verbose=True)
    5963
    60 #----------------------------------------------------------------------------
     64
     65#------------------------------------------------------------------------------
    6166# Create the triangular mesh based on overall clipping polygon with a tagged
    6267# boundary and interior regions defined in project.py along with
    6368# resolutions (maximal area of per triangle) for each polygon
    64 #-------------------------------------------------------------------------------
    65 
    66 from anuga.pmesh.mesh_interface import create_mesh_from_regions
     69#------------------------------------------------------------------------------
     70
    6771remainder_res = 10000000
    6872islands_res = 100000
     
    7680                    [project.poly_shallow, shallow_res]]
    7781
    78 from caching import cache
    79 _ = cache(create_mesh_from_regions,
    80           project.polyAll,
    81            {'boundary_tags': {'top': [0], 'ocean_east': [1],
    82                               'bottom': [2], 'onshore': [3]},
    83            'maximum_triangle_area': remainder_res,
    84            'filename': meshname,
    85            'interior_regions': interior_regions},
    86           verbose = True, evaluate=False)
    87 print 'created mesh'
    88 
    89 #-------------------------------------------------------------------------------                                 
     82create_mesh_from_regions(project.bounding_polygon,
     83                         boundary_tags={'top': [0],
     84                                        'ocean_east': [1],
     85                                        'bottom': [2],
     86                                        'onshore': [3]},
     87                         maximum_triangle_area=remainder_res,
     88                         filename=meshname,
     89                         interior_regions=interior_regions,
     90                         use_cache=True,
     91                         verbose=True)
     92
     93
     94#------------------------------------------------------------------------------
    9095# Setup computational domain
    91 #-------------------------------------------------------------------------------                                 
    92 
    93 domain = Domain(meshname, use_cache = True, verbose = True)
     96#------------------------------------------------------------------------------
     97
     98domain = Domain(meshname, use_cache=True, verbose=True)
    9499
    95100print 'Number of triangles = ', len(domain)
     
    102107domain.set_minimum_storable_height(0.01)
    103108
    104 #-------------------------------------------------------------------------------                                 
     109
     110#------------------------------------------------------------------------------
    105111# Setup initial conditions
    106 #-------------------------------------------------------------------------------
     112#------------------------------------------------------------------------------
    107113
    108114tide = 0.0
     
    110116domain.set_quantity('friction', 0.0)
    111117domain.set_quantity('elevation',
    112                     filename = dem_name + '.pts',
    113                     use_cache = True,
    114                     verbose = True,
    115                     alpha = 0.1
    116                     )
    117 
    118 #-------------------------------------------------------------------------------                                 
     118                    filename=dem_name + '.pts',
     119                    use_cache=True,
     120                    verbose=True,
     121                    alpha=0.1)
     122
     123
     124
     125#------------------------------------------------------------------------------
    119126# Setup information for slide scenario (to be applied 1 min into simulation
    120 #-------------------------------------------------------------------------------
     127#------------------------------------------------------------------------------
    121128
    122129if scenario == 'slide':
    123     from anuga.shallow_water.smf import slide_tsunami  # Function for submarine slide
     130    # Function for submarine slide
     131    from anuga.shallow_water.smf import slide_tsunami 
    124132    tsunami_source = slide_tsunami(length=35000.0,
    125133                                   depth=project.slide_depth,
     
    133141
    134142
    135 #-------------------------------------------------------------------------------                                 
     143#------------------------------------------------------------------------------
    136144# Setup boundary conditions
    137 #-------------------------------------------------------------------------------
     145#------------------------------------------------------------------------------
    138146
    139147print 'Available boundary tags', domain.get_boundary_tags()
     
    146154    Bw = Time_boundary(domain = domain,
    147155                       f=lambda t: [(60<t<3660)*50, 0, 0])
    148     domain.set_boundary( {'ocean_east': Bw, 'bottom': Bd, 'onshore': Bd,
    149                            'top': Bd} )
     156    domain.set_boundary({'ocean_east': Bw,
     157                         'bottom': Bd,
     158                         'onshore': Bd,
     159                         'top': Bd})
    150160
    151161# boundary conditions for slide scenario
    152162if scenario == 'slide':
    153     domain.set_boundary( {'ocean_east': Bd, 'bottom': Bd, 'onshore': Bd,
    154                           'top': Bd} )
    155 
    156 
    157 #-------------------------------------------------------------------------------                                 
     163    domain.set_boundary({'ocean_east': Bd,
     164                         'bottom': Bd,
     165                         'onshore': Bd,
     166                         'top': Bd})
     167   
     168
     169#------------------------------------------------------------------------------
    158170# Evolve system through time
    159 #-------------------------------------------------------------------------------
     171#------------------------------------------------------------------------------
    160172
    161173import time
  • anuga_core/source/anuga/pmesh/mesh_interface.py

    r3943 r4100  
    7676   
    7777    kwargs = {'maximum_triangle_area': maximum_triangle_area,
     78              'filename': filename,
    7879              'interior_regions': interior_regions,
    7980              'interior_holes': interior_holes,
     
    103104                  args, kwargs)
    104105
    105 
    106     # Decide whether to store this mesh or return it   
    107     if filename is None:
    108         return m
    109     else:
    110         if verbose: print 'Generating mesh to file "%s"' %filename
    111         m.generate_mesh(minimum_triangle_angle=minimum_triangle_angle,
    112                         verbose=verbose)
    113         m.export_mesh_file(filename)
     106    return m   
    114107       
    115108
     
    118111                              boundary_tags,
    119112                              maximum_triangle_area=None,
     113                              filename=None,                             
    120114                              interior_regions=None,
    121115                              interior_holes=None,
     
    263257                                    geo_reference=poly_geo_reference)
    264258       
    265            
    266     return m       
    267 
     259
     260
     261
     262    # NOTE (Ole): This was moved here as it is annoying if mesh is always
     263    # stored irrespective of whether the computation
     264    # was cached or not. This caused Domain to
     265    # recompute as it has meshfile as a dependency
     266
     267    # Decide whether to store this mesh or return it   
     268    if filename is None:
     269        return m
     270    else:
     271        if verbose: print 'Generating mesh to file "%s"' %filename
     272        m.generate_mesh(minimum_triangle_angle=minimum_triangle_angle,
     273                        verbose=verbose)
     274        m.export_mesh_file(filename)
     275
     276
Note: See TracChangeset for help on using the changeset viewer.