v0.14.0
sdf_ydirection.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  for indenter in list_indenters[:]:
14  updatePosition(t,indenter)
15  return list_indenters[0].sDF(x,y,z)
16 
17 
18 def grad_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
19  return list_indenters[0].gradSdf(x,y,z)
20 
21 
22 def hess_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
23  return list_indenters[0].hessSdf(x,y,z)
24 
25 # Example Indenters
26 
27 class yPlane:
28  def __init__(self,Xc,Yc,Zc,shift,indentationDepth):
29  # Initial time
30  self.t = 0
31 
32  # Initial Centroid
33  self.Xc = Xc
34  self.Yc = Yc
35  self.Zc = Zc
36 
37  # Current Centroid
38  self.xc = Xc
39  self.yc = Yc
40  self.zc = Zc
41 
42  # Indenter Dimensions
43  self.shift = shift
44  self.depth = indentationDepth
45 
46 
47  def sDF(self, x, y, z):
48  return np.subtract(y,self.shift)
49 
50  def gradSdf(self, x, y, z):
51  dx = np.zeros_like(x).reshape((-1, 1))
52  dy = np.ones_like(y).reshape((-1, 1))
53  dz = np.zeros_like(z).reshape((-1, 1))
54  return np.hstack([dx, dy, dz])
55 
56  def hessSdf(self, x, y, z):
57  zeros = np.zeros_like(x).reshape((-1, 1))
58  return np.hstack([zeros for _ in range(6)]) # xx, yx, zx, yy, zy, zz
59 
60 class CylinderZ:
61  def __init__(self, Xc, Yc, Zc, diameter, indentationDepth):
62  # Initial time
63  self.t = 0
64 
65  # Initial Centroid
66  self.Xc = Xc
67  self.Yc = Yc
68  self.Zc = Zc
69 
70  # Current Centroid
71  self.xc = Xc
72  self.yc = Yc
73  self.zc = Zc
74 
75  # Indenter Dimensions
76  self.radius = diameter/2
77  self.depth = indentationDepth
78 
79  def sDF(self, x, y, z):
80  return np.sqrt((x - self.xc)**2 + (y - self.yc)**2) - self.radius
81 
82  def gradSdf(self, x, y, z):
83  a = (x-self.xc)**2 + (y-self.yc)**2
84  c_val_A = 1./np.sqrt(a)
85  c_val_dx = c_val_A * (x-self.xc)
86  c_val_dy = c_val_A * (y-self.yc)
87  c_val_dz = np.zeros_like(c_val_dy)
88  # x, y, z
89  return np.hstack([c_val_dx.reshape((-1,1)), c_val_dy.reshape((-1,1)), c_val_dz.reshape((-1,1))])
90 
91  def hessSdf(self, x, y, z):
92  a = (x-self.xc)**2 + (y-self.yc)**2
93  c_val_A = 1./np.sqrt(a)
94  c_val_B = 1./(a**(3./2.))
95  Hxx = c_val_A - c_val_B * (x-self.xc)**2
96  Hxy = -c_val_B * (x-self.xc)*(y-self.yc)
97  Hyy = c_val_A - c_val_B * (y-self.yc)**2
98  zeros = np.zeros_like(Hxx).reshape((-1,1))
99  # Hxx, Hxy, Hzx, Hyy, Hzy, Hzz
100  return np.hstack([Hxx.reshape((-1,1)), Hxy.reshape((-1,1)), zeros, Hyy.reshape((-1,1)), zeros, zeros])
101 
102  return hess_array
103 
104 class Sphere:
105  def __init__(self, Xc, Yc, Zc, diameter, indentationDepth):
106  # Initial time
107  self.t = 0
108 
109  # Initial Centroid
110  self.Xc = Xc
111  self.Yc = Yc
112  self.Zc = Zc
113 
114  # Current Centroid
115  self.xc = Xc
116  self.yc = Yc
117  self.zc = Zc
118 
119  # Indenter Dimensions
120  self.radius = diameter/2
121 
122  def sDF(self, x, y, z):
123  return np.sqrt((x - self.xc)**2 + (y - self.yc)**2 + (z - self.zc)**2) - self.radius
124 
125  def gradSdf(self, x, y, z):
126  a = (x-self.xc)**2 + (y-self.yc)**2 + (z-self.zc)**2
127  c_val_A = 1./np.sqrt(a)
128  c_val_dx = c_val_A * (x-self.xc)
129  c_val_dy = c_val_A * (y-self.yc)
130  c_val_dz = c_val_A * (z-self.zc)
131  # x, y, z
132  return np.hstack([c_val_dx.reshape((-1,1)), c_val_dy.reshape((-1,1)), c_val_dz.reshape((-1,1))])
133 
134  def hessSdf(self, x, y, z):
135  x, y, z = x-self.xc, y-self.yc, z-self.zc
136  denom = (x**2 + y**2 + z**2)**(3/2)
137  sqrt_denom = np.sqrt(x**2 + y**2 + z**2)
138  Hxx = -x**2/denom + 1/sqrt_denom
139  Hzx = -x*z/denom
140  Hxy = -x*y/denom
141  Hyy = -y**2/denom + 1/sqrt_denom
142  Hzy = -y*z/denom
143  Hzz = -z**2/denom + 1/sqrt_denom
144  # xx, yx, zx, yy, zy, zz
145  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))])
146 
147 # Define Indenter motion
148 def yDirection(t, obj):
149  offset = (t / indentationEndTime) if (t <= indentationEndTime) else 1
150  obj.yc = obj.Yc + (obj.depth * offset) if (obj.Yc < 0) else obj.Yc - (obj.depth * offset)
151  obj.xc, obj.zc, obj.t = obj.Xc, obj.Zc, t
152  return 0
153 
154 def updatePosition(t, obj):
155  return 0 if obj.t == t else yDirection(t, obj)
156 
157 
158 # Define Indenter geometry below
159 # radius
160 r = 1
161 # Define Indenter motion
162 # Time at which full indentation depth is reached (linear)
163 indentationEndTime = 1
164 # Depth of indentation of moving indenter
165 indentationDepth = 0
166 
167 list_indenters = []
168 list_indenters.append(CylinderZ(0.0,-0.5-r, 0.0, 2*r, 0))
sdf_ydirection.yPlane.t
t
Definition: sdf_ydirection.py:30
sdf_ydirection.Sphere.sDF
def sDF(self, x, y, z)
Definition: sdf_ydirection.py:122
sdf_ydirection.CylinderZ.zc
zc
Definition: sdf_ydirection.py:73
sdf_ydirection.yPlane.zc
zc
Definition: sdf_ydirection.py:40
sdf_ydirection.CylinderZ.hessSdf
def hessSdf(self, x, y, z)
Definition: sdf_ydirection.py:91
sdf_ydirection.hess_sdf
def hess_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id)
Definition: sdf_ydirection.py:22
sdf_ydirection.yDirection
def yDirection(t, obj)
Definition: sdf_ydirection.py:148
sdf_ydirection.Sphere.gradSdf
def gradSdf(self, x, y, z)
Definition: sdf_ydirection.py:125
sdf_ydirection.Sphere.__init__
def __init__(self, Xc, Yc, Zc, diameter, indentationDepth)
Definition: sdf_ydirection.py:105
sdf_ydirection.yPlane.__init__
def __init__(self, Xc, Yc, Zc, shift, indentationDepth)
Definition: sdf_ydirection.py:28
sdf_ydirection.yPlane.shift
shift
Definition: sdf_ydirection.py:43
sdf_ydirection.CylinderZ.t
t
Definition: sdf_ydirection.py:63
sdf_ydirection.yPlane.yc
yc
Definition: sdf_ydirection.py:39
sdf_ydirection.CylinderZ.Zc
Zc
Definition: sdf_ydirection.py:68
sdf_ydirection.yPlane.hessSdf
def hessSdf(self, x, y, z)
Definition: sdf_ydirection.py:56
sdf_ydirection.yPlane.Xc
Xc
Definition: sdf_ydirection.py:33
sdf_ydirection.CylinderZ.__init__
def __init__(self, Xc, Yc, Zc, diameter, indentationDepth)
Definition: sdf_ydirection.py:61
sdf_ydirection.Sphere
Definition: sdf_ydirection.py:104
sdf_ydirection.Sphere.Zc
Zc
Definition: sdf_ydirection.py:112
sdf_ydirection.CylinderZ.xc
xc
Definition: sdf_ydirection.py:71
sdf_ydirection.Sphere.radius
radius
Definition: sdf_ydirection.py:120
sdf_ydirection.CylinderZ.yc
yc
Definition: sdf_ydirection.py:72
sdf_ydirection.Sphere.xc
xc
Definition: sdf_ydirection.py:115
sdf_ydirection.Sphere.Yc
Yc
Definition: sdf_ydirection.py:111
sdf_ydirection.CylinderZ.sDF
def sDF(self, x, y, z)
Definition: sdf_ydirection.py:79
sdf_ydirection.yPlane.Yc
Yc
Definition: sdf_ydirection.py:34
sdf_ydirection.sdf
def sdf(delta_t, t, x, y, z, tx, ty, tz, block_id)
Definition: sdf_ydirection.py:12
sdf_ydirection.yPlane.gradSdf
def gradSdf(self, x, y, z)
Definition: sdf_ydirection.py:50
sdf_ydirection.Sphere.yc
yc
Definition: sdf_ydirection.py:116
sdf_ydirection.updatePosition
def updatePosition(t, obj)
Definition: sdf_ydirection.py:154
sdf_ydirection.yPlane
Definition: sdf_ydirection.py:27
sdf_ydirection.CylinderZ.depth
depth
Definition: sdf_ydirection.py:77
sdf_ydirection.CylinderZ
Definition: sdf_ydirection.py:60
sdf_ydirection.CylinderZ.Xc
Xc
Definition: sdf_ydirection.py:66
sdf_ydirection.CylinderZ.gradSdf
def gradSdf(self, x, y, z)
Definition: sdf_ydirection.py:82
sdf_ydirection.CylinderZ.radius
radius
Definition: sdf_ydirection.py:76
sdf_ydirection.yPlane.sDF
def sDF(self, x, y, z)
Definition: sdf_ydirection.py:47
sdf_ydirection.Sphere.hessSdf
def hessSdf(self, x, y, z)
Definition: sdf_ydirection.py:134
sdf_ydirection.CylinderZ.Yc
Yc
Definition: sdf_ydirection.py:67
sdf_ydirection.Sphere.t
t
Definition: sdf_ydirection.py:107
sdf_ydirection.yPlane.depth
depth
Definition: sdf_ydirection.py:44
sdf_ydirection.grad_sdf
def grad_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id)
Definition: sdf_ydirection.py:18
sdf_ydirection.Sphere.zc
zc
Definition: sdf_ydirection.py:117
sdf_ydirection.Sphere.Xc
Xc
Definition: sdf_ydirection.py:110
sdf_ydirection.yPlane.Zc
Zc
Definition: sdf_ydirection.py:35
sdf_ydirection.yPlane.xc
xc
Definition: sdf_ydirection.py:38