Coverage for mpcforces_extractor\datastructure\subcases.py: 92%

26 statements  

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

1from typing import List 

2 

3 

4class Subcase: 

5 """ 

6 This class is used to store the subcase information 

7 The purpose of this class is to make multiple subcases available 

8 in the mpcforces_extractor 

9 """ 

10 

11 subcases = [] 

12 

13 def __init__(self, subcase_id: int, time: float): 

14 """ 

15 Constructor 

16 """ 

17 self.subcase_id = subcase_id 

18 self.time = time 

19 self.node_id2forces = {} 

20 Subcase.subcases.append(self) 

21 

22 def add_force(self, node_id: int, forces: List) -> None: 

23 """ 

24 This method is used to add the forces for a node 

25 """ 

26 self.node_id2forces[node_id] = forces 

27 

28 def get_sum_forces(self, node_ids: List) -> None: 

29 """ 

30 This method is used to sum the forces for all nodes 

31 """ 

32 sum_forces = [0, 0, 0, 0, 0, 0] 

33 for node_id in node_ids: 

34 forces = self.node_id2forces[node_id] 

35 sum_forces = [sf + f for sf, f in zip(sum_forces, forces)] 

36 return sum_forces 

37 

38 @staticmethod 

39 def get_subcase_by_id(subcase_id: int): 

40 """ 

41 This method is used to get a subcase by its id 

42 """ 

43 for subcase in Subcase.subcases: 

44 if subcase.subcase_id == subcase_id: 

45 return subcase 

46 print(f"No Subcase with id {id} was found.") 

47 return None 

48 

49 @staticmethod 

50 def reset(): 

51 """ 

52 This method is used to reset the subcases list 

53 """ 

54 Subcase.subcases = []