diff --git a/ext/FiniteElementContainersKernelAbstractionsExt.jl b/ext/FiniteElementContainersKernelAbstractionsExt.jl deleted file mode 100644 index 6fd07d9..0000000 --- a/ext/FiniteElementContainersKernelAbstractionsExt.jl +++ /dev/null @@ -1,110 +0,0 @@ -module FiniteElementContainersKernelAbstractionsExt - -using FiniteElementContainers -using KernelAbstractions - -# DofManagers -function FiniteElementContainers.create_fields( - ::DofManager{T, ND, NN, A, V}, - backend::Backend -) where {T, ND, NN, A <: AbstractVector, V} - vals = KernelAbstractions.zeros(backend, eltype(A), ND * NN) - return NodalField{ND, NN, Vector}(vals) -end - -function FiniteElementContainers.create_fields( - ::DofManager{T, ND, NN, A, V}, - backend::Backend -) where {T, ND, NN, A <: AbstractMatrix, V} - vals = KernelAbstractions.zeros(backend, eltype(A), ND, NN) - return NodalField{ND, NN, Matrix}(vals) -end - -function FiniteElementContainers.create_unknowns( - dof::DofManager{T, ND, NN, A, V}, - backend::Backend -) where {T, ND, NN, A, V} - return KernelAbstractions.zeros(backend, eltype(A), length(dof.unknown_dofs)) -end - -@kernel function update_fields_kernel!(U::NodalField, dof::DofManager, Uu::V) where V <: AbstractVector - I = @index(Global) - U[dof.unknown_dofs[I]] = Uu[I] -end - -# TODO add wg size as parameter -function FiniteElementContainers.update_fields!(U::NodalField, dof::DofManager, Uu::V, backend::Backend) where V <: AbstractVector - @assert length(Uu) == length(dof.unknown_dofs)#sum(dof.is_unknown) - kernel = update_fields_kernel!(backend) - kernel(U, dof, Uu, ndrange=length(Uu)) - synchronize(backend) -end - -@kernel function update_unknown_dofs_kernel!(dof, dofs) - I = @index(Global) - dof.unknown_dofs[I] = dofs[I] - nothing -end - -function FiniteElementContainers.update_unknown_dofs!( - dof::DofManager{T, ND, NN, A, V}, - backend::Backend -) where {T, ND, NN, A, V} - resize!(dof.unknown_dofs, ND * NN) - dofs = FiniteElementContainers.dof_ids(dof) - kernel = update_unknown_dofs_kernel!(backend) - kernel(dof, dofs, ndrange=length(dofs)) - nothing -end - -# function FiniteElementContainers.update_unknown_dofs!( -# dof::DofManager{T, ND, NN, A, V1}, -# dofs::V2, -# backend::Backend -# ) where {T, ND, NN, A, V1, V2 <: AbstractVector{<:Integer}} -# resize!(dof.unknown_dofs, ND * NN) -# dofs_all = FiniteElementContainers.dof_ids(dof) -# kernel = update_unknown_dofs_kernel!(backend) -# kernel(dof, dofs_all, ndrange=length(dofs_all)) -# # setdiff!(dofs_all, dofs) -# # resize!(dof.unknown_indices, length(dofs_all)) -# # dof.unknown_indices .= dofs_all -# # deleteat!(dof.unknown_dofs, dofs) -# setdiff!(dof.unknown_dofs, dofs) -# nothing -# end - -# @kernel function update_unknown_dofs_non_default_kernel!(dof, dofs) -# I -# end -# @kernel function update_unknown_ids_nset_kernel!(dof_manager, nset, dof) -# I = @index(Global) -# dof_manager[dof, nset[I]] = 0 -# end - -# @kernel function update_unknown_ids_kernel!(dof, ids) -# I = @index(Global) -# dof.unknown_indices[I] = ids[dof.unknown_dofs[I]] -# end - -# function FiniteElementContainers.update_unknown_dofs!( -# dof::DofManager, -# nsets::Nsets, -# dofs::Dofs, -# backend::Backend -# ) where {Nsets, Dofs} - -# kernel1 = update_unknown_ids_nset_kernel!(backend) -# kernel2 = update_unknown_ids_kernel!(backend) -# @assert length(nsets) == length(dofs) -# for (n, nset) in enumerate(nsets) -# @assert dofs[n] > 0 && dofs[n] <= num_dofs_per_node(dof) -# kernel1(dof, nset, dofs[n], ndrange=length(nset)) -# end -# resize!(dof.unknown_indices, length(dof.unknown_dofs)) -# ids = FiniteElementContainers.dof_ids(dof) -# kernel2(dof, ids, ndrange=length(dof.unknown_dofs)) -# synchronize(backend) -# end - -end # module \ No newline at end of file diff --git a/src/bcs/DirichletBCs.jl b/src/bcs/DirichletBCs.jl index 33b11e3..03967d6 100644 --- a/src/bcs/DirichletBCs.jl +++ b/src/bcs/DirichletBCs.jl @@ -1,15 +1,3 @@ -# struct DirichletBC{S, B, F} <: AbstractBC{S, B, F} -# bookkeeping::B -# func::F -# end - -# function DirichletBC(dof::DofManager, var_name::Symbol, sset_name::Symbol, func::Function) -# bookkeeping = BCBookKeeping(dof, var_name, sset_name; build_dofs_array=true) -# sym = Symbol(var_name, :_, sset_name) -# func = BCFunction(func) -# return DirichletBC{sym, typeof(bookkeeping), typeof(func)}(bookkeeping, func) -# end - """ $(TYPEDEF) $(TYPEDSIGNATURES) @@ -31,13 +19,6 @@ function DirichletBC(var_name::Symbol, sset_name::Symbol, func::Function) return DirichletBC{typeof(func)}(func, sset_name, var_name) end -# struct DirichletBCContainer_old{B, F, I, V} <: AbstractBCContainer{B, F, I, V} -# bookkeeping::B -# funcs::F -# func_ids::I -# vals::V -# end - """ $(TYPEDEF) $(TYPEDSIGNATURES) @@ -54,106 +35,18 @@ end # 1. remove bookkeeping from bcs # 2. have bcs only take in a sset name, var name, and func # 3. create one giant bookkeeper here -function DirichletBCContainer_old_old(dbcs, num_dim) - - # quick hack fix for now - - - blocks = mapreduce(x -> repeat(x.bookkeeping.blocks, length(x.bookkeeping.elements)), vcat, dbcs) - dofs = mapreduce(x -> x.bookkeeping.dofs, vcat, dbcs) - elements = mapreduce(x -> x.bookkeeping.elements, vcat, dbcs) - nodes = mapreduce(x -> x.bookkeeping.nodes, vcat, dbcs) - sides = mapreduce(x -> x.bookkeeping.sides, vcat, dbcs) - func_ids = mapreduce( - (x, y) -> fill(x, length(y.bookkeeping.dofs)), - vcat, - 1:length(dbcs), dbcs - ) - vals = zeros(length(dofs)) - - dof_perm = _unique_sort_perm(dofs) - el_perm = _unique_sort_perm(elements) - blocks = blocks[el_perm] - dofs = dofs[dof_perm] - elements = elements[el_perm] - nodes = nodes[dof_perm] - sides = sides[el_perm] - func_ids = func_ids[dof_perm] - vals = vals[dof_perm] - - sym = Symbol("dirichlet_bcs") - bk = BCBookKeeping{num_dim, sym, Int, typeof(dofs)}(blocks, dofs, elements, nodes, sides) - func_syms = map(x -> Symbol("function_$x"), 1:length(dbcs)) - funcs = map(x -> x.func, dbcs) - funcs = NamedTuple{tuple(func_syms...)}(tuple(funcs...)) - - return DirichletBCContainer(bk, funcs, func_ids, vals) -end - -function DirichletBCContainer_old(dof, dbcs) - var_names = map(x -> x.var_name, dbcs) - sset_names = map(x -> x.sset_name, dbcs) - bk = BCBookKeeping(dof, var_names, sset_names) - - # now sort and unique this stuff - # TODO clean this up or move func ids into bookkeeping - dof_perm = _unique_sort_perm(bk.dofs) - el_perm = _unique_sort_perm(bk.elements) - - # TODO fix up blocks - # copyto!(bk.dofs, bk.dofs[dof_perm]) - # copyto!(bk.elements, bk.elements[el_perm]) - # copyto!(bk.nodes, bk.nodes[dof_perm]) - # copyto!(bk.sides, bk.sides[el_perm]) - # bk.dofs .= bk.dofs[dof_perm] - dofs_new = bk.dofs[dof_perm] - elements_new = bk.elements[el_perm] - nodes_new = bk.nodes[dof_perm] - sides_new = bk.sides[el_perm] - resize!(bk.dofs, length(dofs_new)) - resize!(bk.elements, length(elements_new)) - resize!(bk.nodes, length(nodes_new)) - resize!(bk.sides, length(sides_new)) - copyto!(bk.dofs, dofs_new) - copyto!(bk.elements, elements_new) - copyto!(bk.nodes, nodes_new) - copyto!(bk.sides, sides_new) - # bk.dofs .= dofs_new - - # setup func ids - fspace = dof.H1_vars[1].fspace - n_entries = map(x -> length(getproperty(fspace.sideset_nodes, x.sset_name)), dbcs) - func_ids = mapreduce((x, y) -> fill(x, y), vcat, 1:length(n_entries), n_entries) - func_ids = func_ids[dof_perm] - - func_syms = map(x -> Symbol("function_$x"), 1:length(dbcs)) - funcs = map(x -> x.func, dbcs) - funcs = NamedTuple{tuple(func_syms...)}(tuple(funcs...)) - - vals = zeros(length(bk.nodes)) - - return DirichletBCContainer(bk, funcs, func_ids, vals) -end function DirichletBCContainer(dof, dbc) - # var_names = map(x -> x.var_name, dbcs) - # sset_names = map(x -> x.sset_name, dbcs) var_name = dbc.var_name sset_name = dbc.sset_name - # bk = BCBookKeeping(dof, var_names, sset_names) + bk = BCBookKeeping(dof, var_name, sset_name) # now sort and unique this stuff - # TODO clean this up or move func ids into bookkeeping dof_perm = _unique_sort_perm(bk.dofs) el_perm = _unique_sort_perm(bk.elements) - # TODO fix up blocks - # copyto!(bk.dofs, bk.dofs[dof_perm]) - # copyto!(bk.elements, bk.elements[el_perm]) - # copyto!(bk.nodes, bk.nodes[dof_perm]) - # copyto!(bk.sides, bk.sides[el_perm]) - # bk.dofs .= bk.dofs[dof_perm] + # do permutations dofs_new = bk.dofs[dof_perm] elements_new = bk.elements[el_perm] nodes_new = bk.nodes[dof_perm] @@ -166,25 +59,10 @@ function DirichletBCContainer(dof, dbc) copyto!(bk.elements, elements_new) copyto!(bk.nodes, nodes_new) copyto!(bk.sides, sides_new) - # bk.dofs .= dofs_new - - # setup func ids - # fspace = dof.H1_vars[1].fspace - # n_entries = map(x -> length(getproperty(fspace.sideset_nodes, x.sset_name)), dbcs) - # func_ids = mapreduce((x, y) -> fill(x, y), vcat, 1:length(n_entries), n_entries) - # func_ids = func_ids[dof_perm] - - # func_syms = map(x -> Symbol("function_$x"), 1:length(dbcs)) - # funcs = map(x -> x.func, dbcs) - # funcs = NamedTuple{tuple(func_syms...)}(tuple(funcs...)) - - func = dbc.func vals = zeros(length(bk.nodes)) - # return DirichletBCContainer(bk, funcs, func_ids, vals) - return DirichletBCContainer(bk, func, vals) + return DirichletBCContainer(bk, dbc.func, vals) end -num_dimensions(bc::DirichletBCContainer) = num_dimensions(bc.bookkeeping) KA.get_backend(x::DirichletBCContainer) = KA.get_backend(x.bookkeeping) diff --git a/src/integrators/QuasiStaticIntegrator.jl b/src/integrators/QuasiStaticIntegrator.jl index 1d7b0b6..c9dee57 100644 --- a/src/integrators/QuasiStaticIntegrator.jl +++ b/src/integrators/QuasiStaticIntegrator.jl @@ -16,6 +16,5 @@ function evolve!(integrator::QuasiStaticIntegrator, p) update_time!(p) update_bcs!(H1Field, integrator.solver, integrator.solution, p) solve!(integrator.solver, integrator.solution, p) - # copyto!(integrator.solution, Uu) return nothing end