Browse Source

polish for inclusion into thesis

Stephen McQuay 8 years ago
parent
commit
c682b12bea
10 changed files with 43 additions and 76 deletions
  1. 3
    3
      bin/iqmgr.py
  2. 5
    7
      bin/master.py
  3. 0
    1
      bin/minion.py
  4. 2
    2
      bin/resolution.2D.py
  5. 0
    2
      bin/shepherd.py
  6. 25
    27
      interp/baker/__init__.py
  7. 8
    11
      interp/grid/__init__.py
  8. 0
    3
      interp/grid/delaunay.py
  9. 0
    14
      interp/grid/qhull.py
  10. 0
    6
      interp/tools.py

+ 3
- 3
bin/iqmgr.py View File

@@ -2,9 +2,9 @@
2 2
 
3 3
 import sys
4 4
 import time
5
-import interp.bootstrap
6
-from   interp.cluster import QueueManager, get_qs
7
-from   optparse       import OptionParser
5
+
6
+from   interp.cluster   import QueueManager, get_qs
7
+from   optparse         import OptionParser
8 8
 
9 9
 if __name__ == '__main__':
10 10
   parser = OptionParser(usage = "usage: %s [options] <status|watch|add|fresult #|slay|clear|clearall|clearresults>")

+ 5
- 7
bin/master.py View File

@@ -4,20 +4,18 @@ import sys
4 4
 import os
5 5
 
6 6
 import time
7
-
8 7
 import shelve
9
-from   progressbar import *
10 8
 from   collections import defaultdict
11 9
 from   optparse    import OptionParser
12 10
 
13
-import numpy as np
14
-
15
-import interp.bootstrap
16
-
17 11
 import logging
18 12
 log = logging.getLogger("interp")
19 13
 
20
-from interp.cluster import QueueManager, get_qs
14
+import numpy as np
15
+
16
+from   interp.cluster import QueueManager, get_qs
17
+
18
+from   progressbar import *
21 19
 
22 20
 if __name__ == '__main__':
23 21
   parser = OptionParser(usage = "usage: %s [options] <server> <interp count>")

+ 0
- 1
bin/minion.py View File

@@ -11,7 +11,6 @@ import datetime
11 11
 
12 12
 import numpy as np
13 13
 
14
-import interp.bootstrap
15 14
 from   interp.grid.gmsh import ggrid
16 15
 from   interp.tools import baker_exact_3D as exact
17 16
 

+ 2
- 2
bin/resolution.2D.py View File

@@ -6,8 +6,8 @@ import time
6 6
 from   progressbar import *
7 7
 
8 8
 from interp.grid.DD import *
9
-from interp.tools import *
10
-from interp import bootstrap
9
+from interp.tools   import *
10
+from interp         import bootstrap
11 11
 
12 12
 EXTRA_POINTS = 64
13 13
 

+ 0
- 2
bin/shepherd.py View File

@@ -10,8 +10,6 @@ import pickle
10 10
 
11 11
 import numpy as np
12 12
 
13
-import interp.bootstrap
14
-
15 13
 from interp.cluster import QueueManager, get_qs
16 14
 
17 15
 if __name__ == '__main__':

+ 25
- 27
interp/baker/__init__.py View File

@@ -11,37 +11,35 @@ log = logging.getLogger('interp')
11 11
 
12 12
 def get_phis(X, R):
13 13
   """
14
-    The get_phis function is used to get barycentric coordonites for a point on
15
-    a triangle or tetrahedron:
16
-
14
+    The get_phis function is used to get barycentric coordonites for a
15
+    point on a triangle or tetrahedron. This is equation (*\ref{eq:qlinarea}*)
17 16
 
18 17
     in 2D:
19 18
 
20
-    X -- the destination point (2D)
21
-         X = [0,0]
22
-    r -- the three points that make up the containing triangular simplex (2D)
23
-         r = [[-1, -1], [0, 2], [1, -1]]
19
+    X - the destination point (2D)
20
+        X = [0,0]
21
+    R - the three points that make up the 2-D triangular simplex
22
+        R = [[-1, -1], [0, 2], [1, -1]]
24 23
 
25 24
     this will return [0.333, 0.333, 0.333]
26 25
 
27 26
 
28 27
     in 3D:
29 28
 
30
-    X -- the destination point (3D)
31
-         X = [0,0,0]
32
-    R -- the four points that make up the containing simplex, tetrahedron (3D)
33
-         R = [
34
-               [0.0, 0.0, 1.0],
35
-               [0.94280904333606508, 0.0, -0.3333333283722672],
36
-               [-0.47140452166803232, 0.81649658244673617, -0.3333333283722672],
37
-               [-0.47140452166803298, -0.81649658244673584, -0.3333333283722672],
38
-             ]
29
+    X - the destination point (3D)
30
+        X = [0,0,0]
31
+    R - the four points that make up the 3-D simplex (tetrahedron)
32
+        R = [
33
+           [ 0.0000,  0.0000,  1.0000],
34
+           [ 0.9428,  0.0000, -0.3333],
35
+           [-0.4714,  0.8165, -0.3333],
36
+           [-0.4714, -0.8165, -0.3333],
37
+         ]
39 38
 
40 39
     this will return [0.25, 0.25, 0.25, 0.25]
41 40
   """
42 41
 
43
-  # baker: eq 7
44
-  # TODO: perhaps also test len(R[0])  .. ?
42
+  # equations (*\ref{eq:lin3d}*) and (*\ref{eq:lin2d}*)
45 43
   if len(X) == 2:
46 44
     log.debug("running 2D")
