Changeset 9341


Ignore:
Timestamp:
Sep 19, 2014, 5:05:42 PM (11 years ago)
Author:
davies
Message:

Slight fix to quantity_setting_functions + work on template scripts

Location:
trunk
Files:
2 added
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/utilities/quantity_setting_functions.py

    r9338 r9341  
    198198
    199199            # Get indices fInds of points in pi which are not set
    200             if(pi is 'All'):
     200            if(pi == 'All'):
    201201                fInside=(1-isSet)
    202202                fInds=(fInside==1).nonzero()[0]
    203203            else:
    204                 if(pi is 'Extent' and type(fi) is str and os.path.exists(fi)):
     204                if(pi == 'Extent' and type(fi) is str and os.path.exists(fi)):
    205205                    # Here fi MUST be a gdal-compatible raster
    206206                    # Then we get the extent from the raster itself
     
    250250                isSet[fInds]=1
    251251
    252         if(not min(isSet)==1):
     252        if( min(isSet) != 1):
    253253            raise Exception, 'Some points were not inside any polygon'
    254254
  • trunk/anuga_work/development/gareth/template_scenarios/tsunami/tsunami3/scripts/run_model.py

    r9339 r9341  
    5656# Get key data for the simulation
    5757
    58 import project
     58from prepare_data import PrepareData
     59project = PrepareData('ANUGA_setup.xls')
    5960
    6061###############################################################################
  • trunk/anuga_work/development/gareth/template_scenarios/tsunami/tsunami3/scripts/setup_boundary_conditions.py

    r9339 r9341  
    1313import anuga
    1414import anuga.utilities.spatialInputUtil as su
     15import anuga.shallow_water.boundaries as asb
    1516
    1617
     
    2728    """
    2829
    29 # @@@@@@@@@@@@@@@@@#
    30 # START EDITING HERE
    31 # @@@@@@@@@@@@@@@@@#
     30    # Dict to hold { boundary_tag: boundary_condition_function }
     31    boundary_tags_and_conditions = {}
    3232
    33     # Example:
    34     # "Standard" boundary conditions
     33    for i in range(len(project.boundary_data)):
     34        bd = project.boundary_data[i]
     35        boundary_tag = bd[0]
     36        boundary_condition_type = bd[1]
    3537
    36     br = anuga.Reflective_boundary(domain)
     38        if boundary_condition_type == 'Reflective':
     39            # Simple reflective boundary
     40            boundary_tags_and_conditions[boundary_tag] = \
     41                anuga.Reflective_boundary(domain)
     42        elif boundary_condition_type == 'Stage':
     43            # Here we read a timeseries, offset the starttime, and then pass
     44            # that function as a set stage transmissive n momentum ... boundary
     45            boundary_data_file = bd[2]
     46            start_time = bd[3]
     47            # Read data
     48            boundary_data = scipy.genfromtxt(
     49                boundary_data_file,
     50                delimiter=',',
     51                skip_header=1)
     52            # Make start time = 0
     53            boundary_data[:,0]-=start_time
     54            # Make interpolation function
     55            stage_time_fun = scipy.interpolate.interp1d(
     56                boundary_data[:,0],
     57                boundary_data[:,1])
     58            # Make boundary condition
     59            boundary_function = \
     60                asb.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(
     61                    domain,
     62                    stage_time_fun)
     63           
     64            boundary_tags_and_conditions[boundary_tag] = \
     65                boundary_function
    3766
    38     # Bs = anuga.Transmissive_stage_zero_momentum_boundary(domain) # Be
    39     # careful with this one
     67        else:
     68            msg = 'Boundary condition type ' + boundary_condition_type +\
     69                  ' for tag ' + boundary_tag + ' is not implemented'
    4070
    41     # Example:
    42     # Transmissive with stage being set by a function 'stage_function'
    43 
    44     def stage_function(t):
    45         return min(max(t - 60., 0.) / 60., 1.)
    46 
    47     import anuga.shallow_water.boundaries as asb
    48     b_t_stage_function = \
    49         asb.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary(
    50             domain,
    51             stage_function)
    52 
    53     # Here we associate each tag in boundary_info with its boundary condition
    54     # defined above
    55 
    56     boundary_tags_and_conditions = {'Ocean': b_t_stage_function,
    57                                     'Br': br}
    58 
    59 # @@@@@@@@@@@@@@@@@#
    60 # STOP EDITING HERE
    61 # @@@@@@@@@@@@@@@@@#
     71                       
    6272
    6373    # Check that all tags in boundary_info have been set
     
    7080            raise Exception(msg)
    7181
     82    # Set the boundary
     83
    7284    domain.set_boundary(boundary_tags_and_conditions)
    7385
  • trunk/anuga_work/development/gareth/template_scenarios/tsunami/tsunami3/scripts/setup_initial_conditions.py

    r9339 r9341  
    6969    #
    7070
    71     # @@@@@@@@@@@@@@@@@#
    72     # START EDITING HERE
    73     # @@@@@@@@@@@@@@@@@#
    74 
    75     # #########################################################################
    76     #
    77     # PRELIMINARY DEFINITIONS
    78     #
    79     # #########################################################################
    80 
    81     # If the earthquake slip is given then convert to deformation here
    82     # So that we can add it to both elevation AND stage
    83 
    84     make_earthquake_deformation_from_source_model = False
    85 
    86     if make_earthquake_deformation_from_source_model:
    87         source_model = '../anuga/source/XXXXX.csv'
    88 
    89         # Make an earthquake source model
    90 
    91         eq_function = okada_tsunami.earthquake_source(
    92             source=None,
    93             filename=source_model,
    94             domain=domain,
    95             lon_lat_degrees=True,
    96             lon_before_lat=False,
    97             proj4string=project.proj4string,
    98             verbose=False,
    99         )
    100     else:
    101 
    102         # Make a function that is zero everywhere
    103         # If we pass this to add_quantity, nothing should happen
    104 
    105         def eq_function(x, y):
    106             return x * 0.
    107 
    108     # #########################################################################
    109     #
    110     # Set elevation.
    111     #
    112     # #########################################################################
    113 
    114     # The 'Patong 10m' dataset
    115     elevation_patong_10m = '../anuga/topographies/patong_10m_grid_msl_Project.txt'
    116 
    117     # The 'saddle 10m' dataset
    118     elevation_saddle_10m = \
    119         '../anuga/topographies/patong_10m_small_grid_for_anuga_sub_Project.txt'
    120 
    121     # The '1s grid' dataset
    122     elevation_patong_1s = \
    123             '../anuga/topographies/patong_bay_1s_grid_Project.txt'
    124 
    125     # The background data
    126     elevation_default = \
    127             '../anuga/topographies/andaman_3s_grid_Clip2_Project.txt'
    128 
    129     # Set_quantity data
    130     elevation_data = [['../anuga/polygons/patong_10m.txt',
    131                        elevation_patong_10m],
    132                       ['../anuga/polygons/saddle_10m.txt',
    133                        elevation_saddle_10m],
    134                       ['../anuga/polygons/patong_1s.txt',
    135                        elevation_patong_1s],
    136                       ['All', elevation_default]]
    137 
    138     # Define a function for add_quantity in the same way
    139     # [ ['All', 0.] ] will do nothing
    140 
    141     elevation_additions = [['All', eq_function]]
    142 
    143     # #############################################################################
    144     #
    145     # Set friction
    146     #
    147     # #############################################################################
    148 
    149     default_friction = 0.025
    150 
    151     # Set_quantity data
    152 
    153     friction_data = [['All', default_friction]]
    154 
    155     # Add_quantity data
    156 
    157     friction_additions = [['All', 0.]]
    158 
    159     # ##############################################################################
    160     #
    161     # Set stage
    162     #
    163     # ##############################################################################
    164 
    165     # Set_quantity data
    166 
    167     stage_data = [['All', 0.]]
    168 
    169     # Add_quantity data
    170 
    171     stage_additions = [['All', eq_function]]
    172 
    173     # ##############################################################################
    174     #
    175     # Set depth integrated velocity (called "momentum" in ANUGA although that
    176     # is incorrect")
    177     #
    178     # ##############################################################################
    179 
    180     # Set_quantity data
    181 
    182     xmomentum_data = [['All', 0.]]
    183 
    184     # Add_quantity data
    185 
    186     xmomentum_additions = [['All', 0.]]
    187 
    188     # Set_quantity data
    189 
    190     ymomentum_data = [['All', 0.]]
    191 
    192     # Add_quantity data
    193 
    194     ymomentum_additions = [['All', 0.]]
    195 
    196     # @@@@@@@@@@@@@@@@@#
    197     # STOP EDITING HERE
    198     # @@@@@@@@@@@@@@@@@#
    199 
    20071    # ###############################################################################
    20172    #
     
    20879
    20980    elevation_function = \
    210         qs.composite_quantity_setting_function(elevation_data, domain)
     81        qs.composite_quantity_setting_function(project.elevation_data, domain)
    21182    domain.set_quantity('elevation', elevation_function,
    21283                        location='vertices')
    21384    elevation_addition_function = \
    214         qs.composite_quantity_setting_function(elevation_additions,
     85        qs.composite_quantity_setting_function(project.elevation_additions,
    21586                                               domain)
    21687    domain.add_quantity('elevation', elevation_addition_function)
    21788
    21889    friction_function = \
    219         qs.composite_quantity_setting_function(friction_data, domain)
     90        qs.composite_quantity_setting_function(project.friction_data, domain)
    22091    domain.set_quantity('friction', friction_function,
    22192                        location='centroids')
    22293    friction_addition_function = \
    223         qs.composite_quantity_setting_function(friction_additions,
     94        qs.composite_quantity_setting_function(project.friction_additions,
    22495                                               domain)
    22596    domain.add_quantity('friction', friction_addition_function)
    22697
    227     stage_function = qs.composite_quantity_setting_function(stage_data,
     98    stage_function = qs.composite_quantity_setting_function(project.stage_data,
    22899                                                            domain)
    229100    domain.set_quantity('stage', stage_function, location='centroids')
    230101    stage_addition_function = \
    231         qs.composite_quantity_setting_function(stage_additions, domain)
     102        qs.composite_quantity_setting_function(project.stage_additions, domain)
    232103    domain.add_quantity('stage', stage_addition_function)
    233104
    234105    xmomentum_function = \
    235         qs.composite_quantity_setting_function(xmomentum_data, domain)
     106        qs.composite_quantity_setting_function(project.xmomentum_data, domain)
    236107    domain.set_quantity('xmomentum', xmomentum_function,
    237108                        location='centroids')
    238109    xmomentum_addition_function = \
    239         qs.composite_quantity_setting_function(xmomentum_additions,
     110        qs.composite_quantity_setting_function(project.xmomentum_additions,
    240111                                               domain)
    241112    domain.add_quantity('xmomentum', xmomentum_addition_function)
    242113
    243114    ymomentum_function = \
    244         qs.composite_quantity_setting_function(ymomentum_data, domain)
     115        qs.composite_quantity_setting_function(project.ymomentum_data, domain)
    245116    domain.set_quantity('ymomentum', ymomentum_function,
    246117                        location='centroids')
    247118    ymomentum_addition_function = \
    248         qs.composite_quantity_setting_function(ymomentum_additions,
     119        qs.composite_quantity_setting_function(project.ymomentum_additions,
    249120                                               domain)
    250121    domain.add_quantity('ymomentum', ymomentum_addition_function)
  • trunk/anuga_work/development/gareth/template_scenarios/tsunami/tsunami3/scripts/setup_mesh.py

    r9339 r9341  
    116116    if myid == 0:
    117117
    118         # Make sure files/folders to store everything are there
    119 
    120         project.setup_directory_structure()
    121 
    122118        # Copy code files to output dir. This should be 'nearly the first'
    123119        # thing we do
  • trunk/anuga_work/development/gareth/template_scenarios/tsunami/tsunami3/scripts/user_functions.py

    r9339 r9341  
    9494        {boundary_line_and_tags[0][1]: range(len(bounding_polygon) - 1)}
    9595
    96     #
    97     # import pdb
    98     # pdb.set_trace()
    99 
    10096    for i in range(boundary_segnum - 1):
    10197
Note: See TracChangeset for help on using the changeset viewer.