source: trunk/anuga_core/anuga/extras.py @ 9737

Last change on this file since 9737 was 9737, checked in by steve, 9 years ago

Commit svn after a lot of git updates

File size: 7.9 KB
Line 
1
2from anuga.shallow_water.shallow_water_domain import Domain
3from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross, \
4                                                        rectangular
5
6from anuga.abstract_2d_finite_volumes.pmesh2domain import pmesh_to_domain_instance
7
8
9
10#-----------------------------
11# rectangular domains
12#-----------------------------
13def 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#----------------------------
42def 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
52def 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                               breaklines=None,
62                               regionPtArea=None,
63                               minimum_triangle_angle=28.0,
64                               fail_if_polygons_outside=True,
65                               use_cache=False,
66                               verbose=True):
67   
68
69    """Create domain from bounding polygons and resolutions.
70
71    bounding_polygon is a list of points in Eastings and Northings,
72    relative to the zone stated in poly_geo_reference if specified.
73    Otherwise points are just x, y coordinates with no particular
74    association to any location.
75
76    boundary_tags is a dictionary of symbolic tags. For every tag there
77    is a list of indices referring to segments associated with that tag.
78    If a segment is omitted it will be assigned the default tag ''.
79
80    maximum_triangle_area is the maximal area per triangle
81    for the bounding polygon, excluding the  interior regions.
82
83    Interior_regions is a list of tuples consisting of (polygon,
84    resolution) for each region to be separately refined. Do not have
85    polygon lines cross or be on-top of each other.  Also do not have
86    polygon close to each other.
87   
88    NOTE: If a interior_region is outside the bounding_polygon it should
89    throw an error
90   
91    interior_holes is a list of polygons for each hole. These polygons do not
92    need to be closed, but their points must be specified in a counter-clockwise
93    order.
94
95    hole_tags  is a list of tag segment dictionaries.
96
97    This function does not allow segments to share points - use underlying
98    pmesh functionality for that
99
100    poly_geo_reference is the geo_reference of the bounding polygon and
101    the interior polygons.
102    If none, assume absolute.  Please pass one though, since absolute
103    references have a zone.
104   
105    mesh_geo_reference is the geo_reference of the mesh to be created.
106    If none is given one will be automatically generated.  It was use
107    the lower left hand corner of  bounding_polygon (absolute)
108    as the x and y values for the geo_ref.
109   
110    breaklines is a list of polygons. These lines will be preserved by the
111               triangulation algorithm - useful for coastlines, walls, etc.
112               The polygons are not closed.   
113               
114    regionPtArea is a list of user-specified point-based regions with max area 
115   
116    Returns the shallow water domain instance
117
118    Note, interior regions should be fully nested, as overlaps may cause
119    unintended resolutions.
120
121    fail_if_polygons_outside: If True (the default) Exception in thrown
122    where interior polygons fall outside bounding polygon. If False, these
123    will be ignored and execution continued.
124       
125   
126    """
127
128
129    # Build arguments and keyword arguments for use with caching or apply.
130    args = (bounding_polygon,
131            boundary_tags)
132   
133    kwargs = {'maximum_triangle_area': maximum_triangle_area,
134              'mesh_filename': mesh_filename,
135              'interior_regions': interior_regions,
136              'interior_holes': interior_holes,
137              'hole_tags': hole_tags,
138              'poly_geo_reference': poly_geo_reference,
139              'mesh_geo_reference': mesh_geo_reference,
140              'breaklines' : breaklines,
141              'regionPtArea' : regionPtArea,
142              'minimum_triangle_angle': minimum_triangle_angle,
143              'fail_if_polygons_outside': fail_if_polygons_outside,
144              'verbose': verbose} #FIXME (Ole): See ticket:14
145
146    # Call underlying engine with or without caching
147    if use_cache is True:
148        try:
149            from anuga.caching import cache
150        except:
151            msg = 'Caching was requested, but caching module'+\
152                  'could not be imported'
153            raise (msg)
154
155
156        domain = cache(_create_domain_from_regions,
157                       args, kwargs,
158                       verbose=verbose,
159                       compression=False)
160    else:
161        domain = apply(_create_domain_from_regions,
162                       args, kwargs)
163
164    return domain
165
166       
167def _create_domain_from_regions(bounding_polygon,
168                                boundary_tags,
169                                maximum_triangle_area=None,
170                                mesh_filename=None,                           
171                                interior_regions=None,
172                                interior_holes=None,
173                                hole_tags=None,
174                                poly_geo_reference=None,
175                                mesh_geo_reference=None,
176                                breaklines=None,
177                                regionPtArea=None,
178                                minimum_triangle_angle=28.0,
179                                fail_if_polygons_outside=True,
180                                verbose=True):
181    """_create_domain_from_regions - internal function.
182
183    See create_domain_from_regions for documentation.
184    """
185
186    #from anuga.shallow_water.shallow_water_domain import Domain
187    from anuga.pmesh.mesh_interface import create_mesh_from_regions
188   
189    create_mesh_from_regions(bounding_polygon,
190                             boundary_tags,
191                             maximum_triangle_area=maximum_triangle_area,
192                             interior_regions=interior_regions,
193                             filename=mesh_filename,
194                             interior_holes=interior_holes,
195                             hole_tags=hole_tags,
196                             poly_geo_reference=poly_geo_reference,
197                             mesh_geo_reference=mesh_geo_reference,
198                             breaklines=breaklines,
199                             regionPtArea=regionPtArea,
200                             minimum_triangle_angle=minimum_triangle_angle,
201                             fail_if_polygons_outside=fail_if_polygons_outside,
202                             use_cache=False,
203                             verbose=verbose)
204
205    domain = Domain(mesh_filename, use_cache=False, verbose=verbose)
206
207
208    return domain
209
Note: See TracBrowser for help on using the repository browser.