9 Returns rotation of vector about specified axis by specified angle
23 Coordinates of rotated vector
25 p_np, axis_np = np.array(p), np.array(axis)
26 ct, st = np.cos(theta), np.sin(theta)
27 p_dot_n = np.dot(p_np,axis_np)
28 n_cross_p = np.cross(axis_np, p_np)
30 return (1. - ct) * p_dot_n * axis_np + ct * p_np + st * n_cross_p
34 Returns size points on reference rectangle
47 Coordinates of center of rectangle
49 Length of rectangle in x-direction
51 Length of rectangle in y-direction
53 True if we include the center to the returned list (first point in the returned list will be the center if the flag is true)
61 p1 = [center[0] - Lx/2., center[1] - Ly/2., center[2]]
62 p2 = [center[0] + Lx/2., center[1] - Ly/2., center[2]]
63 p3 = [center[0] + Lx/2., center[1] + Ly/2., center[2]]
64 p4 = [center[0] - Lx/2., center[1] + Ly/2., center[2]]
66 return [p1, p2, p3, p4]
if not add_center
else [center, p1, p2, p3, p4]
70 Returns size points on reference triangle
86 Rotation axis: [0, 0, 1]
91 Coordinates of center of triangle
95 True if we include the center to the returned list (first point in the returned list will be the center if the flag is true)
100 Coordinates of points
103 rotate_axis = [0., 0., 1.]
107 points.append(center)
110 xi =
rotate(axis, i*2*np.pi/3., rotate_axis)
111 points.append([center[i] + radius * xi[i]
for i
in range(3)])
117 Returns size points on reference hexagon
133 Rotation axis: [0, 0, 1]
138 Coordinates of center of hexagon
142 True if we include the center to the returned list (first point in the returned list will be the center if the flag is true)
147 Coordinates of points
150 rotate_axis = [0., 0., 1.]
153 points.append(center)
156 xi =
rotate(axis, i*np.pi/3., rotate_axis)
157 points.append([center[i] + radius * xi[i]
for i
in range(3)])
163 Returns size points on reference concave polygon (we refer to it as drum)
165 Reference concave polygon:
168 + -------------------------------- +
174 + -------------------------------- +
180 Rotation axis: [0, 0, 1]
185 Coordinates of center of polygon
187 Radius of polygon (distance between center x and vertex v2)
189 Width of neck, i.e. distance between vertex v2 and v4
191 True if we include the center to the returned list (first point in the returned list will be the center if the flag is true)
196 Coordinates of points
199 rotate_axis = [0., 0., 1.]
201 x1 =
rotate(axis, np.pi/3., rotate_axis)
202 x2 =
rotate(axis, -np.pi/3., rotate_axis)
206 points.append(center)
209 points.append([center[i] + width*0.5*axis[i]
for i
in range(3)])
211 points.append([center[i] + radius*x1[i]
for i
in range(3)])
213 points.append([center[i] + radius*x1[i] - radius*axis[i]
for i
in range(3)])
215 points.append([center[i] - width*0.5*axis[i]
for i
in range(3)])
217 v6 = [center[i] + radius*x2[i]
for i
in range(3)]
218 points.append([v6[i] - radius*axis[i]
for i
in range(3)])
227 Returns true if particle p intersects or is near enough to existing particles
232 Coordinates of center and radius of particle [x,y,z,r]
234 List of center + radius of multiple particles. E.g. particles[0] is a list containing coordinates of center and radius.
236 Minimum distance between circle boundaries such that if two circles
241 True if particle intersects or is near enough to one of the particle in the list
243 if len(p) < 4:
raise Exception(
'p = {} must have atleast 4 elements'.format(p))
244 if len(particles) == 0:
raise Exception(
'particles = {} can not be empty'.format(particles))
245 if padding < 0.:
raise Exception(
'padding = {} can not be negative'.format(padding))
248 if len(q) < 4:
raise Exception(
'q = {} in particles must have atleast 4 elements'.format(q))
249 pq = np.array([p[i] - q[i]
for i
in range(3)])
250 if np.linalg.norm(pq) <= p[3] + q[3] + padding:
256 Returns true if particle p is sufficiently close or outside the rectangle (in 2d) or cuboid (in 3d)
261 Coordinates of center and radius of particle [x,y,z,r]
263 List of center + radius of multiple particles. E.g. particles[0] is a list containing coordinates of center and radius.
265 Minimum distance between circle boundaries such that if two circles
267 Coordinates of left-bottom and right-top corner points of rectangle (2d) or cuboid (3d). E.g. [x1 y1, z1, x2, y2, z2]
269 True if we are dealing with cuboid
274 True if particle intersects or is near enough to the rectangle
276 if len(p) < 4:
raise Exception(
'p = {} must have atleast 4 elements'.format(p))
277 if len(particles) == 0:
raise Exception(
'particles = {} can not be empty'.format(particles))
278 if padding < 0.:
raise Exception(
'padding = {} can not be negative'.format(padding))
279 if len(rect) < 6:
raise Exception(
'rect = {} must have 6 elements'.format(rect))
281 pr = [p[0] - p[3], p[1] - p[3], p[2], p[0] + p[3], p[1] + p[3], p[2]]
286 if pr[0] < rect[0] + padding
or pr[1] < rect[1] + padding
or pr[3] > rect[3] - padding
or pr[4] > rect[4] - padding:
288 if pr[2] < rect[2] + padding
or pr[5] > rect[5] - padding:
297 for e
in gmsh.model.getEntities():
298 bnd = gmsh.model.getBoundary([e])
299 nod = gmsh.model.mesh.getNodes(e[0], e[1])
300 ele = gmsh.model.mesh.getElements(e[0], e[1])
301 m[e] = (bnd, nod, ele)
309 gmsh.model.addDiscreteEntity(
310 e[0], e[1] + offset_entity,
311 [(abs(b[1]) + offset_entity) * int(math.copysign(1, b[1]))
for b
in m[e][0]])
313 for i
in range(0, len(m[e][1][1]), 3):
314 x = m[e][1][1][i] * tx
315 y = m[e][1][1][i + 1] * ty
316 z = m[e][1][1][i + 2] * tz
320 gmsh.model.mesh.addNodes(e[0], e[1] + offset_entity,
321 [n + offset_node
for n
in m[e][1][0]], coord)
322 gmsh.model.mesh.addElements(e[0], e[1] + offset_entity, m[e][2][0],
323 [[t + offset_element
for t
in typ]
for typ
in m[e][2][1]],
324 [[n + offset_node
for n
in typ]
for typ
in m[e][2][2]])
325 if (tx * ty * tz) < 0:
326 gmsh.model.mesh.reverse([(e[0], e[1] + offset_entity)])
329 """Rotate mesh by angle (in radians) around specified axis
332 m - mesh data dictionary
333 offset_entity - offset for entity numbers
334 offset_node - offset for node numbers
335 offset_element - offset for element numbers
336 angle - rotation angle in radians
337 axis - rotation axis vector (default is z-axis [0,0,1])
341 gmsh.model.addDiscreteEntity(
342 e[0], e[1] + offset_entity,
343 [(abs(b[1]) + offset_entity) * int(math.copysign(1, b[1]))
for b
in m[e][0]])
346 for i
in range(0, len(m[e][1][1]), 3):
347 xi = np.array([m[e][1][1][i], m[e][1][1][i + 1], m[e][1][1][i + 2]])
349 xi_rot =
rotate(xi, angle, axis)
351 coord.append(xi_rot[0])
352 coord.append(xi_rot[1])
353 coord.append(xi_rot[2])
355 gmsh.model.mesh.addNodes(e[0], e[1] + offset_entity,
356 [n + offset_node
for n
in m[e][1][0]], coord)
357 gmsh.model.mesh.addElements(e[0], e[1] + offset_entity, m[e][2][0],
358 [[t + offset_element
for t
in typ]
for typ
in m[e][2][1]],
359 [[n + offset_node
for n
in typ]
for typ
in m[e][2][2]])
362 """Translate mesh by vector xc
365 xc - translation vector [x, y, z]
368 nodeTags, coord, paramCoord = gmsh.model.mesh.getNodes()
369 numNodes = len(nodeTags)
372 translation_vector = np.array([xc[0], xc[1], xc[2]])
375 for i
in range(numNodes):
376 nodeTag = nodeTags[i]
377 old_coord = coord[3*i:3*(i+1)]
378 new_coord = old_coord + translation_vector
380 param = paramCoord[3*i:3*(i+1)]
if paramCoord
is not None and len(paramCoord) > 0
else []
381 gmsh.model.mesh.setNode(nodeTag, new_coord, param)
get_ref_drum_points(center, radius, width, add_center=False)
does_intersect_rect(p, particles, padding, rect, is_3d=False)
gmsh_transform(m, offset_entity, offset_node, offset_element, tx, ty, tz)
get_ref_triangle_points(center, radius, add_center=False)
gmsh_transform_general(m, offset_entity, offset_node, offset_element, angle, axis=[0, 0, 1])
get_ref_rect_points(center, Lx, Ly, add_center=False)
get_ref_hex_points(center, radius, add_center=False)
does_intersect(p, particles, padding)