-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathLinearSpringElement.R
126 lines (110 loc) · 3.48 KB
/
LinearSpringElement.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#' Element stiffness matrix (for a spring)
#'
#'This function generates the matrix for a spring element.
#'The axis of the spring is assumed to coicide with the global x-axis.
#'
#' @param stiffk Spring stiffness k in N/m
#' @return Stiffness matrix of a spring element
#' @export
LinearSpring_Element_Matrix = function(DOF=2,stiffk)
{
ematrix=stiffk*matrix(c(1,-1,-1,1),nrow = DOF,byrow = T)
return(ematrix)
}
#' Expanded stiffness matrix (for a spring)
#'
#'This function generates the expanded matrix for each element in a connected system
#'of springs
#'
#' @param TDOF Total degree of freedom in a connected system of springs
#' @param eMatrix Pre-expanded matrix of a specific spring element
#' @param i Index of the first node
#' @param j Index of the second node
#'
#' @return The expanded matrix (conforming to the total degree of freedom of the system)
#' @export
LinearSpring_ExpandedElement_Matrix = function(TDOF,eMatrix,i,j)
{
bigMatrix = matrix(vector(l = TDOF * TDOF),nrow = TDOF,byrow = T);
bigMatrix[c(i,j),c(i,j)] = eMatrix;
return (bigMatrix)
}
#' Reduced stiffness matrix
#'
#' This function computes the reduced stiffness matrix
#' from the global stiffness matrix using the boundary condition of the system.
#'
#' @param bigKmatrix Global stiffness matrix
#' @param knownloadnodes Vector of nodal index of known loads
#' in the form c(i,j,k)
#'
#' @return Reduced stiffness matrix
#' @export
#'
ReducedStiffnessMatrix = function(bigKmatrix,knownloadnodes)
{
reducedk = bigKmatrix[c(knownloadnodes),(knownloadnodes)]
return(reducedk)
}
#' Reduced force vector (a column matrix of known force)
#'
#' @param forcevector Vector of known loads (be consistent with units)
#'
#' @return Reduced force vector
#' @export
#'
ReducedLoadVector = function(forcevector)
{
reducedforcevector = matrix(forcevector,ncol = 1)
return(reducedforcevector)
}
#' Global nodal displacements
#'
#' @param reducedmatrix Reduced stiffness matrix
#' @param reducedforcevec Reduced force vector
#'
#' @return Global nodal displacements, that is:
#' extensions (spring and bars);
#' vertical displacements and slopes (beams);
#' vertical/horizontal displacements (2D traingle);
#' radial and vertical displacements (2D axisymmetric);
#' Be mindful of units.
#'
#'
#' @export
NodalDisplacement = function(reducedmatrix,reducedforcevec)
{
return(solve(reducedmatrix,reducedforcevec))
}
#' Local element forces (spring)
#'
#' @param DOF Degree of freedom for a spring element (2 by default)
#' @param stiffk Spring stiffness k in N/m
#' @param vec_globalnodaldisp Vector of global displacements
#' @param i Index of the first node
#' @param j Index of the second node
#'
#' @return Local nodal forces (spring)
#' @export
#'
LinearSpring_Element_Forces = function(DOF=2,stiffk,vec_globalnodaldisp,
i,j)
{
nodaldisplacment=vec_globalnodaldisp[c(i,j)]
stiffnessmatrix = stiffk * matrix(c(1,-1,-1,1),nrow = DOF,byrow = T)
nodal_forces = stiffnessmatrix %*% nodaldisplacment
return(nodal_forces)
}
#' Global element forces (spring)
#'
#' @param bigKmatrix Global stiffness matrix
#' @param vec_globalnodaldisp Global nodal displacements
#'
#' @return Global nodal forces (spring)
#' @export
#'
LinearSpring_Global_Forces = function(bigKmatrix,vec_globalnodaldisp)
{
global_forces = bigKmatrix %*% vec_globalnodaldisp
return(round(global_forces))
}