Coverage for mpcforces_extractor\datastructure\test_rigids.py: 96%
25 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-01 11:08 +0100
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-01 11:08 +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 # Test the init method
14 mpc = MPC(
15 element_id=1,
16 mpc_config=MPC_CONFIG.RBE2,
17 master_node=0,
18 nodes=[1, 2],
19 dofs="123",
20 )
21 self.assertEqual(mpc.element_id, 1)
22 self.assertEqual(mpc.nodes, [1, 2])
23 self.assertEqual(mpc.dofs, "123")
25 def test_sum_forces_by_connected_parts(self):
26 node_id2force = {
27 1: [1, 1, 1, 0, 0, 0],
28 2: [2, 2, 2, 0, 0, 0],
29 }
31 node1 = Node(
32 node_id=1,
33 coords=[0, 0, 0],
34 )
35 node2 = Node(
36 node_id=2,
37 coords=[0, 0, 0],
38 )
39 node3 = Node(
40 node_id=3,
41 coords=[0, 0, 0],
42 )
43 node4 = Node(
44 node_id=4,
45 coords=[0, 0, 0],
46 )
47 Element.reset_graph()
48 Element(1, 1, [node1, node2, node3, node4])
50 mpc = MPC(
51 element_id=10,
52 mpc_config=MPC_CONFIG.RBE2,
53 master_node=0,
54 nodes=[node1, node2],
55 dofs="123",
56 )
58 subcase = Subcase(1, 1)
59 subcase.node_id2forces = node_id2force
61 forces = mpc.get_part_id2force(subcase)
62 self.assertTrue(forces[1] == [3, 3, 3, 0, 0, 0])
65if __name__ == "__main__":
66 unittest.main()