Ejemplo n.º 1
0
class unittest_get_all_connectivity(TestCase):
    """unittest for Mesh and Element get_all_connectivity methods. Indirect test add_element """

    def setUp(self):
        self.mesh = Mesh()
        self.mesh.element["Triangle3"] = ElementMat(nb_node_per_element=3)
        self.mesh.element["Segment2"] = ElementMat(nb_node_per_element=2)
        self.mesh.add_element([2, 1, 0], "Triangle3", group=int(3))
        self.mesh.add_element([1, 2, 3], "Triangle3", group=int(2))
        self.mesh.add_element([3, 1, 4], "Triangle3", group=int(2))
        self.mesh.add_element([0, 1], "Segment2", group=int(3))

        self.mesh.node = NodeMat()
        self.mesh.node.add_node([0, 0])
        self.mesh.node.add_node([1, 0])
        self.mesh.node.add_node([0, 1])
        self.mesh.node.add_node([1, -1])
        self.mesh.node.add_node([2, -1])

    def test_ElementMat_NodeMat_1seg(self):
        """unittest with ElementDict and NodeMat objects, get 1 segment"""
        tag_test = self.mesh.add_element([2, 1], "Segment2", group=int(3))
        result = self.mesh.get_connectivity(tag_test)
        solution = np.array([2, 1])
        testA = np.sum(abs(result - solution))
        msg = "Wrong output: returned " + str(result) + ", expected: " + str(solution)
        DELTA = 1e-10
        self.assertAlmostEqual(testA, 0, msg=msg, delta=DELTA)

    def test_ElementMat_NodeMat_1tgl(self):
        """unittest with ElementDict and NodeMat objects, with input None"""
        result = self.mesh.get_connectivity(None)

        testA = result is None
        msg = "Wrong result: returned " + str(result) + ", expected: " + str(None)
        self.assertTrue(testA, msg=msg)

    def test_ElementMat_NodeMat_1seg_stupid(self):
        """unittest with ElementDict and NodeMat objects, with only 1 segment"""
        result = self.mesh.get_connectivity(
            -99999
        )  # We test what happened with stupid entry
        # Check result
        testA = result is None
        msg = "Wrong result: returned " + str(result) + ", expected: " + str(None)
        self.assertTrue(testA, msg=msg)
Ejemplo n.º 2
0
class unittest_get_coord(TestCase):
    """unittest for NodeMat get_node methods"""
    def setUp(self):
        self.mesh = Mesh()
        self.mesh.element["Triangle3"] = ElementMat(nb_node_per_element=3)
        self.mesh.node = NodeMat()
        self.mesh.node.add_node(np.array([0, 0]))
        self.mesh.node.add_node(np.array([1, 0]))
        self.mesh.node.add_node(np.array([1, 2]))
        self.mesh.node.add_node(np.array([2, 3]))

        self.mesh.add_element(np.array([0, 1, 2]), "Triangle3")
        self.mesh.add_element(np.array([1, 2, 3]), "Triangle3")

    def test_NodeMat_1node(self):
        """unittest for a node"""
        node_tags = self.mesh.get_connectivity(1)
        # Method test 1
        coord = self.mesh.node.get_coord(node_tags)
        # Check result
        solution = np.array([[1, 0], [1, 2], [2, 3]])
        testA = np.sum(abs(solution - coord))
        msg = "Wrong output: returned " + str(coord) + ", expected: " + str(
            solution)
        DELTA = 1e-10
        self.assertAlmostEqual(testA, 0, msg=msg, delta=DELTA)

    def test_NodeMat_false(self):
        """unittest for a false node tag"""

        coord = self.mesh.node.get_coord(-999)
        solution = None
        testA = coord is None
        msg = "Wrong out: returned " + str(coord) + ", expected: " + str(
            solution)
        self.assertTrue(testA, msg=msg)

    def test_NodeMat_None(self):
        """unittest for a None node tag"""

        coord = self.mesh.node.get_coord(None)
        solution = None
        testA = coord is None
        msg = "Wrong output: returned " + str(coord) + ", expected: " + str(
            solution)
        self.assertTrue(testA, msg=msg)