1 | |
---|
2 | #------------------------------------------------------------- |
---|
3 | if __name__ == "__main__": |
---|
4 | |
---|
5 | import tempfile |
---|
6 | import os |
---|
7 | |
---|
8 | from anuga.shallow_water import Domain, Reflective_boundary, \ |
---|
9 | Dirichlet_boundary |
---|
10 | |
---|
11 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
12 | |
---|
13 | # Create a scenario outline. |
---|
14 | polygon = [[0,0],[100,0],[100,100],[0,100]] |
---|
15 | |
---|
16 | boundary_tags = {'wall':[0,1,3],'wave':[2]} |
---|
17 | |
---|
18 | inner1_polygon = [[10,10],[20,10],[20,20],[10,20]] |
---|
19 | |
---|
20 | |
---|
21 | inner2_polygon = [[30,30],[40,30],[40,40],[30,40]] |
---|
22 | |
---|
23 | |
---|
24 | max_area = 1 |
---|
25 | interior_regions = [(inner1_polygon, 5),(inner2_polygon, 10)] |
---|
26 | m = create_mesh_from_regions(polygon, |
---|
27 | boundary_tags, |
---|
28 | max_area, |
---|
29 | interior_regions=interior_regions) |
---|
30 | |
---|
31 | # Create an ungenerate file |
---|
32 | fileName = tempfile.mktemp(".txt") |
---|
33 | file = open(fileName,"w") |
---|
34 | file.write(" 1 ?? ??\n\ |
---|
35 | 90.0 90.0\n\ |
---|
36 | 81.0 90.0\n\ |
---|
37 | 81.0 81.0\n\ |
---|
38 | 90.0 81.0\n\ |
---|
39 | 90.0 90.0\n\ |
---|
40 | END\n\ |
---|
41 | 2 ?? ??\n\ |
---|
42 | 10.0 80.0\n\ |
---|
43 | 10.0 90.0\n\ |
---|
44 | 20.0 90.0\n\ |
---|
45 | 10.0 80.0\n\ |
---|
46 | END\n\ |
---|
47 | END\n") |
---|
48 | file.close() |
---|
49 | |
---|
50 | # import the ungenerate file |
---|
51 | m.import_ungenerate_file(fileName) |
---|
52 | os.remove(fileName) |
---|
53 | |
---|
54 | m.generate_mesh(maximum_triangle_area=max_area,verbose=False) |
---|
55 | mesh_filename = "mesh.tsh" |
---|
56 | m.export_mesh_file(mesh_filename) |
---|
57 | |
---|
58 | # Run a simulation on the mesh |
---|
59 | domain = Domain(mesh_filename, use_cache = False) |
---|
60 | |
---|
61 | Br = Reflective_boundary(domain) |
---|
62 | Bd = Dirichlet_boundary([3,0,0]) |
---|
63 | domain.set_boundary( {'wall': Br, 'wave': Bd} ) |
---|
64 | yieldstep = 0.1 |
---|
65 | finaltime = 20 |
---|
66 | for t in domain.evolve(yieldstep, finaltime): |
---|
67 | domain.write_time() |
---|
68 | |
---|
69 | |
---|