def setUp(self): steel = Steel() # create a rectangular element self.width = 5 self.height = 3 self.node1 = Node([0, 0]) self.node2 = Node([self.width, 0]) self.node3 = Node([self.width, self.height]) self.node4 = Node([0, self.height]) self.element = FiniteElement( nodes=[self.node1, self.node2, self.node3, self.node4], material=steel, efs=[True, True, False, False, False, False])
def setUp(self): steel = Steel() section = Section() # create an FrameElement2D elemnetn self.x = 4 self.y = 3 self.node1 = Node([0, 0]) self.node2 = Node([self.x, self.y]) self.element_frame = FrameElement( nodes=[self.node1, self.node2], material=steel, section=section, efs=[True, True, False, False, False, True] ) self.element_frame2D = FrameElement2D( nodes=[self.node1, self.node2], material=steel, section=section, efs=[True, True, False, False, False, False] )
def create_node(self, coords): """Creates a node and adds it to the Fea object. Creates and returns a :class:`~feastruct.fea.node.Node` object and adds it to the :class:`~feastruct.fea.fea.Fea` object. :param coords: Cartesian coordinates of the node *([x], [x, y] or [x, y, z])* :type coords: list[float] :returns: Node object :rtype: :class:`~feastruct.fea.node.Node` """ # TODO:catch any errors thrown by node creation new_node = Node(coords) self.nodes.append(new_node) return new_node
def add_node(self, id, coord): """Adds a node to the fea class. Adds a :class:`feastruct.fea.node.Node` object to the fea object. Checks for an exisiting id and ensures that a node is not already in the desired location. :param int id: Unique id identifying the node :param coord: Cartesian coordinates of the node :type coord: List[float, float] :raises FEAInputError: If the id already exists or if a node already exists at the desired location. The following example creates an analysis object and creates a node at x = 1 and y = 2:: analysis = fea() analysis.add_node(id=1, coord=[1, 2]) """ # TODO: check that node id and location does not already exist self.nodes.append(Node(id, coord))
def setUp(self): self.x = 5 self.y = 10 self.z = 0 self.node = Node([self.x, self.y, self.z])
class TestNode(unittest.TestCase): """Tests the functionality of the Node class""" def setUp(self): self.x = 5 self.y = 10 self.z = 0 self.node = Node([self.x, self.y, self.z]) def test_coordinates(self): self.assertTrue(np.isclose(self.node.x, self.x)) self.assertTrue(np.isclose(self.node.y, self.y)) self.assertTrue(np.isclose(self.node.z, self.z)) def test_dof_size(self): self.assertTrue(len(self.node.dofs) == 6) def test_dof_parent(self): for dof in self.node.dofs: self.assertTrue(dof.node is self.node) def test_node_dof_nums(self): for (i, dof) in enumerate(self.node.dofs): self.assertTrue(dof.node_dof_num is i) def test_node_get_dofs(self): # case 1 - 3D dofs freedom_signature = [True, True, True, True, True, True] indices = [i for i, x in enumerate(freedom_signature) if x] dof_list = self.node.get_dofs(freedom_signature) for (i, dof) in enumerate(dof_list): self.assertTrue(dof.node_dof_num == indices[i]) # case 2 - 2D dofs freedom_signature = [True, True, False, False, False, True] indices = [i for i, x in enumerate(freedom_signature) if x] dof_list = self.node.get_dofs(freedom_signature) for (i, dof) in enumerate(dof_list): self.assertTrue(dof.node_dof_num == indices[i]) # case 3 - single DoF freedom_signature = [True, False, False, False, False, False] indices = [i for i, x in enumerate(freedom_signature) if x] dof_list = self.node.get_dofs(freedom_signature) for (i, dof) in enumerate(dof_list): self.assertTrue(dof.node_dof_num == indices[i]) def test_dof_displacements(self): # add dummy analysis case case1 = AnalysisCase('fc', 'lc') case2 = AnalysisCase('fc', 'lc') # create dummy displacements for (i, dof) in enumerate(self.node.dofs): dof.save_displacement(i, case1) # get displacements for (i, dof) in enumerate(self.node.dofs): self.assertEqual(dof.get_displacement(case1), i) # check exception with self.assertRaises(Exception): dof.get_displacement(case2) def test_node_displacements(self): # add dummy analysis case case1 = AnalysisCase('fc', 'lc') # create dummy displacements for (i, dof) in enumerate(self.node.dofs): # don't save dof index 4 if i == 4: pass else: dof.save_displacement(i, case1) # get displacements disp_vector = self.node.get_displacements(case1) for (i, disp) in enumerate(disp_vector): if i == 4: self.assertEqual(disp, None) else: self.assertEqual(disp, i)