https://mooseframework.inl.gov
Loading...
Searching...
No Matches
AugmentedLagrangianContactConvergence.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
12
13// MOOSE includes
14#include "AuxiliarySystem.h"
15#include "DisplacedProblem.h"
16#include "MooseApp.h"
17#include "MooseMesh.h"
18#include "MooseVariable.h"
19#include "NearestNodeLocator.h"
20#include "NonlinearSystem.h"
21#include "PenetrationLocator.h"
22#include "FEProblemBase.h"
23#include "SystemBase.h"
24#include "Assembly.h"
25#include "Executioner.h"
26#include "AddVariableAction.h"
27#include "ConstraintWarehouse.h"
28#include "MortarUserObject.h"
33
36
37template <class T>
40{
41 InputParameters params = T::validParams();
43 params.addClassDescription("Convergence for augmented Lagrangian contact");
44 return params;
45}
46
47template <class T>
53
54template <class T>
55void
57{
58 T::preLoop();
59
60 _lagrangian_iteration_number = 0;
61}
62
63template <class T>
66{
67 // Check convergence of the nonlinear problem
68 auto reason = T::checkConvergence(iter);
69
70 auto & fe_problem_base = this->getMooseApp().feProblem();
71
72 bool repeat_augmented_lagrange_step = false;
73
74 // Nonlinear solve is converged, now check that the constraints are met
75 if (reason == Convergence::MooseConvergenceStatus::CONVERGED)
76 {
77 if (_lagrangian_iteration_number < _maximum_number_lagrangian_iterations)
78 {
79
80 auto & nonlinear_sys = fe_problem_base.currentNonlinearSystem();
81 nonlinear_sys.update();
82
83 // Get the penetration locator from the displaced mesh if it exist, otherwise get
84 // it from the undisplaced mesh.
85 const auto displaced_problem = fe_problem_base.getDisplacedProblem();
86 const auto & penetration_locators = (displaced_problem ? displaced_problem->geomSearchData()
87 : fe_problem_base.geomSearchData())
88 ._penetration_locators;
89
90 // loop over contact pairs (penetration locators)
91 const ConstraintWarehouse & constraints = nonlinear_sys.getConstraintWarehouse();
92 std::list<std::shared_ptr<MechanicalContactConstraint>> mccs;
93 for (const auto & pair : penetration_locators)
94 {
95 const auto & boundaries = pair.first;
96
97 if (!constraints.hasActiveNodeFaceConstraints(boundaries.second, bool(displaced_problem)))
98 continue;
99 const auto & ncs =
100 constraints.getActiveNodeFaceConstraints(boundaries.second, bool(displaced_problem));
101
102 mccs.emplace_back(nullptr);
103 for (const auto & nc : ncs)
104 if (const auto mcc = std::dynamic_pointer_cast<MechanicalContactConstraint>(nc); !mcc)
105 mooseError("AugmentedLagrangianContactProblem: dynamic cast of "
106 "MechanicalContactConstraint object failed.");
107 else
108 {
109 // Return if this constraint does not correspond to the primary-secondary pair
110 // prepared by the outer loops.
111 // This continue statement is required when, e.g. one secondary surface constrains
112 // more than one primary surface.
113 if (mcc->secondaryBoundary() != boundaries.second ||
114 mcc->primaryBoundary() != boundaries.first)
115 continue;
116
117 // save one constraint pointer for each contact pair
118 if (!mccs.back())
119 mccs.back() = mcc;
120
121 // check if any of the constraints is not yet converged. The check is collective, so
122 // it must run for every constraint on every rank.
123 if (!mcc->AugmentedLagrangianContactConverged())
124 repeat_augmented_lagrange_step = true;
125 }
126 }
127
128 // next loop over penalty mortar user objects
129 const auto & pmuos = this->_app.template getInterfaceObjects<AugmentedLagrangeInterface>();
130 for (auto * pmuo : pmuos)
131 {
132 // check if any of the constraints is not yet converged. The check is collective, so it
133 // must run for every user object on every rank.
134 if (!pmuo->isAugmentedLagrangianConverged())
135 repeat_augmented_lagrange_step = true;
136 }
137
138 // Communicate the repeat_augmented_lagrange_step in parallel.
139 // If one proc needs to do another loop, all do.
140 this->_communicator.max(repeat_augmented_lagrange_step);
141
142 // repeat update step if necessary
143 if (repeat_augmented_lagrange_step)
144 {
145 _lagrangian_iteration_number++;
146 Moose::out << "Augmented Lagrangian contact repeat " << _lagrangian_iteration_number
147 << '\n';
148
149 // Each contact pair will have constraints for all displacements, but those share the
150 // Lagrange multipliers, which are stored on the penetration locator. We call update
151 // only for the first constraint for each contact pair.
152 for (const auto & mcc : mccs)
153 mcc->updateAugmentedLagrangianMultiplier(/* beginning_of_step = */ false);
154
155 // Update all penalty mortar user objects
156 for (const auto & pmuo : pmuos)
157 pmuo->updateAugmentedLagrangianMultipliers();
158
159 // call AM setup again (e.g. to update active sets)
160 for (const auto & pmuo : pmuos)
161 pmuo->augmentedLagrangianSetup();
162
163 // force it to keep iterating
164 reason = Convergence::MooseConvergenceStatus::ITERATING;
165 Moose::out << "Augmented Lagrangian Multiplier needs updating.";
166 }
167 else
168 Moose::out << "Augmented Lagrangian contact constraint enforcement is satisfied.";
169 }
170 else
171 {
172 // maxed out
173 Moose::out << "Maximum Augmented Lagrangian contact iterations have been reached.";
174 reason = Convergence::MooseConvergenceStatus::DIVERGED;
175 }
176 }
177
178 return reason;
179}
180
registerMooseObject("ContactApp", AugmentedLagrangianContactReferenceConvergence)
const double T
void mooseError(Args &&... args)
std::shared_ptr< DisplacedProblem > displaced_problem
Non-templated base of AugmentedLagrangianContactConvergence that owns the augmented Lagrangian iterat...
Class to check convergence for the augmented Lagrangian contact problem.
virtual Convergence::MooseConvergenceStatus checkConvergence(unsigned int iter) override
AugmentedLagrangianContactConvergence(const InputParameters &params)
const std::vector< std::shared_ptr< NodeFaceConstraint > > & getActiveNodeFaceConstraints(BoundaryID boundary_id, bool displaced) const
bool hasActiveNodeFaceConstraints(BoundaryID boundary_id, bool displaced) const
void addClassDescription(const std::string &doc_string)