added files. still not consistently getting better numbers
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
from grid import grid
|
||||
from baker.tools import exact_func
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
class simple_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()
|
||||
|
||||
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
|
||||
|
||||
|
||||
class simple_random_grid(simple_rect_grid):
|
||||
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])
|
||||
q.append(exact_func(cur_x, cur_y))
|
||||
grid.__init__(self, points, q)
|
||||
|
||||
self.points = np.array(self.points)
|
||||
self.q = np.array(self.q)
|
||||
@@ -0,0 +1,76 @@
|
||||
from grid import grid
|
||||
from baker.tools import exact_func_3D
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
class simple_rect_grid(grid):
|
||||
def __init__(self, xres = 5, yres = 5, zres = 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)
|
||||
|
||||
zmin = -1.0
|
||||
zmaz = 1.0
|
||||
zspan = zmaz - zmin
|
||||
zdel = zspan / float(zres - 1)
|
||||
|
||||
|
||||
points = []
|
||||
q = []
|
||||
for x in xrange(xres):
|
||||
cur_x = xmin + (x * xdel)
|
||||
for y in xrange(yres):
|
||||
cur_y = ymin + (y * ydel)
|
||||
for z in xrange(zres):
|
||||
cur_z = zmin + (z * zdel)
|
||||
points.append([cur_x, cur_y, cur_z])
|
||||
q.append(exact_func_3D((cur_x, cur_y, cur_z)))
|
||||
grid.__init__(self, points, q)
|
||||
# self.construct_connectivity()
|
||||
|
||||
def for_qhull_generator(self):
|
||||
"""
|
||||
this returns a generator that should be fed into qdelaunay
|
||||
"""
|
||||
|
||||
yield '3';
|
||||
yield '%d' % len(self.points)
|
||||
|
||||
for p in self.points:
|
||||
yield "%f %f %f" % tuple(p)
|
||||
|
||||
def for_qhull(self):
|
||||
"""
|
||||
this returns a single string that should be fed into qdelaunay
|
||||
"""
|
||||
r = '3\n'
|
||||
r += '%d\n' % len(self.points)
|
||||
for p in self.points:
|
||||
r += "%f %f %f\n" % tuple(p)
|
||||
return r
|
||||
|
||||
class simple_random_grid(simple_rect_grid):
|
||||
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()
|
||||
cur_z = r.rand()
|
||||
|
||||
points.append([cur_x, cur_y, cur_z])
|
||||
q.append(exact_func_3D((cur_x, cur_y, cur_z)))
|
||||
grid.__init__(self, points, q)
|
||||
|
||||
self.points = np.array(self.points)
|
||||
self.q = np.array(self.q)
|
||||
@@ -0,0 +1,38 @@
|
||||
from baker import get_phis
|
||||
|
||||
class face(object):
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.verts = []
|
||||
self.neighbors = []
|
||||
|
||||
def add_vert(self, v):
|
||||
"""
|
||||
v should be an index into grid.points
|
||||
"""
|
||||
self.verts.append(v)
|
||||
|
||||
def add_neighbor(self, n):
|
||||
"""
|
||||
reference to another face object
|
||||
"""
|
||||
self.neighbors.append(n)
|
||||
|
||||
def contains(self, X, grid):
|
||||
R = [grid.points[i] for i in self.verts]
|
||||
|
||||
phis = get_phis(X, R)
|
||||
|
||||
r = True
|
||||
if [i for i in phis if i < 0.0]:
|
||||
r = False
|
||||
return r
|
||||
|
||||
def __str__(self):
|
||||
neighbors = [i.name for i in self.neighbors]
|
||||
return '%s: verts: %s neighbors: [%s]' %\
|
||||
(
|
||||
self.name,
|
||||
self.verts,
|
||||
", ".join(neighbors)
|
||||
)
|
||||
Reference in New Issue
Block a user