www.mooseframework.org
JvarMapInterface.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 #ifndef JVARMAPINTERFACE_H
8 #define JVARMAPINTERFACE_H
9 
10 #include "MooseVariable.h"
11 #include "NonlinearSystemBase.h"
12 
13 template <class T>
15 
26 template <class T>
28 {
29 public:
30  JvarMapKernelInterface(const InputParameters & parameters);
31  virtual void computeOffDiagJacobian(unsigned int jvar) override;
32 };
33 
44 template <class T>
46 {
47 public:
49  virtual void computeJacobianBlock(unsigned int jvar) override;
50 };
51 
56 template <class T>
57 class JvarMapInterfaceBase : public T
58 {
59 public:
60  JvarMapInterfaceBase(const InputParameters & parameters);
61 
63  unsigned int mapJvarToCvar(unsigned int jvar);
64 
73  bool mapJvarToCvar(unsigned int jvar, unsigned int & cvar);
74 
75 private:
77  std::vector<int> _jvar_map;
78 
79  friend class JvarMapKernelInterface<T>;
81 };
82 
83 template <class T>
85  : T(parameters), _jvar_map(this->_fe_problem.getNonlinearSystemBase().nVariables(), -1)
86 {
87  auto nvar = this->_coupled_moose_vars.size();
88 
89  // populate map;
90  for (auto i = beginIndex(this->_coupled_moose_vars); i < nvar; ++i)
91  {
92  auto number = this->_coupled_moose_vars[i]->number();
93 
94  // skip AuxVars as off-diagonal jacobian entries are not calculated for them
95  if (number < _jvar_map.size())
96  _jvar_map[number] = i;
97  }
98 
99  // mark the kernel variable for the check in computeOffDiagJacobian
100  _jvar_map[this->_var.number()] = 0;
101 }
102 
103 template <class T>
104 unsigned int
106 {
107  mooseAssert(jvar < _jvar_map.size(),
108  "Calling mapJvarToCvar for an invalid Moose variable number. Maybe an AuxVariable?");
109  int cit = _jvar_map[jvar];
110 
111  mooseAssert(cit >= 0, "Calling mapJvarToCvar for a variable not coupled to this kernel.");
112  return cit;
113 }
114 
115 template <class T>
117  : JvarMapInterfaceBase<T>(parameters)
118 {
119 }
120 
121 template <class T>
123  : JvarMapInterfaceBase<T>(parameters)
124 {
125 }
126 
127 template <class T>
128 void
130 {
131  // the Kernel is not coupled to the variable; no need to loop over QPs
132  if (this->_jvar_map[jvar] < 0)
133  return;
134 
135  // call the underlying class' off-diagonal Jacobian
136  T::computeOffDiagJacobian(jvar);
137 }
138 
139 template <class T>
140 void
142 {
143  // the Kernel is not coupled to the variable; no need to loop over QPs
144  if (this->_jvar_map[jvar] < 0)
145  return;
146 
147  // call the underlying class' off-diagonal Jacobian
148  T::computeJacobianBlock(jvar);
149 }
150 
151 #endif // JVARMAPINTERFACE_H
JvarMapIntegratedBCInterface(const InputParameters &parameters)
JvarMapInterfaceBase(const InputParameters &parameters)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Interface class ("Veneer") for Kernel to provide a mapping from &#39;jvar&#39; in computeQpOffDiagJacobian in...
virtual void computeOffDiagJacobian(unsigned int jvar) override
unsigned int mapJvarToCvar(unsigned int jvar)
Return index into the _coupled_moose_vars array for a given jvar.
Base class ("Veneer") that implements the actual mapping from &#39;jvar&#39; in into the _coupled_moose_vars ...
virtual void computeJacobianBlock(unsigned int jvar) override
Interface class ("Veneer") for IntegratedBC to provide a mapping from &#39;jvar&#39; in computeJacobianBlock ...
JvarMapKernelInterface(const InputParameters &parameters)
std::vector< int > _jvar_map
look-up table to determine the _coupled_moose_vars index for the jvar parameter