Coverage for src/beamme/core/element.py: 68%

22 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-06-08 11:03 +0000

1# The MIT License (MIT) 

2# 

3# Copyright (c) 2018-2026 BeamMe 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 typing import Any as _Any 

25 

26from beamme.core.material import Material as _Material 

27 

28 

29class Element: 

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

31 

32 def __init__(self, nodes=None, material: _Material | None = None) -> None: 

33 # Global index of this element in a mesh. 

34 self.i_global: None | int = None 

35 

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

37 if nodes is None: 

38 self.nodes = [] 

39 else: 

40 self.nodes = nodes.copy() 

41 

42 # Material of this element. 

43 self.material = material 

44 

45 # VTK cell data for this element. 

46 self.vtk_cell_data: _Any = {} 

47 

48 def flip(self): 

49 """Reverse the nodes of this element. 

50 

51 This is usually used when reflected. 

52 """ 

53 raise NotImplementedError( 

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

55 ) 

56 

57 def replace_node(self, old_node, new_node): 

58 """Replace old_node with new_node.""" 

59 

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

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

62 if node == old_node: 

63 self.nodes[i] = new_node 

64 break 

65 else: 

66 raise ValueError( 

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

68 ) 

69 

70 def check(self) -> None: 

71 """Perform consistency checks for the element. 

72 

73 This can be overwritten in the derived classes. 

74 """ 

75 pass 

76 

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

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

79 beam.""" 

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