Coverage for mpcforces_extractor\datastructure\rigids.py: 98%

46 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-07 22:34 +0100

1from typing import Dict, List 

2from enum import Enum 

3from mpcforces_extractor.datastructure.entities import Node, Element 

4from mpcforces_extractor.datastructure.subcases import Subcase 

5 

6 

7class MPC_CONFIG(Enum): 

8 """ 

9 Enum to represent the MPC configuration 

10 """ 

11 

12 RBE2 = 1 

13 RBE3 = 2 

14 

15 

16class MPC: 

17 """ 

18 This class is a Multiple Point Constraint (MPC) class that is used to store the nodes and the dofs 

19 """ 

20 

21 id_2_instance: Dict[int, "MPC"] = {} 

22 

23 def __init__( 

24 self, 

25 *, 

26 element_id: int, 

27 mpc_config: MPC_CONFIG, 

28 master_node: Node, 

29 nodes: List, 

30 dofs: str, 

31 ): 

32 self.element_id: int = element_id 

33 self.mpc_config: MPC_CONFIG = mpc_config 

34 if master_node is None: 

35 print("Master_node2coords is None for element_id", element_id) 

36 self.master_node = master_node 

37 self.nodes: List = nodes 

38 self.dofs: int = dofs 

39 self.part_id2node_ids = {} 

40 if element_id in MPC.id_2_instance: 

41 print("MPC element_id already exists", element_id) 

42 MPC.id_2_instance[element_id] = self 

43 

44 @staticmethod 

45 def reset(): 

46 """ 

47 This method is used to reset the instances 

48 """ 

49 MPC.id_2_instance = {} 

50 

51 def get_part_id2force(self, subcase: Subcase) -> Dict: 

52 """ 

53 This method is used to get the forces for each part of the MPC (connected slave nodes) 

54 """ 

55 

56 if not self.part_id2node_ids: 

57 # Connected groups of nodes - get then the intersection with the slave nodes 

58 part_id2connected_node_ids = Element.get_part_id2node_ids_graph() 

59 part_id2node_ids = {} 

60 mpc_node_ids = [node.id for node in self.nodes] 

61 mpc_node_ids.append(self.master_node.id) 

62 for part_id, node_ids in part_id2connected_node_ids.items(): 

63 part_id2node_ids[part_id] = list( 

64 set(node_ids).intersection(mpc_node_ids) 

65 ) 

66 

67 self.part_id2node_ids = part_id2node_ids 

68 

69 # Calculate the summed forces for each part 

70 part_id2forces = {} 

71 for part_id, node_ids in self.part_id2node_ids.items(): 

72 sum_forces = [0, 0, 0] 

73 if subcase is not None: 

74 sum_forces = subcase.get_sum_forces(node_ids) 

75 part_id2forces[part_id] = sum_forces 

76 return part_id2forces 

77 

78 def get_subcase_id2part_id2force(self) -> Dict: 

79 """ 

80 This method is used to get the forces for each part of the MPC (connected slave nodes) 

81 """ 

82 

83 subcase_id2part_id2forces = {} 

84 for subcase in Subcase.subcases: 

85 part_id2forces = self.get_part_id2force(subcase) 

86 subcase_id2part_id2forces[subcase.subcase_id] = part_id2forces 

87 return subcase_id2part_id2forces