Skip to content

Commit 8928d0f

Browse files
committed
DiffSolver::set_exact_constraint_enforcement
1 parent 1549c45 commit 8928d0f

4 files changed

Lines changed: 42 additions & 7 deletions

File tree

include/solvers/diff_solver.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,36 @@ class DiffSolver : public ReferenceCountedObject<DiffSolver>,
285285
*/
286286
std::unique_ptr<LinearSolutionMonitor> linear_solution_monitor;
287287

288+
/**
289+
* Enable (or disable; it is \p true by default) exact enforcement
290+
* of constraints at the solver level, correcting any constrained
291+
* DoF coefficients in \p current_local_solution as well as applying
292+
* nonlinear residual and Jacobian terms based on constraint
293+
* equations.
294+
*
295+
* This is probably only safe to disable if user code is setting
296+
* nonlinear residual and Jacobian terms based on constraint
297+
* equations at an element-by-element level, by combining the
298+
* \p asymmetric_constraint_rows option with the
299+
* \p residual_constrain_element_vector processing option in
300+
* \p DofMap.
301+
*/
302+
virtual void set_exact_constraint_enforcement(bool enable) {
303+
_exact_constraint_enforcement = enable;
304+
}
305+
306+
bool exact_constraint_enforcement() {
307+
return _exact_constraint_enforcement;
308+
}
309+
288310
protected:
289311

312+
/**
313+
* Whether we should enforce exact constraints globally during a
314+
* solve.
315+
*/
316+
bool _exact_constraint_enforcement;
317+
290318
/**
291319
* The largest solution norm which the DiffSolver has yet seen will be stored
292320
* here, to be used for stopping criteria based on relative_step_tolerance

src/solvers/diff_solver.C

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ DiffSolver::DiffSolver (sys_type & s) :
4141
relative_step_tolerance(0.),
4242
initial_linear_tolerance(1e-12),
4343
minimum_linear_tolerance(TOLERANCE*TOLERANCE),
44+
_exact_constraint_enforcement(true),
4445
max_solution_norm(0.),
4546
max_residual_norm(0.),
4647
_outer_iterations(0),

src/solvers/newton_solver.C

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ unsigned int NewtonSolver::solve()
295295
rhs.close();
296296

297297
#ifdef LIBMESH_ENABLE_CONSTRAINTS
298-
_system.get_dof_map().enforce_constraints_exactly(_system);
298+
if (this->_exact_constraint_enforcement)
299+
_system.get_dof_map().enforce_constraints_exactly(_system);
299300
#endif
300301

301302
SparseMatrix<Number> & matrix = *(_system.matrix);
@@ -426,8 +427,9 @@ unsigned int NewtonSolver::solve()
426427
_system.update ();
427428
// The linear solver may not have fit our constraints exactly
428429
#ifdef LIBMESH_ENABLE_CONSTRAINTS
429-
_system.get_dof_map().enforce_constraints_exactly
430-
(_system, &linear_solution, /* homogeneous = */ true);
430+
if (this->_exact_constraint_enforcement)
431+
_system.get_dof_map().enforce_constraints_exactly
432+
(_system, &linear_solution, /* homogeneous = */ true);
431433
#endif
432434

433435
const unsigned int linear_steps = rval.first;
@@ -553,7 +555,8 @@ unsigned int NewtonSolver::solve()
553555

554556
// The linear solver may not have fit our constraints exactly
555557
#ifdef LIBMESH_ENABLE_CONSTRAINTS
556-
_system.get_dof_map().enforce_constraints_exactly(_system);
558+
if (this->_exact_constraint_enforcement)
559+
_system.get_dof_map().enforce_constraints_exactly(_system);
557560
#endif
558561

559562
// We may need to localize a parallel solution

src/solvers/petsc_diff_solver.C

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ extern "C"
115115
sys.update();
116116

117117
// We may need to correct a non-conforming solution
118-
sys.get_dof_map().enforce_constraints_exactly(sys, sys.current_local_solution.get());
118+
if (solver.exact_constraint_enforcement())
119+
sys.get_dof_map().enforce_constraints_exactly(sys, sys.current_local_solution.get());
119120

120121
// Do DiffSystem assembly
121122
sys.assembly(true, false);
@@ -168,7 +169,8 @@ extern "C"
168169
sys.update();
169170

170171
// We may need to correct a non-conforming solution
171-
sys.get_dof_map().enforce_constraints_exactly(sys, sys.current_local_solution.get());
172+
if (solver.exact_constraint_enforcement())
173+
sys.get_dof_map().enforce_constraints_exactly(sys, sys.current_local_solution.get());
172174

173175
// Do DiffSystem assembly
174176
sys.assembly(false, true);
@@ -318,7 +320,8 @@ unsigned int PetscDiffSolver::solve()
318320
LIBMESH_CHKERR(ierr);
319321

320322
#ifdef LIBMESH_ENABLE_CONSTRAINTS
321-
_system.get_dof_map().enforce_constraints_exactly(_system);
323+
if (this->_exact_constraint_enforcement)
324+
_system.get_dof_map().enforce_constraints_exactly(_system);
322325
#endif
323326

324327
SNESConvergedReason reason;

0 commit comments

Comments
 (0)