Coverage for mpcforces_extractor\datastructure\rigids.py: 98%
45 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-04 17:32 +0100
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-04 17:32 +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
7class MPC_CONFIG(Enum):
8 """
9 Enum to represent the MPC configuration
10 """
12 RBE2 = 1
13 RBE3 = 2
16class MPC:
17 """
18 This class is a Multiple Point Constraint (MPC) class that is used to store the nodes and the dofs
19 """
21 id_2_instance: Dict[int, "MPC"] = {}
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
44 @staticmethod
45 def reset():
46 """
47 This method is used to reset the instances
48 """
49 MPC.id_2_instance = {}
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 """
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 slave_node_ids = [node.id for node in self.nodes]
61 for part_id, node_ids in part_id2connected_node_ids.items():
62 part_id2node_ids[part_id] = list(
63 set(node_ids).intersection(slave_node_ids)
64 )
66 self.part_id2node_ids = part_id2node_ids
68 # Calculate the summed forces for each part
69 part_id2forces = {}
70 for part_id, node_ids in self.part_id2node_ids.items():
71 sum_forces = [0, 0, 0]
72 if subcase is not None:
73 sum_forces = subcase.get_sum_forces(node_ids)
74 part_id2forces[part_id] = sum_forces
75 return part_id2forces
77 def get_subcase_id2part_id2force(self) -> Dict:
78 """
79 This method is used to get the forces for each part of the MPC (connected slave nodes)
80 """
82 subcase_id2part_id2forces = {}
83 for subcase in Subcase.subcases:
84 part_id2forces = self.get_part_id2force(subcase)
85 subcase_id2part_id2forces[subcase.subcase_id] = part_id2forces
86 return subcase_id2part_id2forces