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  using T::computeJacobianBlock;
55 };
56 
61 template <class T>
62 class JvarMapInterfaceBase : public T
63 {
64 public:
65  typedef std::vector<int> JvarMap;
66 
67  JvarMapInterfaceBase(const InputParameters & parameters);
68 
70  unsigned int mapJvarToCvar(unsigned int jvar);
71 
77  int mapJvarToCvar(unsigned int jvar, const JvarMap & jvar_map);
78 
80  const JvarMap & getParameterJvarMap(std::string parameter_name);
81 
90  bool mapJvarToCvar(unsigned int jvar, unsigned int & cvar);
91 
92 private:
94  const std::size_t _jvar_max_size;
95 
98 
100  std::map<std::string, JvarMap> _jvar_local_map;
101 
102  friend class JvarMapKernelInterface<T>;
104 };
105 
106 template <class T>
108  : T(parameters),
109  _jvar_max_size(this->_fe_problem.getNonlinearSystemBase().nVariables()),
111 {
112  // populate map
113  for (auto it : Moose::enumerate(this->_coupled_moose_vars))
114  {
115  auto number = it.value()->number();
116 
117  // skip AuxVars as off-diagonal jacobian entries are not calculated for them
118  if (number < _jvar_max_size)
119  _jvar_map[number] = it.index();
120  }
121 
122  // mark the kernel variable for the check in computeOffDiagJacobian
123  _jvar_map[this->_var.number()] = 0;
124 }
125 
126 template <class T>
127 unsigned int
129 {
130  mooseAssert(jvar < _jvar_max_size,
131  "Calling mapJvarToCvar for an invalid Moose variable number. Maybe an AuxVariable?");
132  int cit = _jvar_map[jvar];
133 
134  mooseAssert(cit >= 0, "Calling mapJvarToCvar for a variable not coupled to this kernel.");
135  return cit;
136 }
137 
138 template <class T>
139 int
140 JvarMapInterfaceBase<T>::mapJvarToCvar(unsigned int jvar, const JvarMap & jvar_map)
141 {
142  mooseAssert(jvar < _jvar_max_size,
143  "Calling mapJvarToCvar for an invalid Moose variable number. Maybe an AuxVariable?");
144  return jvar_map[jvar];
145 }
146 
147 template <class T>
148 const typename JvarMapInterfaceBase<T>::JvarMap &
150 {
151  auto & jvar_map = _jvar_local_map[parameter_name];
152  jvar_map.assign(_jvar_max_size, -1);
153 
154  // populate local map
155  const auto num = this->coupledComponents(parameter_name);
156  for (std::size_t i = 0; i < num; ++i)
157  {
158  const auto number = this->getVar(parameter_name, i)->number();
159 
160  // skip AuxVars as off-diagonal jacobian entries are not calculated for them
161  if (number < _jvar_max_size)
162  jvar_map[number] = i;
163  }
164 
165  return jvar_map;
166 }
167 
168 template <class T>
170  : JvarMapInterfaceBase<T>(parameters)
171 {
172 }
173 
174 template <class T>
176  : JvarMapInterfaceBase<T>(parameters)
177 {
178 }
179 
180 template <class T>
181 void
183 {
184  // the Kernel is not coupled to the variable; no need to loop over QPs
185  if (this->_jvar_map[jvar.number()] < 0)
186  return;
187 
188  // call the underlying class' off-diagonal Jacobian
189  T::computeOffDiagJacobian(jvar);
190 }
191 
192 template <class T>
193 void
195 {
196  // the Kernel is not coupled to the variable; no need to loop over QPs
197  if (this->_jvar_map[jvar.number()] < 0)
198  return;
199 
200  // call the underlying class' off-diagonal Jacobian
201  T::computeJacobianBlock(jvar);
202 }
MooseVariableFEBase
Definition: MooseVariableFEBase.h:27
JvarMapIntegratedBCInterface::computeJacobianBlock
virtual void computeJacobianBlock(MooseVariableFEBase &jvar) override
Definition: JvarMapInterface.h:194
NonlinearSystemBase.h
JvarMapInterfaceBase::JvarMap
std::vector< int > JvarMap
Definition: JvarMapInterface.h:65
JvarMapInterfaceBase::_jvar_local_map
std::map< std::string, JvarMap > _jvar_local_map
map of local look-up tables for specific parameters
Definition: JvarMapInterface.h:100
JvarMapInterfaceBase
Base class ("Veneer") that implements the actual mapping from 'jvar' in into the _coupled_moose_vars ...
Definition: JvarMapInterface.h:17
JvarMapInterfaceBase::getParameterJvarMap
const JvarMap & getParameterJvarMap(std::string parameter_name)
Make a specific map for a given parameter name representing a couple variable (vector)
Definition: JvarMapInterface.h:149
JvarMapInterfaceBase::mapJvarToCvar
unsigned int mapJvarToCvar(unsigned int jvar)
Return index into the _coupled_moose_vars array for a given jvar.
Definition: JvarMapInterface.h:128
JvarMapKernelInterface::computeOffDiagJacobian
virtual void computeOffDiagJacobian(MooseVariableFEBase &jvar) override
Definition: JvarMapInterface.h:182
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
JvarMapInterfaceBase::JvarMapInterfaceBase
JvarMapInterfaceBase(const InputParameters &parameters)
Definition: JvarMapInterface.h:107
JvarMapKernelInterface::JvarMapKernelInterface
JvarMapKernelInterface(const InputParameters &parameters)
Definition: JvarMapInterface.h:169
MooseVariableFE.h
JvarMapIntegratedBCInterface
Interface class ("Veneer") for IntegratedBC to provide a mapping from 'jvar' in computeJacobianBlock ...
Definition: JvarMapInterface.h:49
JvarMapInterfaceBase::_jvar_max_size
const std::size_t _jvar_max_size
number of nonlinear variables in the system
Definition: JvarMapInterface.h:94
Moose::enumerate
_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
JvarMapIntegratedBCInterface::JvarMapIntegratedBCInterface
JvarMapIntegratedBCInterface(const InputParameters &parameters)
Definition: JvarMapInterface.h:175
Enumerate.h
JvarMapKernelInterface
Interface class ("Veneer") for Kernel to provide a mapping from 'jvar' in computeQpOffDiagJacobian in...
Definition: JvarMapInterface.h:30
JvarMapInterfaceBase::_jvar_map
JvarMap _jvar_map
look-up table to determine the _coupled_moose_vars index for the jvar parameter
Definition: JvarMapInterface.h:97
MooseVariableBase::number
unsigned int number() const
Get variable number coming from libMesh.
Definition: MooseVariableBase.h:48