https://mooseframework.inl.gov
Loading...
Searching...
No Matches
JvarMapInterface.h
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#pragma once
11
12#include "MooseVariableFE.h"
13#include "NonlinearSystemBase.h"
14#include "Enumerate.h"
15
16template <class T>
18
29template <class T>
31{
32public:
34 virtual void computeOffDiagJacobian(unsigned int jvar) override;
35};
36
47template <class T>
49{
50public:
52 virtual void computeOffDiagJacobian(unsigned int jvar) override;
53};
54
59template <class T>
60class JvarMapInterfaceBase : public T
61{
62public:
63 typedef std::vector<int> JvarMap;
64
66
68
70 unsigned int mapJvarToCvar(unsigned int jvar);
71
77 int mapJvarToCvar(unsigned int jvar, const JvarMap & jvar_map);
78
80 const JvarMap & getJvarMap() { return _jvar_map; }
81
83 const JvarMap & getParameterJvarMap(std::string parameter_name);
84
93 bool mapJvarToCvar(unsigned int jvar, unsigned int & cvar);
94
95protected:
97 const unsigned int _n_args;
98
99private:
101 const std::size_t _jvar_max_size;
102
105
107 std::map<std::string, JvarMap> _jvar_local_map;
108
109 friend class JvarMapKernelInterface<T>;
110 friend class JvarMapIntegratedBCInterface<T>;
111};
112
113template <class T>
116{
117 auto params = T::validParams();
118 params.addCoupledVar("coupled_variables",
119 "Vector of nonlinear variable arguments this object depends on");
120
121 return params;
122}
123
124template <class T>
126 : T(parameters),
127 _n_args(this->_coupled_standard_moose_vars.size()),
128 _jvar_max_size(this->_sys.nVariables()),
130{
131 // populate map
132 for (auto it : Moose::enumerate(this->_coupled_moose_vars))
133 {
134 auto number = it.value()->number();
135
136 // skip AuxVars as off-diagonal jacobian entries are not calculated for them
137 if (number < _jvar_max_size)
138 _jvar_map[number] = it.index();
139 }
140
141 // mark the kernel variable for the check in computeOffDiagJacobian
142 _jvar_map[this->_var.number()] = 0;
143}
144
145template <class T>
146unsigned int
148{
149 mooseAssert(jvar < _jvar_max_size,
150 "Calling mapJvarToCvar for an invalid Moose variable number. Maybe an AuxVariable?");
151 int cit = _jvar_map[jvar];
152
153 mooseAssert(cit >= 0, "Calling mapJvarToCvar for a variable not coupled to this kernel.");
154 return cit;
155}
156
157template <class T>
158int
159JvarMapInterfaceBase<T>::mapJvarToCvar(unsigned int jvar, const JvarMap & jvar_map)
160{
161 mooseAssert(jvar < _jvar_max_size,
162 "Calling mapJvarToCvar for an invalid Moose variable number. Maybe an AuxVariable?");
163 return jvar_map[jvar];
164}
165
166template <class T>
169{
170 auto & jvar_map = _jvar_local_map[parameter_name];
171 jvar_map.assign(_jvar_max_size, -1);
172
173 // populate local map
174 const auto num = this->coupledComponents(parameter_name);
175 for (std::size_t i = 0; i < num; ++i)
176 {
177 const auto number = this->getVar(parameter_name, i)->number();
178
179 // skip AuxVars as off-diagonal jacobian entries are not calculated for them
180 if (number < _jvar_max_size)
181 jvar_map[number] = i;
182 }
183
184 return jvar_map;
185}
186
187template <class T>
192
193template <class T>
198
199template <class T>
200void
202{
203 // the Kernel is not coupled to the variable; no need to loop over QPs
204 if (this->_jvar_map[jvar] < 0)
205 return;
206
207 // call the underlying class' off-diagonal Jacobian
208 T::computeOffDiagJacobian(jvar);
209}
210
211template <class T>
212void
214{
215 // the Kernel is not coupled to the variable; no need to loop over QPs
216 if (this->_jvar_map[jvar] < 0)
217 return;
218
219 // call the underlying class' off-diagonal Jacobian
220 T::computeOffDiagJacobian(jvar);
221}
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Interface class ("Veneer") for IntegratedBC to provide a mapping from 'jvar' in computeJacobianBlock ...
JvarMapIntegratedBCInterface(const InputParameters &parameters)
virtual void computeOffDiagJacobian(unsigned int jvar) override
Base class ("Veneer") that implements the actual mapping from 'jvar' in into the _coupled_moose_vars ...
const unsigned int _n_args
number of coupled moose variables
const JvarMap & getParameterJvarMap(std::string parameter_name)
Make a specific map for a given parameter name representing a couple variable (vector)
static InputParameters validParams()
JvarMap _jvar_map
look-up table to determine the _coupled_moose_vars index for the jvar parameter
int mapJvarToCvar(unsigned int jvar, const JvarMap &jvar_map)
Return an index into a specific coupled variable vector for a given jvar.
bool mapJvarToCvar(unsigned int jvar, unsigned int &cvar)
Set the cvar value to the mapped jvar value and return true if the mapping exists.
std::vector< int > JvarMap
std::map< std::string, JvarMap > _jvar_local_map
map of local look-up tables for specific parameters
const std::size_t _jvar_max_size
number of nonlinear variables in the system
const JvarMap & getJvarMap()
Obtain the map connecting libmesh variable ID number to its position in the _coupled_moose_vars vecto...
JvarMapInterfaceBase(const InputParameters &parameters)
unsigned int mapJvarToCvar(unsigned int jvar)
Return index into the _coupled_moose_vars array for a given jvar.
Interface class ("Veneer") for Kernel to provide a mapping from 'jvar' in computeQpOffDiagJacobian in...
JvarMapKernelInterface(const InputParameters &parameters)
virtual void computeOffDiagJacobian(unsigned int jvar) override
_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