@@ -28,6 +28,8 @@ function _unique_sort_perm(array::AbstractArray{T, 1}) where T <: Number
2828 return [id_map[x] for x in sorted_unique]
2929end
3030
31+ const SetName = Union{Nothing, Symbol}
32+
3133"""
3234$(TYPEDEF)
3335$(TYPEDSIGNATURES)
5557$(TYPEDSIGNATURES)
5658"""
5759function BCBookKeeping (
58- mesh, dof:: DofManager , var_name:: Symbol , sset_name:: Symbol
60+ mesh, dof:: DofManager , var_name:: Symbol ; # sset_name::Symbol
61+ block_name:: SetName = nothing ,
62+ nset_name:: SetName = nothing ,
63+ sset_name:: SetName = nothing
5964)
65+ # check to ensure at least one name is supplied
66+ if block_name === nothing &&
67+ nset_name === nothing &&
68+ sset_name === nothing
69+ @assert false " Need to specify either a block, nodeset or sideset."
70+ end
71+
72+ # now check to make sure only one name is not nothing
73+ if block_name != = nothing
74+ @assert nset_name === nothing && sset_name === nothing
75+ elseif nset_name != = nothing
76+ @assert block_name === nothing && sset_name === nothing
77+ elseif sset_name != = nothing
78+ @assert block_name === nothing && nset_name === nothing
79+ end
80+
6081 # get dof index associated with this var
6182 dof_index = _dof_index_from_var_name (dof, var_name)
62-
6383 fspace = function_space (dof)
6484
6585 # get sset specific fields
66- elements = getproperty (mesh. sideset_elems, sset_name)
67- nodes = getproperty (mesh. sideset_nodes, sset_name)
68- sides = getproperty (mesh. sideset_sides, sset_name)
69- side_nodes = getproperty (mesh. sideset_side_nodes, sset_name)
70-
71- blocks = Vector {Int64} (undef, 0 )
72-
73- # gather the blocks that are present in this sideset
74- # TODO this isn't quite right
75- for (n, val) in enumerate (values (mesh. element_id_maps))
76- # note these are the local elem id to the block, e.g. starting from 1.
77- indices_in_sset = indexin (val, elements)
78- filter! (x -> x != = nothing , indices_in_sset)
79-
80- if length (indices_in_sset) > 0
81- append! (blocks, repeat ([n], length (indices_in_sset)))
86+ all_dofs = reshape (1 : length (dof), size (dof))
87+
88+ if block_name != = nothing
89+ # for this case it is likely a DirichletBC or InitialCondition
90+ # so we really only need the nodes/dofs although this might
91+ # not be the case for say Hdiv or Hcurl fields...
92+ # TODO eventually set the blocks, could be useful maybe?
93+ blocks = Vector {Int64} (undef, 0 )
94+ conns = getproperty (mesh. element_conns, block_name)
95+ nodes = sort (unique (conns. data))
96+ dofs = all_dofs[dof_index, nodes]
97+ elements = getproperty (mesh. element_id_maps, block_name)
98+ # below 2 don't make sense for other mesh entity types
99+ sides = Vector {Int64} (undef, 0 )
100+ side_nodes = Matrix {Int64} (undef, 0 , 0 )
101+ elseif nset_name != = nothing
102+ # for this case we only setup the "nodes" and "dofs"
103+ blocks = Vector {Int64} (undef, 0 ) # TODO we could eventually put the blocks present here
104+ nodes = getproperty (mesh. nodeset_nodes, nset_name)
105+ dofs = all_dofs[dof_index, nodes]
106+ elements = Vector {Int64} (undef, 0 ) # TODO we could eventually put the elements present here
107+ # below 2 don't make sense for other mesh entity types
108+ sides = Vector {Int64} (undef, 0 )
109+ side_nodes = Matrix {Int64} (undef, 0 , 0 )
110+ elseif sset_name != = nothing
111+
112+ elements = getproperty (mesh. sideset_elems, sset_name)
113+ nodes = getproperty (mesh. sideset_nodes, sset_name)
114+ sides = getproperty (mesh. sideset_sides, sset_name)
115+ side_nodes = getproperty (mesh. sideset_side_nodes, sset_name)
116+
117+ blocks = Vector {Int64} (undef, 0 )
118+
119+ # gather the blocks that are present in this sideset
120+ # TODO this isn't quite right
121+ for (n, val) in enumerate (values (mesh. element_id_maps))
122+ # note these are the local elem id to the block, e.g. starting from 1.
123+ indices_in_sset = indexin (val, elements)
124+ filter! (x -> x != = nothing , indices_in_sset)
125+
126+ if length (indices_in_sset) > 0
127+ append! (blocks, repeat ([n], length (indices_in_sset)))
128+ end
82129 end
83- end
84130
85- # setup dofs local to this BC
86- all_dofs = reshape (1 : length (dof), size (dof))
87- dofs = all_dofs[dof_index, nodes]
131+ # setup dofs local to this BC
132+ # all_dofs = reshape(1:length(dof), size(dof))
133+ dofs = all_dofs[dof_index, nodes]
134+ end
88135
89136 return BCBookKeeping (
90137 blocks, dofs, elements, nodes, sides, side_nodes
@@ -143,14 +190,15 @@ $(TYPEDEF)
143190$(TYPEDSIGNATURES)
144191$(TYPEDFIELDS)
145192"""
146- abstract type AbstractBCContainer{
147- IT <: Integer ,
148- VT <: Union{<:Number, <:SVector} ,
149- N,
150- IV <: AbstractArray{IT, 1} ,
151- IM <: AbstractArray{IT, 2} ,
152- VV <: AbstractArray{VT, N}
153- } end
193+ # abstract type AbstractBCContainer{
194+ # IT <: Integer,
195+ # VT <: Union{<:Number, <:SVector},
196+ # N,
197+ # IV <: AbstractArray{IT, 1},
198+ # IM <: AbstractArray{IT, 2},
199+ # VV <: AbstractArray{VT, N}
200+ # } end
201+ abstract type AbstractBCContainer end
154202
155203KA. get_backend (x:: AbstractBCContainer ) = KA. get_backend (x. vals)
156204
0 commit comments