www.mooseframework.org
NodalEqualValueConstraint.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
12 // MOOSE includes
13 #include "Assembly.h"
14 #include "MooseVariableScalar.h"
15 
17 
18 template <>
21 {
23  params.addRequiredCoupledVar("var", "Variable(s) to put the constraint on");
24  return params;
25 }
26 
28  : NodalScalarKernel(parameters)
29 {
30  if (_node_ids.size() != 2)
31  paramError("boundary", "invalid number of nodes: want 2, got ", _node_ids.size());
32 
33  unsigned int n = coupledComponents("var");
34  _value.resize(n);
35  _val_number.resize(n);
36  for (unsigned int k = 0; k < n; k++)
37  {
38  _value[k] = &coupledValue("var", k);
39  _val_number[k] = coupled("var", k);
40  }
41 }
42 
43 void
45 {
47 
48  for (unsigned int k = 0; k < _value.size(); k++)
49  _local_re(k) = (*_value[k])[0] - (*_value[k])[1];
50 
52 }
53 
54 void
56 {
58 
59  // put zeroes on the diagonal (we have to do it, otherwise PETSc will complain!)
60  for (unsigned int i = 0; i < _local_ke.m(); i++)
61  for (unsigned int j = 0; j < _local_ke.n(); j++)
62  _local_ke(i, j) = 0.;
63 
65 
66  for (unsigned int k = 0; k < _value.size(); k++)
67  {
69 
70  _local_ke(k, 0) = 1.;
71  _local_ke(k, 1) = -1.;
72 
74  }
75 }
unsigned int coupledComponents(const std::string &var_name)
Number of coupled components.
Definition: Coupleable.C:166
virtual void computeJacobian() override
unsigned int number() const
Get variable number coming from libMesh.
void assignTaggedLocalMatrix()
Local Jacobian blocks will assigned as the current local kernel Jacobian.
void assignTaggedLocalResidual()
Local residual blocks will assigned as the current local kernel residual.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Assembly & _assembly
Definition: ScalarKernel.h:73
registerMooseObject("MooseApp", NodalEqualValueConstraint)
DenseMatrix< Number > _local_ke
Holds residual entries as they are accumulated by this Kernel.
std::vector< unsigned int > _val_number
NodalEqualValueConstraint(const InputParameters &parameters)
MooseVariableScalar & _var
Scalar variable.
Definition: ScalarKernel.h:75
InputParameters validParams< NodalEqualValueConstraint >()
std::vector< const VariableValue * > _value
InputParameters validParams< NodalScalarKernel >()
virtual const VariableValue & coupledValue(const std::string &var_name, unsigned int comp=0)
Returns value of a coupled variable.
Definition: Coupleable.C:361
virtual void computeResidual() override
void paramError(const std::string &param, Args... args)
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseObject.h:108
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
Constraint to enforce equal values (in 1D)
PetscInt n
DenseVector< Number > _local_re
Holds residual entries as they are accumulated by this Kernel.
std::vector< dof_id_type > _node_ids
List of node IDs.
void prepareVectorTag(Assembly &assembly, unsigned int ivar)
Prepare data for computing element residual the according to active tags.
void prepareMatrixTag(Assembly &assembly, unsigned int ivar, unsigned int jvar)
Prepare data for computing element jacobian according to the ative tags.
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:253