www.mooseframework.org
NodalBC.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 "NodalBC.h"
11 
12 #include "Assembly.h"
13 #include "MooseVariableFE.h"
14 #include "SystemBase.h"
15 #include "NonlinearSystemBase.h"
16 
18 
21 {
23 
24  return params;
25 }
26 
27 NodalBC::NodalBC(const InputParameters & parameters)
28  : NodalBCBase(parameters),
29  MooseVariableInterface<Real>(this,
30  true,
31  "variable",
34  _var(*mooseVariable()),
35  _current_node(_var.node()),
36  _u(_var.dofValues())
37 {
39 
40  _save_in.resize(_save_in_strings.size());
41  _diag_save_in.resize(_diag_save_in_strings.size());
42 
43  for (unsigned int i = 0; i < _save_in_strings.size(); i++)
44  {
46 
47  if (var->feType() != _var.feType())
48  paramError(
49  "save_in",
50  "saved-in auxiliary variable is incompatible with the object's nonlinear variable: ",
52 
53  _save_in[i] = var;
56  }
57 
58  _has_save_in = _save_in.size() > 0;
59 
60  for (unsigned int i = 0; i < _diag_save_in_strings.size(); i++)
61  {
63 
64  if (var->feType() != _var.feType())
65  paramError(
66  "diag_save_in",
67  "saved-in auxiliary variable is incompatible with the object's nonlinear variable: ",
69 
70  _diag_save_in[i] = var;
73  }
74 
75  _has_diag_save_in = _diag_save_in.size() > 0;
76 }
77 
78 void
80 {
81  if (_var.isNodalDefined())
82  {
83  Real res = computeQpResidual();
84 
85  for (auto tag_id : _vector_tags)
86  if (_sys.hasVector(tag_id))
87  _var.insertNodalValue(_sys.getVector(tag_id), res);
88 
89  if (_has_save_in)
90  {
91  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
92  for (unsigned int i = 0; i < _save_in.size(); i++)
93  _save_in[i]->sys().solution().set(_save_in[i]->nodalDofIndex(), res);
94  }
95  }
96 }
97 
98 void
100 {
101  // We call the user's computeQpJacobian() function and store the
102  // results in the _assembly object. We can't store them directly in
103  // the element stiffness matrix, as they will only be inserted after
104  // all the assembly is done.
105  if (_var.isNodalDefined())
106  {
107  Real cached_val = 0.;
108  cached_val = computeQpJacobian();
109 
110  dof_id_type cached_row = _var.nodalDofIndex();
111 
112  // Cache the user's computeQpJacobian() value for later use.
113  for (auto tag : _matrix_tags)
114  if (_sys.hasMatrix(tag))
115  _fe_problem.assembly(0).cacheJacobianContribution(cached_row, cached_row, cached_val, tag);
116 
117  if (_has_diag_save_in)
118  {
119  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
120  for (unsigned int i = 0; i < _diag_save_in.size(); i++)
121  _diag_save_in[i]->sys().solution().set(_diag_save_in[i]->nodalDofIndex(), cached_val);
122  }
123  }
124 }
125 
126 void
128 {
129  if (jvar == _var.number())
130  computeJacobian();
131  else
132  {
133  Real cached_val = 0.0;
134  cached_val = computeQpOffDiagJacobian(jvar);
135 
136  dof_id_type cached_row = _var.nodalDofIndex();
137  // Note: this only works for Lagrange variables...
138  dof_id_type cached_col = _current_node->dof_number(_sys.number(), jvar, 0);
139 
140  // Cache the user's computeQpJacobian() value for later use.
141  for (auto tag : _matrix_tags)
142  if (_sys.hasMatrix(tag))
143  _fe_problem.assembly(0).cacheJacobianContribution(cached_row, cached_col, cached_val, tag);
144  }
145 }
146 
147 Real
149 {
150  return 1.;
151 }
152 
153 Real
154 NodalBC::computeQpOffDiagJacobian(unsigned int /*jvar*/)
155 {
156  return 0.;
157 }
Moose::VarFieldType
VarFieldType
Definition: MooseTypes.h:613
Moose
Definition: Moose.h:116
NonlinearSystemBase.h
BoundaryCondition::_fe_problem
FEProblemBase & _fe_problem
Reference to FEProblemBase.
Definition: BoundaryCondition.h:100
MooseVariableInterface< Real >::mooseVariable
MooseVariableFE< Real > * mooseVariable() const
Get the variable that this object is using.
Definition: MooseVariableInterface.C:70
SystemBase.h
MooseVariableBase::feType
const FEType & feType() const
Get the type of finite element object.
Definition: MooseVariableBase.h:53
FEProblemBase::assembly
Assembly & assembly(THREAD_ID tid) override
Definition: FEProblemBase.h:322
SystemBase::hasVector
bool hasVector(const std::string &tag_name) const
Check if the named vector exists in the system.
Definition: SystemBase.C:748
TaggingInterface::_matrix_tags
std::set< TagID > _matrix_tags
The matrices this Kernel will contribute to.
Definition: TaggingInterface.h:138
MooseVariableDependencyInterface::addMooseVariableDependency
void addMooseVariableDependency(MooseVariableFEBase *var)
Call this function to add the passed in MooseVariableFEBase as a variable that this object depends on...
Definition: MooseVariableDependencyInterface.h:36
SystemBase::addVariableToZeroOnJacobian
virtual void addVariableToZeroOnJacobian(std::string var_name)
Adds this variable to the list of variables to be zeroed during each Jacobian evaluation.
Definition: SystemBase.C:183
NodalBC::computeQpOffDiagJacobian
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
This is the virtual that derived classes should override for computing an off-diagonal jacobian compo...
Definition: NodalBC.C:154
TaggingInterface::_vector_tags
std::set< TagID > _vector_tags
The vectors this Kernel will contribute to.
Definition: TaggingInterface.h:135
Assembly.h
SystemBase::hasMatrix
virtual bool hasMatrix(TagID tag) const
Check if the tagged matrix exists in the system.
Definition: SystemBase.C:852
NodalBCBase::_save_in
std::vector< MooseVariableFEBase * > _save_in
Definition: NodalBCBase.h:53
NodalBC::computeResidual
virtual void computeResidual() override
Definition: NodalBC.C:79
Assembly::cacheJacobianContribution
void cacheJacobianContribution(numeric_index_type i, numeric_index_type j, Real value, TagID tag=0)
Caches the Jacobian entry 'value', to eventually be added/set in the (i,j) location of the matrix.
Definition: Assembly.C:3783
NodalBC::computeQpJacobian
virtual Real computeQpJacobian()
The user can override this function to compute the "on-diagonal" Jacobian contribution for this Nodal...
Definition: NodalBC.C:148
NodalBCBase::_has_save_in
bool _has_save_in
The aux variables to save the residual contributions to.
Definition: NodalBCBase.h:52
MooseObject::paramError
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseObject.h:215
NodalBCBase::_save_in_strings
std::vector< AuxVariableName > _save_in_strings
Definition: NodalBCBase.h:54
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
NodalBCBase::_diag_save_in_strings
std::vector< AuxVariableName > _diag_save_in_strings
Definition: NodalBCBase.h:59
NodalBC::_current_node
const Node *const & _current_node
current node being processed
Definition: NodalBC.h:46
SystemBase::addVariableToZeroOnResidual
virtual void addVariableToZeroOnResidual(std::string var_name)
Adds this variable to the list of variables to be zeroed during each residual evaluation.
Definition: SystemBase.C:171
NodalBCBase
Base class for deriving any boundary condition that works at nodes.
Definition: NodalBCBase.h:32
NodalBC::_var
MooseVariable & _var
Definition: NodalBC.h:43
NodalBC::computeOffDiagJacobian
virtual void computeOffDiagJacobian(unsigned int jvar) override
Definition: NodalBC.C:127
moose::internal::incompatVarMsg
std::string incompatVarMsg(MooseVariableFEBase &var1, MooseVariableFEBase &var2)
Builds and returns a string of the form:
Definition: MooseError.C:23
SystemBase::number
virtual unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:973
BoundaryCondition::_sys
SystemBase & _sys
Reference to SystemBase.
Definition: BoundaryCondition.h:103
MooseVariableFE::isNodalDefined
virtual bool isNodalDefined() const override
Is this variable defined at nodes.
Definition: MooseVariableFE.C:777
NodalBC::computeJacobian
virtual void computeJacobian() override
Definition: NodalBC.C:99
NodalBC
Base class for deriving any boundary condition that works at nodes.
Definition: NodalBC.h:26
MooseVariableFE.h
SystemBase::getVector
virtual NumericVector< Number > & getVector(const std::string &name)
Get a raw NumericVector.
Definition: SystemBase.C:798
NodalBCBase::_diag_save_in
std::vector< MooseVariableFEBase * > _diag_save_in
Definition: NodalBCBase.h:58
Moose::VAR_NONLINEAR
Definition: MooseTypes.h:608
NodalBC::computeQpResidual
virtual Real computeQpResidual()=0
Moose::VarKindType
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:606
MooseVariableBase::sys
SystemBase & sys()
Get the system this variable is part of.
Definition: MooseVariableBase.h:58
NodalBC::validParams
static InputParameters validParams()
Definition: NodalBC.C:20
NodalBC.h
NodalBCBase::validParams
static InputParameters validParams()
Definition: NodalBCBase.C:20
NodalBCBase::_has_diag_save_in
bool _has_diag_save_in
The aux variables to save the diagonal Jacobian contributions to.
Definition: NodalBCBase.h:57
BoundaryCondition::_tid
THREAD_ID _tid
Thread id.
Definition: BoundaryCondition.h:106
MooseVariableFE::insertNodalValue
void insertNodalValue(NumericVector< Number > &residual, const OutputData &v)
Write a nodal value to the passed-in solution vector.
Definition: MooseVariableFE.C:685
MooseVariableInterface
Interface for objects that need to get values of MooseVariables.
Definition: MooseVariableInterface.h:24
MooseVariableFE
Class for stuff related to variables.
Definition: Adaptivity.h:31
NodalBC::NodalBC
NodalBC(const InputParameters &parameters)
Definition: NodalBC.C:27
defineLegacyParams
defineLegacyParams(NodalBC)
Moose::VAR_FIELD_STANDARD
Definition: MooseTypes.h:615
SubProblem::getStandardVariable
virtual MooseVariable & getStandardVariable(THREAD_ID tid, const std::string &var_name)=0
Returns the variable reference for requested MooseVariable which may be in any system.
MooseVariableFE::nodalDofIndex
const dof_id_type & nodalDofIndex() const override
Definition: MooseVariableFE.h:164
BoundaryCondition::_subproblem
SubProblem & _subproblem
Reference to SubProblem.
Definition: BoundaryCondition.h:97
MooseVariableBase::number
unsigned int number() const
Get variable number coming from libMesh.
Definition: MooseVariableBase.h:48