www.mooseframework.org
VectorNodalBC.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 
10 #include "VectorNodalBC.h"
11 
12 #include "Assembly.h"
13 #include "MooseVariableFE.h"
14 #include "SystemBase.h"
15 #include "NonlinearSystemBase.h"
16 
17 template <>
20 {
21  return validParams<NodalBCBase>();
22 }
23 
25  : NodalBCBase(parameters),
27  true,
28  "variable",
31  _var(*mooseVariable()),
32  _current_node(_var.node()),
33  _u(_var.nodalValue())
34 {
35  if (_var.feType().family != LAGRANGE_VEC)
36  mooseError("Vector nodal boundary conditions only make sense for LAGRANGE_VEC variables");
38 }
39 
40 void
42 {
43  const std::vector<dof_id_type> & dof_indices = _var.dofIndices();
44 
45  RealVectorValue res(0, 0, 0);
46  res = computeQpResidual();
47 
48  for (auto tag_id : _vector_tags)
49  if (_sys.hasVector(tag_id))
50  for (size_t i = 0; i < dof_indices.size(); ++i)
51  _sys.getVector(tag_id).set(dof_indices[i], res(i));
52 }
53 
54 void
56 {
57  RealVectorValue cached_val = computeQpJacobian();
58  const std::vector<dof_id_type> & cached_rows = _var.dofIndices();
59 
60  // Cache the user's computeQpJacobian() value for later use.
61  for (auto tag : _matrix_tags)
62  if (_sys.hasMatrix(tag))
63  for (size_t i = 0; i < cached_rows.size(); ++i)
65  cached_rows[i], cached_rows[i], cached_val(i), tag);
66 }
67 
68 void
70 {
71  if (jvar == _var.number())
73  else
74  {
75  Real cached_val = computeQpOffDiagJacobian(jvar);
76  const std::vector<dof_id_type> & cached_rows = _var.dofIndices();
77  // Note: this only works for Lagrange variables...
78  dof_id_type cached_col = _current_node->dof_number(_sys.number(), jvar, 0);
79 
80  // Cache the user's computeQpJacobian() value for later use.
81  for (auto tag : _matrix_tags)
82  if (_sys.hasMatrix(tag))
83  for (size_t i = 0; i < cached_rows.size(); ++i)
85  cached_rows[i], cached_col, cached_val, tag);
86  }
87 }
88 
91 {
92  return RealVectorValue(1., 1., 1.);
93 }
94 
95 Real
97 {
98  return 0.;
99 }
VarFieldType
Definition: MooseTypes.h:488
virtual bool hasMatrix(TagID tag) const
Check if the tagged matrix exists in the system.
Definition: SystemBase.C:805
virtual void computeOffDiagJacobian(unsigned int jvar) override
Definition: VectorNodalBC.C:69
bool hasVector(const std::string &tag_name) const
Check if the named vector exists in the system.
Definition: SystemBase.C:701
virtual void computeJacobian() override
Definition: VectorNodalBC.C:55
FEProblemBase & _fe_problem
Reference to FEProblemBase.
VectorValue< Real > RealVectorValue
Definition: Assembly.h:31
unsigned int number() const
Get variable number coming from libMesh.
virtual RealVectorValue computeQpJacobian()
The user can override this function to compute the "on-diagonal" Jacobian contribution for this Vecto...
Definition: VectorNodalBC.C:90
Assembly & assembly(THREAD_ID tid) override
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual RealVectorValue computeQpResidual()=0
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
const FEType & feType() const
Get the type of finite element object.
void addMooseVariableDependency(MooseVariableFEBase *var)
Call this function to add the passed in MooseVariableFEBase as a variable that this object depends on...
VectorMooseVariable & _var
Definition: VectorNodalBC.h:39
MooseVariableFE< RealVectorValue > * mooseVariable() const
Get the variable that this object is using.
const std::vector< dof_id_type > & dofIndices() const final
Get local DoF indices.
void cacheJacobianContribution(numeric_index_type i, numeric_index_type j, Real value, TagID tag=0)
Caches the Jacobian entry &#39;value&#39;, to eventually be added/set in the (i,j) location of the matrix...
Definition: Assembly.C:3430
std::set< TagID > _matrix_tags
The matrices this Kernel will contribute to.
VectorNodalBC(const InputParameters &parameters)
Definition: VectorNodalBC.C:24
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:481
virtual void computeResidual() override
Definition: VectorNodalBC.C:41
std::set< TagID > _vector_tags
The vectors this Kernel will contribute to.
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
This is the virtual that derived classes should override for computing an off-diagonal jacobian compo...
Definition: VectorNodalBC.C:96
virtual unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:926
Base class for deriving any boundary condition that works at nodes.
Definition: NodalBCBase.h:32
SystemBase & _sys
Reference to SystemBase.
Interface for objects that need to get values of MooseVariables.
Definition: Moose.h:112
InputParameters validParams< VectorNodalBC >()
Definition: VectorNodalBC.C:19
virtual NumericVector< Number > & getVector(const std::string &name)
Get a raw NumericVector.
Definition: SystemBase.C:751
InputParameters validParams< NodalBCBase >()
Definition: NodalBCBase.C:14
const Node *const & _current_node
current node being processed
Definition: VectorNodalBC.h:42