www.mooseframework.org
FaceFaceConstraint.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "FaceFaceConstraint.h"
16 
17 // MOOSE includes
18 #include "Assembly.h"
19 #include "FEProblem.h"
20 #include "MooseVariable.h"
21 #include "NearestNodeLocator.h"
22 #include "PenetrationLocator.h"
23 
24 #include "libmesh/quadrature.h"
25 
26 template <>
29 {
31  params.addRequiredParam<std::string>("interface", "The name of the interface.");
32  params.addRequiredParam<VariableName>("master_variable", "Variable on master surface");
33  params.addParam<VariableName>("slave_variable", "Variable on master surface");
34  return params;
35 }
36 
38  : Constraint(parameters),
40  _fe_problem(*parameters.get<FEProblemBase *>("_fe_problem_base")),
41  _dim(_mesh.dimension()),
42 
43  _q_point(_assembly.qPoints()),
44  _qrule(_assembly.qRule()),
45  _JxW(_assembly.JxW()),
46  _coord(_assembly.coordTransformation()),
47  _current_elem(_assembly.elem()),
48 
49  _master_var(_subproblem.getVariable(_tid, getParam<VariableName>("master_variable"))),
50  _slave_var(isParamValid("slave_variable")
51  ? _subproblem.getVariable(_tid, getParam<VariableName>("slave_variable"))
52  : _subproblem.getVariable(_tid, getParam<VariableName>("master_variable"))),
53  _lambda(_var.sln()),
54 
55  _iface(*_mesh.getMortarInterfaceByName(getParam<std::string>("interface"))),
56  _master_penetration_locator(getMortarPenetrationLocator(
57  _iface._master, _iface._slave, Moose::Master, Order(_master_var.order()))),
58  _slave_penetration_locator(getMortarPenetrationLocator(
59  _iface._master, _iface._slave, Moose::Slave, Order(_slave_var.order()))),
60 
61  _test_master(_master_var.phi()),
62  _grad_test_master(_master_var.gradPhi()),
63  _phi_master(_master_var.phi()),
64 
65  _test_slave(_slave_var.phi()),
66  _grad_test_slave(_slave_var.gradPhi()),
67  _phi_slave(_slave_var.phi())
68 {
69 }
70 
71 void
73 {
74  unsigned int nqp = _qrule->n_points();
75 
76  _u_master.resize(nqp);
77  _grad_u_master.resize(nqp);
78  _phys_points_master.resize(nqp);
79  _u_slave.resize(nqp);
80  _grad_u_slave.resize(nqp);
81  _phys_points_slave.resize(nqp);
82  _test = _assembly.getFE(_var.feType(), _dim - 1)->get_phi(); // yes we need to do a copy here
84  ->get_JxW(); // another copy here to preserve the right JxW
85 
86  for (_qp = 0; _qp < nqp; _qp++)
87  {
88  const Node * current_node = _mesh.getQuadratureNode(_current_elem, 0, _qp);
89 
90  PenetrationInfo * master_pinfo =
92  PenetrationInfo * slave_pinfo =
94 
95  if (master_pinfo && slave_pinfo)
96  {
97  const Elem * master_side =
98  master_pinfo->_elem->build_side_ptr(master_pinfo->_side_num, true).release();
99 
100  std::vector<std::vector<Real>> & master_side_phi = master_pinfo->_side_phi;
101  std::vector<std::vector<RealGradient>> & master_side_grad_phi = master_pinfo->_side_grad_phi;
102  mooseAssert(master_side_phi.size() == master_side_grad_phi.size(),
103  "phi and grad phi size are different");
104  _u_master[_qp] = _master_var.getValue(master_side, master_side_phi);
105  _grad_u_master[_qp] = _master_var.getGradient(master_side, master_side_grad_phi);
106  _phys_points_master[_qp] = master_pinfo->_closest_point;
107  _elem_master = master_pinfo->_elem;
108  delete master_side;
109 
110  const Elem * slave_side =
111  slave_pinfo->_elem->build_side_ptr(slave_pinfo->_side_num, true).release();
112  std::vector<std::vector<Real>> & slave_side_phi = slave_pinfo->_side_phi;
113  std::vector<std::vector<RealGradient>> & slave_side_grad_phi = slave_pinfo->_side_grad_phi;
114  mooseAssert(slave_side_phi.size() == slave_side_grad_phi.size(),
115  "phi and grad phi size are different");
116  _u_slave[_qp] = _slave_var.getValue(slave_side, slave_side_phi);
117  _grad_u_slave[_qp] = _slave_var.getGradient(slave_side, slave_side_grad_phi);
118  _phys_points_slave[_qp] = slave_pinfo->_closest_point;
119  _elem_slave = slave_pinfo->_elem;
120  delete slave_side;
121  }
122  }
123 }
124 
125 void
127 {
128  switch (res_type)
129  {
130  case Moose::Master:
134  _assembly.prepare();
136  break;
137 
138  case Moose::Slave:
142  _assembly.prepare();
144  break;
145  }
146 }
147 
148 void
150 {
151  DenseVector<Number> & re = _assembly.residualBlock(_var.number());
152  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
153  for (_i = 0; _i < _test.size(); _i++)
154  re(_i) += _JxW_lm[_qp] * _coord[_qp] * computeQpResidual();
155 }
156 
157 void
159 {
160  switch (side)
161  {
162  case Moose::Master:
163  {
164  DenseVector<Number> & re_master = _assembly.residualBlock(_master_var.number());
165  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
166  {
167  for (_i = 0; _i < _test_master.size(); _i++)
169  }
170  }
171  break;
172 
173  case Moose::Slave:
174  {
175  DenseVector<Number> & re_slave = _assembly.residualBlock(_slave_var.number());
176  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
177  {
178  for (_i = 0; _i < _test_slave.size(); _i++)
180  }
181  }
182  break;
183  }
184 }
185 
186 void
188 {
189  _phi = _assembly.getFE(_var.feType(), _dim - 1)->get_phi(); // yes we need to do a copy here
190  std::vector<std::vector<Real>> phi_master;
191  std::vector<std::vector<Real>> phi_slave;
192 
193  DenseMatrix<Number> & Kee = _assembly.jacobianBlock(_var.number(), _var.number());
194 
195  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
196  for (_i = 0; _i < _test.size(); _i++)
197  for (_j = 0; _j < _phi.size(); _j++)
198  Kee(_i, _j) += _JxW_lm[_qp] * _coord[_qp] * computeQpJacobian();
199 }
200 
201 void
203 {
204  switch (side)
205  {
206  case Moose::Master:
207  {
208  DenseMatrix<Number> & Ken_master =
210  DenseMatrix<Number> & Kne_master =
212 
213  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
214  for (_i = 0; _i < _test_master.size(); _i++)
215  {
216  for (_j = 0; _j < _phi.size(); _j++)
217  {
218  Ken_master(_j, _i) +=
220  Kne_master(_i, _j) +=
222  }
223  }
224  }
225  break;
226 
227  case Moose::Slave:
228  {
229  DenseMatrix<Number> & Ken_slave = _assembly.jacobianBlock(_var.number(), _slave_var.number());
230  DenseMatrix<Number> & Kne_slave = _assembly.jacobianBlock(_slave_var.number(), _var.number());
231  for (_qp = 0; _qp < _qrule->n_points(); _qp++)
232  for (_i = 0; _i < _test_slave.size(); _i++)
233  {
234  for (_j = 0; _j < _phi.size(); _j++)
235  {
236  Ken_slave(_j, _i) +=
238  Kne_slave(_i, _j) +=
240  }
241  }
242  }
243  break;
244  }
245 }
246 
247 Real
249 {
250  return 0.;
251 }
252 
254 {
255  return 0.;
256 }
const VariableTestValue & _test_slave
Values of test functions on the slave side.
InputParameters validParams< FaceFaceConstraint >()
ConstraintType
Definition: MooseTypes.h:198
const MooseArray< Real > & _coord
const FEType & feType() const
Get the type of finite element object.
virtual Real computeQpJacobianSide(Moose::ConstraintJacobianType jac_type)
Data structure used to hold penetration information.
virtual Real computeQpJacobian()
void reinitAtPhysical(const Elem *elem, const std::vector< Point > &physical_points)
Reinitialize the assembly data at specific physical point in the given element.
Definition: Assembly.C:734
Base class for all Constraint types.
Definition: Constraint.h:42
const Elem * _elem_master
Element on the master side.
std::vector< RealGradient > _grad_u_slave
std::vector< Real > _JxW_lm
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
PenetrationLocator & _slave_penetration_locator
std::vector< std::vector< Real > > _phi
std::vector< Point > _phys_points_slave
Physical points on the slave side.
unsigned int _i
Definition: Constraint.h:83
std::vector< std::vector< RealGradient > > _side_grad_phi
std::vector< std::vector< Real > > _side_phi
std::map< dof_id_type, PenetrationInfo * > & _penetration_info
Data structure of nodes and their associated penetration information.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
DenseVector< Number > & residualBlock(unsigned int var_num, Moose::KernelType type=Moose::KT_NONTIME)
Definition: Assembly.h:504
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
FEBase *& getFE(FEType type, unsigned int dim)
Get a reference to a pointer that will contain the current volume FE.
Definition: Assembly.C:244
std::vector< Real > _u_master
Values of the constrained variable on the master side.
void reinit(const Elem *elem)
Reinitialize objects (JxW, q_points, ...) for an elements.
Definition: Assembly.C:650
virtual Real computeQpResidualSide(Moose::ConstraintType res_type)=0
MooseVariable & _master_var
unsigned int _j
Definition: Constraint.h:83
virtual void computeResidual()
Computes the residual for the current element.
std::vector< Real > _u_slave
Values of the constrained variable on the slave side.
const Elem * _elem
MooseMesh & _mesh
Definition: Constraint.h:81
void prepare()
Definition: Assembly.C:1034
virtual void reinitSide(Moose::ConstraintType res_type)
unsigned int _side_num
RealGradient getGradient(const Elem *elem, const std::vector< std::vector< RealGradient >> &phi) const
virtual Real computeQpResidual()=0
Assembly & _assembly
Definition: Constraint.h:79
Node * getQuadratureNode(const Elem *elem, const unsigned short int side, const unsigned int qp)
Get a specified quadrature node.
Definition: MooseMesh.C:899
virtual void computeJacobian()
Computes the Jacobian for the current element (i.e element of the Mortar interface).
const Elem *& _current_elem
Current element on the interface (i.e in the mortar space)
Real getValue(const Elem *elem, const std::vector< std::vector< Real >> &phi) const
Compute the variable value at a point on an element.
const Elem * _elem_slave
Element on the master side.
const VariableTestValue & _test_master
Values of test functions on the master side.
unsigned int number() const
Get variable number coming from libMesh.
void setCurrentSubdomainID(SubdomainID i)
set the current subdomain ID
Definition: Assembly.h:199
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:250
std::vector< RealGradient > _grad_u_master
virtual void reinit()
Evaluate variables, compute q-points, etc.
ConstraintJacobianType
Definition: MooseTypes.h:204
Intermediate base class that ties together all the interfaces for getting MooseVariables with the Moo...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
FaceFaceConstraint(const InputParameters &parameters)
Definition: Moose.h:84
DenseMatrix< Number > & jacobianBlock(unsigned int ivar, unsigned int jvar)
Definition: Assembly.C:887
virtual void computeResidualSide(Moose::ConstraintType side)
Computes residual contributions from master or slave side.
InputParameters validParams< Constraint >()
Definition: Constraint.C:20
std::vector< Point > _phys_points_master
Physical points on the master side.
PenetrationLocator & _master_penetration_locator
MooseVariable & _slave_var
unsigned int _qp
Definition: Constraint.h:84
std::vector< std::vector< Real > > _test
MooseVariable & _var
Definition: Constraint.h:80
virtual void computeJacobianSide(Moose::ConstraintType side)
Computes Jacobian contributions from master or slave side.