def setUp(self):
     self.x = float(1.1)
     self.y = float(2.2)
     self.z = float(3.3)
     self.node_a = Node(1, self.x, self.y, self.z)
     self.node_b = Node(2, self.x + 1.0, self.y, self.z)
     self.node_c = Node(3, self.x, self.y + 1.0, self.z)
     self.config = ElmtConfig(ShapeType.Triangle, 1, False, False)
     self.comp_ID = 2
     self.element = Element.Create(self.config,
                                   [self.node_a, self.node_b, self.node_c],
                                   [self.comp_ID])
Example #2
0
 def setUp(self):
     self.nodeset = NodeSet()
     self.nodeset_def_len = 10
     for i in range(self.nodeset_def_len):
         id = i
         x = float(i)
         y = float(self.nodeset_def_len + i)
         z = float(self.nodeset_def_len**2 + i)
         n = Node(id, x, y, z)
         self.nodeset.add(n)
    def _initialize_nodes(self):
        self.nodes = []
        id_cnt = 0

        for y in range(self.ny):
            tmp = []
            for x in range(self.nx):
                tmp.append(
                    Node(id_cnt, self.x_points[x], self.y_points[y], 0.0))
                id_cnt += 1
            self.nodes.append(tmp)
Example #4
0
 def testNodeSetAdd(self):
     msg = self.getCN() + "::testNodeSetAdd: "
     new_node = Node(len(self.nodeset) + 1, 1.0, 2.0, 3.0)
     self.nodeset.add(new_node)
     try:
         self.assertTrue(new_node in self.nodeset)
         msg += "PASS"
         print(msg)
     except:
         msg += "FAIL"
         print(msg)
         raise
Example #5
0
 def testNodeDistance(self):
     msg = self.getCN() + "::testNodeDistance: "
     node = Node(self.id + 1, self.x + 1, self.y + 2, self.z + 2)
     distance = self.node.Distance(node)
     expected_distance = 3.0
     try:
         self.assertAlmostEqual(distance, expected_distance)
         msg += "PASS"
         print(msg)
     except:
         msg += "FAIL"
         print(msg)
         raise
Example #6
0
 def testMeshFieldAccess(self):
     msg = self.getCN() + "::testMeshFieldAccess: "
     self.nodeset = NodeSet()
     self.nodeset_def_len = 10
     for i in range(self.nodeset_def_len):
         id = i
         x = float(i)
         y = float(self.nodeset_def_len + i)
         z = float(self.nodeset_def_len**2 + i)
         n = Node(id, x, y, z)
         self.nodeset.add(n)
     try:
         self.expDim = 2
         self.spaceDim = 2
         self.nummode = 7
         self.verbose = False
         self.mesh.node = self.nodeset
         self.mesh.expDim = self.expDim
         self.mesh.spaceDim = self.spaceDim
         self.mesh.nummode = self.nummode
         self.mesh.verbose = self.verbose
         for node in self.nodeset:
             self.assertTrue(node in self.mesh.node)
         self.assertEqual(self.mesh.expDim, self.expDim)
         self.assertEqual(self.mesh.spaceDim, self.spaceDim)
         self.assertEqual(self.mesh.nummode, self.nummode)
         self.assertEqual(self.mesh.verbose, self.verbose)
         try:
             self.mesh.element = None
         except AttributeError:
             msg += "PASS"
             print(msg)
     except:
         msg += "FAIL"
         print(msg)
         raise
Example #7
0
 def setUp(self):
     self.id = int(1)
     self.x = float(1.1)
     self.y = float(2.2)
     self.z = float(3.3)
     self.node = Node(self.id, self.x, self.y, self.z)
Example #8
0
class TestNode(unittest.TestCase):
    def getCN(self):
        return self.__class__.__name__

    def setUp(self):
        self.id = int(1)
        self.x = float(1.1)
        self.y = float(2.2)
        self.z = float(3.3)
        self.node = Node(self.id, self.x, self.y, self.z)

    def testNodeConstructor(self):
        msg = self.getCN() + "::testNodeConstructor: "
        try:
            self.assertEqual(self.node.id, self.id)
            self.assertEqual(self.node.x, self.x)
            self.assertEqual(self.node.y, self.y)
            self.assertEqual(self.node.z, self.z)
            msg += "PASS"
            print(msg)
        except:
            msg += "FAIL"
            print(msg)
            raise

    def testNodeGetID(self):
        msg = self.__class__.__name__ + "::testNodeGetID: "
        try:
            self.assertEqual(self.node.GetID(), self.id)
            msg += "PASS"
            print(msg)
        except:
            msg += "FAIL"
            print(msg)
            raise

    def testNodeSetID(self):
        msg = self.getCN() + "::testNodeSetID: "
        self.id = 2
        self.node.SetID(self.id)
        try:
            self.assertEqual(self.node.GetID(), self.id)
            msg += "PASS"
            print(msg)
        except:
            msg += "FAIL"
            print(msg)
            raise

    def testNodeDistance(self):
        msg = self.getCN() + "::testNodeDistance: "
        node = Node(self.id + 1, self.x + 1, self.y + 2, self.z + 2)
        distance = self.node.Distance(node)
        expected_distance = 3.0
        try:
            self.assertAlmostEqual(distance, expected_distance)
            msg += "PASS"
            print(msg)
        except:
            msg += "FAIL"
            print(msg)
            raise

    def testNodeGetLoc(self):
        msg = self.getCN() + "::testNodeGetLoc: "
        expected_locations = [self.x, self.y, self.z]
        locations = self.node.GetLoc()
        try:
            for i in range(len(locations)):
                self.assertEqual(locations[i], expected_locations[i])
            msg += "PASS"
            print(msg)
        except:
            msg += "FAIL"
            print(msg)
            raise

    def testNodeAbs2(self):
        msg = self.getCN() + "::testNodeAbs2: "
        expected_abs2 = self.x**2 + self.y**2 + self.z**2
        abs2 = self.node.abs2()
        try:
            self.assertAlmostEqual(abs2, expected_abs2)
            msg += "PASS"
            print(msg)
        except:
            msg += "FAIL"
            print(msg)
            raise

    def testNodeFieldAccess(self):
        msg = self.getCN() + "::testNodeFieldAccess: "
        id = int(2)
        x = float(11.1)
        y = float(12.2)
        z = float(13.3)
        try:
            self.node.id = id
            self.node.x = x
            self.node.y = y
            self.node.z = z
            self.assertEqual(self.node.id, id)
            self.assertEqual(self.node.x, x)
            self.assertEqual(self.node.y, y)
            self.assertEqual(self.node.z, z)
            msg += "PASS"
            print(msg)
        except:
            msg += "FAIL"
            print(msg)
            raise