1 | import sys |
---|
2 | from os import sep |
---|
3 | sys.path.append('..'+sep+'pyvolution') |
---|
4 | |
---|
5 | """Class Parallel_Domain - |
---|
6 | 2D triangular domains for finite-volume computations of |
---|
7 | the advection equation, with extra structures to allow |
---|
8 | communication between other Parallel_Domains and itself |
---|
9 | |
---|
10 | This module contains a specialisation of class Domain from module advection.py |
---|
11 | |
---|
12 | Ole Nielsen, Stephen Roberts, Duncan Gray, Christopher Zoppou |
---|
13 | Geoscience Australia, 2004 |
---|
14 | """ |
---|
15 | |
---|
16 | from advection import * |
---|
17 | Advection_Domain = Domain |
---|
18 | from Numeric import zeros, Float, Int |
---|
19 | |
---|
20 | class Parallel_Domain(Advection_Domain): |
---|
21 | |
---|
22 | def __init__(self, coordinates, vertices, boundary = None, velocity = None, |
---|
23 | processor = 0, global_ids = None): |
---|
24 | |
---|
25 | Advection_Domain.__init__(self, coordinates, vertices, boundary, velocity) |
---|
26 | |
---|
27 | self.processor = processor |
---|
28 | |
---|
29 | N = self.number_of_elements |
---|
30 | |
---|
31 | if global_ids == None: |
---|
32 | self.global_ids = global_ids |
---|
33 | else: |
---|
34 | self.global_ids = zeros(N, Int) |
---|
35 | |
---|
36 | |
---|
37 | def check_integrity(self): |
---|
38 | Advection_Domain.check_integrity(self) |
---|
39 | |
---|
40 | msg = 'Will need to check global and local numbering' |
---|
41 | assert self.conserved_quantities[0] == 'stage', msg |
---|
42 | |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | def evolve(self, yieldstep = None, finaltime = None): |
---|
47 | """Specialisation of basic evolve method from parent class |
---|
48 | """ |
---|
49 | |
---|
50 | #Initialise real time viz if requested |
---|
51 | if self.visualise is True and self.time == 0.0: |
---|
52 | import realtime_visualisation_new as visualise |
---|
53 | self.visualiser = visualise.Visualiser(self) |
---|
54 | |
---|
55 | #Call basic machinery from parent class |
---|
56 | for t in Advection_Domain.evolve(self, yieldstep, finaltime): |
---|
57 | #Real time viz |
---|
58 | if self.visualise is True: |
---|
59 | self.visualiser.update_quantity('stage') |
---|
60 | |
---|
61 | #Pass control on to outer loop for more specific actions |
---|
62 | yield(t) |
---|
63 | |
---|
64 | |
---|
65 | |
---|
66 | def rectangular_with_ghosts(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)): |
---|
67 | |
---|
68 | """Setup a rectangular grid of triangles |
---|
69 | with m+1 by n+1 grid points |
---|
70 | and side lengths len1, len2. If side lengths are omitted |
---|
71 | the mesh defaults to the unit square. |
---|
72 | |
---|
73 | len1: x direction (left to right) |
---|
74 | len2: y direction (bottom to top) |
---|
75 | |
---|
76 | Also returns a list of |
---|
77 | |
---|
78 | Return to lists: points and elements suitable for creating a Mesh or |
---|
79 | FVMesh object, e.g. Mesh(points, elements) |
---|
80 | """ |
---|
81 | |
---|
82 | from config import epsilon |
---|
83 | |
---|
84 | #E = m*n*2 #Number of triangular elements |
---|
85 | #P = (m+1)*(n+1) #Number of initial vertices |
---|
86 | |
---|
87 | delta1 = float(len1)/m |
---|
88 | delta2 = float(len2)/n |
---|
89 | |
---|
90 | #Dictionary of vertex objects |
---|
91 | vertices = {} |
---|
92 | points = [] |
---|
93 | |
---|
94 | for i in range(m+1): |
---|
95 | for j in range(n+1): |
---|
96 | vertices[i,j] = len(points) |
---|
97 | points.append([i*delta1 + origin[0], j*delta2 + origin[1]]) |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | #Construct 2 triangles per rectangular element and assign tags to boundary |
---|
102 | elements = [] |
---|
103 | boundary = {} |
---|
104 | for i in range(m): |
---|
105 | for j in range(n): |
---|
106 | v1 = vertices[i,j+1] |
---|
107 | v2 = vertices[i,j] |
---|
108 | v3 = vertices[i+1,j+1] |
---|
109 | v4 = vertices[i+1,j] |
---|
110 | |
---|
111 | #Update boundary dictionary and create elements |
---|
112 | if i == m-1: |
---|
113 | boundary[(len(elements), 2)] = 'right' |
---|
114 | if j == 0: |
---|
115 | boundary[(len(elements), 1)] = 'bottom' |
---|
116 | elements.append([v4,v3,v2]) #Lower element |
---|
117 | |
---|
118 | if i == 0: |
---|
119 | boundary[(len(elements), 2)] = 'left' |
---|
120 | if j == n-1: |
---|
121 | boundary[(len(elements), 1)] = 'top' |
---|
122 | elements.append([v1,v2,v3]) #Upper element |
---|
123 | |
---|
124 | ghosts = {} |
---|
125 | i=0 |
---|
126 | for j in range(n): |
---|
127 | v1 = vertices[i,j+1] |
---|
128 | v2 = vertices[i,j] |
---|
129 | v3 = vertices[i+1,j+1] |
---|
130 | v4 = vertices[i+1,j] |
---|
131 | ghosts.append(elements.index([ |
---|
132 | |
---|
133 | return points, elements, boundary |
---|