www.mooseframework.org
JvarMapInterface.h
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 #pragma once
11 
12 #include "MooseVariableFE.h"
13 #include "NonlinearSystemBase.h"
14 #include "Enumerate.h"
15 
16 template <class T>
18 
29 template <class T>
31 {
32 public:
33  JvarMapKernelInterface(const InputParameters & parameters);
34  virtual void computeOffDiagJacobian(MooseVariableFEBase & jvar) override;
35  using T::computeOffDiagJacobian;
36 };
37 
48 template <class T>
50 {
51 public:
53  virtual void computeJacobianBlock(MooseVariableFEBase & jvar) override;
54 };
55 
60 template <class T>
61 class JvarMapInterfaceBase : public T
62 {
63 public:
64  JvarMapInterfaceBase(const InputParameters & parameters);
65 
67  unsigned int mapJvarToCvar(unsigned int jvar);
68 
77  bool mapJvarToCvar(unsigned int jvar, unsigned int & cvar);
78 
79 private:
81  std::vector<int> _jvar_map;
82 
83  friend class JvarMapKernelInterface<T>;
85 };
86 
87 template <class T>
89  : T(parameters), _jvar_map(this->_fe_problem.getNonlinearSystemBase().nVariables(), -1)
90 {
91  // populate map;
92  for (auto it : Moose::enumerate(this->_coupled_moose_vars))
93  {
94  auto number = it.value()->number();
95 
96  // skip AuxVars as off-diagonal jacobian entries are not calculated for them
97  if (number < _jvar_map.size())
98  _jvar_map[number] = it.index();
99  }
100 
101  // mark the kernel variable for the check in computeOffDiagJacobian
102  _jvar_map[this->_var.number()] = 0;
103 }
104 
105 template <class T>
106 unsigned int
108 {
109  mooseAssert(jvar < _jvar_map.size(),
110  "Calling mapJvarToCvar for an invalid Moose variable number. Maybe an AuxVariable?");
111  int cit = _jvar_map[jvar];
112 
113  mooseAssert(cit >= 0, "Calling mapJvarToCvar for a variable not coupled to this kernel.");
114  return cit;
115 }
116 
117 template <class T>
119  : JvarMapInterfaceBase<T>(parameters)
120 {
121 }
122 
123 template <class T>
125  : JvarMapInterfaceBase<T>(parameters)
126 {
127 }
128 
129 template <class T>
130 void
132 {
133  // the Kernel is not coupled to the variable; no need to loop over QPs
134  if (this->_jvar_map[jvar.number()] < 0)
135  return;
136 
137  // call the underlying class' off-diagonal Jacobian
138  T::computeOffDiagJacobian(jvar);
139 }
140 
141 template <class T>
142 void
144 {
145  // the Kernel is not coupled to the variable; no need to loop over QPs
146  if (this->_jvar_map[jvar.number()] < 0)
147  return;
148 
149  // call the underlying class' off-diagonal Jacobian
150  T::computeJacobianBlock(jvar);
151 }
152 
JvarMapIntegratedBCInterface(const InputParameters &parameters)
unsigned int number() const
Get variable number coming from libMesh.
JvarMapInterfaceBase(const InputParameters &parameters)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
_enumerate_range< Iterator > enumerate(Iterator first, Iterator last, typename std::iterator_traits< Iterator >::difference_type initial)
Enumerate function for iterating over a range and obtaining both a reference to the underlying type a...
Definition: Enumerate.h:52
virtual void computeJacobianBlock(MooseVariableFEBase &jvar) override
Interface class ("Veneer") for Kernel to provide a mapping from &#39;jvar&#39; in computeQpOffDiagJacobian in...
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 computeOffDiagJacobian(MooseVariableFEBase &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