2 from scipy.optimize
import brentq
6 w = 2. * np.pi / wave_len
11 q = A * (1. - np.cos(w * p)) - ind * t
13 return 2. * (p - x) - lag * A * w * np.sin(w * p)
17 p0 = brentq(WavySurface.F, a, b, args=(x, y, t))
18 q0 = A * (1. - np.cos(w * p0)) - ind * t
19 return np.sqrt((p0 - x)**2 + (q0 - y)**2)
24 y0 = A * (1. - np.cos(w * x)) - ind * t
25 if np.any(np.abs(y0 - y)) < 1e-12:
28 x = np.abs(x) % wave_len
29 x = np.where(x > wave_len / 2, wave_len - x, x)
33 d1 = np.vectorize(WavySurface.dist)(x, y, eps, wave_len / 2 - eps, t)
34 wave_y = A * (1 - np.cos(w * x)) - ind * t
35 sgn_d1 = np.sign(wave_y - y)
38 sgn_d2 = np.sign(wave_y_d2 - y)
39 d2 = np.sqrt(x**2 + (wave_y_d2 - y)**2)
41 wave_y_d3 = A * (1 - np.cos(w * (wave_len / 2))) - ind * t
42 sgn_d3 = np.sign(wave_y_d3 - y)
43 d3 = np.sqrt((wave_len / 2 - x)**2 + (A * (1 - np.cos(w * (wave_len / 2))) - ind * t - y)**2)
45 d_min = np.minimum(d2, d3)
46 d_final = np.where(d1 < d_min, d1, np.where(d2 < d3, d2, d3))
47 sgn_final = np.where(d1 < d_min, sgn_d1, np.where(d2 < d3, sgn_d2, sgn_d3))
48 sdf = sgn_final * d_final
54 df_dx = ((WavySurface.sDF(x + delta, y, z, t) - WavySurface.sDF(x - delta, y, z, t)) / (2 * delta)).reshape((-1, 1))
55 df_dy = ((WavySurface.sDF(x, y + delta,z, t) - WavySurface.sDF(x, y - delta,z, t)) / (2 * delta)).reshape((-1, 1))
56 df_dz = np.zeros_like(df_dy).reshape((-1, 1))
57 return np.hstack([df_dx, df_dy, df_dz])
61 df2_dx2 = (WavySurface.sDF(x + delta, y,z,t) - 2 * WavySurface.sDF(x, y,z,t) + WavySurface.sDF(x - delta, y,z, t)) / (delta ** 2)
62 df2_dy2 = (WavySurface.sDF(x, y + delta,z,t) - 2 * WavySurface.sDF(x, y,z,t) + WavySurface.sDF(x, y - delta,z, t)) / (delta ** 2)
63 df2_dxdy = (WavySurface.sDF(x + delta, y + delta,z,t) - WavySurface.sDF(x + delta, y - delta, z, t) - WavySurface.sDF(x - delta, y + delta,z, t) + WavySurface.sDF(x - delta, y - delta,z,t)) / (4 * delta ** 2)
65 return np.hstack([df2_dx2.reshape((-1,1)), df2_dxdy.reshape((-1,1)), np.zeros_like(df2_dy2).reshape((-1,1)),df2_dy2.reshape((-1,1)), np.zeros_like(df2_dy2).reshape((-1,1)), np.zeros_like(df2_dy2).reshape((-1,1))])
67 def sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
68 return WavySurface.sDF(x, y, z, t)
70 def grad_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
71 return WavySurface.gradSDF(x, y,z, t)
73 def hess_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
74 return WavySurface.hessSDF(x, y,z, t)