https://mooseframework.inl.gov
MortarNodalAuxKernel.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 "MortarNodalAuxKernel.h"
11 #include "MooseVariableField.h"
12 #include "MortarUtils.h"
13 #include "MooseUtils.h"
14 #include "libmesh/quadrature.h"
15 
16 namespace
17 {
18 const InputParameters &
19 setBoundaryParam(const InputParameters & params_in)
20 {
21  InputParameters & ret = const_cast<InputParameters &>(params_in);
22  ret.set<std::vector<BoundaryName>>("boundary") = {
23  params_in.get<BoundaryName>("secondary_boundary")};
24  return ret;
25 }
26 }
27 
28 template <typename ComputeValueType>
31 {
34  params.set<bool>("ghost_point_neighbors") = true;
35  params.suppressParameter<std::vector<BoundaryName>>("boundary");
36  params.suppressParameter<std::vector<SubdomainName>>("block");
37  params.addParam<bool>(
38  "incremental", false, "Whether to accumulate mortar auxiliary kernel value");
39 
40  // We should probably default use_displaced_mesh to true. If no displaced mesh exists
41  // FEProblemBase::addKernel will automatically correct it to false. However,
42  // this will still prompt a call from AugmentSparsityOnInterface to get a displaced
43  // mortar interface since object._use_displaced_mesh = true.
44 
45  return params;
46 }
47 
48 template <typename ComputeValueType>
50  const InputParameters & parameters)
51  : AuxKernelTempl<ComputeValueType>(setBoundaryParam(parameters)),
53  _displaced(this->template getParam<bool>("use_displaced_mesh")),
54  _fe_problem(*this->template getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
55  _msm_volume(0),
56  _incremental(this->template getParam<bool>("incremental")),
57  _u_old(uOld()),
58  _test_lower(_var.phiLower()),
59  _coord_msm(_assembly.mortarCoordTransformation())
60 {
61  if (!isNodal())
62  paramError("variable",
63  "MortarNodalAuxKernel derived classes populate nodal aux variables only.");
64 }
65 
66 template <typename ComputeValueType>
67 void
69 {
70  std::array<const MortarNodalAuxKernelTempl<ComputeValueType> *, 1> consumers = {{this}};
71 
73  _fe_problem,
74  amg(),
75  _tid,
76  _secondary_ip_sub_to_mats,
77  _primary_ip_sub_to_mats,
78  _secondary_boundary_mats);
79 }
80 
81 template <typename ComputeValueType>
82 void
84 {
85  if (!_var.isNodalDefined())
86  return;
87 
88  ComputeValueType value(0);
89  Real total_volume = 0;
90 
91  const auto & its = amg().secondariesToMortarSegments(*_current_node);
92 
93  auto act_functor = [&value, &total_volume, this]()
94  {
95  _msm_volume = 0;
96  setNormals();
97  value += computeValue();
98  total_volume += _msm_volume;
99  };
100 
101  std::array<MortarNodalAuxKernelTempl<ComputeValueType> *, 1> consumers = {{this}};
102 
104  _assembly,
105  _subproblem,
106  _fe_problem,
107  amg(),
108  _displaced,
109  consumers,
110  _tid,
111  _secondary_ip_sub_to_mats,
112  _primary_ip_sub_to_mats,
113  _secondary_boundary_mats,
114  act_functor,
115  /*reinit_mortar_user_objects=*/false);
116 
117  // We have to reinit the node for this variable in order to get the dof index set for the node
118  _var.reinitNode();
119 
120  // If the node doesn't have corresponding mortar segments, force the value assigned in this step
121  // to be zero. This can be useful when nodes initially do not project but will project at a
122  // different stage of the simulation
123 
124  if (MooseUtils::relativeFuzzyEqual(total_volume, 0.0))
125  value = 0;
126  else
127  value /= total_volume;
128 
129  // Allow mortar auxiliary kernels to compute quantities incrementally
130  if (!_incremental)
131  _var.setNodalValue(value);
132  else
133  {
134  mooseAssert(_u_old.size() == 1,
135  "Expected 1 value in MortarNodalAuxKernel, but got " << _u_old.size());
136  _var.setNodalValue(value + _u_old[0]);
137  }
138 }
139 
140 template <typename ComputeValueType>
141 void
143 {
144  mooseError(
145  "not clear where this should be implemented in the compute loop. If you want to implement "
146  "this function, please contact a MOOSE developer and tell them your use case");
147 }
148 
149 // Explicitly instantiates the two versions of the MortarNodalAuxKernelTempl class
150 template class MortarNodalAuxKernelTempl<Real>;
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:435
void precalculateValue() override final
This callback is used for AuxKernelTempls that need to perform a per-element calculation.
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
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:333
void compute() override
Computes the value and stores it in the solution vector.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
static InputParameters validParams()
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
An interface for accessing mortar mesh data.
MortarNodalAuxKernelTempl(const InputParameters &parameters)
void suppressParameter(const std::string &name)
This method suppresses an inherited parameter so that it isn&#39;t required or valid in the derived class...
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
Base class for creating new nodally-based mortar auxiliary kernels.
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
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool relativeFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within a relative tolerance.
Definition: MooseUtils.h:492
static InputParameters validParams()
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
static InputParameters validParams()
Definition: AuxKernel.C:27
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
Definition: AuxKernel.h:36
bool isNodal() const
Nodal or elemental kernel?
Definition: AuxKernel.h:86