https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
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
27// C++
28#include <cstring> // for "Jacobian" exception test
29
31 const std::vector<std::shared_ptr<MortarConstraintBase>> & mortar_constraints,
32 const AutomaticMortarGeneration & amg,
33 SubProblem & subproblem,
34 FEProblemBase & fe_problem,
35 bool displaced,
36 Assembly & assembly)
37 : MortarExecutorInterface(fe_problem),
38 _amg(amg),
39 _subproblem(subproblem),
40 _fe_problem(fe_problem),
41 _displaced(displaced),
42 _assembly(assembly)
43{
44 // Construct the mortar constraints we will later loop over
45 for (auto mc : mortar_constraints)
46 _mortar_constraints.push_back(mc.get());
47
49}
50
51void
53{
54 // We may be registered with a warehouse that owns multiple interfaces; only react to the one
55 // we actually consume.
56 if (&amg == &_amg)
58}
59
60void
71
72void
74 const std::set<TagID> & vector_tag_ids,
75 const std::set<TagID> & /*matrix_tag_ids*/)
76{
77 libmesh_parallel_only(_fe_problem.comm());
78
79 unsigned int num_cached = 0;
80 const auto & vector_tags = _fe_problem.getVectorTags(vector_tag_ids);
81
82 const auto & secondary_elems_to_mortar_segments = _amg.secondariesToMortarSegments();
83 typedef decltype(secondary_elems_to_mortar_segments.begin()) it_type;
84
85 std::vector<it_type> iterators;
86 for (auto it = secondary_elems_to_mortar_segments.begin();
87 it != secondary_elems_to_mortar_segments.end();
88 ++it)
89 {
90 auto * const secondary_elem = _subproblem.mesh().getMesh().query_elem_ptr(it->first);
91
92 if (secondary_elem && secondary_elem->processor_id() == _subproblem.processor_id() &&
93 !it->second.empty())
94 {
95 // This is local and the mortar segment set isn't empty, so include
96 iterators.push_back(it);
97 mooseAssert(secondary_elem->active(),
98 "We loop over active elements when building the mortar segment mesh, so we golly "
99 "well hope this is active.");
100 }
101 }
102
103 auto act_functor = [this, &num_cached, compute_type, &vector_tags]()
104 {
105 ++num_cached;
106
107 switch (compute_type)
108 {
110 {
111 for (auto * const mc : _mortar_constraints)
112 {
113 mc->setNormals();
114 mc->computeResidual();
115 }
116
120
121 if (num_cached % 20 == 0)
123
124 break;
125 }
126
128 {
129 for (auto * const mc : _mortar_constraints)
130 {
131 mc->setNormals();
132 mc->computeJacobian();
133 }
134
136
137 if (num_cached % 20 == 0)
139 break;
140 }
141
143 {
144 for (auto * const mc : _mortar_constraints)
145 {
146 mc->setNormals();
147 mc->computeResidualAndJacobian();
148 }
149
154
155 if (num_cached % 20 == 0)
156 {
159 }
160 break;
161 }
162 }
163 };
164
165 PARALLEL_TRY
166 {
167 try
168 {
170 _assembly,
173 _amg,
176 0,
180 act_functor,
181 /*reinit_mortar_user_objects=*/true);
182 }
183 catch (MooseException & e)
184 {
186 }
187 catch (MetaPhysicL::LogicError & e)
188 {
190 }
191 catch (std::exception & e)
192 {
193 if (!strstr(e.what(), "Jacobian") && !strstr(e.what(), "singular") &&
194 !strstr(e.what(), "det != 0"))
195 throw;
196
198 "We caught a libMesh degeneracy exception in ComputeMortarFunctor:\n" +
199 std::string(e.what()));
200 }
201 }
202 PARALLEL_CATCH;
203
204 // Call any post operations for our mortar constraints
205 for (auto * const mc : _mortar_constraints)
206 {
208 mc->incorrectEdgeDroppingPost(_amg.getInactiveLMNodes());
209 else
210 mc->post();
211
212 mc->zeroInactiveLMDofs(_amg.getInactiveLMNodes(), _amg.getInactiveLMElems());
213 }
214
215 // Make sure any remaining cached residuals/Jacobians get added
218 if (_assembly.computingJacobian())
219 _assembly.addCachedJacobian(Assembly::GlobalDataKey{});
220}
Key structure for APIs manipulating global vectors/matrices.
Definition Assembly.h:836
Keeps track of stuff related to assembling.
Definition Assembly.h:101
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:3477
bool computingResidual() const
Definition Assembly.h:1937
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:3491
void cacheJacobianMortar(GlobalDataKey)
Cache all portions of the Jacobian, e.g.
Definition Assembly.C:4170
void addCachedJacobian(GlobalDataKey)
Adds the values that have been cached by calling cacheJacobian() and or cacheJacobianNeighbor() to th...
Definition Assembly.C:3835
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:3427
void addCachedResiduals(GlobalDataKey, const std::vector< VectorTag > &tags)
Pushes all cached residuals to the global residual vectors associated with each tag.
Definition Assembly.C:3505
This class is a container/interface for the objects involved in automatic generation of mortar spaces...
std::vector< MortarFilterIter > secondariesToMortarSegments(const Node &node) const
const std::unordered_set< const Elem * > & getInactiveLMElems() const
const std::unordered_set< const Node * > & getInactiveLMNodes() const
Assembly & _assembly
A reference to the assembly object.
void setupMortarMaterials()
Setup step for materials that needs to be re-done if subdomains change.
void mortarSetup(const AutomaticMortarGeneration &amg) override
Called by the MortarInterfaceWarehouse whenever amg's mortar segment mesh coverage has changed,...
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 AutomaticMortarGeneration & _amg
Automatic mortar generation (amg) object providing the mortar mesh to loop over.
SubProblem & _subproblem
A reference to the SubProblem object for reiniting lower-dimensional element quantities.
FEProblemBase & _fe_problem
A reference to the FEProblemBase object for reiniting higher-dimensional element and neighbor element...
const bool _displaced
Whether the mortar constraints are operating on the displaced mesh.
std::vector< MortarConstraintBase * > _mortar_constraints
The mortar constraints to loop over when on each element.
ComputeMortarFunctor(const std::vector< std::shared_ptr< MortarConstraintBase > > &mortar_constraints, const AutomaticMortarGeneration &amg, SubProblem &subproblem, FEProblemBase &fe_problem, bool displaced, Assembly &assembly)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void setException(const std::string &message)
Set an exception, which is stored at this point by toggling a member variable in this class,...
Provides a way for users to bail out of the current solve.
virtual const char * what() const
Get out the error message.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3512
Interface for objects that need to be notified when the mortar segment mesh for an interface they con...
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'd on...
std::deque< MaterialBase * > _secondary_boundary_mats
A container that holds the boundary materials that will need to be reinit'd on the secondary face.
std::map< SubdomainID, std::deque< MaterialBase * > > _secondary_ip_sub_to_mats
Generic class for solving transient nonlinear problems.
Definition SubProblem.h:79
virtual MooseMesh & mesh()=0
std::vector< VectorTag > getVectorTags(const std::set< TagID > &tag_ids) const
Definition SubProblem.C:161
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
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:91
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...
ComputeType
The type of nonlinear computation being performed.
Definition MooseTypes.h:835
void translateMetaPhysicLError(const MetaPhysicL::LogicError &)
emit a relatively clear error message when we catch a MetaPhysicL logic error
Definition MooseError.C:153