2011-03-23 10:15:05 -07:00
|
|
|
from interp.grid.delaunay import dgrid as basegrid
|
2011-03-24 15:15:08 -07:00
|
|
|
from interp.tools import baker_exact_2D as exact_func
|
2010-03-18 22:32:24 -07:00
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2011-03-23 10:16:50 -07:00
|
|
|
class rect_grid(basegrid):
|
2010-03-20 16:10:02 -07:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2010-10-23 16:06:57 -07:00
|
|
|
verts = []
|
2010-03-20 16:10:02 -07:00
|
|
|
q = []
|
|
|
|
for x in xrange(xres):
|
|
|
|
cur_x = xmin + (x * xdel)
|
|
|
|
for y in xrange(yres):
|
|
|
|
cur_y = ymin + (y * ydel)
|
2010-10-23 16:06:57 -07:00
|
|
|
verts.append([cur_x, cur_y])
|
2010-03-20 16:10:02 -07:00
|
|
|
q.append(exact_func((cur_x, cur_y)))
|
2011-03-23 23:27:30 -07:00
|
|
|
basegrid.__init__(self, verts, q)
|
2010-03-20 16:10:02 -07:00
|
|
|
|
2010-03-18 22:32:24 -07:00
|
|
|
|
2010-03-20 16:10:02 -07:00
|
|
|
class random_grid(rect_grid):
|
2010-10-23 16:06:57 -07:00
|
|
|
def __init__(self, num_verts = 10):
|
|
|
|
verts = []
|
2010-03-18 22:32:24 -07:00
|
|
|
q = []
|
|
|
|
|
|
|
|
r = np.random
|
2010-10-23 16:06:57 -07:00
|
|
|
appx_side_res = int(np.sqrt(num_verts))
|
2010-04-24 17:26:44 -07:00
|
|
|
delta = 1.0 / float(appx_side_res)
|
2010-04-29 22:29:35 -07:00
|
|
|
|
2010-04-30 10:56:01 -07:00
|
|
|
for x in xrange(appx_side_res + 1):
|
2010-04-24 17:26:44 -07:00
|
|
|
cur_x = x * delta
|
2010-04-29 22:29:35 -07:00
|
|
|
for cur_y in (0, 1):
|
|
|
|
new_point = [cur_x, cur_y]
|
2010-10-23 16:06:57 -07:00
|
|
|
verts.append(new_point)
|
2010-04-29 22:29:35 -07:00
|
|
|
q.append(exact_func(new_point))
|
|
|
|
|
2010-04-30 10:56:01 -07:00
|
|
|
for y in xrange(appx_side_res + 1):
|
2010-04-29 22:29:35 -07:00
|
|
|
cur_y = y * delta
|
|
|
|
for cur_x in (0, 1):
|
2010-04-24 17:26:44 -07:00
|
|
|
new_point = [cur_x, cur_y]
|
2010-10-23 16:06:57 -07:00
|
|
|
verts.append(new_point)
|
2010-04-24 17:26:44 -07:00
|
|
|
q.append(exact_func(new_point))
|
2010-03-18 22:32:24 -07:00
|
|
|
|
2010-10-23 16:06:57 -07:00
|
|
|
for i in xrange(num_verts):
|
2010-03-18 22:32:24 -07:00
|
|
|
cur_x = r.rand()
|
|
|
|
cur_y = r.rand()
|
|
|
|
|
2010-10-23 16:06:57 -07:00
|
|
|
verts.append([cur_x, cur_y])
|
2010-03-20 16:10:02 -07:00
|
|
|
q.append( exact_func( (cur_x, cur_y) ) )
|
2011-03-23 23:27:30 -07:00
|
|
|
basegrid.__init__(self, verts, q)
|
2010-03-18 22:32:24 -07:00
|
|
|
|
2010-10-23 16:06:57 -07:00
|
|
|
self.verts = np.array(self.verts)
|
2010-03-18 22:32:24 -07:00
|
|
|
self.q = np.array(self.q)
|