2010-03-20 16:10:02 -07:00
|
|
|
from grid import grid as basegrid
|
|
|
|
|
2010-03-18 22:32:24 -07:00
|
|
|
from baker.tools import exact_func
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
2010-03-20 16:10:02 -07:00
|
|
|
class grid(basegrid):
|
|
|
|
def __init__(self, points, q):
|
|
|
|
basegrid.__init__(self, points, q)
|
2010-03-18 22:32:24 -07:00
|
|
|
|
|
|
|
def for_qhull_generator(self):
|
|
|
|
"""
|
|
|
|
this returns a generator that should be fed into qdelaunay
|
|
|
|
"""
|
|
|
|
|
|
|
|
yield '2';
|
|
|
|
yield '%d' % len(self.points)
|
|
|
|
|
|
|
|
for p in self.points:
|
|
|
|
yield "%f %f" % (p[0], p[1])
|
|
|
|
|
|
|
|
def for_qhull(self):
|
|
|
|
"""
|
|
|
|
this returns a single string that should be fed into qdelaunay
|
|
|
|
"""
|
|
|
|
r = '2\n'
|
|
|
|
r += '%d\n' % len(self.points)
|
|
|
|
for p in self.points:
|
|
|
|
r += "%f %f\n" % (p[0], p[1])
|
|
|
|
return r
|
|
|
|
|
2010-03-20 16:10:02 -07:00
|
|
|
class rect_grid(grid):
|
|
|
|
def __init__(self, xres = 5, yres = 5):
|
|
|
|
xmin = -1.0
|
|
|
|
xmax = 1.0
|
|
|
|
xspan = xmax - xmin
|
|
|
|
xdel = xspan / float(xres - 1)
|
|
|
|
|
|
|
|
ymin = -1.0
|
|
|
|
ymay = 1.0
|
|
|
|
yspan = ymay - ymin
|
|
|
|
ydel = yspan / float(yres - 1)
|
|
|
|
|
|
|
|
|
|
|
|
points = []
|
|
|
|
q = []
|
|
|
|
for x in xrange(xres):
|
|
|
|
cur_x = xmin + (x * xdel)
|
|
|
|
for y in xrange(yres):
|
|
|
|
cur_y = ymin + (y * ydel)
|
|
|
|
points.append([cur_x, cur_y])
|
|
|
|
q.append(exact_func((cur_x, cur_y)))
|
|
|
|
grid.__init__(self, points, q)
|
|
|
|
self.construct_connectivity()
|
|
|
|
|
2010-03-18 22:32:24 -07:00
|
|
|
|
2010-03-20 16:10:02 -07:00
|
|
|
class random_grid(rect_grid):
|
2010-03-18 22:32:24 -07:00
|
|
|
def __init__(self, num_points = 10):
|
|
|
|
points = []
|
|
|
|
q = []
|
|
|
|
|
|
|
|
r = np.random
|
|
|
|
|
|
|
|
for i in xrange(num_points):
|
|
|
|
cur_x = r.rand()
|
|
|
|
cur_y = r.rand()
|
|
|
|
|
|
|
|
points.append([cur_x, cur_y])
|
2010-03-20 16:10:02 -07:00
|
|
|
q.append( exact_func( (cur_x, cur_y) ) )
|
2010-03-18 22:32:24 -07:00
|
|
|
grid.__init__(self, points, q)
|
|
|
|
|
|
|
|
self.points = np.array(self.points)
|
|
|
|
self.q = np.array(self.q)
|