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):
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 NoIndenter:
26
27  def sDF(self, x, y, z):
28  return np.ones_like(x)
29
31  zeros = np.zeros_like(x)
32  zeros = zeros.reshape((-1,1))
33
34  grad_array = np.hstack([zeros, zeros, zeros])
36
37  def hessSdf(self,x, y,z):
38  zeros = np.zeros_like(x)
39  zeros = zeros.reshape((-1,1))
40
41  hess_array = np.hstack([zeros, zeros, zeros, zeros, zeros, zeros])
42
43  # xx, yx, zx, yy, zy, zz
44  return hess_array
45
46 class yPlane:
47  def __init__(self,Xc,Yc,Zc,shift):
48  # Initial Centroid
49  self.Xc = Xc
50  self.Yc = Yc
51  self.Zc = Zc
52
53  # Current Centroid
54  self.xc = Xc
55  self.yc = Yc
56  self.zc = Zc
57
58  # Indenter Dimensions
59  self.shift = shift
60
61
62  def sDF(self, x, y, z):
63  return np.subtract(y,self.shift)
64
66  dx = np.zeros_like(x)
67  dy = np.ones_like(y)
68  dz = np.zeros_like(z)
69  dx = dx.reshape((-1,1))
70  dy = dy.reshape((-1,1))
71  dz = dz.reshape((-1,1))
72  grad_array = np.hstack([dx, dy, dz])
74
75  def hessSdf(self,x, y,z):
76  zeros = np.zeros_like(x)
77  zeros = zeros.reshape((-1,1))
78
79  hess_array = np.hstack([zeros, zeros, zeros, zeros, zeros, zeros])
80
81  # xx, yx, zx, yy, zy, zz
82  return hess_array
83
84 class CylinderZ:
85  def __init__(self, Xc, Yc, Zc, diameter):
86  # Initial Centroid
87  self.Xc = Xc
88  self.Yc = Yc
89  self.Zc = Zc
90
91  # Current Centroid
92  self.xc = Xc
93  self.yc = Yc
94  self.zc = Zc
95
96  # Indenter Dimensions
98
99  def sDF(self, x, y, z):
100  a = (x-self.xc)**2 + (y-self.yc)**2
102
104  self.dNormal = self.hessSdf(x,y,z)
105
106  return gap
107
108  def gradSdf(self, x, y, z):
109  a = (x-self.xc)**2 + (y-self.yc)**2
110  c_val = np.sqrt(a)
111  c_val_A = 1./c_val
112  c_val_dx = c_val_A * (x-self.xc)
113  c_val_dy = c_val_A * (y-self.yc)
114  c_val_dz = np.zeros_like(c_val_dy)
115  # x, y, z
116  c_val_dx = c_val_dx.reshape((-1,1))
117  c_val_dy = c_val_dy.reshape((-1,1))
118  c_val_dz = c_val_dz.reshape((-1,1))
121
122  def hessSdf(self, x, y, z):
123  a = (x-self.xc)**2 + (y-self.yc)**2
124  c_val = np.sqrt(a)
125  c_val_A = 1./c_val
126  c_val_B = 1./(a**(3./2.))
127  Hxx = c_val_A - c_val_B * (x-self.xc)**2
128  Hxy = -c_val_B * (x-self.xc)*(y-self.yc)
129  Hyy = c_val_A - c_val_B * (y-self.yc)**2
130
131  Hxx = Hxx.reshape((-1,1))
132  Hzx = np.zeros_like(Hxx)
133  Hxy = Hxy.reshape((-1,1))
134  Hyy = Hyy.reshape((-1,1))
135  Hzy = np.zeros_like(Hxx)
136  Hzz = np.zeros_like(Hxx)
137  hess_array = np.hstack([Hxx, Hxy, Hzx, Hyy, Hzy, Hzz])
138
139  return hess_array
140
141 class Sphere:
142  def __init__(self, Xc, Yc, Zc, diameter):
143  # Initial Centroid
144  self.Xc = Xc
145  self.Yc = Yc
146  self.Zc = Zc
147
148  # Current Centroid
149  self.xc = Xc
150  self.yc = Yc
151  self.zc = Zc
152
153  # Indenter Dimensions
155
156  def sDF(self, x, y, z):
157  dx = np.subtract(x, self.xc)
158  dy = np.subtract(y, self.yc)
159  dz = np.subtract(z, self.zc)
160  a = (dx)**2+(dy)**2 + (dz)**2
161  gap = np.sqrt(a) - self.radius
162
163  return gap
164
166  a = (x-self.xc)**2 + (y-self.yc)**2 + (z-self.zc)**2
167  c_val = np.sqrt(a)
168  c_val_A = 1./c_val
169  c_val_dx = c_val_A * (x-self.xc)
170  c_val_dy = c_val_A * (y-self.yc)
171  c_val_dz = c_val_A * (z-self.zc)
172  # x, y, z
173  #size = np.size(x)
175  c_val_dx = c_val_dx.reshape((-1,1))
176  c_val_dy = c_val_dy.reshape((-1,1))
177  c_val_dz = c_val_dz.reshape((-1,1))
180
181  def hessSdf(self,x, y, z):
182  x = x-self.xc
183  y = y-self.yc
184  z = z-self.zc
185  Hxx = -x**2/(x**2 + y**2 + z**2)**(3/2) + 1/np.sqrt(x**2 + y**2 + z**2)
186  Hzx = -x*z/(x**2 + y**2 + z**2)**(3/2)
187  Hxy = -x*y/(x**2 + y**2 + z**2)**(3/2)
188  Hyy = -y**2/(x**2 + y**2 + z**2)**(3/2) + 1/np.sqrt(x**2 + y**2 + z**2)
189  Hzy = -y*z/(x**2 + y**2 + z**2)**(3/2)
190  Hzz = -z**2/(x**2 + y**2 + z**2)**(3/2) + 1/np.sqrt(x**2 + y**2 + z**2)
191  # xx, yx, zx, yy, zy, zz
192  Hxx = Hxx.reshape((-1,1))
193  Hzx = Hzx.reshape((-1,1))
194  Hxy = Hxy.reshape((-1,1))
195  Hyy = Hyy.reshape((-1,1))
196  Hzy = Hzy.reshape((-1,1))
197  Hzz = Hzz.reshape((-1,1))
198  hess_array = np.hstack([Hxx, Hxy, Hzx, Hyy, Hzy, Hzz])
199
200  return hess_array
201
202
203
204 # Define Indenters below
205 r = 1
206
207 list_indenters = []
208 list_indenters.append(NoIndenter())
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.CylinderZ.dNormal
dNormal
Definition: sdf.py:104
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
Definition: sdf.py:97
Definition: sdf.py:28
sdf.Sphere.yc
yc
Definition: sdf.py:150
sdf.Sphere.Zc
Zc
Definition: sdf.py:146
sdf.CylinderZ.normal
normal
Definition: sdf.py:103
Definition: sdf.py:44
sdf.Sphere.Xc
Xc
Definition: sdf.py:144
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
Definition: sdf.py:30
Definition: sdf.py:154
sdf.NoIndenter.sDF
def sDF(self, x, y, z)
Definition: sdf.py:27
sdf.yPlane
Definition: sdf.py:24
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.NoIndenter
Definition: sdf.py:25