-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaterial.py
56 lines (47 loc) · 1.89 KB
/
material.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import dataclasses
from typing import Optional
import numpy as np
import jax.numpy as jnp
@dataclasses.dataclass
class Material:
""" Linear elasticity material constants.
Attributes:
youngs_modulus: The young's modulus of the material.
poissons_ratio: The poisson's ratio of the material.
delta_youngs_modulus: A small epsilon value of the void material. This is
added to ensure numerical stability during finite element analysis.
"""
youngs_modulus: float = 1.
poissons_ratio: float = 0.3
delta_youngs_modulus: Optional[float] = 1e-3
def compute_simp_material_modulus(density: jnp.ndarray,
mat_const: Material,
penal: float = 3.,
young_min: float = 1e-3)->jnp.ndarray:
"""
E = rho_min + E0*( density)^penal
Args:
density: Array of size (num_elems,) with values in range [0,1]
penal: SIMP penalization constant, usually assumes a value of 3
young_min: Small value added to the modulus to prevent matrix singularity
Returns: Array of size (num_elems,) which contain the penalized modulus
at each element
"""
return young_min + mat_const.youngs_modulus*(density**penal)
def projection_filter(density: jnp.ndarray,
beta: float,
eta: float=0.5
)->jnp.ndarray:
"""Threshold project the density, pushing the values towards 0/1.
Args:
density: Array of size (num_elems,) that are in [0,1] that contain the
density of the elements.
beta: Sharpness of projection (typically ~ 1-32). Larger value indicates
a sharper projection.
eta: Center value about which the values are projected.
Returns: The thresholded density value array of size (num_elems,).
"""
v1 = np.tanh(eta*beta)
nm = v1 + jnp.tanh(beta*(density-eta))
dnm = v1 + jnp.tanh(beta*(1.-eta))
return nm/dnm