v0.14.0
Loading...
Searching...
No Matches
sdf_ydirection.py
Go to the documentation of this file.
1import math
2import 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
12def 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
18def grad_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
19 return list_indenters[0].gradSdf(x,y,z)
20
21
22def 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
27class 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
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
104class 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
148def 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
154def updatePosition(t, obj):
155 return 0 if obj.t == t else yDirection(t, obj)
156
157
158# Define Indenter geometry below
159# radius
160r = 1
161# Define Indenter motion
162# Time at which full indentation depth is reached (linear)
163indentationEndTime = 1
164# Depth of indentation of moving indenter
165indentationDepth = 0
166
167list_indenters = []
168list_indenters.append(CylinderZ(0.0,-0.5-r, 0.0, 2*r, 0))
__init__(self, Xc, Yc, Zc, diameter, indentationDepth)
__init__(self, Xc, Yc, Zc, diameter, indentationDepth)
__init__(self, Xc, Yc, Zc, shift, indentationDepth)
gradSdf(self, x, y, z)
hessSdf(self, x, y, z)
grad_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id)
hess_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id)
Definition sdf.py:1