/
tipmoment.jl
340 lines (261 loc) · 9.3 KB
/
tipmoment.jl
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# # [Cantilever with a Tip Moment](@id tipmoment)
#
# This example shows how to predict the behavior of a cantilever beam that is subjected
# to a constant tip moment. This is a common benchmark problem for the geometrically
# nonlinear analysis of beams.
#
# ![](../assets/tipmoment-drawing.svg)
#
#-
#md # !!! tip
#md # This example is also available as a Jupyter notebook:
#md # [`tipmoment.ipynb`](@__NBVIEWER_ROOT_URL__/examples/tipmoment.ipynb).
#-
using GXBeam, LinearAlgebra
L = 12 # inches
h = w = 1 # inches
E = 30e6 # lb/in^4 Young's Modulus
A = h*w
Iyy = w*h^3/12
Izz = w^3*h/12
## bending moment (applied at end)
λ = [0.0, 0.4, 0.8, 1.2, 1.6, 1.8, 2.0]
m = pi*E*Iyy/L
M = λ*m
## create points
nelem = 16
x = range(0, L, length=nelem+1)
y = zero(x)
z = zero(x)
points = [[x[i],y[i],z[i]] for i = 1:length(x)]
## index of endpoints of each beam element
start = 1:nelem
stop = 2:nelem+1
## compliance matrix for each beam element
compliance = fill(Diagonal([1/(E*A), 0, 0, 0, 1/(E*Iyy), 1/(E*Izz)]), nelem)
## create assembly of interconnected nonlinear beams
assembly = Assembly(points, start, stop, compliance=compliance)
## pre-initialize system storage
system = StaticSystem(assembly)
## run an analysis for each prescribed bending moment
states = Vector{AssemblyState{Float64}}(undef, length(M))
for i = 1:length(M)
## create dictionary of prescribed conditions
prescribed_conditions = Dict(
## fixed left side
1 => PrescribedConditions(ux=0, uy=0, uz=0, theta_x=0, theta_y=0, theta_z=0),
## moment on right side
nelem+1 => PrescribedConditions(Mz = M[i])
)
## perform a static analysis
_, states[i], converged = static_analysis!(system, assembly;
prescribed_conditions = prescribed_conditions)
end
#!jl nothing #hide
# ## Comparison with Analytical Results
#
# This problem has a simple analytical solution, which we obtained from "Study of the
# Geometric Stiffening Effect: Comparison of Different Formulations" by Juana M. Mayo,
# Daniel Garcia-Vallejo, and Jaime Dominguez.
#
## analytical solution (ρ = E*I/M)
analytical(x, ρ) = ifelse(ρ == Inf, zeros(3), [ρ*sin(x/ρ)-x, ρ*(1-cos(x/ρ)), 0])
#!jl nothing #hide
#
# Plotting the results reveals that the analytical and computational results show
# excellent agreement.
#
using Plots
#md using Suppressor #hide
pyplot()
#!jl nothing #hide
#-
#md @suppress_err begin #hide
## set up the plot
plot(
xlim = (-0.25, 1.1),
xticks = -0.25:0.25:1.0,
xlabel = "x/L",
ylim = (-0.05, 0.8),
yticks = 0.0:0.2:0.8,
ylabel = "y/L",
aspect_ratio = 1.0,
grid = false,
overwrite_figure=false
)
## create dummy legend entries for GXBeam and Analytical
scatter!([], [], color=:black, label="GXBeam")
plot!([], [], color=:black, label="Analytical")
## plot the data
for i = 1:length(M)
local x, y
## GXBeam
x = [assembly.points[ipoint][1] + states[i].points[ipoint].u[1] for ipoint =
1:length(assembly.points)]
y = [assembly.points[ipoint][2] + states[i].points[ipoint].u[2] for ipoint =
1:length(assembly.points)]
scatter!(x/L, y/L, label="", color = i)
## Analytical
x0 = range(0, L, length=100)
deflection = analytical.(x0, E*Iyy/M[i])
x = (x0 + getindex.(deflection, 1))
y = getindex.(deflection, 2)
plot!(x/L, y/L, label="\$\\lambda\$=$(λ[i])", color=i)
end
#nb plot!()
plot!(show=true) #!nb
#md savefig("../assets/tipmoment-deflection.svg") #hide
#md closeall() #hide
#md end #hide
#md nothing #hide
#md # ![](../assets/tipmoment-deflection.svg)
#-
# ## Grid Convergence Study
# We can use this problem to test the accuracy and convergence of this package. To do so
# we set ``\lambda = 1`` and repeat the analysis for a variety of grid sizes. We measure
# the normalized tip displacement error ``\varepsilon(u)`` using the following expression
# ```math
# \varepsilon(u) = \left| \frac{u - u^a}{u^a} \right|
# ```
# where ``u`` is the calculated tip displacement (at x=L) and ``u^a`` is the analytical
# tip displacement.
grid_sizes = unique(round.(Int, 10 .^ range(0,3,length=25)))
L = 12 # inches
h = w = 1 # inches
E = 30e6 # lb/in^4 Young's Modulus
A = h*w
Iyy = w*h^3/12
Izz = w^3*h/12
## bending moment (applied at end)
λ = 1.0
m = pi*E*Iyy/L
M = λ*m
## run an analysis for each grid size
states = Vector{AssemblyState{Float64}}(undef, length(grid_sizes))
for (igrid, nelem) in enumerate(grid_sizes)
local x, y, z, points, start, stop, compliance, assembly, system
## create points
x = range(0, L, length=nelem+1)
y = zero(x)
z = zero(x)
points = [[x[i],y[i],z[i]] for i = 1:length(x)]
## index of endpoints of each beam element
start = 1:nelem
stop = 2:nelem+1
## compliance matrix for each beam element
compliance = fill(Diagonal([1/(E*A), 0, 0, 0, 1/(E*Iyy), 1/(E*Izz)]), nelem)
## create assembly of interconnected nonlinear beams
assembly = Assembly(points, start, stop, compliance=compliance)
## create dictionary of prescribed conditions
prescribed_conditions = Dict(
## fixed left side
1 => PrescribedConditions(ux=0, uy=0, uz=0, theta_x=0, theta_y=0, theta_z=0),
## moment on right side
nelem+1 => PrescribedConditions(Mz = M)
)
## perform a static analysis
system, states[igrid], converged = static_analysis(assembly;
prescribed_conditions = prescribed_conditions)
end
#!jl nothing #hide
#-
## calculate analytical solution
dxa, dya = analytical(L, E*Iyy/M)
## extract computational solution
dx = [states[igrid].points[end].u[1] for igrid = 1:length(grid_sizes)]
dy = [states[igrid].points[end].u[2] for igrid = 1:length(grid_sizes)]
## compute error
εx = abs.((dx .- dxa) ./ dxa)
εy = abs.((dy .- dya) ./ dya)
#!jl nothing #hide
#-
using Plots
#md using Suppressor #hide
pyplot()
#!jl nothing #hide
#-
#md @suppress_err begin #hide
## plot the x-error
p1 = plot(grid_sizes .+ 1, εx, label="",
xlabel = "Number of Nodes",
xaxis=:log,
xlim = (10^0, 10^3),
xtick = 10.0 .^ (0:3),
ylabel = "\$\\varepsilon(u_x)\$",
yaxis=:log,
ylim = (-Inf, 10^0),
ytick = 10.0 .^ -(0:7),
overwrite_figure=false,
show=true)
#md savefig("../assets/tipmoment-x-convergence.svg") #hide
#md closeall() #hide
#md end #hide
#md nothing #hide
#md # ![](../assets/tipmoment-x-convergence.svg)
#-
#md @suppress_err begin #hide
## plot the y-error
p2 = plot(grid_sizes .+ 1, εy, label="",
xlabel = "Number of Nodes",
xaxis=:log,
xlim = (10^0, 10^3),
xtick = 10.0 .^ (0:3),
ylabel = "\$\\varepsilon(u_y)\$",
yaxis=:log,
ylim = (-Inf, 10^0),
ytick = 10.0 .^ -(0:7),
overwrite_figure=false,
show=true)
#md savefig("../assets/tipmoment-y-convergence.svg") #hide
#md closeall() #hide
#md end #hide
#md nothing #hide
#md # ![](../assets/tipmoment-y-convergence.svg)
#-
# We observe second-order algebraic convergence for both x and y tip displacement errors.
# We can therefore conclude that a large number of elements are likely necessary in order
# to obtain highly accurate solutions using this package. For problems where high
# accuracy solutions are critical, higher order shape functions, such as the Legendre
# spectral finite elements used by [BeamDyn](https://www.nrel.gov/wind/nwtc/beamdyn.html)
# are likely more computationally efficient.
# ## Sensitivity Analysis
# Suppose we are interested in the sensitivity of tip x and y-displacement with respect to
# the nondimensional tip moment ``\lambda`` when ``\lambda=1``. As described in the
# [`sensitivity analysis documentation`](@ref sensitivities), these sensitivities may be
# computed using the following code:
using ForwardDiff
## construct pfunc to overwrite prescribed conditions
pfunc = (p, t) -> begin
## non-dimensional tip moment
λ = p[1]
## dimensionalized tip moment
m = pi*E*Iyy/L
M = λ*m
## create dictionary of prescribed conditions
prescribed_conditions = Dict(
## fixed left side
1 => PrescribedConditions(ux=0, uy=0, uz=0, theta_x=0, theta_y=0, theta_z=0),
## moment on right side
nelem+1 => PrescribedConditions(Mz = M)
)
## return named tuple with new arguments
return (; prescribed_conditions=prescribed_conditions)
end
## construct objective function
objfun = (p) -> begin
## perform static analysis
system, state, converged = static_analysis(assembly; pfunc, p)
## return the desired outputs
return [state.points[end].u[1], state.points[end].u[2]]
end
## compute sensitivities using ForwardDiff with λ = 1.0
ForwardDiff.jacobian(objfun, [1.0])
# Note that these sensitivities are the exact sensitivities of the numerical (discretized)
# solution rather than the exact sensitivities of the analytic (continuous) solution. The
# former is more appropriate for gradient-based optimization (which operates on the
# discretized solution) while the latter better describes the system's actual sensitivities.
# For this problem, continuous sensitivities may be derived from the analytic solution as
# ``\frac{d y}{d \lambda} = -L = -12`` and ``\frac{d y}{d \lambda} = \frac{-2 L}{\pi} = \frac{-24}{\pi}``
# To obtain continuous sensitivities using GXBeam, a sufficiently fine grid discretization
# must be used. If analytic results are not available, a grid convergence study must be
# performed in order to find a sufficiently fine grid discretization.