Path: blob/main/docs/literate/src/files/behind_the_scenes_simulation_setup_plots/src/generate_elements_figure.jl
2078 views
using Plots12function min(coordinates::Vector{Tuple{Float64, Float64}}, i)3min = coordinates[1][i]4for j in coordinates5if min > j[i]6min = j[i]7end8end9return min10end1112function max(coordinates::Vector{Tuple{Float64, Float64}}, i)13max = coordinates[1][i]14for j in coordinates15if max < j[i]16max = j[i]17end18end19return max20end2122function nodes_project_four(coordinates::Vector{Tuple{Float64, Float64}})23nodes_1d = [-1.0, -0.4472135954999579, 0.4472135954999579, 1.0]24nodes_2d = Array{Float64, 2}(undef, 16, 2)25for i in range(1, length(nodes_1d))26for j in range(1, length(nodes_1d))27nodes_2d[(i - 1) * 4 + j, :] = [nodes_1d[i], nodes_1d[j]]28end29end30k_x = (max(coordinates, 1) - min(coordinates, 1)) / 231k_y = (max(coordinates, 2) - min(coordinates, 2)) / 232b_x = min(coordinates, 1)33b_y = min(coordinates, 2)34for i in range(1, Int(length(nodes_2d) / 2))35nodes_2d[i, 1] = k_x * (nodes_2d[i, 1] + 1) + b_x36nodes_2d[i, 2] = k_y * (nodes_2d[i, 2] + 1) + b_y37end38return nodes_2d39end4041import Base.+42+(a::Tuple, b::Tuple) = a .+ b4344# level 145plot(Shape([(2, 0), (2, -2), (0, -2), (0, 0)] .+46[(0.5, -0.75), (0.5, -0.75), (0.5, -0.75), (0.5, -0.75)]), linecolor = "black",47fillcolor = "white", label = "elements", legend_position = :right, linewidth = 2,48size = (800, 600), showaxis = false, grid = false, x_lims = (-3, 5.5),49ylims = (-3.5, 3))5051nodes_2d = nodes_project_four([(2, 0), (2, -2), (0, -2), (0, 0)] .+52[(0.5, -0.75), (0.5, -0.75), (0.5, -0.75), (0.5, -0.75)])53scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = "Gauss-Lobatto nodes",54markersize = 5)5556# level 25758# upper right59plot!(Shape([(2, 2), (2, 1), (1, 1), (1, 2)] .+60[(0.75, 0.5), (0.75, 0.5), (0.75, 0.5), (0.75, 0.5)]), linecolor = "black",61fillcolor = "white", label = false, linewidth = 2)6263nodes_2d = nodes_project_four([(2, 2), (2, 1), (1, 1), (1, 2)] .+64[(0.75, 0.5), (0.75, 0.5), (0.75, 0.5), (0.75, 0.5)])65scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)6667plot!(Shape([(0, 2), (1, 2), (1, 1), (0, 1)] .+68[(0.25, 0.5), (0.25, 0.5), (0.25, 0.5), (0.25, 0.5)]), linecolor = "black",69fillcolor = "white", label = false, linewidth = 2)7071nodes_2d = nodes_project_four([(0, 2), (1, 2), (1, 1), (0, 1)] .+72[(0.25, 0.5), (0.25, 0.5), (0.25, 0.5), (0.25, 0.5)])73scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)7475plot!(Shape([(0, 0), (0, 1), (1, 1), (1, 0)] .+76[(0.25, 0.0), (0.25, 0.0), (0.25, 0.0), (0.25, 0.0)]), linecolor = "black",77fillcolor = "white", label = false, linewidth = 2)7879nodes_2d = nodes_project_four([(0, 0), (0, 1), (1, 1), (1, 0)] .+80[(0.25, 0.0), (0.25, 0.0), (0.25, 0.0), (0.25, 0.0)])81scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)8283plot!(Shape([(2, 0), (2, 1), (1, 1), (1, 0)] .+84[(0.75, 0.0), (0.75, 0.0), (0.75, 0.0), (0.75, 0.0)]), linecolor = "black",85fillcolor = "white", label = false, linewidth = 2)8687nodes_2d = nodes_project_four([(2, 0), (2, 1), (1, 1), (1, 0)] .+88[(0.75, 0.0), (0.75, 0.0), (0.75, 0.0), (0.75, 0.0)])89scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)9091# upper left92plot!(Shape([(-0, 2), (-0, 1), (-1, 1), (-1, 2)] .+93[(-0.25, 0.5), (-0.25, 0.5), (-0.25, 0.5), (-0.25, 0.5)]), linecolor = "black",94fillcolor = "white", label = false, linewidth = 2)9596nodes_2d = nodes_project_four([(-0, 2), (-0, 1), (-1, 1), (-1, 2)] .+97[(-0.25, 0.5), (-0.25, 0.5), (-0.25, 0.5), (-0.25, 0.5)])98scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)99100plot!(Shape([(-2, 2), (-1, 2), (-1, 1), (-2, 1)] .+101[(-0.75, 0.5), (-0.75, 0.5), (-0.75, 0.5), (-0.75, 0.5)]), linecolor = "black",102fillcolor = "white", label = false, linewidth = 2)103104nodes_2d = nodes_project_four([(-2, 2), (-1, 2), (-1, 1), (-2, 1)] .+105[(-0.75, 0.5), (-0.75, 0.5), (-0.75, 0.5), (-0.75, 0.5)])106scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)107108plot!(Shape([(-2, 0), (-2, 1), (-1, 1), (-1, 0)] .+109[(-0.75, 0.0), (-0.75, 0.0), (-0.75, 0.0), (-0.75, 0.0)]), linecolor = "black",110fillcolor = "white", label = false, linewidth = 2)111112nodes_2d = nodes_project_four([(-2, 0), (-2, 1), (-1, 1), (-1, 0)] .+113[(-0.75, 0.0), (-0.75, 0.0), (-0.75, 0.0), (-0.75, 0.0)])114scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)115116plot!(Shape([(-0, 0), (-1, 0), (-1, 1), (-0, 1)] .+117[(-0.25, 0.0), (-0.25, 0.0), (-0.25, 0.0), (-0.25, 0.0)]), linecolor = "black",118fillcolor = "white", label = false, linewidth = 2)119120nodes_2d = nodes_project_four([(-0, 0), (-1, 0), (-1, 1), (-0, 1)] .+121[(-0.25, 0.0), (-0.25, 0.0), (-0.25, 0.0), (-0.25, 0.0)])122scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)123124# lower left125plot!(Shape([(-0, -0), (-0, -1), (-1, -1), (-1, -0)] .+126[(-0.25, -0.5), (-0.25, -0.5), (-0.25, -0.5), (-0.25, -0.5)]),127linecolor = "black", fillcolor = "white", label = false, linewidth = 2)128129nodes_2d = nodes_project_four([(-0, -0), (-0, -1), (-1, -1), (-1, -0)] .+130[(-0.25, -0.5), (-0.25, -0.5), (-0.25, -0.5), (-0.25, -0.5)])131scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)132133plot!(Shape([(-2, -1), (-2, 0), (-1, -0), (-1, -1)] .+134[(-0.75, -0.5), (-0.75, -0.5), (-0.75, -0.5), (-0.75, -0.5)]),135linecolor = "black", fillcolor = "white", label = false, linewidth = 2)136137nodes_2d = nodes_project_four([(-2, -1), (-2, 0), (-1, -0), (-1, -1)] .+138[(-0.75, -0.5), (-0.75, -0.5), (-0.75, -0.5), (-0.75, -0.5)])139scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)140141plot!(Shape([(-2, -2), (-2, -1), (-1, -1), (-1, -2)] .+142[(-0.75, -1), (-0.75, -1), (-0.75, -1), (-0.75, -1)]), linecolor = "black",143fillcolor = "white", label = false, linewidth = 2)144145nodes_2d = nodes_project_four([(-2.0, -2.0), (-2.0, -1.0), (-1.0, -1.0), (-1.0, -2.0)] .+146[(-0.75, -1), (-0.75, -1), (-0.75, -1), (-0.75, -1)])147scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)148149plot!(Shape([(-1, -2), (-1, -1), (-0, -1), (-0, -2)] .+150[(-0.25, -1), (-0.25, -1), (-0.25, -1), (-0.25, -1)]), linecolor = "black",151fillcolor = "white", label = false, linewidth = 2)152153nodes_2d = nodes_project_four([(-1.0, -2.0), (-1.0, -1.0), (-0.0, -1.0), (-0.0, -2.0)] .+154[(-0.25, -1), (-0.25, -1), (-0.25, -1), (-0.25, -1)])155scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)156157savefig("./elements")158159160