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

20 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-28 15:20 +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 beamme.core.conf import ElementType as _ElementType 

25from beamme.core.material import Material as _Material 

26 

27 

28class Element: 

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

30 

31 # Type of this element. 

32 element_type: _ElementType | None = None 

33 

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

35 # Global index of this element in a mesh. 

36 self.i_global: None | int = None 

37 

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

39 if nodes is None: 

40 self.nodes = [] 

41 else: 

42 self.nodes = nodes.copy() 

43 

44 # Material of this element. 

45 self.material = material 

46 

47 def flip(self): 

48 """Reverse the nodes of this element. 

49 

50 This is usually used when reflected. 

51 """ 

52 raise NotImplementedError( 

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

54 ) 

55 

56 def replace_node(self, old_node, new_node): 

57 """Replace old_node with new_node.""" 

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

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

60 if node == old_node: 

61 self.nodes[i] = new_node 

62 break 

63 else: 

64 raise ValueError( 

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

66 ) 

67 

68 def check(self) -> None: 

69 """Perform consistency checks for the element. 

70 

71 This can be overwritten in the derived classes. 

72 """ 

73 pass