source: inundation/ga/storm_surge/parallel/parallel_advection.py @ 1387

Last change on this file since 1387 was 1387, checked in by steve, 20 years ago

Need to look at uint test for inscribed circle

File size: 3.9 KB
Line 
1import sys
2from os import sep
3sys.path.append('..'+sep+'pyvolution')
4
5"""Class Parallel_Domain -
62D triangular domains for finite-volume computations of
7the advection equation, with extra structures to allow
8communication between other Parallel_Domains and itself
9
10This module contains a specialisation of class Domain from module advection.py
11
12Ole Nielsen, Stephen Roberts, Duncan Gray, Christopher Zoppou
13Geoscience Australia, 2004
14"""
15
16from advection import *
17Advection_Domain = Domain
18from Numeric import zeros, Float, Int
19
20class 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
66def 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
Note: See TracBrowser for help on using the repository browser.