https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ShapeUserObject.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 "Assembly.h"
13#include "Coupleable.h"
14#include "InputParameters.h"
15#include "MooseVariableFE.h"
16#include "MooseObject.h"
17
26enum class ShapeType
27{
28 Element,
29 Side
30};
31
40template <typename T>
41class ShapeUserObject : public T
42{
43public:
45
46 ShapeUserObject(const InputParameters & parameters, ShapeType type);
47
49 const bool & computeJacobianFlag() const { return _compute_jacobians; }
50
54 const std::set<const MooseVariableFEBase *> & jacobianMooseVariables() const
55 {
57 }
58
63 virtual void executeJacobianWrapper(unsigned int jvar,
64 const std::vector<dof_id_type> & dof_indices);
65
66protected:
72 virtual void executeJacobian(unsigned int /*jvar*/) = 0;
73
79 virtual unsigned int coupled(const std::string & var_name, unsigned int comp = 0) const override;
80
83
86
88 unsigned int _j;
89
91 dof_id_type _j_global;
92
93private:
95 mutable std::set<const MooseVariableFEBase *> _jacobian_moose_variables;
96};
97
98template <typename T>
100 : T(parameters),
101 _phi(type == ShapeType::Element ? this->_assembly.phi() : this->_assembly.phiFace()),
102 _grad_phi(type == ShapeType::Element ? this->_assembly.gradPhi()
103 : this->_assembly.gradPhiFace()),
104 _compute_jacobians(MooseObject::getParam<bool>("compute_jacobians"))
105{
106 mooseWarning("Jacobian calculation in UserObjects is an experimental capability with a "
107 "potentially unstable interface.");
108}
109
110template <typename T>
113{
115 params.addParam<bool>("compute_jacobians", true, "Compute Jacobians for coupled variables");
116 params.addParamNamesToGroup("compute_jacobians", "Advanced");
117 return params;
118}
119
120template <typename T>
121unsigned int
122ShapeUserObject<T>::coupled(const std::string & var_name, unsigned int comp) const
123{
124 const auto * var = this->template getVarHelper<MooseVariable>(var_name, comp);
125
126 // add to the set of variables for which executeJacobian will be called
127 if (_compute_jacobians && var->kind() == Moose::VAR_SOLVER)
128 _jacobian_moose_variables.insert(var);
129
130 // return the variable number
131 return T::coupled(var_name, comp);
132}
133
134template <typename T>
135void
137 const std::vector<dof_id_type> & dof_indices)
138{
139 for (_j = 0; _j < _phi.size(); ++_j)
140 {
141 _j_global = dof_indices[_j];
142 executeJacobian(jvar);
143 }
144}
InputParameters emptyInputParameters()
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition MooseError.h:345
OutputTools< Real >::VariablePhiValue VariablePhiValue
Definition MooseTypes.h:353
OutputTools< Real >::VariablePhiGradient VariablePhiGradient
Definition MooseTypes.h:354
ShapeType
Users of this template class must specify the type of shape functions that will be used in the Jacobi...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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 addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
UserObject template class in which the _phi and _grad_phi shape function data is available and correc...
const bool & computeJacobianFlag() const
check if jacobian is to be computed in user objects
ShapeUserObject(const InputParameters &parameters, ShapeType type)
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.
virtual unsigned int coupled(const std::string &var_name, unsigned int comp=0) const override
Returns the index for a coupled variable by name and requests the computation of a Jacobian w....
static InputParameters validParams()
std::set< const MooseVariableFEBase * > _jacobian_moose_variables
const VariablePhiGradient & _grad_phi
shape function gradients
dof_id_type _j_global
global DOF ID corresponding to _j
const std::set< const MooseVariableFEBase * > & jacobianMooseVariables() const
Returns the set of variables a Jacobian has been requested for.
const VariablePhiValue & _phi
shape function values
unsigned int _j
j-th index for enumerating the shape functions
virtual void executeJacobian(unsigned int)=0
Implement this function to compute Jacobian terms for this UserObject.
const bool _compute_jacobians
@ VAR_SOLVER
Definition MooseTypes.h:770