Return this model's stiffness and mass matrices.
(self, dense=False)
| 141 | return str(self) |
| 142 | # }}} |
| 143 | def KM(self, dense=False): # {{{ |
| 144 | """ |
| 145 | Return this model's stiffness and mass matrices. |
| 146 | """ |
| 147 | nD = self.nDof |
| 148 | M = np.zeros(nD) |
| 149 | if dense: |
| 150 | K = np.zeros((nD,nD)) |
| 151 | for eid in self.elem: |
| 152 | E = self.elem[eid] |
| 153 | dof = np.array([2*E.node_a.id, 2*E.node_a.id+1, |
| 154 | 2*E.node_b.id, 2*E.node_b.id+1,]) |
| 155 | K[np.ix_(dof, dof)] += E.stiffness_matrix() |
| 156 | M[np.ix_(dof)] += E.mass_matrix() |
| 157 | # apply constraints |
| 158 | for dof in sorted(self.constrained_dof): |
| 159 | M[dof] = 0 |
| 160 | K[dof, : ] = 0 |
| 161 | K[ : ,dof] = 0 |
| 162 | K[dof,dof] = 1 |
| 163 | else: |
| 164 | # sparse K in COO (coordinate) form |
| 165 | I, J, kV = [], [], [] |
| 166 | for eid in self.elem: |
| 167 | self.add_element(eid, kV, I, J, M) |
| 168 | # Apply constraints by zeroing out the value. |
| 169 | # Keep track of diagonal terms so as to not |
| 170 | # double-book 1's. |
| 171 | did_diag = {} |
| 172 | for i,(i_dof,j_dof) in enumerate(zip(I,J)): |
| 173 | if (i_dof in self.constrained_dof) or \ |
| 174 | (j_dof in self.constrained_dof): |
| 175 | #print(f'DOF {i_dof} or {j_dof} is constrained') |
| 176 | if i_dof == j_dof and i_dof not in did_diag: |
| 177 | # the diagonal |
| 178 | kV[i] = 1.0 # stiffness term |
| 179 | M[i_dof] = 0.0 # mass term |
| 180 | did_diag[i_dof] = True |
| 181 | else: |
| 182 | kV[i] = 0 |
| 183 | |
| 184 | K = sp.coo_matrix((kV,(I,J)),shape=(nD,nD)) |
| 185 | M = sp.diags(M) |
| 186 | |
| 187 | return K, M |
| 188 | # }}} |
| 189 | def print_summary(self, str=False): # {{{ |
| 190 | S = f'nDof : {self.nDof} elem : {len(self.elem)} ' |
no test coverage detected