47 45
     A = np.array([
@@ -85,7 +83,7 @@ def qlinear(X, R):
85 83
   """
86 84
     this calculates the linear portion of q from R to X
87 85
 
88
-    also, this is baker eq 3
86
+    This is equation (*\ref{eq:qlinbasis}*)
89 87
 
90 88
     X = destination point
91 89
     R = a inter.grid object; must have R.points and R.q
@@ -100,9 +98,12 @@ def qlinear(X, R):
100 98
   return phis, qlin
101 99
 
102 100
 def get_error(phi, R, S, order = 2):
103
-  #TODO: change the equation names in the comments
104
-  B = [] # baker eq 9
105
-  w = [] # baker eq 11
101
+  """
102
+    Calculate the error approximation terms, returning the unknowns
103
+    a,b, and c in equation (*\ref{eq:quadratic2d}*).
104
+  """
105
+  B = [] # equation ((*\ref{eq:B2d}*)
106
+  w = [] # equation ((*\ref{eq:w}*)
106 107
 
107 108
   cur_pattern  = pattern(len(phi), order)
108 109
   log.info("pattern: %s" % cur_pattern)
@@ -150,8 +151,7 @@ def run_baker(X, R, S, order=2):
150 151
     This is the main function to call to get an interpolation to X from the
151 152
     input meshes
152 153
 
153
-    X -- the destination point (2D)
154
-         X = [0,0]
154
+    X -- the destination point
155 155
 
156 156
     R = Simplex
157 157
     S = extra points
@@ -190,9 +190,7 @@ def run_baker(X, R, S, order=2):
190 190
 
191 191
 def memoize(f):
192 192
   """
193
-    for more information on what I'm doing here,
194
-    please read:
195
-
193
+    for more information on what I'm doing here, please read:
196 194
     http://en.wikipedia.org/wiki/Memoize
197 195
   """
198 196
   cache = {}

+ 8
- 11
interp/grid/__init__.py View File

@@ -20,8 +20,9 @@ class grid(object):
20 20
     """
21 21
       verts = array of arrays (if passed in, will convert to numpy.array)
22 22
               [
23
-                [x0,y0],
24
-                [x1,y1], ...
23
+                [x0,y0 <, z0>],
24
+                [x1,y1 <, z1>],
25
+                ...
25 26
               ]
26 27
 
27 28
       q     = array (1D) of physical values
@@ -97,10 +98,9 @@ class grid(object):
97 98
     """
98 99
       this returns two grid objects: R and S.
99 100
 
100
-      R is a grid object that is supposedly a containing simplex around point X
101
+      R is a grid object that is a containing simplex around point X
101 102
 
102
-      S is S_j from baker's paper : some verts from all point that are not the
103
-      simplex
103
+      S : some verts from all points that are not the simplex
104 104
     """
105 105
     simplex_size = self.dim + 1
106 106
     log.debug("extra verts: %d" % extra_points)
@@ -228,8 +228,9 @@ class cell(object):
228 228
       X = point of interest
229 229
       G = corrensponding grid object (G.verts)
230 230
 
231
-      because of the way i'm storing things, a cell simply stores indicies, and
232
-      so one must pass in a reference to the grid object containing real verts.
231
+      because of the way i'm storing things, a cell simply stores indicies,
232
+      and so one must pass in a reference to the grid object containing real
233
+      verts.
233 234
 
234 235
       this simply calls grid.simplex.contains
235 236
     """
@@ -255,10 +256,6 @@ def contains(X, R):
255 256
     tests if X (point) is in R
256 257
 
257 258
     R is a simplex, represented by a list of n-degree coordinates
258
-
259
-    it now correctly checks for 2/3-D verts
260
-
261
-    TODO: write unit test ...
262 259
   """
263 260
   phis = get_phis(X, R)
264 261
 

+ 0
- 3
interp/grid/delaunay.py View File

@@ -51,9 +51,6 @@ class dgrid(basegrid):
51 51
   def construct_connectivity(self):
52 52
     """
53 53
       a call to this method prepares the internal connectivity structure.
54
-
55
-      this is part of the __init__ for a interp.grid.delaunay.grid, but can be
56
-      called from any grid object
57 54
     """
58 55
     log.info('start')
59 56
     qdelaunay_string = get_qdelaunay_dump_str(self)

+ 0
- 14
interp/grid/qhull.py View File

@@ -1,14 +0,0 @@
1
-def parse_qhull_file(filename, verbose=False):
2
-  f = open(filename, 'r')
3
-
4
-  if verbose:
5
-    print 'filename: ', filename
6
-    degree = int(f.readline().strip())
7
-    print "degree:", degree
8
-    print "number of points", f.readline().strip()
9
-
10
-  verts = []
11
-  for p in f:
12
-    v = [float(i) for i in p.strip().split()]
13
-    verts.append(v)
14
-  return verts

+ 0
- 6
interp/tools.py View File

@@ -1,6 +1,5 @@
1 1
 import os
2 2
 
3
-import inspect
4 3
 import numpy as np
5 4
 
6 5
 import logging
@@ -27,8 +26,6 @@ def baker_exact_2D(X):
27 26
   """
28 27
   x ,y = X
29 28
 
30
-  # TODO: this is not baker's function!! this is:
31
-  #        np.power(np.sin(x*np.pi/2.0) * np.sin(y*np.pi/2.0),2)
32 29
   answer = np.power((np.sin(x * np.pi) * np.cos(y * np.pi)), 2)
33 30
   log.debug(answer)
34 31
   return answer
@@ -83,6 +80,3 @@ def improved(qlin, err, final, exact):
83 80
     return True
84 81
   else:
85 82
     return False
86
-
87
-def percent_improvement(answer, exact):
88
-  return np.abs(answer['error']) / exact

Loading…
Cancel
Save