mirror of
https://github.com/JuliaFEM/JuliaFEM.jl.git
synced 2026-09-17 17:22:10 +00:00
53 lines
1.5 KiB
Julia
53 lines
1.5 KiB
Julia
# This file is a part of JuliaFEM.
|
|
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
|
|
|
|
"""
|
|
Calculate field values to nodal points from Gauss points using least-squares fitting.
|
|
"""
|
|
function calc_nodal_values!(elements, field_name, field_dim, time)
|
|
A = SparseMatrixCOO()
|
|
b = SparseMatrixCOO()
|
|
for element in elements
|
|
gdofs = get_connectivity(element)
|
|
for ip in get_integration_points(element)
|
|
detJ = element(ip, time, Val{:detJ})
|
|
w = ip.weight*detJ
|
|
f = ip(field_name, time)
|
|
N = element(ip, time)
|
|
add!(A, gdofs, gdofs, w*kron(N', N))
|
|
for dim=1:field_dim
|
|
add!(b, gdofs, w*f[dim]*N, dim)
|
|
end
|
|
end
|
|
end
|
|
A = sparse(A)
|
|
b = sparse(b)
|
|
nz = get_nonzero_rows(A)
|
|
x = zeros(size(b)...)
|
|
x[nz, :] = A[nz,nz] \ b[nz, :]
|
|
nodal_values = Dict()
|
|
for i=1:size(x,1)
|
|
nodal_values[i] = vec(x[i,:])
|
|
end
|
|
update!(elements, field_name, nodal_values)
|
|
end
|
|
|
|
"""
|
|
Return node ids + vector of values
|
|
"""
|
|
function get_nodal_vector(elements, field_name, time)
|
|
f = Dict{Int64, Vector{Float64}}()
|
|
for element in elements
|
|
for (c, v) in zip(get_connectivity(element), element[field_name](time))
|
|
if haskey(f, c)
|
|
@assert isapprox(f[c], v)
|
|
end
|
|
f[c] = v
|
|
end
|
|
end
|
|
node_ids = sort(collect(keys(f)))
|
|
field = [f[nid] for nid in node_ids]
|
|
return node_ids, field
|
|
end
|
|
|