Closed mvanzulli closed 2 months ago
Use @eval to define less line numbers of code
# TODO use @eval
"Returns the displacements solution at the `PointEvalHandler` `peh`."
function displacements(st_sol::StatesSolution, peh::PointEvalHandler)
points_interpolators = interpolator(peh)
vec_points = points(peh)
num_points = length(vec_points)
sol_points = Vector{Vector{Vector{Float64}}}(undef, num_points)
for index_p in 1:num_points
interpolator_p = node_to_weights(points_interpolators)[index_p]
# Compute the first node contribution and the sum up
node_values = [weight * displacements(st_sol, node) for (node, weight) in pairs(interpolator_p)]
p_values = reduce(+, node_values)
sol_points[index_p] = p_values
end
return sol_points
end
"Returns the displacements component `i` solution at the `PointEvalHandler` `peh`."
displacements(st_sol::StatesSolution, peh::PointEvalHandler, i::Int) = getindex.(displacements(st_sol, peh), i)
"Returns the internal forces solution at the `PointEvalHandler` `peh`."
function internal_forces(st_sol::StatesSolution, peh::PointEvalHandler)
interpolators = interpolator(peh)
vec_points = points(peh)
num_points = length(vec_points)
sol_points = Vector{Vector{Vector{Float64}}}(undef, num_points)
for index_p in 1:num_points
interpolator_p = node_to_weights(points_interpolators)[index_p]
# Compute the first node contribution and the sum up
node_values = [weight * internal_forces(st_sol, node) for (node, weight) in pairs(node_to_weights(interpolator_p))]
p_values = reduce(+, node_values)
sol_points[index_p] = p_values
end
return sol_points
end
"Returns the internal ftorce component `i` solution at the `PointEvalHandler` `peh`."
internal_forces(st_sol::StatesSolution, peh::PointEvalHandler, i::Int) = getindex.(internal_forces(st_sol, peh), i)
"Returns the external forces solution at the `PointEvalHandler` `peh`."
function external_forces(st_sol::StatesSolution, peh::PointEvalHandler)
interpolators = interpolator(peh)
vec_points = points(peh)
num_points = length(vec_points)
sol_points = Vector{Vector{Vector{Float64}}}(undef, num_points)
for index_p in 1:num_points
interpolator_p = node_to_weights(points_interpolators)[index_p]
# Compute the first node contribution and the sum up
node_values = [weight * external_forces(st_sol, node) for (node, weight) in pairs(interpolator_p)]
p_values = reduce(+, node_values)
sol_points[index_p] = p_values
end
return sol_points
end
"Returns the internal force component `i` solution at the `PointEvalHandler` `peh`."
external_forces(st_sol::StatesSolution, peh::PointEvalHandler, i::Int) = getindex.(external_forces(st_sol, peh), i)
"Returns the stresses solution at the `PointEvalHandler` `peh`."
function stress(st_sol::StatesSolution, peh::PointEvalHandler)
point_to_element_vec = points_to_element(interpolator(peh))
vec_points = points(peh)
num_points = length(vec_points)
sol_points = Vector{Vector{<:AbstractMatrix{Float64}}}(undef, num_points)
for index_p in 1:num_points
element_p = point_to_element_vec[index_p]
sol_points[index_p] = stress(st_sol, element_p)
end
return sol_points
end
Create access with @eval :
Instead of:
Another option for composition is:
Modules to check