www.mooseframework.org
ShapeUserObject.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef SHAPEUSEROBJECT_H
16 #define SHAPEUSEROBJECT_H
17 
18 #include "Assembly.h"
19 #include "Coupleable.h"
20 #include "InputParameters.h"
21 #include "MooseVariable.h"
22 #include "MooseObject.h"
23 
32 enum class ShapeType
33 {
34  Element,
35  Side
36 };
37 
46 template <typename T>
47 class ShapeUserObject : public T
48 {
49 public:
50  ShapeUserObject(const InputParameters & parameters, ShapeType type);
51 
53  const bool & computeJacobianFlag() const { return _compute_jacobians; }
54 
58  const std::set<MooseVariable *> & jacobianMooseVariables() const
59  {
60  return _jacobian_moose_variables;
61  }
62 
67  virtual void executeJacobianWrapper(unsigned int jvar,
68  const std::vector<dof_id_type> & dof_indices);
69 
71 
72 protected:
78  virtual void executeJacobian(unsigned int /*jvar*/) = 0;
79 
85  virtual unsigned int coupled(const std::string & var_name, unsigned int comp = 0);
86 
89 
92 
94  unsigned int _j;
95 
97  dof_id_type _j_global;
98 
99 private:
100  const bool _compute_jacobians;
101  std::set<MooseVariable *> _jacobian_moose_variables;
102 };
103 
104 template <typename T>
106  : T(parameters),
107  _phi(type == ShapeType::Element ? this->_assembly.phi() : this->_assembly.phiFace()),
108  _grad_phi(type == ShapeType::Element ? this->_assembly.gradPhi()
109  : this->_assembly.gradPhiFace()),
110  _compute_jacobians(MooseObject::getParam<bool>("compute_jacobians"))
111 {
112  mooseWarning("Jacobian calculation in UserObjects is an experimental capability with a "
113  "potentially unstable interface.");
114 }
115 
116 template <typename T>
119 {
121  params.addParam<bool>("compute_jacobians", true, "Compute Jacobians for coupled variables");
122  params.addParamNamesToGroup("compute_jacobians", "Advanced");
123  return params;
124 }
125 
126 template <typename T>
127 unsigned int
128 ShapeUserObject<T>::coupled(const std::string & var_name, unsigned int comp)
129 {
130  MooseVariable * var = Coupleable::getVar(var_name, comp);
131 
132  // add to the set of variables for which executeJacobian will be called
134  _jacobian_moose_variables.insert(var);
135 
136  // return the variable number
137  return T::coupled(var_name, comp);
138 }
139 
140 template <typename T>
141 void
143  const std::vector<dof_id_type> & dof_indices)
144 {
145  for (_j = 0; _j < _phi.size(); ++_j)
146  {
147  _j_global = dof_indices[_j];
148  executeJacobian(jvar);
149  }
150 }
151 
152 #endif // SHAPEUSEROBJECT_H
const bool _compute_jacobians
const bool & computeJacobianFlag() const
check if jacobian is to be computed in user objects
static InputParameters validParams()
dof_id_type _j_global
global DOF ID corresponding to _j
Class for stuff related to variables.
Definition: MooseVariable.h:43
std::set< MooseVariable * > _jacobian_moose_variables
Moose::VarKindType kind() const
Kind of the variable (Nonlinear, Auxiliary, ...)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MooseVariable * getVar(const std::string &var_name, unsigned int comp)
Extract pointer to a coupled variable.
Definition: Coupleable.C:117
InputParameters emptyInputParameters()
unsigned int _j
j-th index for enumerating the shape functions
InputParameters validParams()
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:36
ShapeType
Users of this template class must specify the type of shape functions that will be used in the Jacobi...
const std::set< MooseVariable * > & jacobianMooseVariables() const
Returns the set of variables a Jacobian has been requested for.
virtual unsigned int coupled(const std::string &var_name, unsigned int comp=0)
Returns the index for a coupled variable by name and requests the computation of a Jacobian w...
UserObject template class in which the _phi and _grad_phi shape function data is available and correc...
virtual void executeJacobian(unsigned int)=0
Implement this function to compute Jacobian terms for this UserObject.
virtual void executeJacobianWrapper(unsigned int jvar, const std::vector< dof_id_type > &dof_indices)
This function will be called with the shape functions for jvar initialized.
MatType type
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:250
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
const VariablePhiGradient & _grad_phi
shape function gradients
const VariablePhiValue & _phi
shape function values
ShapeUserObject(const InputParameters &parameters, ShapeType type)
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
void mooseWarning(Args &&...args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:194