17void OptContactProblem::ReleaseMemory()
19 delete J; J =
nullptr;
20 delete Jt; Jt =
nullptr;
21 delete Pc; Pc =
nullptr;
22 delete NegId; NegId =
nullptr;
23 delete Iu; Iu =
nullptr;
24 delete negIu; negIu =
nullptr;
25 delete Mv; Mv =
nullptr;
26 delete Mcs; Mcs =
nullptr;
34void OptContactProblem::ComputeGapJacobian()
39 mortar_attrs, nonmortar_attrs,gapv, tribol_ratio));
42 dof_starts[0] = J->
ColPart()[0];
43 dof_starts[1] = J->
ColPart()[1];
46 if (bound_constraints_activated)
53 constraints_starts[0] = J->
RowPart()[0];
54 constraints_starts[1] = J->
RowPart()[1];
59 const std::set<int> & mortar_attrs_,
60 const std::set<int> & nonmortar_attrs_,
62 bool bound_constraints_)
63 :
problem(problem_), mortar_attrs(mortar_attrs_),
64 nonmortar_attrs(nonmortar_attrs_),
65 tribol_ratio(tribol_ratio_),
66 bound_constraints(bound_constraints_)
101 block_offsetsg[0] = 0;
102 block_offsetsg[1] = dimG;
103 block_offsetsg[2] = dimU;
104 block_offsetsg[3] = dimU;
107 Vector diagVec(dimU); diagVec = 0.0;
136 Mv->
Mult(onev, Mvlump);
141 if (bound_constraints)
150 if (bound_constraints_activated)
153 dcduBlockMatrix(0, 0) = J;
154 dcduBlockMatrix(1, 0) = Iu;
155 dcduBlockMatrix(2, 0) = negIu;
156 if (dcdu) {
delete dcdu; }
170 Vector negone(dimM); negone = -1.0;
192 for (
int i = 0; i<hJt; i++)
199 int nrows_c = nonzerorows.
Size();
202 for (
int i = 0; i<nrows_c; i++)
216 row_offset_c-=nrows_c_bigint;
217 rows_c[0] = row_offset_c;
218 rows_c[1] = row_offset_c+nrows_c;
222 MPI_Allreduce(&nrows_c_bigint, &glob_nrows_c,1,
233 J[i] = Pct.
GetJ()[i];
237 glob_ncols_c, Pct.
GetI(), J,
250 Vector temp(dimU); temp = 0.0;
252 temp.
Add(-1.0, xref);
265 if (bound_constraints_activated)
303 Vector dx(dimU); dx = 0.0;
304 Vector temp(dimU); temp = 0.0;
306 dx.
Add(-1.0, xrefbc);
307 Kref->
Mult(dx, temp);
309 temp.
Add(1.0, grad_ref);
311 energy += energy_ref;
328 mfem::out <<
"energy = " << energy << std::endl;
329 mfem::out <<
"eval_err = " << eval_err << std::endl;
340 Vector dx(dimU); dx = 0.0;
342 dx.
Add(-1.0, xrefbc);
343 Kref->
Mult(dx, gradE);
344 gradE.
Add(1.0, grad_ref);
358 bool activate_constraints)
360 if (activate_constraints)
363 for (
int j = 0; j < dimU; j++)
365 eps(j) = std::max(eps_min, eps(j));
370 for (
int j = 0; j < dimU; j++)
372 eps(j) = std::max(eps(j), std::abs(dx(j)));
380 bound_constraints_activated =
true;
384 dimM = dimG + 2 * dimU;
390 const Array<int> & ess_tdofs,
const std::set<int> & mortar_attrs,
391 const std::set<int> & non_mortar_attrs,
394 axom::slic::SimpleLogger logger;
397 int coupling_scheme_id = 0;
398 int mesh1_id = 0;
int mesh2_id = 1;
400 tribol::registerMfemCouplingScheme(
401 coupling_scheme_id, mesh1_id, mesh2_id,
402 *pmesh, *coords, mortar_attrs, non_mortar_attrs,
403 tribol::SURFACE_TO_SURFACE,
405 tribol::SINGLE_MORTAR,
406 tribol::FRICTIONLESS,
407 tribol::LAGRANGE_MULTIPLIER,
411 tribol::setBinningProximityScale(coupling_scheme_id, ratio);
414 auto& pressure = tribol::getMfemPressure(coupling_scheme_id);
425 Mcs->
Mult(onecs, Mcslumpfull);
428 tribol::setLagrangeMultiplierOptions(
430 tribol::ImplicitEvalMode::MORTAR_RESIDUAL_JACOBIAN
434 tribol::updateMfemParallelDecomposition();
440 tribol::update(cycle, t, dt);
443 auto A_blk = tribol::getMfemBlockJacobian(coupling_scheme_id);
455 real_t max_l1_row_norm = 0.0;
456 real_t rel_row_norm_threshold = 1.e-5;
457 for (
int i = 0; i < h; i++)
461 max_l1_row_norm = std::max( max_l1_row_norm, merged.
GetRowNorml1(i));
465 for (
int i = 0; i<h; i++)
469 if (merged.
GetRowNorml1(i) > rel_row_norm_threshold * max_l1_row_norm)
476 int hnew = nonzero_rows.
Size();
479 for (
int i = 0; i<hnew; i++)
481 int col = nonzero_rows[i];
489 int nrows = reduced_merged->
Height();
496 rows[0] = row_offset;
497 rows[1] = row_offset+nrows;
506 J = reduced_merged->
GetJ();
511 J[i] = reduced_merged->
GetJ()[i];
516 glob_ncols, reduced_merged->
GetI(), J,
518 delete reduced_merged;
525 tribol::getMfemGap(coupling_scheme_id, gap_full);
527 auto& P_submesh = *pressure.ParFESpace()->GetProlongationMatrix();
528 Vector gap_true(P_submesh.Width());
530 P_submesh.MultTranspose(gap_full,gap_true);
534 for (
int i = 0; i<nrows; i++)
536 gap[i] = gap_true[nonzero_rows[i]];
537 Mcslump(i) = Mcslumpfull(nonzero_rows[i]);
Dynamic 2D array using row-major layout.
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
int Size() const
Return the logical size of the array.
void PartialSum()
Fill the entries of the array with the cumulative sum of the entries.
int Append(const T &el)
Append element 'el' to array, resize if necessary.
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.
ParMesh * GetMesh() const
ParFiniteElementSpace * GetFESpace() const
const Array< int > & GetEssentialDofs() const
bool IsNonlinear()
Check if the operator is nonlinear.
void GetGradient(const Vector &u, Vector &gradE) const
Compute the gradient of the energy functional at a given displacement vector.
HypreParMatrix * GetHessian(const Vector &u)
Get the Hessian (stiffness matrix) at a given displacement vector.
void Getxrefbc(Vector &xrefbc) const
Get the displacement with essential boundary conditions applied.
real_t GetEnergy(const Vector &u) const
Compute the elastic energy functional at a given displacement vector.
Wrapper for hypre's ParCSR matrix class.
HYPRE_BigInt * ColPart()
Returns the column partitioning.
void EliminateRows(const Array< int > &rows)
Eliminate rows from the diagonal and off-diagonal blocks of the matrix.
void InvScaleRows(const Vector &s)
Scale the local row i by 1./s(i)
HYPRE_BigInt GetGlobalNumRows() const
Return the global number of rows.
HYPRE_BigInt GetGlobalNumCols() const
Return the global number of columns.
HYPRE_Int Mult(HypreParVector &x, HypreParVector &y, real_t alpha=1.0, real_t beta=0.0) const
Computes y = alpha * A * x + beta * y.
MPI_Comm GetComm() const
MPI communicator.
HYPRE_BigInt * RowPart()
Returns the row partitioning.
HypreParMatrix * Transpose() const
Returns the transpose of *this.
void MergeDiagAndOffd(SparseMatrix &merged)
Get a single SparseMatrix containing all rows from this processor, merged from the diagonal and off-d...
HypreParMatrix * EliminateCols(const Array< int > &cols)
static bool Root()
Return true if the rank in MPI_COMM_WORLD is zero.
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols().
HYPRE_BigInt * GetTrueDofOffsets() const
HYPRE_BigInt GlobalTrueVSize() const
HYPRE_BigInt GetMyTDofOffset() const
Class for parallel grid function.
Class for parallel meshes.
real_t GetRowNorml1(int irow) const
For i = irow compute .
bool RowIsEmpty(const int row) const
int NumNonZeroElems() const override
Returns the number of the nonzero elements in the matrix.
real_t * GetData()
Return the element data, i.e. the array A.
void Finalize(int skip_zeros=1) override
Finalize the matrix initialization, switching the storage format from LIL to CSR.
int * GetJ()
Return the array J.
int * GetI()
Return the array I.
void Set(const int i, const int j, const real_t val)
void SetDataAndSize(real_t *d, int s)
Set the Vector data and size.
real_t Normlinf() const
Returns the l_infinity norm of the vector.
void SetSubVector(const Array< int > &dofs, const real_t value)
Set the entries listed in dofs to the given value.
Vector & Set(const real_t a, const Vector &x)
(*this) = a * x
int Size() const
Returns the size of the vector.
void SetSize(int s)
Resize the vector to size s.
real_t * GetData() const
Return a pointer to the beginning of the Vector data.
void GetSubVector(const Array< int > &dofs, Vector &elemvect) const
Extract entries listed in dofs to the output Vector elemvect.
Vector & Add(const real_t a, const Vector &Va)
(*this) += a * Va
real_t infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
real_t GlobalLpNorm(const real_t p, real_t loc_norm, MPI_Comm comm)
Compute a global Lp norm from the local Lp norms computed by each processor.
bool IsFinite(const real_t &val)
real_t InnerProduct(HypreParVector *x, HypreParVector *y)
HypreParMatrix * HypreParMatrixFromBlocks(Array2D< const HypreParMatrix * > &blocks, Array2D< real_t > *blockCoeff)
Returns a merged hypre matrix constructed from hypre matrix blocks.
void HypreStealOwnership(HypreParMatrix &A_hyp, SparseMatrix &A_diag)
Make A_hyp steal ownership of its diagonal part A_diag.
Helper struct to convert a C++ type to an MPI type.