Skip to content

Commit

Permalink
Remove grid representation from MixedDofHandler (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimauth committed Mar 21, 2023
1 parent 52ef7dc commit cc81e6c
Showing 1 changed file with 7 additions and 29 deletions.
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

0 comments on commit cc81e6c

Please sign in to comment.