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
122 if (repeat_augmented_lagrange_step || !mcc->AugmentedLagrangianContactConverged())
123 {
124 repeat_augmented_lagrange_step = true;
125 break;
126 }
127 }
128 }
129
130 // next loop over penalty mortar user objects
131 const auto & pmuos = this->_app.template getInterfaceObjects<AugmentedLagrangeInterface>();
132 for (auto * pmuo : pmuos)
133 {
134 // check if any of the constraints is not yet converged
135 if (!repeat_augmented_lagrange_step && !pmuo->isAugmentedLagrangianConverged())
136 repeat_augmented_lagrange_step = true;
137 }
138
139 // Communicate the repeat_augmented_lagrange_step in parallel.
140 // If one proc needs to do another loop, all do.
141 this->_communicator.max(repeat_augmented_lagrange_step);
142
143 // repeat update step if necessary
144 if (repeat_augmented_lagrange_step)
145 {
146 _lagrangian_iteration_number++;
147 Moose::out << "Augmented Lagrangian contact repeat " << _lagrangian_iteration_number
148 << '\n';
149
150 // Each contact pair will have constraints for all displacements, but those share the
151 // Lagrange multipliers, which are stored on the penetration locator. We call update
152 // only for the first constraint for each contact pair.
153 for (const auto & mcc : mccs)
154 mcc->updateAugmentedLagrangianMultiplier(/* beginning_of_step = */ false);
155
156 // Update all penalty mortar user objects
157 for (const auto & pmuo : pmuos)
158 pmuo->updateAugmentedLagrangianMultipliers();
159
160 // call AM setup again (e.g. to update active sets)
161 for (const auto & pmuo : pmuos)
162 pmuo->augmentedLagrangianSetup();
163
164 // force it to keep iterating
165 reason = Convergence::MooseConvergenceStatus::ITERATING;
166 Moose::out << "Augmented Lagrangian Multiplier needs updating.";
167 }
168 else
169 Moose::out << "Augmented Lagrangian contact constraint enforcement is satisfied.";
170 }
171 else
172 {
173 // maxed out
174 Moose::out << "Maximum Augmented Lagrangian contact iterations have been reached.";
175 reason = Convergence::MooseConvergenceStatus::DIVERGED;
176 }
177 }
178
179 return reason;
180}
181
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)