[6190] | 1 | """This is the public API to ANUGA. |
---|
| 2 | |
---|
| 3 | Ideally, all tools needed to run simulations should be |
---|
| 4 | imported from this module |
---|
| 5 | """ |
---|
| 6 | |
---|
| 7 | # FIXME(Ole): This is one step towards the API envisioned in ticket:308 |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | from anuga.shallow_water import Domain |
---|
| 11 | from anuga.shallow_water import Dirichlet_boundary |
---|
| 12 | from anuga.shallow_water import File_boundary |
---|
| 13 | from anuga.shallow_water import Reflective_boundary |
---|
| 14 | from anuga.shallow_water import Field_boundary |
---|
[6266] | 15 | from anuga.shallow_water import Transmissive_stage_zero_momentum_boundary |
---|
[7326] | 16 | from anuga.shallow_water import Transmissive_momentum_set_stage_boundary |
---|
| 17 | from anuga.shallow_water import Transmissive_n_momentum_zero_t_momentum_set_stage_boundary |
---|
[7325] | 18 | |
---|
[6444] | 19 | from anuga.abstract_2d_finite_volumes.generic_boundary_conditions import Time_boundary |
---|
| 20 | from anuga.abstract_2d_finite_volumes.util import file_function |
---|
[6190] | 21 | |
---|
| 22 | from anuga.shallow_water.data_manager import export_grid, create_sts_boundary |
---|
| 23 | from anuga.shallow_water.data_manager import csv2building_polygons |
---|
| 24 | |
---|
| 25 | from anuga.utilities.polygon import read_polygon, plot_polygons, polygon_area |
---|
| 26 | from anuga.utilities.polygon import Polygon_function |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | #--------------------------- |
---|
| 30 | # Create domain from regions |
---|
| 31 | #--------------------------- |
---|
| 32 | |
---|
| 33 | def create_domain_from_regions(bounding_polygon, |
---|
| 34 | boundary_tags, |
---|
| 35 | maximum_triangle_area=None, |
---|
| 36 | mesh_filename=None, |
---|
| 37 | interior_regions=None, |
---|
| 38 | interior_holes=None, |
---|
| 39 | poly_geo_reference=None, |
---|
| 40 | mesh_geo_reference=None, |
---|
| 41 | minimum_triangle_angle=28.0, |
---|
| 42 | fail_if_polygons_outside=True, |
---|
| 43 | use_cache=False, |
---|
| 44 | verbose=True): |
---|
| 45 | """Create domain from bounding polygons and resolutions. |
---|
| 46 | |
---|
| 47 | bounding_polygon is a list of points in Eastings and Northings, |
---|
| 48 | relative to the zone stated in poly_geo_reference if specified. |
---|
| 49 | Otherwise points are just x, y coordinates with no particular |
---|
| 50 | association to any location. |
---|
| 51 | |
---|
| 52 | boundary_tags is a dictionary of symbolic tags. For every tag there |
---|
| 53 | is a list of indices referring to segments associated with that tag. |
---|
| 54 | If a segment is omitted it will be assigned the default tag ''. |
---|
| 55 | |
---|
| 56 | maximum_triangle_area is the maximal area per triangle |
---|
| 57 | for the bounding polygon, excluding the interior regions. |
---|
| 58 | |
---|
| 59 | Interior_regions is a list of tuples consisting of (polygon, |
---|
| 60 | resolution) for each region to be separately refined. Do not have |
---|
| 61 | polygon lines cross or be on-top of each other. Also do not have |
---|
| 62 | polygon close to each other. |
---|
| 63 | |
---|
| 64 | NOTE: If a interior_region is outside the bounding_polygon it should |
---|
| 65 | throw an error |
---|
| 66 | |
---|
| 67 | Interior_holes is a list of ploygons for each hole. |
---|
| 68 | |
---|
| 69 | This function does not allow segments to share points - use underlying |
---|
| 70 | pmesh functionality for that |
---|
| 71 | |
---|
| 72 | poly_geo_reference is the geo_reference of the bounding polygon and |
---|
| 73 | the interior polygons. |
---|
| 74 | If none, assume absolute. Please pass one though, since absolute |
---|
| 75 | references have a zone. |
---|
| 76 | |
---|
| 77 | mesh_geo_reference is the geo_reference of the mesh to be created. |
---|
| 78 | If none is given one will be automatically generated. It was use |
---|
| 79 | the lower left hand corner of bounding_polygon (absolute) |
---|
| 80 | as the x and y values for the geo_ref. |
---|
| 81 | |
---|
| 82 | Returns the shallow water domain instance |
---|
| 83 | |
---|
| 84 | Note, interior regions should be fully nested, as overlaps may cause |
---|
| 85 | unintended resolutions. |
---|
| 86 | |
---|
| 87 | fail_if_polygons_outside: If True (the default) Exception in thrown |
---|
| 88 | where interior polygons fall outside bounding polygon. If False, these |
---|
| 89 | will be ignored and execution continued. |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | """ |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | # Build arguments and keyword arguments for use with caching or apply. |
---|
| 96 | args = (bounding_polygon, |
---|
| 97 | boundary_tags) |
---|
| 98 | |
---|
| 99 | kwargs = {'maximum_triangle_area': maximum_triangle_area, |
---|
| 100 | 'mesh_filename': mesh_filename, |
---|
| 101 | 'interior_regions': interior_regions, |
---|
| 102 | 'interior_holes': interior_holes, |
---|
| 103 | 'poly_geo_reference': poly_geo_reference, |
---|
| 104 | 'mesh_geo_reference': mesh_geo_reference, |
---|
| 105 | 'minimum_triangle_angle': minimum_triangle_angle, |
---|
| 106 | 'fail_if_polygons_outside': fail_if_polygons_outside, |
---|
| 107 | 'verbose': verbose} #FIXME (Ole): See ticket:14 |
---|
| 108 | |
---|
| 109 | # Call underlying engine with or without caching |
---|
| 110 | if use_cache is True: |
---|
| 111 | try: |
---|
| 112 | from anuga.caching import cache |
---|
| 113 | except: |
---|
| 114 | msg = 'Caching was requested, but caching module'+\ |
---|
| 115 | 'could not be imported' |
---|
| 116 | raise msg |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | domain = cache(_create_domain_from_regions, |
---|
| 120 | args, kwargs, |
---|
| 121 | verbose=verbose, |
---|
| 122 | compression=False) |
---|
| 123 | else: |
---|
| 124 | domain = apply(_create_domain_from_regions, |
---|
| 125 | args, kwargs) |
---|
| 126 | |
---|
| 127 | return domain |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | def _create_domain_from_regions(bounding_polygon, |
---|
| 131 | boundary_tags, |
---|
| 132 | maximum_triangle_area=None, |
---|
| 133 | mesh_filename=None, |
---|
| 134 | interior_regions=None, |
---|
| 135 | interior_holes=None, |
---|
| 136 | poly_geo_reference=None, |
---|
| 137 | mesh_geo_reference=None, |
---|
| 138 | minimum_triangle_angle=28.0, |
---|
| 139 | fail_if_polygons_outside=True, |
---|
| 140 | verbose=True): |
---|
| 141 | """_create_domain_from_regions - internal function. |
---|
| 142 | |
---|
| 143 | See create_domain_from_regions for documentation. |
---|
| 144 | """ |
---|
| 145 | |
---|
| 146 | from anuga.shallow_water import Domain |
---|
[6193] | 147 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
[6190] | 148 | |
---|
| 149 | create_mesh_from_regions(bounding_polygon, |
---|
| 150 | boundary_tags, |
---|
| 151 | maximum_triangle_area=maximum_triangle_area, |
---|
| 152 | interior_regions=interior_regions, |
---|
| 153 | filename=mesh_filename, |
---|
| 154 | interior_holes=interior_holes, |
---|
| 155 | poly_geo_reference=poly_geo_reference, |
---|
| 156 | mesh_geo_reference=mesh_geo_reference, |
---|
| 157 | minimum_triangle_angle=minimum_triangle_angle, |
---|
| 158 | fail_if_polygons_outside=fail_if_polygons_outside, |
---|
| 159 | use_cache=False, |
---|
| 160 | verbose=verbose) |
---|
[7133] | 161 | domain = Domain(mesh_filename, use_cache=False, verbose=verbose) |
---|
[6190] | 162 | |
---|
| 163 | |
---|
| 164 | return domain |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | |
---|