Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1D Elements #41

Open
koehlerson opened this issue Aug 25, 2022 · 6 comments
Open

1D Elements #41

koehlerson opened this issue Aug 25, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@koehlerson
Copy link
Member

koehlerson commented Aug 25, 2022

How to triangulate Line, Line2D, Line3D ? Maybe just lines from Makie? How to incorporate this properly? https://makie.juliaplots.org/stable/examples/plotting_functions/lines/#example_11610848752349455524

@koehlerson koehlerson added the enhancement New feature or request label Aug 25, 2022
@termi-official
Copy link
Member

Related to this and if I remember correctly, then quads and triangles in 3D also do not work yet.

@termi-official
Copy link
Member

Maybe we should rearrange the plotter struct to hold sets of triangles and additionally sets of lines for e.g 1D elements, wireframes, streamlines and so on. This way we only have one point where we need to update lines to fix e.g. deformed domains. Should also fix #26 .

@asinghvi17
Copy link

I assume the MakiePlotter struct's definition is here,

struct MakiePlotter{dim,DH<:Ferrite.AbstractDofHandler,T1,TOP<:Union{Nothing,Ferrite.AbstractTopology},T2,M,TRI} <: AbstractPlotter
dh::DH
u::Makie.Observable{Vector{T1}} # original solution on the original mesh (i.e. dh.mesh)
topology::TOP
visible::Vector{Bool} #TODO change from per cell to per triangle
gridnodes::Vector{GeometryBasics.Point{dim,T2}} # coordinates of grid nodes in matrix form
physical_coords::Vector{GeometryBasics.Point{dim,T2}} #original coordinates in physical space of a vertex
physical_coords_mesh::ShaderAbstractions.Buffer{GeometryBasics.Point{dim,T2},Vector{GeometryBasics.Point{dim,T2}}} # coordinates in physical space of a vertex
all_triangles::Vector{TRI}
vis_triangles::ShaderAbstractions.Buffer{TRI,Vector{TRI}}
triangle_cell_map::Vector{Int}
cell_triangle_offsets::Vector{Int}
reference_coords::Matrix{T1} # coordinates on the associated reference cell for the corresponding triangle vertex
mesh::M
end

and it looks like cells are triangulated and assembled here,

function MakiePlotter(dh::Ferrite.AbstractDofHandler, u::Vector, topology::TOP) where {TOP<:Union{Nothing,Ferrite.AbstractTopology}}
cells = Ferrite.getcells(dh.grid)
dim = Ferrite.getdim(dh.grid)
visible = zeros(Bool,length(cells))
if dim > 2
boundaryfaces = findall(isempty,topology.face_neighbor)
boundaryelements = Ferrite.getindex.(boundaryfaces,1)
else
boundaryelements = collect(1:Ferrite.getncells(dh.grid))
end
visible[boundaryelements] .= true
# We do not take any assumptions on the mesh, so first we have to loopkup
num_triangles = 0
cell_triangle_offsets = Vector{Int}(undef, length(cells)+1)
cell_triangle_offsets[1] = 0
for (cell_idx, cell) in enumerate(cells)
num_triangles += ntriangles(cell)
cell_triangle_offsets[cell_idx+1] = num_triangles
end

so maybe we could filter all line elements out of cells before they go into the triangulation loop, and apply some preprocessing? I'd be happy to do a first implementation (branched off from #103 of course) with some guidance from you all!

@termi-official
Copy link
Member

Thanks for your interest on this Anshul! Happy to give you some guidance on this.

You are right, we have the plotter struct, which acts essentially as a cache. This cache contains some kind of remeshing of the Ferrite mesh that is comaptible with Makie (to overcome the issue that GeometryBasics has no sane way to handle nonlinear geometries yet).

My idea here was slightly different. In this loop we could just set ntriangles to 0 and also just do a no-op in the discretization function decompose! in utils.jl . The issue is that I am not sure if we can make decompose work on 1D elements with Makie right now, because we cannot dynamically generate screen-facing triangles.

To render the lines we can then add an additional fields to the struct to track 1D elements separately as Makie.lines, analogue to the way we handle triangles. An alternative idea is that we can also mesh line elements as cylinder geometries with some associated thickness. I am open to experiment here.

If 103 does not work, then I will find some time tomorrow to update it. This should be easy on my side.

Out of interest, what is your application? Do you "just" want to plot some solution in 1D with a 1D discretization or is this one more about beams, wires, ... in 2D/3D? If you want to make the former work, then we can get away with something much simpler by "just" adding specialized dispatches for dim=1.

@asinghvi17
Copy link

Thanks for the advice! I'm primarily looking at 1D discretizations, but if I'm putting the effort in anyway, may as well write it for 2/3D too :D

I'd lean towards the lines proposal as an initial implementation, just because it seems simplest. Meshing as a cylinder would need UV support etc that seems like a pain at this point, but it can always be added later under this framework.

@termi-official
Copy link
Member

I'd lean towards the lines proposal as an initial implementation [...]

Sure, let us start there. :)

[...] would need UV support [...]

Note that we have a different approach. Instead of providing textures directly we discretize the geometry manually on our end and map colors to the vertices of the triangles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants