93 lines
2.1 KiB
Python
93 lines
2.1 KiB
Python
from interp.grid import grid as basegrid
|
|
|
|
from interp.tools import exact_func, log
|
|
|
|
import numpy as np
|
|
|
|
|
|
class grid(basegrid):
|
|
def __init__(self, verts, q):
|
|
basegrid.__init__(self, verts, q)
|
|
|
|
def for_qhull_generator(self):
|
|
"""
|
|
this returns a generator that should be fed into qdelaunay
|
|
"""
|
|
|
|
yield '2';
|
|
yield '%d' % len(self.verts)
|
|
|
|
for p in self.verts:
|
|
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.verts)
|
|
for p in self.verts:
|
|
r += "%f %f\n" % (p[0], p[1])
|
|
return r
|
|
|
|
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)
|
|
|
|
|
|
verts = []
|
|
q = []
|
|
for x in xrange(xres):
|
|
cur_x = xmin + (x * xdel)
|
|
for y in xrange(yres):
|
|
cur_y = ymin + (y * ydel)
|
|
verts.append([cur_x, cur_y])
|
|
q.append(exact_func((cur_x, cur_y)))
|
|
grid.__init__(self, verts, q)
|
|
self.construct_connectivity()
|
|
|
|
|
|
class random_grid(rect_grid):
|
|
def __init__(self, num_verts = 10):
|
|
log.debug("number of verts: %d" % num_verts)
|
|
verts = []
|
|
q = []
|
|
|
|
r = np.random
|
|
appx_side_res = int(np.sqrt(num_verts))
|
|
log.debug("appx_side_res: %d" % appx_side_res)
|
|
delta = 1.0 / float(appx_side_res)
|
|
|
|
for x in xrange(appx_side_res + 1):
|
|
cur_x = x * delta
|
|
for cur_y in (0, 1):
|
|
new_point = [cur_x, cur_y]
|
|
verts.append(new_point)
|
|
q.append(exact_func(new_point))
|
|
|
|
for y in xrange(appx_side_res + 1):
|
|
cur_y = y * delta
|
|
for cur_x in (0, 1):
|
|
new_point = [cur_x, cur_y]
|
|
verts.append(new_point)
|
|
q.append(exact_func(new_point))
|
|
|
|
for i in xrange(num_verts):
|
|
cur_x = r.rand()
|
|
cur_y = r.rand()
|
|
|
|
verts.append([cur_x, cur_y])
|
|
q.append( exact_func( (cur_x, cur_y) ) )
|
|
grid.__init__(self, verts, q)
|
|
|
|
self.verts = np.array(self.verts)
|
|
self.q = np.array(self.q)
|