v0.15.0
Loading...
Searching...
No Matches
sdf.py
Go to the documentation of this file.
1import math
2import numpy as np
3
4r = 20
5R = r # radius of the indenter
6
7
8xc = 0
9yc = -2.250e+01-r
10zc = 0
11
12def sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
13 return Sphere.sDF(R, xc, yc, zc, x, y, z)
14
15def grad_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
16 return Sphere.gradSdf(xc, yc, zc, x, y, z)
17
18def hess_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
19 return Sphere.hessSdf(xc, yc, zc, x, y, z)
20
21class Sphere:
22 def sDF(r, xc, yc, zc, x, y, z):
23 return np.sqrt((x - xc)**2 + (y - yc)**2 + (z - zc)**2) - r
24
25 def gradSdf(xc, yc, zc, x, y, z):
26 c_val_A = 1./np.sqrt((x-xc)**2 + (y-yc)**2 + (z-zc)**2)
27 return np.hstack([(c_val_A * (x-xc)).reshape((-1,1)), (c_val_A * (y-yc)).reshape((-1,1)), (c_val_A * (z-zc)).reshape((-1,1))])
28
29 def hessSdf(xc, yc, zc, x, y, z):
30 x, y, z = x-xc, y-yc, z-zc
31 denom = (x**2 + y**2 + z**2)**(3/2)
32 sqrt_denom = np.sqrt(x**2 + y**2 + z**2)
33 Hxx = -x**2/denom + 1/sqrt_denom
34 Hzx = -x*z/denom
35 Hxy = -x*y/denom
36 Hyy = -y**2/denom + 1/sqrt_denom
37 Hzy = -y*z/denom
38 Hzz = -z**2/denom + 1/sqrt_denom
39 # xx, yx, zx, yy, zy, zz
40 return np.hstack([Hxx.reshape((-1,1)), Hxy.reshape((-1,1)), Hzx.reshape((-1,1)), Hyy.reshape((-1,1)), Hzy.reshape((-1,1)), Hzz.reshape((-1,1))])
41
42
gradSdf(xc, yc, zc, x, y, z)
Definition sdf.py:25
hessSdf(xc, yc, zc, x, y, z)
Definition sdf.py:29
sDF(r, xc, yc, zc, x, y, z)
Definition sdf.py:22
Definition sdf.py:1
hess_sdf(t, x, y, z, tx, ty, tz)
Definition sdf.py:19
grad_sdf(t, x, y, z, tx, ty, tz)
Definition sdf.py:15