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

Remove grid representation from MixedDofHandler #577

Merged
merged 2 commits into from
Mar 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 7 additions & 29 deletions src/Dofs/MixedDofHandler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,14 @@ Construct a `MixedDofHandler` based on `grid`. Supports:
struct MixedDofHandler{dim,T,G<:AbstractGrid{dim}} <: AbstractDofHandler
fieldhandlers::Vector{FieldHandler}
cell_dofs::CellVector{Int}
cell_nodes::CellVector{Int}
cell_coords::CellVector{Vec{dim,T}}
closed::ScalarWrapper{Bool}
grid::G
ndofs::ScalarWrapper{Int}
end

function MixedDofHandler(grid::Grid{dim,C,T}) where {dim,C,T}
ncells = getncells(grid)
MixedDofHandler{dim,T,typeof(grid)}(FieldHandler[], CellVector(Int[],zeros(Int,ncells),zeros(Int,ncells)), CellVector(Int[],Int[],Int[]), CellVector(Vec{dim,T}[],Int[],Int[]), ScalarWrapper(false), grid, ScalarWrapper(-1))
MixedDofHandler{dim,T,typeof(grid)}(FieldHandler[], CellVector(Int[],zeros(Int,ncells),zeros(Int,ncells)), ScalarWrapper(false), grid, ScalarWrapper(-1))
end

getfieldnames(fh::FieldHandler) = [field.name for field in fh.fields]
Expand All @@ -73,7 +71,7 @@ Return the number of degrees of freedom for the cell with index `cell`.
See also [`ndofs`](@ref).
"""
ndofs_per_cell(dh::MixedDofHandler, cell::Int=1) = dh.cell_dofs.length[cell]
nnodes_per_cell(dh::MixedDofHandler, cell::Int=1) = dh.cell_nodes.length[cell]
nnodes_per_cell(dh::MixedDofHandler, cell::Int=1) = nnodes_per_cell(dh.grid, cell) # TODO: deprecate, shouldn't belong to MixedDofHandler any longer

"""
celldofs!(global_dofs::Vector{Int}, dh::AbstractDofHandler, i::Int)
Expand Down Expand Up @@ -101,21 +99,15 @@ function celldofs(dh::MixedDofHandler, i::Int)
return dh.cell_dofs[i]
end

function cellcoords!(global_coords::Vector{Vec{dim,T}}, dh::MixedDofHandler, i::Int) where {dim,T}
@assert isclosed(dh)
@assert length(global_coords) == nnodes_per_cell(dh, i)
unsafe_copyto!(global_coords, 1, dh.cell_coords.values, dh.cell_coords.offset[i], length(global_coords))
return global_coords
#TODO: perspectively remove in favor of `getcoordinates!(global_coords, grid, i)`?
function cellcoords!(global_coords::Vector{Vec{dim,T}}, dh::MixedDofHandler, i::Union{Int, <:AbstractCell}) where {dim,T}
cellcoords!(global_coords, dh.grid, i)
end

function cellnodes!(global_nodes::Vector{Int}, dh::MixedDofHandler, i::Int)
@assert isclosed(dh)
@assert length(global_nodes) == nnodes_per_cell(dh, i)
unsafe_copyto!(global_nodes, 1, dh.cell_nodes.values, dh.cell_nodes.offset[i], length(global_nodes))
return global_nodes
function cellnodes!(global_nodes::Vector{Int}, dh::MixedDofHandler, i::Union{Int, <:AbstractCell})
cellnodes!(global_nodes, dh.grid, i)
end


"""
getfieldnames(dh::MixedDofHandler)
getfieldnames(fh::FieldHandler)
Expand Down Expand Up @@ -265,20 +257,6 @@ function __close!(dh::MixedDofHandler{dim}) where {dim}
dh.ndofs[] = maximum(dh.cell_dofs.values)
dh.closed[] = true

#Create cell_nodes and cell_coords (similar to cell_dofs)
push!(dh.cell_nodes.offset, 1)
push!(dh.cell_coords.offset, 1)
for cell in dh.grid.cells
for nodeid in cell.nodes
push!(dh.cell_nodes.values, nodeid)
push!(dh.cell_coords.values, dh.grid.nodes[nodeid].x)
end
push!(dh.cell_nodes.offset, length(dh.cell_nodes.values)+1)
push!(dh.cell_coords.offset, length(dh.cell_coords.values)+1)
push!(dh.cell_nodes.length, length(cell.nodes))
push!(dh.cell_coords.length, length(cell.nodes))
end

return dh, vertexdicts, edgedicts, facedicts

end
Expand Down