Coverage for src/meshpy/core/element.py: 85%

20 statements  

« prev     ^ index     » next       coverage.py v7.9.0, created at 2025-06-13 04:26 +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 module implements the class that represents one element in the Mesh.""" 

23 

24from meshpy.core.base_mesh_item import BaseMeshItem as _BaseMeshItem 

25 

26 

27class Element(_BaseMeshItem): 

28 """A base class for an FEM element in the mesh.""" 

29 

30 def __init__(self, nodes=None, material=None, **kwargs): 

31 super().__init__(**kwargs) 

32 

33 # List of nodes that are connected to the element. 

34 if nodes is None: 

35 self.nodes = [] 

36 else: 

37 self.nodes = nodes 

38 

39 # Material of this element. 

40 self.material = material 

41 

42 # VTK cell data for this element. 

43 self.vtk_cell_data = {} 

44 

45 def flip(self): 

46 """Reverse the nodes of this element. 

47 

48 This is usually used when reflected. 

49 """ 

50 raise NotImplementedError( 

51 f"The flip method is not implemented for {self.__class__}" 

52 ) 

53 

54 def replace_node(self, old_node, new_node): 

55 """Replace old_node with new_node.""" 

56 

57 # Look for old_node and replace it. If it is not found, throw error. 

58 for i, node in enumerate(self.nodes): 

59 if node == old_node: 

60 self.nodes[i] = new_node 

61 break 

62 else: 

63 raise ValueError( 

64 "The node that should be replaced is not in the current element" 

65 ) 

66 

67 def dump_element_specific_section(self, yaml_dict): 

68 """Add information of this element to specific section (e.g. STRUCTURE 

69 KNOTVECTORS for NURBS elements).""" 

70 

71 def get_vtk(self, vtk_writer_beam, vtk_writer_solid, **kwargs): 

72 """Add representation of this element to the vtk_writers for solid and 

73 beam.""" 

74 raise NotImplementedError("VTK output has to be implemented in the class!")