In [49]:
#Pkg.update()
In [50]:
versioninfo()
using PtFEM
As in the book, the input are subdivided by chapter name (e.g. "4 Static Equilibrium") in the "examples" sub-directory.
This version (p4_1.jl) is an almost straight translation from Fortran to Julia (maybe with the exception of the inputs). This is true for all FEx_x.jl files.
These experiments are aimed at a next version (P4.1.jl) which contains a more Julia-based implementation, e.g. using Julia sparse matrices vs. the skyline format and using Julia (and underlying libraries) for solving the global matrix equations, e.g. y = A \ x. All Px.x.jl will be similarly be Julia based scripts, and Px.x.x.jl contain the corresponding input files.
In [51]:
N = 4;
F = 5.0;
In [52]:
dist_loads = [[(i, [-F/N]) for i in 1:(N+1)];]
dist_loads[1] = (1, [-F/(2*N)])
dist_loads[size(dist_loads,1)] = (N+1, [-F/(2*N)])
dist_loads = convert(Vector{Tuple{Int64, Vector{Float64}}}, dist_loads)
Out[52]:
Notice that in this example the x axis goes from left to right (not as in the book) and the distributed load is compressive. Clamped end is node 1.
In [53]:
?p4_1
Out[53]:
In [54]:
data = Dict(
# Rod(nxe, np_types, nip, fin_el(nod, nodof))
:struc_el => Rod(N, 1, 1, Line(2, 1)),
:properties => [1.0e5;],
:x_coords => linspace(0, 1, (N+1)),
:support => [(1, [0])],
:loaded_nodes => dist_loads
);
In [55]:
m = p4_1(data);
In [56]:
m.displacements
Out[56]:
In [57]:
m.actions
Out[57]:
In [58]:
if :struc_el in keys(data)
struc_el = data[:struc_el]
end
Out[58]:
In [59]:
?Rod
Out[59]:
In [60]:
ndim = 1
nst = struc_el.np_types;
In [61]:
fin_el = struc_el.fin_el
Out[61]:
In [62]:
?PtFEM.mesh_size
Out[62]:
In [63]:
if typeof(fin_el) == Line
(nels, nn) = PtFEM.mesh_size(fin_el, struc_el.nxe)
elseif typeof(fin_el) == Triangle || typeof(fin_el) == Quadrilateral
(nels, nn) = PtFEM.mesh_size(fin_el, struc_el.nxe, struc_el.nye)
elseif typeof(fin_el) == Hexahedron
(nels, nn) = PtFEM.mesh_size(fin_el, struc_el.nxe, struc_el.nye, struc_el.nze)
end
Out[63]:
In [64]:
nodof = fin_el.nodof # Degrees of freedom per node
Out[64]:
In [65]:
ndof = fin_el.nod * nodof # Degrees of freedom per fin_el
Out[65]:
In [66]:
penalty = 1e20
if :penalty in keys(data)
penalty = data[:penalty]
end
In [67]:
if :properties in keys(data)
prop = zeros(size(data[:properties], 1), size(data[:properties], 2))
for i in 1:size(data[:properties], 1)
prop[i, :] = data[:properties][i, :]
end
end
In [68]:
prop
Out[68]:
In [69]:
nf = ones(Int64, nodof, nn)
if :support in keys(data)
for i in 1:size(data[:support], 1)
nf[:, data[:support][i][1]] = data[:support][i][2]
end
end
(size(nf), nf)
Out[69]:
In [70]:
x_coords = zeros(nn)
if :x_coords in keys(data)
x_coords = data[:x_coords]
end
y_coords = zeros(nn)
if :y_coords in keys(data)
y_coords = data[:y_coords]
end
z_coords = zeros(nn)
if :z_coords in keys(data)
z_coords = data[:z_coords]
end
etype = ones(Int64, nels)
if :etype in keys(data)
etype = data[:etype]
end
x_coords
Out[70]:
In [71]:
collect(x_coords)
Out[71]:
In [72]:
#
# Initialize all dynamic arrays storen in the FEM object
#
points = zeros(struc_el.nip, ndim)
g = zeros(Int64, ndof)
g_coord = zeros(ndim,nn)
fun = zeros(fin_el.nod)
coord = zeros(fin_el.nod, ndim)
gamma = zeros(nels)
jac = zeros(ndim, ndim)
g_num = zeros(Int64, fin_el.nod, nels)
der = zeros(ndim, fin_el.nod)
deriv = zeros(ndim, fin_el.nod)
bee = zeros(nst,ndof)
km = zeros(ndof, ndof)
mm = zeros(ndof, ndof)
gm = zeros(ndof, ndof)
kg = zeros(ndof, ndof)
eld = zeros(ndof)
weights = zeros(struc_el.nip)
g_g = zeros(Int64, ndof, nels)
num = zeros(Int64, fin_el.nod)
actions = zeros(nels, ndof)
displacements = zeros(size(nf, 1), ndim)
gc = ones(ndim, ndim)
dee = zeros(nst,nst)
sigma = zeros(nst)
axial = zeros(nels);
Ok, all arrays have been initialized. Time to start the real work. First determine the global numbering:
In [73]:
?PtFEM.formnf!
Out[73]:
In [74]:
PtFEM.formnf!(nodof, nn, nf)
nf
Out[74]:
Node 1 is fixed, nodes 2 to 5 represents degrees of freedom. We need 4 equations to solve for 4 displacements.
In [75]:
neq = maximum(nf)
Out[75]:
In [76]:
kdiag = zeros(Int64, neq);
In [77]:
ell = zeros(nels)
if :x_coords in keys(data)
for i in 1:length(data[:x_coords])-1
ell[i] = data[:x_coords][i+1] - data[:x_coords][i]
end
end
ell
Out[77]:
In [78]:
for i in 1:nels
num = [i; i+1]
num_to_g!(fin_el.nod, nodof, nn, ndof, num, nf, g)
println(g)
g_g[:, i] = g
fkdiag!(ndof, neq, g, kdiag)
println(kdiag)
end
In [79]:
kdiag
Out[79]:
In [80]:
g_g
Out[80]:
In [81]:
for i in 2:neq
kdiag[i] = kdiag[i] + kdiag[i-1]
end
kdiag
Out[81]:
In [82]:
kv = zeros(kdiag[neq])
gv = zeros(kdiag[neq])
print("There are $(neq) equations,")
println(" and the skyline storage is $(kdiag[neq]).\n")
In [83]:
loads = zeros(neq+1)
if :loaded_nodes in keys(data)
for i in 1:size(data[:loaded_nodes], 1)
loads[nf[:, data[:loaded_nodes][i][1]]+1] =
data[:loaded_nodes][i][2]
end
end
nf
Out[83]:
In [84]:
for i in 1:nels
km = PtFEM.rod_km!(km, prop[etype[i], 1], ell[i])
g = g_g[:, i]
PtFEM.fsparv!(kv, km, g, kdiag)
end
In [85]:
km
Out[85]:
In [86]:
kv
Out[86]:
In [87]:
# Add radial stress if fin_el is 3d and axisymmetric
if ndim == 3 && struc_el.axisymmetric
nst = 4
end
In [88]:
fixed_freedoms = 0
if :fixed_freedoms in keys(data)
fixed_freedoms = size(data[:fixed_freedoms], 1)
end
no = zeros(Int64, fixed_freedoms)
node = zeros(Int64, fixed_freedoms)
sense = zeros(Int64, fixed_freedoms)
value = zeros(Float64, fixed_freedoms)
if :fixed_freedoms in keys(data) && fixed_freedoms > 0
for i in 1:fixed_freedoms
node[i] = data[:fixed_freedoms][i][1]
sense[i] = data[:fixed_freedoms][i][2]
no[i] = nf[sense[i], node[i]]
value[i] = data[:fixed_freedoms][i][3]
end
kv[kdiag[no]] = kv[kdiag[no]] + penalty
loads[no+1] = kv[kdiag[no]] .* value
end
loads
Out[88]:
In [89]:
sparin!(kv, kdiag)
loads[2:end] = spabac!(kv, loads[2:end], kdiag)
loads
In [90]:
displacements = zeros(size(nf))
for i in 1:size(displacements, 1)
for j in 1:size(displacements, 2)
if nf[i, j] > 0
displacements[i,j] = loads[nf[i, j]+1]
end
end
end
displacements = displacements'
Out[90]:
loads[1] = 0.0 for i in 1:nels km = PtFEM.rod_km!(km, prop[etype[i], 1], ell[i]) g = g_g[:, i] eld = loads[g+1] actions[i, :] = km * eld end actions
In [96]:
eld
Out[96]:
In [92]:
m=FEM(struc_el, fin_el, ndim, nels, nst, ndof, nn, nodof, neq, penalty,
etype, g, g_g, g_num, kdiag, nf, no, node, num, sense, actions,
bee, coord, gamma, dee, der, deriv, displacements, eld, fun, gc,
g_coord, jac, km, mm, gm, kv, gv, loads, points, prop, sigma, value,
weights, x_coords, y_coords, z_coords, axial);
In [93]:
m.displacements
Out[93]:
In [94]:
m.actions
Out[94]:
In [ ]: