v0.14.0
sdf.py
Go to the documentation of this file.
1 import math
2 import numpy as np
3 
4 # SDF Indenter
5 
6 # Negative level set represents interior of the indenter.
7 # This normal points outside of the indenter.
8 
9 
10 
11 # Functions for MoFEM
12 def sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
13  return list_indenters[0].sDF(x,y,z)
14 
15 
16 def grad_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
17  return list_indenters[0].gradSdf(x,y,z)
18 
19 
20 def hess_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
21  return list_indenters[0].hessSdf(x,y,z)
22 
23 # Example Indenters
24 
25 class yPlane:
26  def __init__(self,Xc,Yc,Zc,shift):
27  # Initial Centroid
28  self.Xc = Xc
29  self.Yc = Yc
30  self.Zc = Zc
31 
32  # Current Centroid
33  self.xc = Xc
34  self.yc = Yc
35  self.zc = Zc
36 
37  # Indenter Dimensions
38  self.shift = shift
39 
40 
41  def sDF(self, x, y, z):
42  return np.subtract(y,self.shift)
43 
44  def gradSdf(self, x, y, z):
45  dx = np.zeros_like(x).reshape((-1, 1))
46  dy = np.ones_like(y).reshape((-1, 1))
47  dz = np.zeros_like(z).reshape((-1, 1))
48  return np.hstack([dx, dy, dz])
49 
50  def hessSdf(self, x, y, z):
51  zeros = np.zeros_like(x).reshape((-1, 1))
52  return np.hstack([zeros for _ in range(6)]) # xx, yx, zx, yy, zy, zz
53 
54 class CylinderZ:
55  def __init__(self, Xc, Yc, Zc, diameter):
56  # Initial Centroid
57  self.Xc = Xc
58  self.Yc = Yc
59  self.Zc = Zc
60 
61  # Current Centroid
62  self.xc = Xc
63  self.yc = Yc
64  self.zc = Zc
65 
66  # Indenter Dimensions
67  self.radius = diameter/2
68 
69  def sDF(self, x, y, z):
70  return np.sqrt((x - self.xc)**2 + (y - self.yc)**2) - self.radius
71 
72  def gradSdf(self, x, y, z):
73  a = (x-self.xc)**2 + (y-self.yc)**2
74  c_val_A = 1./np.sqrt(a)
75  c_val_dx = c_val_A * (x-self.xc)
76  c_val_dy = c_val_A * (y-self.yc)
77  c_val_dz = np.zeros_like(c_val_dy)
78  # x, y, z
79  return np.hstack([c_val_dx.reshape((-1,1)), c_val_dy.reshape((-1,1)), c_val_dz.reshape((-1,1))])
80 
81  def hessSdf(self, x, y, z):
82  a = (x-self.xc)**2 + (y-self.yc)**2
83  c_val_A = 1./np.sqrt(a)
84  c_val_B = 1./(a**(3./2.))
85  Hxx = c_val_A - c_val_B * (x-self.xc)**2
86  Hxy = -c_val_B * (x-self.xc)*(y-self.yc)
87  Hyy = c_val_A - c_val_B * (y-self.yc)**2
88  zeros = np.zeros_like(Hxx).reshape((-1,1))
89  # Hxx, Hxy, Hzx, Hyy, Hzy, Hzz
90  return np.hstack([Hxx.reshape((-1,1)), Hxy.reshape((-1,1)), zeros, Hyy.reshape((-1,1)), zeros, zeros])
91 
92 class Sphere:
93  def __init__(self, Xc, Yc, Zc, diameter):
94  # Initial Centroid
95  self.Xc = Xc
96  self.Yc = Yc
97  self.Zc = Zc
98 
99  # Current Centroid
100  self.xc = Xc
101  self.yc = Yc
102  self.zc = Zc
103 
104  # Indenter Dimensions
105  self.radius = diameter/2
106 
107  def sDF(self, x, y, z):
108  return np.sqrt((x - self.xc)**2 + (y - self.yc)**2 + (z - self.zc)**2) - self.radius
109 
110  def gradSdf(self, x, y, z):
111  a = (x-self.xc)**2 + (y-self.yc)**2 + (z-self.zc)**2
112  c_val_A = 1./np.sqrt(a)
113  c_val_dx = c_val_A * (x-self.xc)
114  c_val_dy = c_val_A * (y-self.yc)
115  c_val_dz = c_val_A * (z-self.zc)
116  # x, y, z
117  return np.hstack([c_val_dx.reshape((-1,1)), c_val_dy.reshape((-1,1)), c_val_dz.reshape((-1,1))])
118 
119  def hessSdf(self, x, y, z):
120  x, y, z = x-self.xc, y-self.yc, z-self.zc
121  denom = (x**2 + y**2 + z**2)**(3/2)
122  sqrt_denom = np.sqrt(x**2 + y**2 + z**2)
123  Hxx = -x**2/denom + 1/sqrt_denom
124  Hzx = -x*z/denom
125  Hxy = -x*y/denom
126  Hyy = -y**2/denom + 1/sqrt_denom
127  Hzy = -y*z/denom
128  Hzz = -z**2/denom + 1/sqrt_denom
129  # xx, yx, zx, yy, zy, zz
130  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))])
131 
132 
133 # Define Indenters below
134 r = 1
135 
136 list_indenters = []
137 list_indenters.append(CylinderZ(0.0,-0.5-r, 0.0, 2*r))
138 
sdf.Sphere.Yc
Yc
Definition: sdf.py:145
sdf.CylinderZ.__init__
def __init__(self, Xc, Yc, Zc, diameter)
Definition: sdf.py:85
sdf.yPlane.zc
zc
Definition: sdf.py:56
sdf.Sphere.zc
zc
Definition: sdf.py:151
sdf.hess_sdf
def hess_sdf(t, x, y, z, tx, ty, tz)
Definition: sdf.py:19
sdf.yPlane.sDF
def sDF(shift, y)
Definition: sdf.py:25
sdf.yPlane.Zc
Zc
Definition: sdf.py:51
sdf.Sphere.hessSdf
def hessSdf(self, x, y, z)
Definition: sdf.py:181
sdf.CylinderZ.Yc
Yc
Definition: sdf.py:88
sdf.CylinderZ.radius
radius
Definition: sdf.py:97
sdf.yPlane.gradSdf
def gradSdf()
Definition: sdf.py:28
sdf.Sphere.yc
yc
Definition: sdf.py:150
sdf.Sphere.Zc
Zc
Definition: sdf.py:146
sdf.CylinderZ.gradSdf
def gradSdf(xc, yc, x, y)
Definition: sdf.py:44
sdf.Sphere.Xc
Xc
Definition: sdf.py:144
sdf.Sphere.gradSdf
def gradSdf(self, x, y, z)
Definition: sdf.py:165
sdf.CylinderZ.sDF
def sDF(r, xc, yc, x, y)
Definition: sdf.py:39
sdf.yPlane.hessSdf
def hessSdf()
Definition: sdf.py:32
sdf.CylinderZ.Zc
Zc
Definition: sdf.py:89
sdf.CylinderZ.yc
yc
Definition: sdf.py:93
sdf.Sphere.xc
xc
Definition: sdf.py:149
sdf.CylinderZ
Definition: sdf.py:37
sdf.Sphere
Definition: sdf.py:141
sdf.yPlane.Xc
Xc
Definition: sdf.py:49
sdf.Sphere.radius
radius
Definition: sdf.py:154
sdf.yPlane.__init__
def __init__(self, Xc, Yc, Zc, shift)
Definition: sdf.py:47
sdf.yPlane.shift
shift
Definition: sdf.py:59
sdf.CylinderZ.Xc
Xc
Definition: sdf.py:87
sdf.sdf
def sdf(t, x, y, z, tx, ty, tz)
Definition: sdf.py:11
sdf.yPlane.Yc
Yc
Definition: sdf.py:50
sdf.Sphere.__init__
def __init__(self, Xc, Yc, Zc, diameter)
Definition: sdf.py:142
sdf.CylinderZ.zc
zc
Definition: sdf.py:94
sdf.yPlane.xc
xc
Definition: sdf.py:54
sdf.yPlane.yc
yc
Definition: sdf.py:55
sdf.Sphere.sDF
def sDF(self, x, y, z)
Definition: sdf.py:156
sdf.grad_sdf
def grad_sdf(t, x, y, z, tx, ty, tz)
Definition: sdf.py:15
sdf.CylinderZ.xc
xc
Definition: sdf.py:92
sdf.CylinderZ.hessSdf
def hessSdf(xc, yc, x, y)
Definition: sdf.py:53