Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
contact_constraint.hpp
Go to the documentation of this file.
1 // Copyright Lawrence Livermore National Security, LLC and
2 // other Smith Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
14 #pragma once
15 
16 #include <vector>
17 
18 #include "smith/smith_config.hpp"
19 
20 #ifdef SMITH_USE_TRIBOL
21 
22 #include "tribol/interface/tribol.hpp"
23 
28 
29 namespace mfem {
30 class Vector;
31 class HypreParMatrix;
32 } // namespace mfem
33 
34 namespace smith {
35 
39 enum ContactFields
40 {
41  SHAPE,
42  DISP,
43 };
44 
45 class FiniteElementState;
46 
55 class ContactConstraint : public Constraint {
56  public:
67  ContactConstraint(int interaction_id, const mfem::ParMesh& mesh, const std::set<int>& bdry_attr_surf1,
68  const std::set<int>& bdry_attr_surf2, ContactOptions contact_opts,
69  const std::string& name = "contact_constraint")
70  : Constraint(name), contact_(mesh), contact_opts_{contact_opts}
71  {
72  contact_opts_.enforcement = ContactEnforcement::LagrangeMultiplier;
73  contact_.addContactInteraction(interaction_id, bdry_attr_surf1, bdry_attr_surf2, contact_opts_);
74  interaction_id_ = interaction_id;
75  }
76 
78  virtual ~ContactConstraint() {}
79 
88  mfem::Vector evaluate([[maybe_unused]] double time, [[maybe_unused]] double dt,
89  [[maybe_unused]] const std::vector<ConstFieldPtr>& fields) const
90  {
91  contact_.setDisplacements(*fields[ContactFields::SHAPE], *fields[ContactFields::DISP]);
92  tribol::setLagrangeMultiplierOptions(interaction_id_, tribol::ImplicitEvalMode::MORTAR_GAP);
93 
94  // note: Tribol does not use cycle.
95  int cycle = 0;
96  contact_.update(cycle, time, dt);
97  auto gaps_hpv = contact_.mergedGaps(false);
98  // Note: this copy is needed to prevent the HypreParVector pointer from going out of scope. see
99  // https://github.com/mfem/mfem/issues/5029
100  mfem::Vector gaps = gaps_hpv;
101  return gaps;
102  };
103 
112  std::unique_ptr<mfem::HypreParMatrix> jacobian([[maybe_unused]] double time, [[maybe_unused]] double dt,
113  [[maybe_unused]] const std::vector<ConstFieldPtr>& fields,
114  [[maybe_unused]] int direction) const
115  {
116  contact_.setDisplacements(*fields[ContactFields::SHAPE], *fields[ContactFields::DISP]);
117  tribol::setLagrangeMultiplierOptions(interaction_id_, tribol::ImplicitEvalMode::MORTAR_JACOBIAN);
118 
119  int cycle = 0;
120  contact_.update(cycle, time, dt);
121  auto J_contact = contact_.mergedJacobian();
122  J_contact->owns_blocks = false;
123 
124  int iblock = 1;
125  int jblock = 0;
126  for (int i = 0; i < 2; i++) {
127  for (int j = 0; j < 2; j++) {
128  if (i == iblock && j == jblock) {
129  continue;
130  }
131  if (!J_contact->IsZeroBlock(i, j)) {
132  delete &J_contact->GetBlock(i, j);
133  }
134  }
135  }
136 
137  SLIC_ERROR_IF(J_contact->IsZeroBlock(iblock, jblock), "attempting to extract a null block");
138  auto dgdu = dynamic_cast<mfem::HypreParMatrix*>(&J_contact->GetBlock(iblock, jblock));
139  std::unique_ptr<mfem::HypreParMatrix> dgdu_unique(dgdu);
140  return dgdu_unique;
141  };
142 
143  protected:
147  mutable ContactData contact_;
148 
152  ContactOptions contact_opts_;
153 
157  int interaction_id_;
158 };
159 
160 } // namespace smith
161 
162 #endif
Specifies interface for evaluating distributed constriants from fields as well as their Jacobians and...
This file contains enumerations and record types for contact configuration.
Class for storing contact data.
Defines common types and helper functions for using the residual and scalar_objective classes.
Accelerator functionality.
Definition: smith.cpp:36