https://mooseframework.inl.gov
ComputeMortarFunctor.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 
10 #include "ComputeMortarFunctor.h"
11 #include "FEProblemBase.h"
12 #include "SubProblem.h"
13 #include "Assembly.h"
14 #include "ADMortarConstraint.h"
16 #include "MooseMesh.h"
17 #include "Assembly.h"
18 #include "MortarUtils.h"
19 #include "MaterialBase.h"
20 
21 #include "libmesh/fe_base.h"
22 #include "libmesh/quadrature.h"
23 #include "libmesh/elem.h"
24 #include "libmesh/point.h"
25 #include "libmesh/mesh_base.h"
26 
28  const std::vector<std::shared_ptr<MortarConstraintBase>> & mortar_constraints,
29  const AutomaticMortarGeneration & amg,
30  SubProblem & subproblem,
31  FEProblemBase & fe_problem,
32  bool displaced,
33  Assembly & assembly)
34  : _amg(amg),
35  _subproblem(subproblem),
36  _fe_problem(fe_problem),
37  _displaced(displaced),
38  _assembly(assembly)
39 {
40  // Construct the mortar constraints we will later loop over
41  for (auto mc : mortar_constraints)
42  _mortar_constraints.push_back(mc.get());
43 
46  _amg,
47  0,
51 }
52 
53 void
55 {
58  _amg,
59  /*thread id*/ 0,
63 }
64 
65 void
67  const std::set<TagID> & vector_tag_ids,
68  const std::set<TagID> & /*matrix_tag_ids*/)
69 {
70  libmesh_parallel_only(_fe_problem.comm());
71 
72  unsigned int num_cached = 0;
73  const auto & vector_tags = _fe_problem.getVectorTags(vector_tag_ids);
74 
75  const auto & secondary_elems_to_mortar_segments = _amg.secondariesToMortarSegments();
76  typedef decltype(secondary_elems_to_mortar_segments.begin()) it_type;
77 
78  std::vector<it_type> iterators;
79  for (auto it = secondary_elems_to_mortar_segments.begin();
80  it != secondary_elems_to_mortar_segments.end();
81  ++it)
82  {
83  auto * const secondary_elem = _subproblem.mesh().getMesh().query_elem_ptr(it->first);
84 
85  if (secondary_elem && secondary_elem->processor_id() == _subproblem.processor_id() &&
86  !it->second.empty())
87  {
88  // This is local and the mortar segment set isn't empty, so include
89  iterators.push_back(it);
90  mooseAssert(secondary_elem->active(),
91  "We loop over active elements when building the mortar segment mesh, so we golly "
92  "well hope this is active.");
93  }
94  }
95 
96  auto act_functor = [this, &num_cached, compute_type, &vector_tags]()
97  {
98  ++num_cached;
99 
100  switch (compute_type)
101  {
103  {
104  for (auto * const mc : _mortar_constraints)
105  {
106  mc->setNormals();
107  mc->computeResidual();
108  }
109 
113 
114  if (num_cached % 20 == 0)
116 
117  break;
118  }
119 
121  {
122  for (auto * const mc : _mortar_constraints)
123  {
124  mc->setNormals();
125  mc->computeJacobian();
126  }
127 
129 
130  if (num_cached % 20 == 0)
132  break;
133  }
134 
136  {
137  for (auto * const mc : _mortar_constraints)
138  {
139  mc->setNormals();
140  mc->computeResidualAndJacobian();
141  }
142 
147 
148  if (num_cached % 20 == 0)
149  {
152  }
153  break;
154  }
155  }
156  };
157 
158  PARALLEL_TRY
159  {
160  try
161  {
163  _assembly,
164  _subproblem,
165  _fe_problem,
166  _amg,
167  _displaced,
169  0,
173  act_functor,
174  /*reinit_mortar_user_objects=*/true);
175  }
176  catch (libMesh::LogicError & e)
177  {
178  _fe_problem.setException("We caught a libMesh::LogicError: " + std::string(e.what()));
179  }
180  catch (MooseException & e)
181  {
183  }
184  catch (MetaPhysicL::LogicError & e)
185  {
187  }
188  }
189  PARALLEL_CATCH;
190 
191  // Call any post operations for our mortar constraints
192  for (auto * const mc : _mortar_constraints)
193  {
195  mc->incorrectEdgeDroppingPost(_amg.getInactiveLMNodes());
196  else
197  mc->post();
198 
199  mc->zeroInactiveLMDofs(_amg.getInactiveLMNodes(), _amg.getInactiveLMElems());
200  }
201 
202  // Make sure any remaining cached residuals/Jacobians get added
207 }
virtual MooseMesh & mesh()=0
void cacheResidualNeighbor(GlobalDataKey, const std::vector< VectorTag > &tags)
Takes the values that are currently in _sub_Rn of all field variables and appends them to the cached ...
Definition: Assembly.C:3455
std::vector< MortarFilterIter > secondariesToMortarSegments(const Node &node) const
virtual const char * what() const
Get out the error message.
void cacheResidualLower(GlobalDataKey, const std::vector< VectorTag > &tags)
Takes the values that are currently in _sub_Rl and appends them to the cached values.
Definition: Assembly.C:3470
Keeps track of stuff related to assembling.
Definition: Assembly.h:101
void setupMortarMaterials(const Consumers &consumers, FEProblemBase &fe_problem, const AutomaticMortarGeneration &amg, const THREAD_ID tid, std::map< SubdomainID, std::deque< MaterialBase *>> &secondary_ip_sub_to_mats, std::map< SubdomainID, std::deque< MaterialBase *>> &primary_ip_sub_to_mats, std::deque< MaterialBase *> &secondary_boundary_mats)
This function creates containers of materials necessary to execute the mortar method for a supplied s...
Definition: MortarUtils.h:316
SubProblem & _subproblem
A reference to the SubProblem object for reiniting lower-dimensional element quantities.
const AutomaticMortarGeneration & _amg
Automatic mortar generation (amg) object providing the mortar mesh to loop over.
void translateMetaPhysicLError(const MetaPhysicL::LogicError &)
emit a relatively clear error message when we catch a MetaPhysicL logic error
Definition: MooseError.C:118
virtual void setException(const std::string &message)
Set an exception, which is stored at this point by toggling a member variable in this class...
const Parallel::Communicator & comm() const
const std::unordered_set< const Elem * > & getInactiveLMElems() const
std::map< SubdomainID, std::deque< MaterialBase * > > _secondary_ip_sub_to_mats
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const bool _displaced
Whether the mortar constraints are operating on the displaced mesh.
void addCachedResiduals(GlobalDataKey, const std::vector< VectorTag > &tags)
Pushes all cached residuals to the global residual vectors associated with each tag.
Definition: Assembly.C:3485
This class is a container/interface for the objects involved in automatic generation of mortar spaces...
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3448
ComputeMortarFunctor(const std::vector< std::shared_ptr< MortarConstraintBase >> &mortar_constraints, const AutomaticMortarGeneration &amg, SubProblem &subproblem, FEProblemBase &fe_problem, bool displaced, Assembly &assembly)
void cacheResidual(GlobalDataKey, const std::vector< VectorTag > &tags)
Takes the values that are currently in _sub_Re of all field variables and appends them to the cached ...
Definition: Assembly.C:3404
std::deque< MaterialBase * > _secondary_boundary_mats
A container that holds the boundary materials that will need to be reinit&#39;d on the secondary face...
std::vector< VectorTag > getVectorTags(const std::set< TagID > &tag_ids) const
Definition: SubProblem.C:172
void loopOverMortarSegments(const Iterators &secondary_elems_to_mortar_segments, Assembly &assembly, SubProblem &subproblem, FEProblemBase &fe_problem, const AutomaticMortarGeneration &amg, const bool displaced, const Consumers &consumers, const THREAD_ID tid, const std::map< SubdomainID, std::deque< MaterialBase *>> &secondary_ip_sub_to_mats, const std::map< SubdomainID, std::deque< MaterialBase *>> &primary_ip_sub_to_mats, const std::deque< MaterialBase *> &secondary_boundary_mats, const ActionFunctor act, const bool reinit_mortar_user_objects)
This method will loop over pairs of secondary elements and their corresponding mortar segments...
Definition: MortarUtils.h:69
ComputeType
The type of nonlinear computation being performed.
Definition: MooseTypes.h:781
std::vector< MortarConstraintBase * > _mortar_constraints
The mortar constraints to loop over when on each element.
Provides a way for users to bail out of the current solve.
void setupMortarMaterials()
Setup step for materials that needs to be re-done if subdomains change.
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
bool computingResidual() const
Definition: Assembly.h:1901
std::map< SubdomainID, std::deque< MaterialBase * > > _primary_ip_sub_to_mats
A map from primary interior parent subdomain IDs to the block materials that will need to reinit&#39;d on...
void operator()(Moose::ComputeType compute_type, const std::set< TagID > &vector_tag_ids, const std::set< TagID > &matrix_tag_ids)
Loops over the mortar segment mesh and computes the residual/Jacobian.
const std::unordered_set< const Node * > & getInactiveLMNodes() const
bool computingJacobian() const
Definition: Assembly.h:1906
void cacheJacobianMortar(GlobalDataKey)
Cache all portions of the Jacobian, e.g.
Definition: Assembly.C:4150
processor_id_type processor_id() const
FEProblemBase & _fe_problem
A reference to the FEProblemBase object for reiniting higher-dimensional element and neighbor element...
void addCachedJacobian(GlobalDataKey)
Adds the values that have been cached by calling cacheJacobian() and or cacheJacobianNeighbor() to th...
Definition: Assembly.C:3815
Assembly & _assembly
A reference to the assembly object.
Key structure for APIs manipulating global vectors/matrices.
Definition: Assembly.h:805