# externalForces: list of externalForces each force is list with [Fx, Fy, NodeIndex] so a single force in y direction on node 3 would look like: [[0,F,3]] (zero indexed!!)
# nodeCoordinates: noarray of nodes x and y coordinates: [[x1,y1],[x2,y2]]
# beams: ndarray of beams every beam contains node indices it connects. e.g. beam0 connnects nodes 0 and 1 -> beams= [[0,1]]
def__init__(
self,
s:int,
n:int,
externalForces:list,
nodeCoordinates:np.ndarray,
beams:np.ndarray,
):
self.n=n
self.s=s
self.externalForces=externalForces
self.nodes=nodeCoordinates
self.beams=beams
defsolve(self):
# coeficient matrices A in x and y dir. with #beams rows and #nodes cols
# Ax,Ay is padded because numpy requires square coefficient matrix
# Ax and Ay are concatenated efter lineaer system is constructed
Ax=np.zeros((self.n,2*self.n))# lhsx
Ay=np.zeros((self.n,2*self.n))# lhsy
# rhs vectors all zero or external force
bx=np.zeros(self.n)
by=np.zeros((self.n))
forefinself.externalForces:
bx[ef[2]]=ef[0]
by[ef[2]]=ef[1]
# construct lgs
forniinrange(len(self.nodes)):# for every node index ni
forbinnp.where(self.beams==ni)[
0
]:# for every beam connected to node[ni]
(x1,y1)=self.nodes[self.beams[b][0]]
(x2,y2)=self.nodes[self.beams[b][1]]
# find deltaX and deltaY of beam to calculate force components