www.mooseframework.org
NodalEqualValueConstraint.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 
16 
17 // MOOSE includes
18 #include "Assembly.h"
19 #include "MooseVariableScalar.h"
20 
21 template <>
24 {
26  params.addRequiredCoupledVar("var", "Variable(s) to put the constraint on");
27  return params;
28 }
29 
31  : NodalScalarKernel(parameters)
32 {
33  if (_node_ids.size() != 2)
34  mooseError(name(), ": The number of nodes has to be 2, but it is ", _node_ids.size(), ".");
35 
36  unsigned int n = coupledComponents("var");
37  _value.resize(n);
38  _val_number.resize(n);
39  for (unsigned int k = 0; k < n; k++)
40  {
41  _value[k] = &coupledValue("var", k);
42  _val_number[k] = coupled("var", k);
43  }
44 }
45 
46 void
48 {
49  // LM residuals
50  DenseVector<Number> & lm_re = _assembly.residualBlock(_var.number());
51 
52  for (unsigned int k = 0; k < _value.size(); k++)
53  lm_re(k) = (*_value[k])[0] - (*_value[k])[1];
54 }
55 
56 void
58 {
59  // do the diagonal block
60  DenseMatrix<Number> & ke = _assembly.jacobianBlock(_var.number(), _var.number());
61  // put zeroes on the diagonal (we have to do it, otherwise PETSc will complain!)
62  for (unsigned int i = 0; i < ke.m(); i++)
63  for (unsigned int j = 0; j < ke.n(); j++)
64  ke(i, j) = 0.;
65 
66  for (unsigned int k = 0; k < _value.size(); k++)
67  {
68  DenseMatrix<Number> & ken = _assembly.jacobianBlock(_var.number(), _val_number[k]);
69 
70  ken(k, 0) = 1.;
71  ken(k, 1) = -1.;
72  }
73 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
unsigned int coupledComponents(const std::string &var_name)
Number of coupled components.
Definition: Coupleable.C:111
virtual void computeJacobian() override
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Assembly & _assembly
Definition: ScalarKernel.h:79
DenseVector< Number > & residualBlock(unsigned int var_num, Moose::KernelType type=Moose::KT_NONTIME)
Definition: Assembly.h:504
InputParameters validParams< NodalScalarKernel >()
std::vector< unsigned int > _val_number
NodalEqualValueConstraint(const InputParameters &parameters)
MooseVariableScalar & _var
Scalar variable.
Definition: ScalarKernel.h:81
InputParameters validParams< NodalEqualValueConstraint >()
std::vector< const VariableValue * > _value
virtual const VariableValue & coupledValue(const std::string &var_name, unsigned int comp=0)
Returns value of a coupled variable.
Definition: Coupleable.C:167
virtual void computeResidual() override
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
unsigned int number() const
Get variable number coming from libMesh.
PetscInt n
std::vector< dof_id_type > _node_ids
List of node IDs.
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
DenseMatrix< Number > & jacobianBlock(unsigned int ivar, unsigned int jvar)
Definition: Assembly.C:887
virtual unsigned int coupled(const std::string &var_name, unsigned int comp=0)
Returns the index for a coupled variable by name.
Definition: Coupleable.C:136