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