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 
19 {
21  return params;
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  if (dof_indices.empty())
45  return;
46 
47  const RealVectorValue res = computeQpResidual();
48 
49  for (const auto i : index_range(dof_indices))
50  setResidual(_sys, res(i), dof_indices[i]);
51 }
52 
53 void
55 {
56  const std::vector<dof_id_type> & cached_rows = _var.dofIndices();
57  if (cached_rows.empty())
58  return;
59 
60  const RealVectorValue cached_val = computeQpJacobian();
61 
62  // Cache the user's computeQpJacobian() value for later use.
63  for (const auto i : index_range(cached_rows))
65  cached_val(i),
66  cached_rows[i],
67  cached_rows[i],
68  /*scaling_factor=*/1);
69 }
70 
71 void
72 VectorNodalBC::computeOffDiagJacobian(const unsigned int jvar_num)
73 {
74  if (jvar_num == _var.number())
76  else
77  {
78  const std::vector<dof_id_type> & cached_rows = _var.dofIndices();
79  if (cached_rows.empty())
80  return;
81 
82  const Real cached_val = computeQpOffDiagJacobian(jvar_num);
83  // Note: this only works for Lagrange variables...
84  const dof_id_type cached_col = _current_node->dof_number(_sys.number(), jvar_num, 0);
85 
86  // Cache the user's computeQpJacobian() value for later use.
87  for (const auto i : index_range(cached_rows))
89  cached_val,
90  cached_rows[i],
91  cached_col,
92  /*scaling_factor=*/1);
93  }
94 }
95 
98 {
99  return RealVectorValue(1., 1., 1.);
100 }
101 
102 Real
104 {
105  return 0.;
106 }
VarFieldType
Definition: MooseTypes.h:634
virtual void computeOffDiagJacobian(unsigned int jvar) override
Computes this object&#39;s contribution to off-diagonal blocks of the system Jacobian matrix...
Definition: VectorNodalBC.C:72
LAGRANGE_VEC
virtual void computeJacobian() override
Compute this object&#39;s contribution to the diagonal Jacobian entries.
Definition: VectorNodalBC.C:54
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:97
static InputParameters validParams()
Definition: VectorNodalBC.C:18
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual RealVectorValue computeQpResidual()=0
const FEType & feType() const
Get the type of finite element object.
SystemBase & _sys
Reference to the EquationSystem object.
MooseVariableFE< RealVectorValue > * mooseVariable() const
const std::vector< dof_id_type > & dofIndices() const final
Get local DoF indices.
VectorNodalBC(const InputParameters &parameters)
Definition: VectorNodalBC.C:24
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:627
FEProblemBase & _fe_problem
Reference to this kernel&#39;s FEProblemBase.
virtual void computeResidual() override
Compute this object&#39;s contribution to the residual.
Definition: VectorNodalBC.C:41
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
This is the virtual that derived classes should override for computing an off-diagonal jacobian compo...
unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:1125
Base class for deriving any boundary condition that works at nodes.
Definition: NodalBCBase.h:26
void addMooseVariableDependency(MooseVariableFieldBase *var)
Call this function to add the passed in MooseVariableFieldBase as a variable that this object depends...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Interface for objects that need to get values of MooseVariables.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
void addJacobianElement(Assembly &assembly, Real value, dof_id_type row_index, dof_id_type column_index, Real scaling_factor)
Add into a single Jacobian element.
Assembly & assembly(const THREAD_ID tid, const unsigned int nl_sys_num) override
void setResidual(SystemBase &sys, const T &residual, MooseVariableFE< T > &var)
Set residual using the variables&#39; insertion API.
auto index_range(const T &sizable)
const VectorMooseVariable & _var
Definition: VectorNodalBC.h:35
uint8_t dof_id_type
const Node *const & _current_node
current node being processed
Definition: VectorNodalBC.h:38
static InputParameters validParams()
Definition: NodalBCBase.C:13