def closest_point(self, xx):
     x,y,z = xx.T
     # no boundaries for now
     if self.axis == 'x':
         th, r, zz = cart2pol(y,z,x)
         cpzzr, dist, _, _ = self.curve.closest_point(np.column_stack((zz, r)))
         cpzz, cpr = cpzzr.T
         cpy, cpz, cpx = pol2cart(th, cpr, cpzz)
     elif self.axis == 'y':
         th, r, zz = cart2pol(z,x,y)
         cprzz, dist, _, _ = self.curve.closest_point(np.column_stack((r, zz)))
         cpr, cpzz = cprzz.T
         cpz, cpx, cpy = pol2cart(th, cpr, cpzz)
     
     cpxx = np.column_stack((cpx, cpy, cpz))
     return cpxx, dist, np.zeros(xx.ndim), {}                                       
def uexactfn(t,cp):
    k1 = 2
    k2 = 4
    k3 = 6
    th, r = cart2pol(cp[:,0],cp[:,1])
    return np.exp(-k1**2*t)*np.cos(k1*th) +  np.exp(-k2**2*t)*np.sin(k2*th)\
           + np.exp(-k3**2*t)*np.cos(k3*th)
Exemple #3
0
def uexactfn(t, cp):
    k1 = 2
    k2 = 4
    k3 = 6
    th, r = cart2pol(cp[:, 0], cp[:, 1])
    return np.exp(-k1**2*t)*np.cos(k1*th) +  np.exp(-k2**2*t)*np.sin(k2*th)\
           + np.exp(-k3**2*t)*np.cos(k3*th)
                                   p=p,
                                   diff_stencil_arm=diff_stencil_arm)
cp2, distance2, _, _ = s.closest_point(grid)
assert np.allclose(cp, cp2)
assert np.allclose(distance, distance2)

# Corners of the virtual grid, superset of `grid`
ll = np.array(dim * [grid.min()]) - 3 * dx
ur = np.array(dim * [grid.max()]) + 3 * dx
virtual_grid_shape = np.abs(ur-ll) / dx + 1

# The (i,j,...) indices of the grid points, taking `ll` as origin.
int_grid = np.round((grid - ll) / dx).astype(np.int)

# Initial conditions
th, r = cart2pol(grid[:, 0], grid[:, 1])
u = np.cos(th + np.pi / 2)
# Let's keep a copy of the initial conditions
initial_u = u.copy()

# Build interpolation and differential matrix.
E = build_interp_matrix(int_grid, cp, dx, p, ll, virtual_grid_shape)
L = build_diff_matrix(int_grid, dx, virtual_grid_shape)


xp, yp = s.parametric_grid(65)
th_plot, _ = cart2pol(xp, yp)
Eplot = build_interp_matrix(int_grid,
                            np.column_stack((xp.ravel(),
                                             yp.ravel())),
                            dx, p, ll, virtual_grid_shape)
def uexactfn(t,cp):
    k = 2
    th, r = cart2pol(cp[:,0],cp[:,1])
    return np.exp(-k**2*t)*np.cos(k*th) 
Exemple #6
0
                                p=p,
                                diff_stencil_arm=diff_stencil_arm)
cp2, distance2, _, _ = s.closest_point(grid)
assert np.allclose(cp, cp2)
assert np.allclose(distance, distance2)

# Corners of the virtual grid, superset of `grid`
ll = np.array(dim * [grid.min()]) - 3 * dx
ur = np.array(dim * [grid.max()]) + 3 * dx
virtual_grid_shape = np.abs(ur - ll) / dx + 1

# The (i,j,...) indices of the grid points, taking `ll` as origin.
int_grid = np.round((grid - ll) / dx).astype(np.int)

# Initial conditions
th, r = cart2pol(grid[:, 0], grid[:, 1])
u = np.cos(th + np.pi / 2)
# Let's keep a copy of the initial conditions
initial_u = u.copy()

# Build interpolation and differential matrix.
E = build_interp_matrix(int_grid, cp, dx, p, ll, virtual_grid_shape)
L = build_diff_matrix(int_grid, dx, virtual_grid_shape)

xp, yp = s.parametric_grid(65)
th_plot, _ = cart2pol(xp, yp)
Eplot = build_interp_matrix(int_grid, np.column_stack(
    (xp.ravel(), yp.ravel())), dx, p, ll, virtual_grid_shape)

# choose a Closest Point Method algorithm
cpm = 0