MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
optcontactproblem.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#ifndef MFEM_OPT_CONTACT_PROBLEM
13#define MFEM_OPT_CONTACT_PROBLEM
14
15#include "elastoperator.hpp"
16#include "axom/slic.hpp"
17#include "tribol/interface/tribol.hpp"
18#include "tribol/interface/mfem_tribol.hpp"
19
20namespace mfem
21{
22
23/** @class OptContactProblem
24 * @brief Contact optimization problem with mortar and non-mortar interfaces.
25 *
26 * This class formulates and manages a parallel finite element contact problem
27 * built on top of an `ElasticityOperator`. It sets up the contact system using
28 * Tribol and provides operators for objective evaluation, gradients, Hessians,
29 * and constraints.
30 *
31 * Features include:
32 * - Construction of gap constraints and Jacobians through Tribol.
33 * - Optional bound constraints.
34 * - Objective and gradient evaluation for optimization solvers.
35 */
37{
38private:
39 /// MPI communicator for the problem.
40 MPI_Comm comm;
41
42 /// Underlying elasticity problem.
43 ElasticityOperator * problem = nullptr;
44
45 /// Finite element space for displacements
46 ParFiniteElementSpace * vfes = nullptr;
47
48 /// Dimensions: displacement, slack, constraint and gap variables.
49 int dimU, dimM, dimC, dimG;
50
51 /// Global number of constraints.
52 int num_constraints;
53
54 /// Energy value at reference configuration.
55 real_t energy_ref;
56
57 /// Energy gradient at reference configuration.
58 Vector grad_ref;
59
60 /// Reference configuration displacement vector.
61 Vector xref;
62
63 /// Reference configuration displacement vector with updated BCs.
64 Vector xrefbc;
65
66 /// Gap vector on contact interface.
67 Vector gapv;
68
69 /// Mortar and non-mortar attribute sets.
70 std::set<int> mortar_attrs;
71 std::set<int> nonmortar_attrs;
72
73 /// Negative identity matrix (used in constraints).
74 HypreParMatrix * NegId = nullptr;
75
76 /// Reference stiffness (Hessian) matrix.
77 HypreParMatrix * Kref=nullptr;
78
79 /// Jacobian of the gap function.
80 HypreParMatrix * J = nullptr;
81
82 /// Transpose of gap Jacobian.
83 HypreParMatrix * Jt = nullptr;
84
85 /// Transfer operator from contact space to displacement space.
86 HypreParMatrix * Pc = nullptr;
87
88 /// Coordinates of mesh nodes (grid function).
89 ParGridFunction * coords = nullptr;
90
91 /// Free allocated matrices/vectors.
92 void ReleaseMemory();
93
94 /// Compute gap and its Jacobian using Tribol.
95 void ComputeGapJacobian();
96
97 /// Constraint partition offsets (for distributed data).
98 Array<HYPRE_BigInt> constraints_starts;
99
100 /// DOF partition offsets (for distributed data).
101 Array<HYPRE_BigInt> dof_starts;
102
103 // with additional constraints
104 // [ g ]
105 // g_new = [ eps + (d - dl) ]
106 // [ eps - (d - dl) ]
107 // there are additional components to the Jacobian
108 // [ J ]
109 // J_new = [ I ]
110 // [-I ]
111
112 /// Identity matrices for bound constraints.
113 HypreParMatrix * Iu = nullptr;
114 HypreParMatrix * negIu = nullptr;
115
116 /// Cached constraint Jacobian with bounds.
117 HypreParMatrix * dcdu = nullptr;
118
119 /// Mass matrix in the volume.
120 HypreParMatrix * Mv = nullptr;
121
122 /// Mass matrix on the contact surface.
123 HypreParMatrix * Mcs = nullptr;
124
125 /// Lumped volume mass vector.
126 Vector Mvlump;
127
128 /// Lumped contact surface mass (full).
129 Vector Mcslumpfull;
130
131 /// Lumped contact surface mass (reduced).
132 Vector Mcslump;
133
134 /// Bound displacement vector for constraints.
135 Vector dl;
136
137 /// Epsilon vector (slack/bounds).
138 Vector eps;
139
140 /// Minimum epsilon value (>0).
141 real_t eps_min = 1.e-4;
142
143 /// Offsets for block vector partitioning of constraints.
144 Array<int> block_offsetsg;
145
146 /// Proximity ratio for Tribol binning.
147 real_t tribol_ratio;
148
149 /// Flag: whether bound constraints are enabled.
150 bool bound_constraints;
151
152 /// Flag: whether bound constraints have been activated.
153 bool bound_constraints_activated = false;
154
155public:
157 const std::set<int> & mortar_attrs_,
158 const std::set<int> & nonmortar_attrs_,
159 real_t tribol_ratio_,
160 bool bound_constraints_);
161
162 /// Build contact system, assemble gap Jacobian and mass matrices.
163 void FormContactSystem(ParGridFunction * coords_, const Vector & xref);
164
165 /// Return displacement space dimension.
166 int GetDimU() {return dimU;}
167
168 /// Return slack variable dimension.
169 int GetDimM() {return dimM;}
170
171 /// Return constraint space dimension.
172 int GetDimC() {return dimC;}
173
174 /// Get MPI communicator.
175 MPI_Comm GetComm() {return comm ;}
176
177 /// Get distributed constraint partition offsets.
178 HYPRE_BigInt * GetConstraintsStarts() {return constraints_starts.GetData();}
179
180 /// Return global number of constraints.
181 HYPRE_BigInt GetGlobalNumConstraints() {return num_constraints;}
182
183 /// Get distributed DOF partition offsets.
184 HYPRE_BigInt * GetDofStarts() {return dof_starts.GetData();}
185
186 /// Return global number of DOFs (from Jacobian).
188
189 /// Return underlying elasticity operator.
191
192 /// Hessian of the objective wrt displacement
193 HypreParMatrix * Duuf(const BlockVector &x) {return DddE(x.GetBlock(0));}
194
195 /// Hessian of the objective wrt the slack variables
196 HypreParMatrix * Dmmf(const BlockVector &) {return nullptr;}
197
198 /// Jacobian of the constraints wrt displacement
199 HypreParMatrix * Duc(const BlockVector &);
200
201 /// Jacobian of the constraints wrt slack variables
202 HypreParMatrix * Dmc(const BlockVector &);
203
204 /// Return transfer operator from contact to displacement subspace.
206
207 /// Evaluate gap function
208 void g(const Vector &, Vector &);
209
210 /// Evaluate contact constraints
211 void c(const BlockVector &, Vector &);
212
213 /// Compute objective functional value.
214 real_t CalcObjective(const BlockVector &, int &);
215
216 /// Compute gradient of objective functional.
218
219 /// Evaluate elastic energy functional.
220 real_t E(const Vector & d, int & eval_err);
221
222 /// Evaluate gradient of energy functional.
223 void DdE(const Vector & d, Vector & gradE);
224
225 /// Return Hessian of energy functional.
226 HypreParMatrix * DddE(const Vector & d);
227
228 /// Update displacement and eps for bound constraints.
229 void SetDisplacement(const Vector & dx, bool active_constraints);
230
231 /// Activate bound constraints (if enabled).
233
234 /// Get Gap and its Jacobian from Tribol.
236 const Array<int> & ess_tdofs,
237 const std::set<int> & mortar_attrs,
238 const std::set<int> & non_mortar_attrs,
239 Vector &gap, real_t tribol_ratio);
240
241 /// Get lumped mass weights for contact and volume spaces.
242 void GetLumpedMassWeights(Vector & Mcslump_, Vector & Mvlump_)
243 {
244 Mcslump_.SetSize(Mcslump.Size()); Mcslump_ = 0.0;
245 Mcslump_.Set(1.0, Mcslump);
246 Mvlump_.SetSize(Mvlump.Size()); Mvlump_ = 0.0;
247 Mvlump_.Set(1.0, Mvlump);
248 };
249 ~OptContactProblem() { ReleaseMemory(); }
250};
251
252}
253
254#endif
T * GetData()
Returns the data.
Definition array.hpp:140
A class to handle Vectors in a block fashion.
Vector & GetBlock(int i)
Get the i-th vector in the block.
Parallel finite element operator for linear and nonlinear elasticity.
Wrapper for hypre's ParCSR matrix class.
Definition hypre.hpp:419
HYPRE_BigInt GetGlobalNumCols() const
Return the global number of columns.
Definition hypre.hpp:714
Contact optimization problem with mortar and non-mortar interfaces.
void FormContactSystem(ParGridFunction *coords_, const Vector &xref)
Build contact system, assemble gap Jacobian and mass matrices.
MPI_Comm GetComm()
Get MPI communicator.
real_t E(const Vector &d, int &eval_err)
Evaluate elastic energy functional.
HYPRE_BigInt * GetConstraintsStarts()
Get distributed constraint partition offsets.
void CalcObjectiveGrad(const BlockVector &, BlockVector &)
Compute gradient of objective functional.
void ActivateBoundConstraints()
Activate bound constraints (if enabled).
int GetDimM()
Return slack variable dimension.
void GetLumpedMassWeights(Vector &Mcslump_, Vector &Mvlump_)
Get lumped mass weights for contact and volume spaces.
void DdE(const Vector &d, Vector &gradE)
Evaluate gradient of energy functional.
int GetDimU()
Return displacement space dimension.
int GetDimC()
Return constraint space dimension.
HypreParMatrix * Dmc(const BlockVector &)
Jacobian of the constraints wrt slack variables.
OptContactProblem(ElasticityOperator *problem_, const std::set< int > &mortar_attrs_, const std::set< int > &nonmortar_attrs_, real_t tribol_ratio_, bool bound_constraints_)
HypreParMatrix * DddE(const Vector &d)
Return Hessian of energy functional.
HypreParMatrix * GetContactSubspaceTransferOperator()
Return transfer operator from contact to displacement subspace.
real_t CalcObjective(const BlockVector &, int &)
Compute objective functional value.
HypreParMatrix * SetupTribol(ParMesh *pmesh, ParGridFunction *coords, const Array< int > &ess_tdofs, const std::set< int > &mortar_attrs, const std::set< int > &non_mortar_attrs, Vector &gap, real_t tribol_ratio)
Get Gap and its Jacobian from Tribol.
void SetDisplacement(const Vector &dx, bool active_constraints)
Update displacement and eps for bound constraints.
HypreParMatrix * Duc(const BlockVector &)
Jacobian of the constraints wrt displacement.
HypreParMatrix * Duuf(const BlockVector &x)
Hessian of the objective wrt displacement.
HYPRE_BigInt GetGlobalNumConstraints()
Return global number of constraints.
void c(const BlockVector &, Vector &)
Evaluate contact constraints.
HypreParMatrix * Dmmf(const BlockVector &)
Hessian of the objective wrt the slack variables.
HYPRE_BigInt * GetDofStarts()
Get distributed DOF partition offsets.
ElasticityOperator * GetElasticityOperator()
Return underlying elasticity operator.
void g(const Vector &, Vector &)
Evaluate gap function.
HYPRE_BigInt GetGlobalNumDofs()
Return global number of DOFs (from Jacobian).
Abstract parallel finite element space.
Definition pfespace.hpp:31
Class for parallel grid function.
Definition pgridfunc.hpp:50
Class for parallel meshes.
Definition pmesh.hpp:34
Vector data type.
Definition vector.hpp:82
Vector & Set(const real_t a, const Vector &x)
(*this) = a * x
Definition vector.cpp:341
int Size() const
Returns the size of the vector.
Definition vector.hpp:234
void SetSize(int s)
Resize the vector to size s.
Definition vector.hpp:584
int problem
Definition ex15.cpp:62
HYPRE_Int HYPRE_BigInt
float real_t
Definition config.hpp:46