Skip to content

Commit

Permalink
Merge pull request #10 from co1emi11er2:makie_extension
Browse files Browse the repository at this point in the history
Create Makie Extension
  • Loading branch information
AkchurinDA authored Oct 2, 2024
2 parents c5e1c34 + d3d3412 commit 09b0299
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 65 deletions.
7 changes: 6 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ version = "0.1.0"
BlockDiagonals = "0a1fb500-61f7-11e9-3c65-f5ef3456f9f0"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MakieCore = "20f20a25-4f0e-4fdf-b5d1-57303727442b"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
StyledStrings = "f489334b-da3d-4c2e-b8f0-e476e12c162b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[weakdeps]
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

[extensions]
HephaestusMakieExt = "Makie"

[compat]
BlockDiagonals = "0.1"
DocStringExtensions = "0.9"
Expand Down
2 changes: 2 additions & 0 deletions docs/src/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ del_dist_load!
get_node_u_g
get_element_u_l
get_element_f_l
plotmodel
plotmodel!
```
80 changes: 80 additions & 0 deletions ext/HephaestusMakieExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
module HephaestusMakieExt
using Hephaestus
using Makie

import Hephaestus: plotmodel, plotmodel!

Makie.@recipe(PlotModel, Model) do scene
Makie.Attributes(
# Nodes:
node_color = :red ,
node_marker = :circle,
node_markersize = 6,
node_strokecolor = :black,
node_strokewidth = 1,

# Node labels:
label_nodes = true,
align_node_labels = (:center, :bottom),
node_label_color = :red,

# Elements:
element_color = :black,
element_linestyle = :solid,
element_linewidth = 1,

# Element labels:
label_elements = true,
align_element_labels = (:center, :bottom),
element_label_color = :black)
end

function Makie.plot!(P::PlotModel)
model = P[:Model]

for element in values(model[].elements)
x_i, y_i, z_i = element.x_i, element.y_i, element.z_i
x_j, y_j, z_j = element.x_j, element.y_j, element.z_j

lines!(P, [x_i, x_j], [y_i, y_j], [z_i, z_j],
color = P[:element_color ],
linestyle = P[:element_linestyle],
linewidth = P[:element_linewidth])

if P[:label_elements][]
x_m = (x_i + x_j) / 2
y_m = (y_i + y_j) / 2
z_m = (z_i + z_j) / 2

text!(P, [x_m], [y_m], [z_m],
text = string(element.ID),
color = P[:element_label_color ],
align = P[:align_element_labels])
end
end

for node in values(model[].nodes)
x, y, z = node.x, node.y, node.z

scatter!(P, [x], [y], [z],
color = P[:node_color ],
marker = P[:node_marker ],
markersize = P[:node_markersize ],
strokecolor = P[:node_strokecolor],
strokewidth = P[:node_strokewidth],
overdraw = true)

if P[:label_nodes][]
text!(P, [x], [y], [z],
text = string(node.ID),
color = P[:node_label_color ],
align = P[:align_node_labels])
end
end

# Return the updated model plot:
return P
end

Makie.preferred_axis_type(P::PlotModel) = Makie.Axis3
end
10 changes: 10 additions & 0 deletions src/Analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,20 @@ struct O2ESolutionCache <: AbstractSolutionCache

end

"""
struct EBAnalysis
A type that represents the elastic buckling (`EB`) analysis.
"""
struct EBAnalysis <: AbstractAnalysisType

end

"""
struct EBSolutionCache
A type that stores the results of the elastic buckling analysis.
"""
struct EBSolutionCache <: AbstractSolutionCache
Λ::Vector{<:Real}
Φ::Matrix{<:Real}
Expand Down
4 changes: 2 additions & 2 deletions src/Hephaestus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export add_node!, add_material!, add_section!, add_element!, add_support!, add_c
export del_node!, del_material!, del_section!, del_element!, del_support!, del_conc_load!, del_dist_load!
export get_node_u_g, get_element_u_l, get_element_f_l
include("Analysis.jl")
export O1EAnalysis, O1EAnalysisCache
export O2EAnalysis, O2EAnalysisCache
export O1EAnalysis, O1ESolutionCache
export O2EAnalysis, O2ESolutionCache
export EBAnalysis, EBSolutionCache
export solve
include("AnalysisUtilities.jl")
Expand Down
98 changes: 37 additions & 61 deletions src/Plotting.jl
Original file line number Diff line number Diff line change
@@ -1,73 +1,49 @@
using MakieCore
"""
plotmodel(model::Model, [options])
MakieCore.@recipe(PlotModel, Model) do scene
MakieCore.Attributes(
# Nodes:
node_color = :red ,
node_marker = :circle,
node_markersize = 6,
node_strokecolor = :black,
node_strokewidth = 1,
Plots a model of a structure of interest ([`Model`](@ref)) into a new `Makie.jl` scene.
# Node labels:
label_nodes = true,
align_node_labels = (:center, :bottom),
node_label_color = :red,
# Plotting Options
# Elements:
element_color = :black,
element_linestyle = :solid,
element_linewidth = 1,

# Element labels:
label_elements = true,
align_element_labels = (:center, :bottom),
element_label_color = :black)
end
## Nodes
function MakieCore.plot!(P::PlotModel)
model = P[:Model]
| Option | Description | Default |
| :--- | :--- | :--- |
| `node_color` | Color of the nodes | `:red` |
| `node_marker` | Marker of the nodes | `:circle` |
| `node_markersize`| Size of the nodes | `6` |
| `node_strokecolor`| Stroke color of the nodes | `:black` |
| `node_strokewidth`| Stroke width of the nodes | `1` |
for element in values(model[].elements)
x_i, y_i, z_i = element.x_i, element.y_i, element.z_i
x_j, y_j, z_j = element.x_j, element.y_j, element.z_j
## Node Labels
lines!(P, [x_i, x_j], [y_i, y_j], [z_i, z_j],
color = P[:element_color ],
linestyle = P[:element_linestyle],
linewidth = P[:element_linewidth])
| Option | Description | Default |
| :--- | :--- | :--- |
| `label_nodes` | Whether to label the nodes| `true` |
| `align_node_labels`| Alignment of the node labels | `(:center, :bottom)` |
| `node_label_color`| Color of the node labels | `:red` |
if P[:label_elements][]
x_m = (x_i + x_j) / 2
y_m = (y_i + y_j) / 2
z_m = (z_i + z_j) / 2
## Elements
text!(P, [x_m], [y_m], [z_m],
text = string(element.ID),
color = P[:element_label_color ],
align = P[:align_element_labels])
end
end
| Option | Description | Default |
| :--- | :--- | :--- |
| `element_color` | Color of the elements | `:black` |
| `element_linestyle`| Line style of the elements | `:solid` |
| `element_linewidth`| Line width of the elements | `1` |
for node in values(model[].nodes)
x, y, z = node.x, node.y, node.z
## Element Labels
scatter!(P, [x], [y], [z],
color = P[:node_color ],
marker = P[:node_marker ],
markersize = P[:node_markersize ],
strokecolor = P[:node_strokecolor],
strokewidth = P[:node_strokewidth],
overdraw = true)
| Option | Description | Default |
| :--- | :--- | :--- |
| `label_elements` | Whether to label the elements | `true` |
| `align_element_labels`| Alignment of the element labels | `(:center, :bottom)` |
| `element_label_color`| Color of the element labels | `:black` |
"""
function plotmodel end

if P[:label_nodes][]
text!(P, [x], [y], [z],
text = string(node.ID),
color = P[:node_label_color ],
align = P[:align_node_labels])
end
end
"""
plotmodel!(model::Model, [options])
# Return the updated model plot:
return P
end
Plots a model of a structure of interest ([`Model`](@ref)) into an existing scene. The plotting options are the same as in [`plotmodel()`](@ref) function.
"""
function plotmodel! end
12 changes: 11 additions & 1 deletion test/test.jl → test/Plotting.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Hephaestus
using GLMakie

M = Model()

Expand Down Expand Up @@ -43,4 +44,13 @@ add_support!(M, 11, false, false, true, true, true, false)

add_conc_load!(M, 11, 0, -1, 0, 0, 0, 0)

Solution = solve(M, EBAnalysis())
plotmodel(M)

begin
F = Figure()
A = Axis3(F[1, 1])

plotmodel!(A, M)

display(F)
end

0 comments on commit 09b0299

Please sign in to comment.