-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_examples.py
More file actions
148 lines (116 loc) · 4.1 KB
/
run_examples.py
File metadata and controls
148 lines (116 loc) · 4.1 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"""
Examples for FEMethods showing how to use the module
"""
import numpy as np
from femethods.elements import Beam
from femethods.loads import MomentLoad, PointLoad
from femethods.reactions import FixedReaction, PinnedReaction
def intro_demo():
"""
Simply supported beam with a single centered point load
This is the example shown in the intro docs
"""
print("=" * 79)
print("Intro Demo")
print("Show an example of a simply supported beam with centered load")
# Note that both the reaction and load are both lists. They must always be
# given to Beam as a list,
r = [PinnedReaction(x) for x in [0, 30]] # define reactions as list
p = [PointLoad(magnitude=-100, location=15)] # define loads as list
b = Beam(30, loads=p, reactions=r)
# an explicit solve is required to calculate the reaction values
b.solve()
print(b)
b.plot(
diagrams=("shear", "moment", "deflection"),
# plot_kwargs={"label": "approx solution"},
)
b.show()
def example_1():
"""
Cantilevered Beam with Fixed Support and End Loading
"""
print("=" * 79)
print("Example 1")
print(
"Show an example with a cantilevered beam with a fixed support and "
"point load at the end\n"
)
beam_len = 10
P = -200
E = 29e6
I = 125
# Note that both the reaction and load are both lists. They must always be
# given to Beam as a list,
r = [FixedReaction(beam_len)] # define reactions as list
p = [PointLoad(magnitude=P, location=0)] # define loads as list
b = Beam(beam_len, loads=p, reactions=r, mesh=None, E=E, Ixx=I)
# an explicit solve is required to calculate the reaction values
b.solve()
print(b)
fig, axes = b.plot(
diagrams=("shear", "moment", "deflection"),
plot_kwargs={"label": "approx solution"},
)
x = np.linspace(0, beam_len, 100)
Mx = -P * x
Vx = -P * np.ones(np.size(x))
dx = (P / (6 * E * I)) * (2 * beam_len**3 - 3 * beam_len**2 * x + x**3)
axes[0].plot(x, Vx, "--", label="exact solution")
axes[1].plot(x, Mx, "--", label="exact solution")
axes[-1].plot(x, dx, "--", label="exact solution")
axes[-1].legend()
b.show()
def example_2():
"""
Cantilevered Beam with 3 Pinned Supports and End Loading
"""
print("=" * 79)
print("Example 2")
print("Show an example with 3 Pinned Supports and End Loading\n")
beam_len = 10
# Note that both the reaction and load are both lists. They must always be
# given to Beam as a list,
r = [PinnedReaction(0), PinnedReaction(2), PinnedReaction(6)] # define reactions
p = [PointLoad(magnitude=-2, location=beam_len)] # define loads
b = Beam(beam_len, loads=p, reactions=r, E=29e6, Ixx=125)
# an explicit solve is required to calculate the reaction values
b.solve()
print(b)
b.plot()
b.show()
def example_3():
"""
Cantilevered Beam with Fixed Support and Force and Moment at end
"""
print("=" * 79)
print("Example 3")
print(
"Show an example with a cantilevered beam with a fixed support and "
"point load and moment load at the end\n"
)
beam_len = 10
# Note that both the reaction and load are both lists. They must always be
# given to Beam as a list,
r = [FixedReaction(0)] # define reactions as list
p = [PointLoad(-2, beam_len), MomentLoad(-2, beam_len)] # define loads as list
# since the force and moment are acting at the same location, it can also be applied
# using the base Load and defining the fm_factor, as shown below. Defining the loads
# this way will give the same results
# from femethods.loads import Load
# p = [Load(magnitude=1, location=beam_len, fm_factor=(-2, -2))]
b = Beam(beam_len, loads=p, reactions=r, E=29e6, Ixx=125)
print(b)
b.plot()
b.show()
if __name__ == "__main__":
np.set_printoptions(
precision=None,
linewidth=300,
suppress=True,
formatter={"float": "{:0,.5f}".format, "int": "{:0,.0f}".format},
)
# intro_demo()
# example_1()
example_2()
# example_3()