@@ -266,20 +266,22 @@ void add_element_system(FEMSystem & _sys,
266266 libMesh ::out .precision (old_precision );
267267 }
268268
269- // We turn off the asymmetric constraint application;
270- // enforce_constraints_exactly() should be called in the solver
269+ // We turn off the asymmetric constraint application iff we expect
270+ // enforce_constraints_exactly() to be called in the solver
271+ const bool constrain_in_solver = _sys .get_constrain_in_solver ();
272+
271273 if (_get_residual && _get_jacobian )
272274 {
273275 if (_constrain_heterogeneously )
274276 _sys .get_dof_map ().heterogenously_constrain_element_matrix_and_vector
275277 (_femcontext .get_elem_jacobian (),
276278 _femcontext .get_elem_residual (),
277- _femcontext .get_dof_indices (), false );
279+ _femcontext .get_dof_indices (), ! constrain_in_solver );
278280 else if (!_no_constraints )
279281 _sys .get_dof_map ().constrain_element_matrix_and_vector
280282 (_femcontext .get_elem_jacobian (),
281283 _femcontext .get_elem_residual (),
282- _femcontext .get_dof_indices (), false );
284+ _femcontext .get_dof_indices (), ! constrain_in_solver );
283285 // Do nothing if (_no_constraints)
284286 }
285287 else if (_get_residual )
@@ -288,10 +290,11 @@ void add_element_system(FEMSystem & _sys,
288290 _sys .get_dof_map ().heterogenously_constrain_element_vector
289291 (_femcontext .get_elem_jacobian (),
290292 _femcontext .get_elem_residual (),
291- _femcontext .get_dof_indices (), false );
293+ _femcontext .get_dof_indices (), ! constrain_in_solver );
292294 else if (!_no_constraints )
293295 _sys .get_dof_map ().constrain_element_vector
294- (_femcontext .get_elem_residual (), _femcontext .get_dof_indices (), false);
296+ (_femcontext .get_elem_residual (),
297+ _femcontext .get_dof_indices (), !constrain_in_solver );
295298 // Do nothing if (_no_constraints)
296299 }
297300 else if (_get_jacobian )
@@ -302,8 +305,14 @@ void add_element_system(FEMSystem & _sys,
302305 if (!_no_constraints )
303306 _sys .get_dof_map ().constrain_element_matrix (_femcontext .get_elem_jacobian (),
304307 _femcontext .get_dof_indices (),
305- false );
308+ ! constrain_in_solver );
306309 }
310+
311+ if (_get_residual && !_no_constraints && !constrain_in_solver )
312+ _sys .get_dof_map ().residual_constrain_element_vector
313+ (_femcontext .get_elem_residual (),
314+ _femcontext .get_dof_indices (),
315+ * _sys .current_local_solution );
307316#else
308317 libmesh_ignore (_constrain_heterogeneously , _no_constraints );
309318#endif // #ifdef LIBMESH_ENABLE_CONSTRAINTS
0 commit comments