20 #include "libmesh/numeric_vector.h" 21 #include "libmesh/dof_map.h" 22 #include "libmesh/quadrature.h" 23 #include "libmesh/boundary_info.h" 25 template <
typename ComputeValueType>
46 "The name of the variable that this object applies to");
48 params.
addParam<
bool>(
"use_displaced_mesh",
50 "Whether or not this object should use the " 51 "displaced mesh for computation. Note that " 52 "in the case this is true but no " 53 "displacements are provided in the Mesh block " 54 "the undisplaced mesh will still be used.");
56 params.
addParam<
bool>(
"check_boundary_restricted",
58 "Whether to check for multiple element sides on the boundary " 59 "in the case of a boundary restricted, element aux variable. " 60 "Setting this to false will allow contribution to a single element's " 61 "elemental value(s) from multiple boundary sides on the same element " 62 "(example: when the restricted boundary exists on two or more sides " 63 "of an element, such as at a corner of a mesh");
83 template <
typename ComputeValueType>
88 parameters.getCheckedPointerParam<
SystemBase *>(
"_sys")
90 parameters.
get<AuxVariableName>(
"variable"))
110 *parameters.getCheckedPointerParam<
FEProblemBase *>(
"_fe_problem_base"),
112 mooseVariableBase()->isNodal()),
119 _check_boundary_restricted(getParam<bool>(
"check_boundary_restricted")),
120 _subproblem(*getCheckedPointerParam<
SubProblem *>(
"_subproblem")),
121 _sys(*getCheckedPointerParam<
SystemBase *>(
"_sys")),
122 _nl_sys(*getCheckedPointerParam<
SystemBase *>(
"_nl_sys")),
125 _var(_aux_sys.getActualFieldVariable<ComputeValueType>(
126 _tid, parameters.
get<AuxVariableName>(
"variable"))),
127 _nodal(_var.isNodal()),
128 _u(_nodal ? _var.nodalValueArray() : _var.sln()),
130 _assembly(_subproblem.assembly(_tid, 0)),
132 _mesh(_subproblem.
mesh()),
134 _test(_bnd ? _var.phiFace() : _var.phi()),
135 _q_point(_bnd ? _assembly.qPointsFace() : _assembly.qPoints()),
136 _qrule(_bnd ? _assembly.qRuleFace() : _assembly.qRule()),
137 _JxW(_bnd ? _assembly.JxWFace() : _assembly.JxW()),
138 _coord(_assembly.coordTransformation()),
140 _current_elem(_assembly.elem()),
141 _current_side(_assembly.side()),
142 _current_elem_volume(_assembly.elemVolume()),
143 _current_side_volume(_assembly.sideElemVolume()),
145 _current_node(_assembly.node()),
146 _current_boundary_id(_assembly.currentBoundaryID()),
147 _solution(_aux_sys.solution()),
149 _current_lower_d_elem(_assembly.lowerDElem()),
150 _coincident_lower_d_calc(_bnd && !isNodal() && _var.isLowerD())
160 auto boundaries =
_mesh.
getMesh().get_boundary_info().build_side_list();
161 std::set<dof_id_type> elements;
162 for (
const auto & t : boundaries)
166 const auto eid = std::get<0>(t);
167 const auto stat = elements.insert(eid);
170 "Boundary restricted auxiliary kernel '",
172 "' has element (id=",
174 ") connected with more than one boundary sides.\nTo skip this error check, " 175 "set 'check_boundary_restricted = false'.\nRefer to the AuxKernel " 176 "documentation on boundary restricted aux kernels for understanding this error.");
193 template <
typename ComputeValueType>
194 const std::set<std::string> &
200 template <
typename ComputeValueType>
201 const std::set<std::string> &
204 return _supplied_vars;
207 template <
typename ComputeValueType>
211 _depend_uo.insert(uo.
name());
213 _depend_uo.insert(indirect_dependent);
216 template <
typename ComputeValueType>
219 const PostprocessorName & name)
const 221 getUserObjectBaseByName(
name);
224 template <
typename ComputeValueType>
227 const VectorPostprocessorName & name)
const 229 getUserObjectBaseByName(
name);
232 template <
typename ComputeValueType>
238 const auto & var_names = getParam<std::vector<VariableName>>(var_name);
239 _depend_vars.insert(var_names.begin(), var_names.end());
243 template <
typename ComputeValueType>
247 auto var = getVar(var_name, comp);
251 ": Unable to couple time derivative of an auxiliary variable into the auxiliary system.");
256 template <
typename ComputeValueType>
259 unsigned int comp)
const 261 auto var = getVar(var_name, comp);
265 ": Unable to couple time derivative of an auxiliary variable into the auxiliary system.");
275 "Should only be calling setDofValue if there is one dof for the aux var");
286 template <
typename ComputeValueType>
290 if (_coincident_lower_d_calc)
291 _var.insertLower(_aux_sys.solution());
293 _var.insert(_aux_sys.solution());
296 template <
typename ComputeValueType>
304 mooseAssert(!_coincident_lower_d_calc,
305 "Nodal evaluations are point evaluations. We don't have to concern ourselves with " 306 "coincidence of lower-d blocks and higher-d faces because they share nodes");
307 if (_var.isNodalDefined())
310 ComputeValueType
value = computeValue();
312 _var.setNodalValue(
value);
317 _n_local_dofs = _coincident_lower_d_calc ? _var.dofIndicesLower().size() : _var.numberOfDofs();
319 if (_coincident_lower_d_calc)
321 static const std::string lower_error =
"Make sure that the lower-d variable lives on a " 322 "lower-d block that is a superset of the boundary";
323 if (!_current_lower_d_elem)
324 mooseError(
"No lower-dimensional element. ", lower_error);
326 mooseError(
"No degrees of freedom. ", lower_error);
329 if (_n_local_dofs == 1)
331 ComputeValueType
value = 0;
332 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
333 value += _JxW[_qp] * _coord[_qp] * computeValue();
334 value /= (_bnd ? _current_side_volume : _current_elem_volume);
336 setDofValueHelper(
value);
342 if (_coincident_lower_d_calc)
344 _local_sol.resize(1);
345 if constexpr (std::is_same<Real, ComputeValueType>::value)
346 _local_sol(0) =
value;
348 mooseAssert(
false,
"We should not enter the single dof branch with a vector variable");
349 _var.setLowerDofValues(_local_sol);
352 _var.setNodalValue(
value);
357 _local_re.resize(_n_local_dofs);
359 _local_ke.resize(_n_local_dofs, _n_local_dofs);
362 const auto & test = _coincident_lower_d_calc ? _var.phiLower() : _test;
365 for (
unsigned int i = 0; i < test.size(); i++)
366 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
368 ComputeValueType t = _JxW[_qp] * _coord[_qp] * test[i][_qp];
369 _local_re(i) += t * computeValue();
370 for (
unsigned int j = 0; j < test.size(); j++)
371 _local_ke(i, j) += t * test[j][_qp];
374 _local_sol.resize(_n_local_dofs);
376 _local_ke.svd_solve(_local_re, _local_sol);
378 _local_ke.cholesky_solve(_local_re, _local_sol);
380 _coincident_lower_d_calc ? _var.setLowerDofValues(_local_sol) : _var.setDofValues(_local_sol);
393 if (_var.isNodalDefined())
398 _var.setNodalValue(
value);
403 _n_local_dofs = _var.numberOfDofs();
404 if (_n_local_dofs == 1)
407 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
408 value += _JxW[_qp] * _coord[_qp] * computeValue();
409 value /= (_bnd ? _current_side_volume : _current_elem_volume);
413 _var.setNodalValue(
value);
417 _local_re.resize(_n_local_dofs);
418 for (
unsigned int i = 0; i < _local_re.size(); ++i)
419 _local_re(i) = RealEigenVector::Zero(_var.count());
420 _local_ke.resize(_n_local_dofs, _n_local_dofs);
424 for (
unsigned int i = 0; i < _test.size(); i++)
425 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
427 Real t = _JxW[_qp] * _coord[_qp] * _test[i][_qp];
428 _local_re(i) += t * computeValue();
429 for (
unsigned int j = 0; j < _test.size(); j++)
430 _local_ke(i, j) += t * _test[j][_qp];
434 _local_sol.resize(_n_local_dofs);
435 for (
unsigned int i = 0; i < _local_re.size(); ++i)
436 _local_sol(i) = RealEigenVector::Zero(_var.count());
439 for (
unsigned int i = 0; i < _var.count(); ++i)
441 for (
unsigned int j = 0; j < _n_local_dofs; ++j)
442 re(j) = _local_re(j)(i);
445 _local_ke.svd_solve(re, sol);
447 _local_ke.cholesky_solve(re, sol);
449 for (
unsigned int j = 0; j < _n_local_dofs; ++j)
450 _local_sol(j)(i) = sol(j);
453 _var.setDofValues(_local_sol);
458 template <
typename ComputeValueType>
462 if (_sys.solutionStatesInitialized())
463 mooseError(
"The solution states have already been initialized when calling ",
466 "Make sure to call uOld() within the object constructor.");
468 return _nodal ? _var.nodalValueOldArray() : _var.slnOld();
471 template <
typename ComputeValueType>
475 if (_sys.solutionStatesInitialized())
476 mooseError(
"The solution states have already been initialized when calling ",
479 "Make sure to call uOlder() within the object constructor.");
481 return _nodal ? _var.nodalValueOlderArray() : _var.slnOlder();
484 template <
typename ComputeValueType>
An interface for accessing Moose::Functors for systems that do not care about automatic differentiati...
std::string name(const ElemQuality q)
Interface for objects that need parallel consistent random numbers without patterns over the course o...
virtual bool isNodal() const
Is this variable nodal.
const libMesh::FEType & feType() const
Get the type of finite element object.
A MultiMooseEnum object to hold "execute_on" flags.
A class for creating restricted objects.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
MooseMesh & _mesh
Mesh this kernel is active on.
const OutputTools< ComputeValueType >::VariableValue & uOlder() const
Retrieves the older value of the variable that this AuxKernel operates on.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
void addPostprocessorDependencyHelper(const PostprocessorName &name) const override final
Helper for deriving classes to override to add dependencies when a Postprocessor is requested...
const InputParameters & parameters() const
Get the parameters of the object.
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
virtual const VariableValue & coupledDot(const std::string &var_name, unsigned int comp=0) const
Time derivative of a coupled variable.
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
static InputParameters validParams()
void addAvailableFlags(const ExecFlagType &flag, Args... flags)
Add additional execute_on flags to the list of possible flags.
static InputParameters validParams()
const ExecFlagType EXEC_TIMESTEP_END
virtual void setDofValue(const OutputData &value, unsigned int index)=0
Degree of freedom value setters.
Base class for a system (of equations)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
static InputParameters validParams()
bool _bnd
true if the kernel is boundary kernel, false if it is interior kernels
virtual void compute()
Computes the value and stores it in the solution vector.
Interface for objects that needs transient capabilities.
const std::string & name() const
Get the name of the class.
static InputParameters validParams()
Interface for notifications that the mesh has changed.
virtual const std::set< std::string > & getRequestedItems() override
Return a set containing the names of items requested by the object.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Every object that can be built by the factory should be derived from this class.
static InputParameters validParams()
VarKindType
Framework-wide stuff.
AuxKernelTempl(const InputParameters ¶meters)
const std::string & type() const
Get the type of this class.
std::string getDocString() const
Generate a documentation string for the "execute_on" parameter.
virtual const OutputTools< ComputeValueType >::VariableValue & value()
The value of the variable this object is operating on.
Interface for objects that need to use UserObjects.
Base class for creating new nodally-based mortar auxiliary kernels.
std::set< UserObjectName > getDependObjects() const
Recursively return a set of user objects this user object depends on Note: this can be called only af...
const ExecFlagType EXEC_LINEAR
std::string stringify(const T &t)
conversion to string
static InputParameters validParams()
virtual const VariableValue & coupledDot(const std::string &var_name, unsigned int comp=0) const override
Time derivative of a coupled variable.
static InputParameters validParams()
virtual const std::set< std::string > & getSuppliedItems() override
Return a set containing the names of items owned by the object.
bool hasBoundary(const BoundaryName &name) const
Test if the supplied boundary name is valid for this object.
OutputTools< Real >::VariableValue VariableValue
const ExecFlagType EXEC_PRE_DISPLACE
virtual const VariableValue & coupledDotDu(const std::string &var_name, unsigned int comp=0) const
Time derivative of a coupled variable with respect to the coefficients.
const OutputTools< ComputeValueType >::VariableValue & uOld() const
Retrieves the old value of the variable that this AuxKernel operates on.
void insert()
Insert the just computed values into the auxiliary solution vector.
void addMooseVariableDependency(MooseVariableFieldBase *var)
Call this function to add the passed in MooseVariableFieldBase as a variable that this object depends...
MooseVariableField< ComputeValueType > & _var
This is a regular kernel so we cast to a regular MooseVariable.
void addVectorPostprocessorDependencyHelper(const VectorPostprocessorName &name) const override final
Helper for deriving classes to override to add dependencies when a VectorPostprocessor is requested...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Generic class for solving transient nonlinear problems.
An interface for accessing Materials.
Interface for objects that need to get values of MooseVariables.
An interface that restricts an object to subdomains via the 'blocks' input parameter.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Interface for sorting dependent vectors of objects.
void addUserObjectDependencyHelper(const UserObject &uo) const override final
Helper for deriving classes to override to add dependencies when a UserObject is requested.
static InputParameters validParams()
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealEigenVector
Base class for creating new auxiliary kernels and auxiliary boundary conditions.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
const bool & _check_boundary_restricted
Whether or not to check for repeated element sides on the sideset to which the auxkernel is restricte...
virtual const VariableValue & coupledDotDu(const std::string &var_name, unsigned int comp=0) const override
Time derivative of a coupled variable with respect to the coefficients.
void setDofValueHelper(const ComputeValueType &dof_value)
Currently only used when the auxiliary variable is a finite volume variable, this helps call through ...
static InputParameters validParams()
static InputParameters validParams()
void coupledCallback(const std::string &var_name, bool is_old) const override
A call-back function provided by the derived object for actions before coupling a variable with funct...
bool boundaryRestricted(const std::set< BoundaryID > &boundary_ids)
std::set< std::string > _supplied_vars
Interface for objects that need to use functions.
A system that holds auxiliary variables.
Base class for user-specific data.
bool isNodal() const
Nodal or elemental kernel?
unsigned int _n_local_dofs
number of local dofs for elemental variables
Interface class for classes which interact with Postprocessors.
const bool _coincident_lower_d_calc
Whether we are computing for a lower dimensional variable using boundary restriction, e.g.