@@ -8,7 +8,7 @@ $(TYPEDSIGNATURES)
88"""
99KA. get_backend (asm:: AbstractAssembler ) = KA. get_backend (asm. dof)
1010
11- function _adjust_matrix_action_entries_for_condensed ! (
11+ function _adjust_matrix_action_entries_for_constraints ! (
1212 Av, constraint_storage, v, :: KA.CPU
1313 # TODO do we need a penalty scale here as well?
1414)
@@ -22,7 +22,25 @@ function _adjust_matrix_action_entries_for_condensed!(
2222 return nothing
2323end
2424
25- function _adjust_vector_entries_for_condensed! (b, constraint_storage, :: KA.CPU )
25+ KA. @kernel function _adjust_matrix_action_entries_for_constraints_kernel! (
26+ Av, constraint_storage, v
27+ )
28+ I = KA. @index (Global)
29+ # modify Av => (I - G) * Av + Gv
30+ @inbounds Av[I] = (1. - constraint_storage[I]) * Av[I] + constraint_storage[I] * v[I]
31+ end
32+
33+ function _adjust_matrix_action_entries_for_constraints! (
34+ Av, constraint_storage, v, backend:: KA.Backend
35+ )
36+ @assert length (Av) == length (constraint_storage)
37+ @assert length (v) == length (constraint_storage)
38+ kernel! = _adjust_matrix_action_entries_for_constraints_kernel! (backend)
39+ kernel! (Av, constraint_storage, v, ndrange = length (Av))
40+ return nothing
41+ end
42+
43+ function _adjust_vector_entries_for_constraints! (b, constraint_storage, :: KA.CPU )
2644 @assert length (b) == length (constraint_storage)
2745 # modify b => (I - G) * b + (Gu - g)
2846 # but Gu = g, so we don't need that here
@@ -34,6 +52,19 @@ function _adjust_vector_entries_for_condensed!(b, constraint_storage, ::KA.CPU)
3452 return nothing
3553end
3654
55+ KA. @kernel function _adjust_vector_entries_for_constraints_kernel (b, constraint_storage)
56+ I = KA. @index (Global)
57+ # modify b => (I - G) * b + (Gu - g)
58+ @inbounds b[I] = (1. - constraint_storage[I]) * b[I]
59+ end
60+
61+ function _adjust_vector_entries_for_constraints! (b, constraint_storage, backend:: KA.Backend )
62+ @assert length (b) == length (constraint_storage)
63+ kernel! = _adjust_vector_entries_for_constraints_kernel (backend)
64+ kernel! (b, constraint_storage, ndrange = length (b))
65+ return nothing
66+ end
67+
3768"""
3869$(TYPEDSIGNATURES)
3970Assembly method for an H1Field, e.g. internal force
@@ -162,30 +193,31 @@ function _quadrature_level_state(state::L2QuadratureField, q::Int, e::Int)
162193 return state_q
163194end
164195
196+
197+ # function hvp(asm::AbstractAssembler)
198+ # if _is_condensed(asm.dof)
199+ # _adjust_matrix_action_entries_for_constraints!(
200+ # asm.stiffness_action_storage, asm.constraint_storage,
201+ # KA.get_backend(asm)
202+ # )
203+ # return asm.stiffness_action_storage.data
204+ # else
205+ # extract_field_unknowns!(
206+ # asm.stiffness_action_unknowns,
207+ # asm.dof,
208+ # asm.stiffness_action_storage
209+ # )
210+ # return asm.stiffness_action_unknowns
211+ # end
212+ # end
213+
214+ # new approach requiring access to the v that makes Hv
165215"""
166216$(TYPEDSIGNATURES)
167217"""
168- function hvp (asm:: AbstractAssembler )
169- if _is_condensed (asm. dof)
170- _adjust_matrix_action_entries_for_condensed! (
171- asm. stiffness_action_storage, asm. constraint_storage,
172- KA. get_backend (asm)
173- )
174- return asm. stiffness_action_storage. data
175- else
176- extract_field_unknowns! (
177- asm. stiffness_action_unknowns,
178- asm. dof,
179- asm. stiffness_action_storage
180- )
181- return asm. stiffness_action_unknowns
182- end
183- end
184-
185- # new approach requiring access to the v that makes Hv
186218function hvp (asm:: AbstractAssembler , v)
187219 if _is_condensed (asm. dof)
188- _adjust_matrix_action_entries_for_condensed ! (
220+ _adjust_matrix_action_entries_for_constraints ! (
189221 asm. stiffness_action_storage, asm. constraint_storage, v,
190222 KA. get_backend (asm)
191223 )
@@ -213,7 +245,7 @@ assumes assemble_vector! has already been called
213245"""
214246function residual (asm:: AbstractAssembler )
215247 if _is_condensed (asm. dof)
216- _adjust_vector_entries_for_condensed ! (
248+ _adjust_vector_entries_for_constraints ! (
217249 asm. residual_storage, asm. constraint_storage,
218250 KA. get_backend (asm)
219251 )
0 commit comments