Coverage for src/meshpy/core/material.py: 100%

28 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-28 04:21 +0000

1# The MIT License (MIT) 

2# 

3# Copyright (c) 2018-2025 MeshPy Authors 

4# 

5# Permission is hereby granted, free of charge, to any person obtaining a copy 

6# of this software and associated documentation files (the "Software"), to deal 

7# in the Software without restriction, including without limitation the rights 

8# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 

9# copies of the Software, and to permit persons to whom the Software is 

10# furnished to do so, subject to the following conditions: 

11# 

12# The above copyright notice and this permission notice shall be included in 

13# all copies or substantial portions of the Software. 

14# 

15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 

16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 

17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 

18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 

19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 

20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 

21# THE SOFTWARE. 

22"""This file implements basic classes to manage materials in MeshPy.""" 

23 

24import numpy as _np 

25 

26from meshpy.core.base_mesh_item import BaseMeshItem as _BaseMeshItem 

27 

28 

29class Material(_BaseMeshItem): 

30 """Base class for all materials.""" 

31 

32 def __init__(self, data=None, **kwargs): 

33 super().__init__(data=data, **kwargs) 

34 

35 def __deepcopy__(self, memo): 

36 """When deepcopy is called on a mesh, we do not want the materials to 

37 be copied, as this will result in multiple equal materials in the input 

38 file.""" 

39 

40 # Add this object to the memo dictionary. 

41 memo[id(self)] = self 

42 

43 # Return this object again, as no copy should be created. 

44 return self 

45 

46 

47class MaterialBeam(Material): 

48 """Base class for all beam materials.""" 

49 

50 def __init__( 

51 self, 

52 radius=-1.0, 

53 material_string=None, 

54 youngs_modulus=-1.0, 

55 nu=0.0, 

56 density=0.0, 

57 interaction_radius=None, 

58 **kwargs, 

59 ): 

60 """Set the material values that all beams have.""" 

61 super().__init__(**kwargs) 

62 

63 self.radius = radius 

64 self.material_string = material_string 

65 self.youngs_modulus = youngs_modulus 

66 self.nu = nu 

67 self.density = density 

68 self.radius = radius 

69 self.interaction_radius = interaction_radius 

70 self.area = None 

71 self.mom2 = None 

72 self.mom3 = None 

73 self.polar = None 

74 

75 def calc_area_stiffness(self): 

76 """Calculate the relevant stiffness terms and the area for the given 

77 beam.""" 

78 area = 4 * self.radius**2 * _np.pi * 0.25 

79 mom2 = self.radius**4 * _np.pi * 0.25 

80 mom3 = mom2 

81 polar = mom2 + mom3 

82 return area, mom2, mom3, polar