Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/docs/literate/src/files/behind_the_scenes_simulation_setup_plots/src/generate_elements_figure.jl
2078 views
1
using Plots
2
3
function min(coordinates::Vector{Tuple{Float64, Float64}}, i)
4
min = coordinates[1][i]
5
for j in coordinates
6
if min > j[i]
7
min = j[i]
8
end
9
end
10
return min
11
end
12
13
function max(coordinates::Vector{Tuple{Float64, Float64}}, i)
14
max = coordinates[1][i]
15
for j in coordinates
16
if max < j[i]
17
max = j[i]
18
end
19
end
20
return max
21
end
22
23
function nodes_project_four(coordinates::Vector{Tuple{Float64, Float64}})
24
nodes_1d = [-1.0, -0.4472135954999579, 0.4472135954999579, 1.0]
25
nodes_2d = Array{Float64, 2}(undef, 16, 2)
26
for i in range(1, length(nodes_1d))
27
for j in range(1, length(nodes_1d))
28
nodes_2d[(i - 1) * 4 + j, :] = [nodes_1d[i], nodes_1d[j]]
29
end
30
end
31
k_x = (max(coordinates, 1) - min(coordinates, 1)) / 2
32
k_y = (max(coordinates, 2) - min(coordinates, 2)) / 2
33
b_x = min(coordinates, 1)
34
b_y = min(coordinates, 2)
35
for i in range(1, Int(length(nodes_2d) / 2))
36
nodes_2d[i, 1] = k_x * (nodes_2d[i, 1] + 1) + b_x
37
nodes_2d[i, 2] = k_y * (nodes_2d[i, 2] + 1) + b_y
38
end
39
return nodes_2d
40
end
41
42
import Base.+
43
+(a::Tuple, b::Tuple) = a .+ b
44
45
# level 1
46
plot(Shape([(2, 0), (2, -2), (0, -2), (0, 0)] .+
47
[(0.5, -0.75), (0.5, -0.75), (0.5, -0.75), (0.5, -0.75)]), linecolor = "black",
48
fillcolor = "white", label = "elements", legend_position = :right, linewidth = 2,
49
size = (800, 600), showaxis = false, grid = false, x_lims = (-3, 5.5),
50
ylims = (-3.5, 3))
51
52
nodes_2d = nodes_project_four([(2, 0), (2, -2), (0, -2), (0, 0)] .+
53
[(0.5, -0.75), (0.5, -0.75), (0.5, -0.75), (0.5, -0.75)])
54
scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = "Gauss-Lobatto nodes",
55
markersize = 5)
56
57
# level 2
58
59
# upper right
60
plot!(Shape([(2, 2), (2, 1), (1, 1), (1, 2)] .+
61
[(0.75, 0.5), (0.75, 0.5), (0.75, 0.5), (0.75, 0.5)]), linecolor = "black",
62
fillcolor = "white", label = false, linewidth = 2)
63
64
nodes_2d = nodes_project_four([(2, 2), (2, 1), (1, 1), (1, 2)] .+
65
[(0.75, 0.5), (0.75, 0.5), (0.75, 0.5), (0.75, 0.5)])
66
scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)
67
68
plot!(Shape([(0, 2), (1, 2), (1, 1), (0, 1)] .+
69
[(0.25, 0.5), (0.25, 0.5), (0.25, 0.5), (0.25, 0.5)]), linecolor = "black",
70
fillcolor = "white", label = false, linewidth = 2)
71
72
nodes_2d = nodes_project_four([(0, 2), (1, 2), (1, 1), (0, 1)] .+
73
[(0.25, 0.5), (0.25, 0.5), (0.25, 0.5), (0.25, 0.5)])
74
scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)
75
76
plot!(Shape([(0, 0), (0, 1), (1, 1), (1, 0)] .+
77
[(0.25, 0.0), (0.25, 0.0), (0.25, 0.0), (0.25, 0.0)]), linecolor = "black",
78
fillcolor = "white", label = false, linewidth = 2)
79
80
nodes_2d = nodes_project_four([(0, 0), (0, 1), (1, 1), (1, 0)] .+
81
[(0.25, 0.0), (0.25, 0.0), (0.25, 0.0), (0.25, 0.0)])
82
scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)
83
84
plot!(Shape([(2, 0), (2, 1), (1, 1), (1, 0)] .+
85
[(0.75, 0.0), (0.75, 0.0), (0.75, 0.0), (0.75, 0.0)]), linecolor = "black",
86
fillcolor = "white", label = false, linewidth = 2)
87
88
nodes_2d = nodes_project_four([(2, 0), (2, 1), (1, 1), (1, 0)] .+
89
[(0.75, 0.0), (0.75, 0.0), (0.75, 0.0), (0.75, 0.0)])
90
scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)
91
92
# upper left
93
plot!(Shape([(-0, 2), (-0, 1), (-1, 1), (-1, 2)] .+
94
[(-0.25, 0.5), (-0.25, 0.5), (-0.25, 0.5), (-0.25, 0.5)]), linecolor = "black",
95
fillcolor = "white", label = false, linewidth = 2)
96
97
nodes_2d = nodes_project_four([(-0, 2), (-0, 1), (-1, 1), (-1, 2)] .+
98
[(-0.25, 0.5), (-0.25, 0.5), (-0.25, 0.5), (-0.25, 0.5)])
99
scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)
100
101
plot!(Shape([(-2, 2), (-1, 2), (-1, 1), (-2, 1)] .+
102
[(-0.75, 0.5), (-0.75, 0.5), (-0.75, 0.5), (-0.75, 0.5)]), linecolor = "black",
103
fillcolor = "white", label = false, linewidth = 2)
104
105
nodes_2d = nodes_project_four([(-2, 2), (-1, 2), (-1, 1), (-2, 1)] .+
106
[(-0.75, 0.5), (-0.75, 0.5), (-0.75, 0.5), (-0.75, 0.5)])
107
scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)
108
109
plot!(Shape([(-2, 0), (-2, 1), (-1, 1), (-1, 0)] .+
110
[(-0.75, 0.0), (-0.75, 0.0), (-0.75, 0.0), (-0.75, 0.0)]), linecolor = "black",
111
fillcolor = "white", label = false, linewidth = 2)
112
113
nodes_2d = nodes_project_four([(-2, 0), (-2, 1), (-1, 1), (-1, 0)] .+
114
[(-0.75, 0.0), (-0.75, 0.0), (-0.75, 0.0), (-0.75, 0.0)])
115
scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)
116
117
plot!(Shape([(-0, 0), (-1, 0), (-1, 1), (-0, 1)] .+
118
[(-0.25, 0.0), (-0.25, 0.0), (-0.25, 0.0), (-0.25, 0.0)]), linecolor = "black",
119
fillcolor = "white", label = false, linewidth = 2)
120
121
nodes_2d = nodes_project_four([(-0, 0), (-1, 0), (-1, 1), (-0, 1)] .+
122
[(-0.25, 0.0), (-0.25, 0.0), (-0.25, 0.0), (-0.25, 0.0)])
123
scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)
124
125
# lower left
126
plot!(Shape([(-0, -0), (-0, -1), (-1, -1), (-1, -0)] .+
127
[(-0.25, -0.5), (-0.25, -0.5), (-0.25, -0.5), (-0.25, -0.5)]),
128
linecolor = "black", fillcolor = "white", label = false, linewidth = 2)
129
130
nodes_2d = nodes_project_four([(-0, -0), (-0, -1), (-1, -1), (-1, -0)] .+
131
[(-0.25, -0.5), (-0.25, -0.5), (-0.25, -0.5), (-0.25, -0.5)])
132
scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)
133
134
plot!(Shape([(-2, -1), (-2, 0), (-1, -0), (-1, -1)] .+
135
[(-0.75, -0.5), (-0.75, -0.5), (-0.75, -0.5), (-0.75, -0.5)]),
136
linecolor = "black", fillcolor = "white", label = false, linewidth = 2)
137
138
nodes_2d = nodes_project_four([(-2, -1), (-2, 0), (-1, -0), (-1, -1)] .+
139
[(-0.75, -0.5), (-0.75, -0.5), (-0.75, -0.5), (-0.75, -0.5)])
140
scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)
141
142
plot!(Shape([(-2, -2), (-2, -1), (-1, -1), (-1, -2)] .+
143
[(-0.75, -1), (-0.75, -1), (-0.75, -1), (-0.75, -1)]), linecolor = "black",
144
fillcolor = "white", label = false, linewidth = 2)
145
146
nodes_2d = nodes_project_four([(-2.0, -2.0), (-2.0, -1.0), (-1.0, -1.0), (-1.0, -2.0)] .+
147
[(-0.75, -1), (-0.75, -1), (-0.75, -1), (-0.75, -1)])
148
scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)
149
150
plot!(Shape([(-1, -2), (-1, -1), (-0, -1), (-0, -2)] .+
151
[(-0.25, -1), (-0.25, -1), (-0.25, -1), (-0.25, -1)]), linecolor = "black",
152
fillcolor = "white", label = false, linewidth = 2)
153
154
nodes_2d = nodes_project_four([(-1.0, -2.0), (-1.0, -1.0), (-0.0, -1.0), (-0.0, -2.0)] .+
155
[(-0.25, -1), (-0.25, -1), (-0.25, -1), (-0.25, -1)])
156
scatter!(nodes_2d[:, 1], nodes_2d[:, 2], color = "red", label = false, markersize = 5)
157
158
savefig("./elements")
159
160