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

Improve of Line generation #1122

Open
zkk960317 opened this issue Dec 29, 2024 · 1 comment
Open

Improve of Line generation #1122

zkk960317 opened this issue Dec 29, 2024 · 1 comment

Comments

@zkk960317
Copy link

function Ferrite.generate_grid(::Type{Line}, nel::NTuple{1,Int}, left::Vec{dim,T}=Vec{1}((-1.0,)), right::Vec{dim,T}=Vec{1}((1.0, ))) where {T,dim}
    nel_x = nel[1]
    n_nodes = nel_x + 1

    # Generate nodes
    coords = Vector{Float64}[]
    for i in 1:dim
        coords_x = collect(range(left[i], stop=right[i], length=n_nodes))
        push!(coords, coords_x)
    end
    nodes = Node{dim,T}[]
    for i in 1:n_nodes
        push!(nodes, Node(Tuple(coords[j][i] for j in 1:dim)))
    end

    # Generate cells
    cells = Line[]
    for i in 1:nel_x
        push!(cells, Line((i, i + 1)))
    end

    # Cell faces
    boundary = Vector([FacetIndex(1, 1),
                       FacetIndex(nel_x, 2)])

    # Cell face sets
    facetsets = Dict("left"  => Ferrite.OrderedSet{FacetIndex}([boundary[1]]),
                     "right" => Ferrite.OrderedSet{FacetIndex}([boundary[2]]))
    return Grid(cells, nodes, facetsets=facetsets)
end

Compared to the original code, this can generate 2D and 3D lines based on the dimension of input left / right node, and the default is 1D line.

@KnutAM
Copy link
Member

KnutAM commented Dec 29, 2024

Thanks for the suggestion!
To me, this functionality makes sense. If you would like to include it in Ferrite, please open a pull request.

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

No branches or pull requests

2 participants