-
Notifications
You must be signed in to change notification settings - Fork 1
/
testscript.py
130 lines (89 loc) · 2.46 KB
/
testscript.py
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
124
125
126
127
128
129
130
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 26 22:45:47 2020
@author: ccapr
"""
import numpy as np
def sysK(grid):
''' Returns the restricted global stiffness matrix for a pre-defined
basic grid topology
'''
L,I,J,E,G,M = grid
EI = E*I
GJ = G*J
K = np.array([[8*EI/L + 2*GJ/L, 2*EI/L, 2*EI/L],
[2*EI/L, 4*EI/L, 0],
[2*EI/L, 0, 4*EI/L]])
return K
def det_K(K):
detK = np.linalg.det(K)
return detK
def inv_K(K):
invK = np.linalg.inv(K)
return invK
def getF(grid):
M = grid[5]
return np.array([M,0,0])
def solve_D(grid):
K = sysK(grid)
F = getF(grid)
return np.linalg.solve(K, F)*1e-3
def eleK(grid):
L,I,J,E,G,M = grid
EI = E*I
GJ = G*J
return np.array([[GJ/L, 0, -GJ/L, 0],
[0, 4*EI/L, 0, 2*EI/L],
[-GJ/L, 0, GJ/L, 0],
[0, 2*EI/L, 0, 4*EI/L]])
def d_CD(D):
return np.array([0,D[0],0,D[2]])
def d_DC(D):
return np.array([0,-D[2],0,-D[0]])
def d_CE(D):
return np.array([D[0],0,0,0])
def d_FC(D):
return np.array([0,D[2],0,D[0]])
def d_CF(D):
return np.array([0,D[0],0,D[2]])
def d_GC(D):
return np.array([0,0,D[0],0])
def d_CG(D):
return np.array([D[0],0,0,0])
def eleF(k,D):
return k.dot(D)
def m2ltx(a,style='bmatrix',suppress_small=True):
"""Returns a LaTeX bmatrix
:a: numpy array
:returns: LaTeX bmatrix as a string
"""
if len(a.shape) > 2:
raise ValueError('bmatrix can at most display two dimensions')
lines = [np.array2string(s,precision=3,separator=',',
suppress_small=suppress_small) for s in a]
lines = [s.replace('[', '').replace(']', '') for s in lines]
lines = [' ' + ' & '.join(s.split(',')) + r'\\' for s in lines]
lines = [s.replace('.\\','\\') for s in lines]
lines = [s.replace('. ',' ') for s in lines]
rv = [r'\begin{' + style + '}']
rv += lines
rv += [r'\end{' + style + '}']
return '\n'.join(rv)
if (__name__ == '__main__'):
print('Executing as standalone script')
# Define some inputs
L = 4.0 # m
I = 37.5e-6 # m4
J = 75e-6 # m4
E = 200 # GPa
G = 80 # GPa
M = -57 # Nm
# Unit conversions MN/m2
E *= 1e3
G *= 1e3
grid = [L,I,J,E,G,M]
D = solve_D(grid)
theta_C, theta_D, theta_F = D
print(theta_C)
print(theta_D)
print(theta_F)