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 const auto & var = *it.value();
135
136 // skip variables from other systems (AuxVariables or variables of another nonlinear system)
137 // as off-diagonal jacobian entries are not calculated for them. Their numbers are local to
138 // their own system, so they cannot be distinguished by comparing against nVariables()
139 if (&var.sys() == &this->_sys)
140 _jvar_map[var.number()] = it.index();
141 }
142
143 // mark the kernel variable for the check in computeOffDiagJacobian
144 _jvar_map[this->_var.number()] = 0;
145}
146
147template <class T>
148unsigned int
150{
151 mooseAssert(jvar < _jvar_max_size,
152 "Calling mapJvarToCvar for an invalid Moose variable number. Maybe an AuxVariable?");
153 int cit = _jvar_map[jvar];
154
155 mooseAssert(cit >= 0, "Calling mapJvarToCvar for a variable not coupled to this kernel.");
156 return cit;
157}
158
159template <class T>
160int
161JvarMapInterfaceBase<T>::mapJvarToCvar(unsigned int jvar, const JvarMap & jvar_map)
162{
163 mooseAssert(jvar < _jvar_max_size,
164 "Calling mapJvarToCvar for an invalid Moose variable number. Maybe an AuxVariable?");
165 return jvar_map[jvar];
166}
167
168template <class T>
171{
172 auto & jvar_map = _jvar_local_map[parameter_name];
173 jvar_map.assign(_jvar_max_size, -1);
174
175 // populate local map
176 const auto num = this->coupledComponents(parameter_name);
177 for (std::size_t i = 0; i < num; ++i)
178 {
179 const auto & var = *this->getVar(parameter_name, i);
180
181 // skip variables from other systems, see the constructor
182 if (&var.sys() == &this->_sys)
183 jvar_map[var.number()] = i;
184 }
185
186 return jvar_map;
187}
188
189template <class T>
194
195template <class T>
200
201template <class T>
202void
204{
205 // the Kernel is not coupled to the variable; no need to loop over QPs
206 if (this->_jvar_map[jvar] < 0)
207 return;
208
209 // call the underlying class' off-diagonal Jacobian
210 T::computeOffDiagJacobian(jvar);
211}
212
213template <class T>
214void
216{
217 // the Kernel is not coupled to the variable; no need to loop over QPs
218 if (this->_jvar_map[jvar] < 0)
219 return;
220
221 // call the underlying class' off-diagonal Jacobian
222 T::computeOffDiagJacobian(jvar);
223}
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