1 | |
---|
2 | from anuga.shallow_water.shallow_water_domain import Domain |
---|
3 | from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross, \ |
---|
4 | rectangular |
---|
5 | |
---|
6 | from anuga.abstract_2d_finite_volumes.pmesh2domain import pmesh_to_domain_instance |
---|
7 | |
---|
8 | |
---|
9 | |
---|
10 | #----------------------------- |
---|
11 | # rectangular domains |
---|
12 | #----------------------------- |
---|
13 | def rectangular_cross_domain(*args, **kwargs): |
---|
14 | """ |
---|
15 | Create a rectangular domain with triangulation made |
---|
16 | up of m+1 by n+1 uniform rectangular cells divided |
---|
17 | into 4 triangles in a cross pattern |
---|
18 | |
---|
19 | Arguments |
---|
20 | m: number of cells in x direction |
---|
21 | n: number of cells in y direction |
---|
22 | len1: length of domain in x direction (left to right) |
---|
23 | (default 1.0) |
---|
24 | len2: length of domain in y direction (bottom to top) |
---|
25 | (default 1.0) |
---|
26 | origin: tuple (x,y) specifying location of lower left corner |
---|
27 | of domain (default (0,0)) |
---|
28 | """ |
---|
29 | |
---|
30 | try: |
---|
31 | verbose = kwargs.pop('verbose') |
---|
32 | except: |
---|
33 | verbose = False |
---|
34 | |
---|
35 | |
---|
36 | points, vertices, boundary = rectangular_cross(*args, **kwargs) |
---|
37 | return Domain(points, vertices, boundary, verbose= verbose) |
---|
38 | |
---|
39 | #---------------------------- |
---|
40 | # Create domain from file |
---|
41 | #---------------------------- |
---|
42 | def create_domain_from_file(filename, DomainClass=Domain): |
---|
43 | """ |
---|
44 | Create a domain from a file |
---|
45 | """ |
---|
46 | return pmesh_to_domain_instance(filename,DomainClass=DomainClass) |
---|
47 | |
---|
48 | #--------------------------- |
---|
49 | # Create domain from regions |
---|
50 | #--------------------------- |
---|
51 | |
---|
52 | def create_domain_from_regions(bounding_polygon, |
---|
53 | boundary_tags, |
---|
54 | maximum_triangle_area=None, |
---|
55 | mesh_filename=None, |
---|
56 | interior_regions=None, |
---|
57 | interior_holes=None, |
---|
58 | hole_tags=None, |
---|
59 | poly_geo_reference=None, |
---|
60 | mesh_geo_reference=None, |
---|
61 | minimum_triangle_angle=28.0, |
---|
62 | fail_if_polygons_outside=True, |
---|
63 | use_cache=False, |
---|
64 | verbose=True): |
---|
65 | """Create domain from bounding polygons and resolutions. |
---|
66 | |
---|
67 | bounding_polygon is a list of points in Eastings and Northings, |
---|
68 | relative to the zone stated in poly_geo_reference if specified. |
---|
69 | Otherwise points are just x, y coordinates with no particular |
---|
70 | association to any location. |
---|
71 | |
---|
72 | boundary_tags is a dictionary of symbolic tags. For every tag there |
---|
73 | is a list of indices referring to segments associated with that tag. |
---|
74 | If a segment is omitted it will be assigned the default tag ''. |
---|
75 | |
---|
76 | maximum_triangle_area is the maximal area per triangle |
---|
77 | for the bounding polygon, excluding the interior regions. |
---|
78 | |
---|
79 | Interior_regions is a list of tuples consisting of (polygon, |
---|
80 | resolution) for each region to be separately refined. Do not have |
---|
81 | polygon lines cross or be on-top of each other. Also do not have |
---|
82 | polygon close to each other. |
---|
83 | |
---|
84 | NOTE: If a interior_region is outside the bounding_polygon it should |
---|
85 | throw an error |
---|
86 | |
---|
87 | interior_holes is a list of polygons for each hole. These polygons do not |
---|
88 | need to be closed, but their points must be specified in a counter-clockwise |
---|
89 | order. |
---|
90 | |
---|
91 | hole_tags is a list of tag segment dictionaries. |
---|
92 | |
---|
93 | This function does not allow segments to share points - use underlying |
---|
94 | pmesh functionality for that |
---|
95 | |
---|
96 | poly_geo_reference is the geo_reference of the bounding polygon and |
---|
97 | the interior polygons. |
---|
98 | If none, assume absolute. Please pass one though, since absolute |
---|
99 | references have a zone. |
---|
100 | |
---|
101 | mesh_geo_reference is the geo_reference of the mesh to be created. |
---|
102 | If none is given one will be automatically generated. It was use |
---|
103 | the lower left hand corner of bounding_polygon (absolute) |
---|
104 | as the x and y values for the geo_ref. |
---|
105 | |
---|
106 | Returns the shallow water domain instance |
---|
107 | |
---|
108 | Note, interior regions should be fully nested, as overlaps may cause |
---|
109 | unintended resolutions. |
---|
110 | |
---|
111 | fail_if_polygons_outside: If True (the default) Exception in thrown |
---|
112 | where interior polygons fall outside bounding polygon. If False, these |
---|
113 | will be ignored and execution continued. |
---|
114 | |
---|
115 | |
---|
116 | """ |
---|
117 | |
---|
118 | |
---|
119 | # Build arguments and keyword arguments for use with caching or apply. |
---|
120 | args = (bounding_polygon, |
---|
121 | boundary_tags) |
---|
122 | |
---|
123 | kwargs = {'maximum_triangle_area': maximum_triangle_area, |
---|
124 | 'mesh_filename': mesh_filename, |
---|
125 | 'interior_regions': interior_regions, |
---|
126 | 'interior_holes': interior_holes, |
---|
127 | 'hole_tags': hole_tags, |
---|
128 | 'poly_geo_reference': poly_geo_reference, |
---|
129 | 'mesh_geo_reference': mesh_geo_reference, |
---|
130 | 'minimum_triangle_angle': minimum_triangle_angle, |
---|
131 | 'fail_if_polygons_outside': fail_if_polygons_outside, |
---|
132 | 'verbose': verbose} #FIXME (Ole): See ticket:14 |
---|
133 | |
---|
134 | # Call underlying engine with or without caching |
---|
135 | if use_cache is True: |
---|
136 | try: |
---|
137 | from anuga.caching import cache |
---|
138 | except: |
---|
139 | msg = 'Caching was requested, but caching module'+\ |
---|
140 | 'could not be imported' |
---|
141 | raise (msg) |
---|
142 | |
---|
143 | |
---|
144 | domain = cache(_create_domain_from_regions, |
---|
145 | args, kwargs, |
---|
146 | verbose=verbose, |
---|
147 | compression=False) |
---|
148 | else: |
---|
149 | domain = apply(_create_domain_from_regions, |
---|
150 | args, kwargs) |
---|
151 | |
---|
152 | return domain |
---|
153 | |
---|
154 | |
---|
155 | def _create_domain_from_regions(bounding_polygon, |
---|
156 | boundary_tags, |
---|
157 | maximum_triangle_area=None, |
---|
158 | mesh_filename=None, |
---|
159 | interior_regions=None, |
---|
160 | interior_holes=None, |
---|
161 | hole_tags=None, |
---|
162 | poly_geo_reference=None, |
---|
163 | mesh_geo_reference=None, |
---|
164 | minimum_triangle_angle=28.0, |
---|
165 | fail_if_polygons_outside=True, |
---|
166 | verbose=True): |
---|
167 | """_create_domain_from_regions - internal function. |
---|
168 | |
---|
169 | See create_domain_from_regions for documentation. |
---|
170 | """ |
---|
171 | |
---|
172 | #from anuga.shallow_water.shallow_water_domain import Domain |
---|
173 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
174 | |
---|
175 | create_mesh_from_regions(bounding_polygon, |
---|
176 | boundary_tags, |
---|
177 | maximum_triangle_area=maximum_triangle_area, |
---|
178 | interior_regions=interior_regions, |
---|
179 | filename=mesh_filename, |
---|
180 | interior_holes=interior_holes, |
---|
181 | hole_tags=hole_tags, |
---|
182 | poly_geo_reference=poly_geo_reference, |
---|
183 | mesh_geo_reference=mesh_geo_reference, |
---|
184 | minimum_triangle_angle=minimum_triangle_angle, |
---|
185 | fail_if_polygons_outside=fail_if_polygons_outside, |
---|
186 | use_cache=False, |
---|
187 | verbose=verbose) |
---|
188 | |
---|
189 | domain = Domain(mesh_filename, use_cache=False, verbose=verbose) |
---|
190 | |
---|
191 | |
---|
192 | return domain |
---|
193 | |
---|