| 1 |
import numpy as np |
| 2 |
|
| 3 |
from ._cube import cube_hexa, cube_tetra |
| 4 |
|
| 5 |
|
| 6 |
def ball_hexa(n: int): |
| 7 |
a = 1 / np.sqrt(3) |
| 8 |
ls = np.linspace(-a, a, n + 1) |
| 9 |
nodes, cells = cube_hexa(ls, ls, ls) |
| 10 |
|
| 11 |
# Inflate the nodes towards the circle boundary. |
| 12 |
# Inflate each point such that the 2-norm of the new point is the max-norm of the |
| 13 |
# old. |
| 14 |
alpha = np.max(np.abs(nodes), axis=1) |
| 15 |
beta = np.linalg.norm(nodes, axis=1) |
| 16 |
idx = beta > 1.0e-13 |
| 17 |
nodes[idx] = (nodes[idx].T * (alpha[idx] / beta[idx])).T |
| 18 |
|
| 19 |
return nodes, cells |
| 20 |
|
| 21 |
|
| 22 |
def ball_tetra(n: int): |
| 23 |
a = 1 / np.sqrt(3) |
| 24 |
ls = np.linspace(-a, a, n + 1) |
| 25 |
nodes, cells = cube_tetra(ls, ls, ls) |
| 26 |
|
| 27 |
# Inflate the nodes towards the circle boundary. |
| 28 |
# Inflate each point such that the 2-norm of the new point is the max-norm of the |
| 29 |
# old. |
| 30 |
alpha = np.max(np.abs(nodes), axis=1) |
| 31 |
beta = np.linalg.norm(nodes, axis=1) |
| 32 |
idx = beta > 1.0e-13 |
| 33 |
nodes[idx] = (nodes[idx].T * (alpha[idx] / beta[idx])).T |
| 34 |
|
| 35 |
return nodes, cells |