https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ArrayNodalBC.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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 "ArrayNodalBC.h"
11
12#include "Assembly.h"
13#include "MooseVariableFE.h"
14#include "SystemBase.h"
15#include "NonlinearSystemBase.h"
16#include "FEProblemBase.h"
17
20{
22 return params;
23}
24
26 : NodalBCBase(parameters),
27 MooseVariableInterface<RealEigenVector>(this,
28 true,
29 "variable",
30 Moose::VarKindType::VAR_SOLVER,
31 Moose::VarFieldType::VAR_FIELD_ARRAY),
32 _var(*mooseVariable()),
33 _current_node(_var.node()),
34 _u(_var.nodalValue()),
35 _count(_var.count()),
36 _work_vector(_count)
37{
39}
40
41void
43{
44 if (_var.isNodalDefined())
45 {
46 _work_vector.setZero();
48 mooseAssert(_work_vector.size() == _count,
49 "Size of local residual is not equal to the number of array variable components");
50
52 }
53}
54
55void
57{
58 if (_var.isNodalDefined())
59 {
60 const RealEigenVector cached_val = computeQpJacobian();
61 const dof_id_type cached_row = _var.nodalDofIndex();
62
63 for (const auto i : make_range(_var.count()))
65 cached_val(i),
66 cached_row + i,
67 cached_row + i,
68 /*scaling_factor=*/1);
69 }
70}
71
72void
73ArrayNodalBC::computeOffDiagJacobian(const unsigned int jvar_num)
74{
75 if (!_var.isNodalDefined())
76 return;
77
78 const auto & jvar = getVariable(jvar_num);
79
80 const RealEigenMatrix cached_val =
82 const dof_id_type cached_row = _var.nodalDofIndex();
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 : make_range(_var.count()))
88 for (const auto j : make_range(jvar.count()))
90 cached_val(i, j),
91 cached_row + i,
92 cached_col + j,
93 /*scaling_factor=*/1);
94}
95
96RealEigenVector
98{
99 return RealEigenVector::Ones(_var.count());
100}
101
102RealEigenMatrix
104{
105 if (jvar.number() == _var.number())
106 return RealEigenMatrix::Identity(_var.count(), jvar.count());
107 else
108 return RealEigenMatrix::Zero(_var.count(), jvar.count());
109}
unsigned int count
Definition MortarUtils.C:53
const unsigned int _count
Number of components of the array variable.
ArrayNodalBC(const InputParameters &parameters)
virtual void computeResidual() override
Compute this object's contribution to the residual.
virtual RealEigenMatrix computeQpOffDiagJacobian(MooseVariableFEBase &jvar)
This is the virtual that derived classes should override for computing an off-diagonal jacobian compo...
virtual void computeQpResidual(RealEigenVector &residual)=0
Compute this BC's contribution to the residual at the current quadrature point, to be filled in resid...
ArrayMooseVariable & _var
RealEigenVector _work_vector
Work vector for residual.
const Node *const & _current_node
current node being processed
static InputParameters validParams()
virtual void computeJacobian() override
Compute this object's contribution to the diagonal Jacobian entries.
virtual RealEigenVector computeQpJacobian()
The user can override this function to compute the "on-diagonal" Jacobian contribution for this Vecto...
virtual void computeOffDiagJacobian(unsigned int jvar) override
Computes this object's contribution to off-diagonal blocks of the system Jacobian matrix.
virtual Assembly & assembly(const THREAD_ID tid, const unsigned int sys_num) override
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
unsigned int number() const
Get variable number coming from libMesh.
unsigned int count() const
Get the number of components Note: For standard and vector variables, the number is one.
void addMooseVariableDependency(MooseVariableFieldBase *var)
Call this function to add the passed in MooseVariableFieldBase as a variable that this object depends...
const dof_id_type & nodalDofIndex() const override
virtual bool isNodalDefined() const override
Is this variable defined at nodes.
This class provides an interface for common operations on field variables of both FE and FV types wit...
Interface for objects that need to get values of MooseVariables.
MooseVariableFE< RealEigenVector > * mooseVariable() const
Return the MooseVariableFE object that this interface acts on.
Base class for deriving any boundary condition that works at nodes.
Definition NodalBCBase.h:28
static InputParameters validParams()
Definition NodalBCBase.C:13
const MooseVariableFieldBase & getVariable(unsigned int jvar_num) const
Retrieve the variable object from our system associated with jvar_num.
SystemBase & _sys
Reference to the EquationSystem object.
FEProblemBase & _fe_problem
Reference to this kernel's FEProblemBase.
unsigned int number() const
Gets the number of this system.
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.
void setResidual(SystemBase &sys, const T &residual, MooseVariableFE< T > &var)
Set residual using the variables' insertion API.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...