Class Node

Class Node represents the nodes (or joints) of the structure. A node has $x-$ and $y-$ coordinate values, a set of up to 3 constrained directions, and a list giving the DOF #'s for each of the three directions (the DOF#'s are used to build the structural stiffness and other matrices).


In [1]:
import math

In [2]:
class Node(object):
    
    DIRECTIONS = {'FX':0, 'FY':1, 'MZ':2}
    
    def __init__(self,ident,x,y):
        """Initialize a new instance with the given identifier and x-
        and y- coordinate values. The set of constraints is set to empty,
        and the 3 dof numbers are unset."""
        self.id = ident
        self.x = x
        self.y = y
        self.constraints = set()
        self.dofnums = [None] * 3
        
    def add_constraint(self,cname):
        """Add a constrained direction to the set of constraints.  The constraint
        name, cname, must be one of the 3 valid directions (FX, FY or MZ)."""
        c = cname.upper()
        if c not in self.DIRECTIONS:
            raise ValueError('Invalid constraint name: {}'.format(cname))
        self.constraints.add(c)
        
    def to(self,other):
        """Return the directional cosines and distance to the other node as
        a 3-tuple."""
        dx = other.x-self.x
        dy = other.y-self.y
        L = math.sqrt(dx*dx + dy*dy)
        return dx/L,dy/L,L
        
    def __repr__(self):
        return '{}("{}",{},{})'.format(self.__class__.__name__,self.id,self.x,self.y)

In [3]:
##test:
a = Node('A',10.,20.)
b = Node('B',a.x+4.,a.y-3.)
a,b,a.to(b)


Out[3]:
(Node("A",10.0,20.0), Node("B",14.0,17.0), (0.8, -0.6, 5.0))

In [4]:
##test:
cx,cy,l = b.to(a)
l,cx,cy


Out[4]:
(5.0, -0.8, 0.6)

In [ ]: