| 3 | import numpy as np |
| 4 | |
| 5 | class Material: |
| 6 | @classmethod |
| 7 | def create_isotropic(cls, dim, density, young, poisson): |
| 8 | """ Create an isotropic material. |
| 9 | |
| 10 | Args: |
| 11 | dim: Dimension of the ambient space (must be 2 or 3). |
| 12 | density: Material density. |
| 13 | young: Young's modulus. |
| 14 | poisson: Poisson's ratio |
| 15 | (must be in (-1, 0.5) in 3D and (-1, 1) in 2D). |
| 16 | """ |
| 17 | return Material(PyMesh.Material.create_isotropic( |
| 18 | dim, density, young, poisson)) |
| 19 | |
| 20 | @classmethod |
| 21 | def create_orthotropic(cls, density, young, poisson, shear): |
| 22 | """ Create an orthotropic material. |
| 23 | |
| 24 | Args: |
| 25 | desnity: Material density. |
| 26 | young: Array of Young's modulus, [young_x, young_y, young_z] |
| 27 | poisson: Array of Poisson's ratio, [poisson_yz, poisson_zy, |
| 28 | poisson_zx, poisson_xz, |
| 29 | poisson_xy, poisson_yx] |
| 30 | shear: Array of Shear modulus, [shear_yz, shear_zx, shear_xy] |
| 31 | """ |
| 32 | return Material(PyMesh.Material.create_orthotropic( |
| 33 | density, young, poisson, shear)) |
| 34 | |
| 35 | @classmethod |
| 36 | def create_element_wise_isotropic(cls, density, mesh, |
| 37 | young_attribute_name, poisson_attribute_name): |
| 38 | return Material(PyMesh.Material.create_element_wise_isotropic( |
| 39 | density, mesh.raw_mesh, |
| 40 | young_attribute_name, poisson_attribute_name)) |
| 41 | |
| 42 | def __init__(self, raw_material=None): |
| 43 | self.raw_material = raw_material |
| 44 | |
| 45 | def strain_to_stress(self, strain, coord=None): |
| 46 | if coord is None: |
| 47 | coord = np.zeros(self.dim) |
| 48 | return self.raw_material.strain_to_stress(strain, coord) |
| 49 | |
| 50 | def get_material_tensor(self, coord): |
| 51 | """ Return 4th order material tensor of size d x d x d x d evaluated at |
| 52 | coord. |
| 53 | """ |
| 54 | tensor = np.empty([self.dim, self.dim, self.dim, self.dim]) |
| 55 | indices = np.arange(self.dim) |
| 56 | I,J,K,L = np.meshgrid(indices, indices, indices, indices) |
| 57 | for i,j,k,l in zip(I.ravel(), J.ravel(), K.ravel(), L.ravel()): |
| 58 | tensor[i,j,k,l] = self.raw_material.get_material_tensor( |
| 59 | int(i),int(j),int(k),int(l),coord) |
| 60 | return tensor |
| 61 | |
| 62 | def get_density(self, coord): |
no outgoing calls
no test coverage detected