Coverage for mpcforces_extractor\datastructure\test_rigids.py: 97%
30 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-07 22:34 +0100
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-07 22:34 +0100
1import unittest
2from mpcforces_extractor.datastructure.rigids import MPC, MPC_CONFIG
3from mpcforces_extractor.datastructure.entities import Node, Element
4from mpcforces_extractor.datastructure.subcases import Subcase
7class TestRigids(unittest.TestCase):
8 def test_init(self):
9 """
10 Test the init method. Make sure all variables are set correctly (correct type)
11 """
13 Node.reset()
14 node1 = Node(
15 node_id=1,
16 coords=[0, 0, 0],
17 )
18 node2 = Node(
19 node_id=2,
20 coords=[0, 0, 0],
21 )
23 # Test the init method
24 mpc = MPC(
25 element_id=1,
26 mpc_config=MPC_CONFIG.RBE2,
27 master_node=node1,
28 nodes=[node2],
29 dofs="123",
30 )
31 self.assertEqual(mpc.element_id, 1)
32 self.assertEqual(mpc.nodes, [node2])
33 self.assertEqual(mpc.master_node, node1)
34 self.assertEqual(mpc.dofs, "123")
36 def test_sum_forces_by_connected_parts(self):
37 node_id2force = {
38 1: [1, 1, 1, 0, 0, 0],
39 2: [2, 2, 2, 0, 0, 0],
40 }
41 node0 = Node(
42 node_id=0,
43 coords=[0, 0, 0],
44 )
46 node1 = Node(
47 node_id=1,
48 coords=[0, 0, 0],
49 )
50 node2 = Node(
51 node_id=2,
52 coords=[0, 0, 0],
53 )
54 node3 = Node(
55 node_id=3,
56 coords=[0, 0, 0],
57 )
58 node4 = Node(
59 node_id=4,
60 coords=[0, 0, 0],
61 )
62 Element.reset_graph()
63 Element(1, 1, [node1, node2, node3, node4])
65 mpc = MPC(
66 element_id=10,
67 mpc_config=MPC_CONFIG.RBE2,
68 master_node=node0,
69 nodes=[node1, node2],
70 dofs="123",
71 )
73 subcase = Subcase(1, 1)
74 subcase.node_id2forces = node_id2force
76 forces = mpc.get_part_id2force(subcase)
77 self.assertTrue(forces[1] == [3, 3, 3, 0, 0, 0])
80if __name__ == "__main__":
81 unittest.main()