1+ struct VariableNameNotFoundError <: Exception
2+ end
3+
4+ _var_not_found_err () = throw (VariableNameNotFoundError ())
5+
6+ function _dof_index_from_var_name (dof, var_name)
7+ dof_index = 0
8+ found = false
9+ for name in names (dof. var)
10+ dof_index = dof_index + 1
11+ if var_name == name
12+ found = true
13+ break
14+ end
15+ end
16+
17+ if dof_index == 0 || dof_index > length (names (dof. var))
18+ _var_not_found_err ()
19+ end
20+
21+ return dof_index
22+ end
23+
124function _unique_sort_perm (array:: AbstractArray{T, 1} ) where T <: Number
225 # chatgpt BS below. Make this not use a dict
326 sorted_unique = sort (unique (array))
@@ -15,8 +38,9 @@ for all types of boundary conditions.
1538TODO need to add a domain ID for extending to Schwarz
1639"""
1740struct BCBookKeeping{
18- M <: AbstractArray{<:Integer, 2} ,
19- V <: AbstractArray{<:Integer, 1}
41+ I <: Integer ,
42+ V <: AbstractArray{I, 1} ,
43+ M <: AbstractArray{I, 2}
2044}
2145 blocks:: V
2246 dofs:: V
@@ -33,36 +57,9 @@ $(TYPEDSIGNATURES)
3357function BCBookKeeping (
3458 mesh, dof:: DofManager , var_name:: Symbol , sset_name:: Symbol
3559)
36- # check if var exists
37- # var_index = 0
38- dof_index = 0
39- found = false
40- # for (vi, var) in enumerate(dof.H1_vars)
41- # for name in names(var)
42- # dof_index = dof_index + 1
43- # if var_name == name
44- # var_index = vi
45- # found = true
46- # break
47- # end
48- # end
49- # end
50- for name in names (dof. var)
51- dof_index = dof_index + 1
52- if var_name == name
53- # var_index = vi
54- found = true
55- break
56- end
57- end
58-
59- # some error checking
60- # @assert found == true "Failed to find variable $var_name"
61- # @assert dof_index <= length(mapreduce(x -> names(x), +, dof.H1_vars)) "Found invalid dof index"
62- @assert dof_index <= length (names (dof. var)) " Found invalid dof index"
60+ # get dof index associated with this var
61+ dof_index = _dof_index_from_var_name (dof, var_name)
6362
64- # TODO
65- # fspace = dof.H1_vars[var_index].fspace
6663 fspace = function_space (dof)
6764
6865 # get sset specific fields
@@ -71,7 +68,6 @@ function BCBookKeeping(
7168 sides = getproperty (mesh. sideset_sides, sset_name)
7269 side_nodes = getproperty (mesh. sideset_side_nodes, sset_name)
7370
74- dofs = Vector {Int64} (undef, 0 )
7571 blocks = Vector {Int64} (undef, 0 )
7672
7773 # gather the blocks that are present in this sideset
@@ -86,48 +82,11 @@ function BCBookKeeping(
8682 end
8783 end
8884
89- # setting up dofs for use in dirichlet bcs
90- # TODO only works for H1
91- # ND, NN = num_dofs_per_node(dof), num_nodes(dof)
92- ND, NN = size (dof)
93- n_total_dofs = ND * NN
94- all_dofs = reshape (1 : n_total_dofs, ND, NN)
95- # temp_dofs = all_dofs[dof_index, temp_nodes]
96- temp_dofs = all_dofs[dof_index, nodes]
97- append! (dofs, temp_dofs)
98- # end
99-
100- # now sort and unique this stuff
101- # dof_perm = _unique_sort_perm(dofs)
102- # # el_perm = _unique_sort_perm(elements)
103-
104- # # do permutations
105- # # TODO need to do this in different BC types
106- # # since different BC types might want things
107- # # organized differently
108- # # blocks_new = blocks[el_perm]
109- # dofs_new = dofs[dof_perm]
110- # # elements_new = elements[el_perm]
111- # nodes_new = nodes[dof_perm]
112- # # sides_new = sides[el_perm]
113- # # side_nodes_new = side_nodes[:, el_perm]
114-
115- # # resize!(blocks, length(blocks_new))
116- # resize!(dofs, length(dofs_new))
117- # # resize!(elements, length(elements_new))
118- # resize!(nodes, length(nodes_new))
119- # # resize!(sides, length(sides_new))
120- # # resize!(side_nodes, size(side_nodes_new)...)
121- # # reshape(side_nodes, size(side_nodes_new))
122-
123- # # copyto!(blocks, blocks_new)
124- # copyto!(dofs, dofs_new)
125- # # copyto!(elements, elements_new)
126- # copyto!(nodes, nodes_new)
127- # # copyto!(sides, sides_new)
128- # # copyto!(side_nodes, side_nodes_new)
129-
130- return BCBookKeeping {typeof(side_nodes), typeof(blocks)} (
85+ # setup dofs local to this BC
86+ all_dofs = reshape (1 : length (dof), size (dof))
87+ dofs = all_dofs[dof_index, nodes]
88+
89+ return BCBookKeeping (
13190 blocks, dofs, elements, nodes, sides, side_nodes
13291 )
13392end
@@ -158,10 +117,12 @@ $(TYPEDSIGNATURES)
158117$(TYPEDFIELDS)
159118"""
160119abstract type AbstractBCContainer{
161- B <: BCBookKeeping ,
162- T <: Union{<:Number, <:SVector} ,
120+ IT <: Integer ,
121+ VT <: Union{<:Number, <:SVector} ,
163122 N,
164- V <: AbstractArray{T, N}
123+ IV <: AbstractArray{IT, 1} ,
124+ IM <: AbstractArray{IT, 2} ,
125+ VV <: AbstractArray{VT, N}
165126} end
166127
167128KA. get_backend (x:: AbstractBCContainer ) = KA. get_backend (x. vals)
@@ -171,6 +132,13 @@ function Base.show(io::IO, bc::AbstractBCContainer)
171132 println (io, " $(bc. bookkeeping) " )
172133end
173134
135+ """
136+ $(TYPEDEF)
137+ $(TYPEDSIGNATURES)
138+ $(TYPEDFIELDS)
139+ """
140+ abstract type AbstractBCFunction{F} end
141+
174142"""
175143$(TYPEDSIGNATURES)
176144Wrapper that is generic for all architectures to
@@ -181,8 +149,6 @@ function update_bc_values!(bcs, funcs, X, t)
181149 backend = KA. get_backend (bc)
182150 _update_bc_values! (bc, func, X, t, backend)
183151 end
184- backend = KA. get_backend (X)
185- KA. synchronize (backend)
186152 return nothing
187153end
188154
0 commit comments