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>
45 "The name of the variable that this object applies to");
47 params.
addParam<
bool>(
"use_displaced_mesh",
49 "Whether or not this object should use the " 50 "displaced mesh for computation. Note that " 51 "in the case this is true but no " 52 "displacements are provided in the Mesh block " 53 "the undisplaced mesh will still be used.");
55 params.
addParam<
bool>(
"check_boundary_restricted",
57 "Whether to check for multiple element sides on the boundary " 58 "in the case of a boundary restricted, element aux variable. " 59 "Setting this to false will allow contribution to a single element's " 60 "elemental value(s) from multiple boundary sides on the same element " 61 "(example: when the restricted boundary exists on two or more sides " 62 "of an element, such as at a corner of a mesh");
82 template <
typename ComputeValueType>
87 parameters.getCheckedPointerParam<
SystemBase *>(
"_sys")
89 parameters.
get<AuxVariableName>(
"variable"))
109 *parameters.getCheckedPointerParam<
FEProblemBase *>(
"_fe_problem_base"),
111 mooseVariableBase()->isNodal()),
118 _check_boundary_restricted(getParam<bool>(
"check_boundary_restricted")),
119 _subproblem(*getCheckedPointerParam<
SubProblem *>(
"_subproblem")),
120 _sys(*getCheckedPointerParam<
SystemBase *>(
"_sys")),
121 _nl_sys(*getCheckedPointerParam<
SystemBase *>(
"_nl_sys")),
124 _var(_aux_sys.getActualFieldVariable<ComputeValueType>(
125 _tid, parameters.
get<AuxVariableName>(
"variable"))),
126 _nodal(_var.isNodal()),
127 _u(_nodal ? _var.nodalValueArray() : _var.sln()),
129 _assembly(_subproblem.assembly(_tid, 0)),
131 _mesh(_subproblem.
mesh()),
133 _test(_bnd ? _var.phiFace() : _var.phi()),
134 _q_point(_bnd ? _assembly.qPointsFace() : _assembly.qPoints()),
135 _qrule(_bnd ? _assembly.qRuleFace() : _assembly.qRule()),
136 _JxW(_bnd ? _assembly.JxWFace() : _assembly.JxW()),
137 _coord(_assembly.coordTransformation()),
139 _current_elem(_assembly.elem()),
140 _current_side(_assembly.side()),
141 _current_elem_volume(_assembly.elemVolume()),
142 _current_side_volume(_assembly.sideElemVolume()),
144 _current_node(_assembly.node()),
145 _current_boundary_id(_assembly.currentBoundaryID()),
146 _solution(_aux_sys.solution()),
148 _current_lower_d_elem(_assembly.lowerDElem()),
149 _coincident_lower_d_calc(_bnd && !isNodal() && _var.isLowerD())
159 auto boundaries =
_mesh.
getMesh().get_boundary_info().build_side_list();
160 std::set<dof_id_type> elements;
161 for (
const auto & t : boundaries)
165 const auto eid = std::get<0>(t);
166 const auto stat = elements.insert(eid);
169 "Boundary restricted auxiliary kernel '",
171 "' has element (id=",
173 ") connected with more than one boundary sides.\nTo skip this error check, " 174 "set 'check_boundary_restricted = false'.\nRefer to the AuxKernel " 175 "documentation on boundary restricted aux kernels for understanding this error.");
192 template <
typename ComputeValueType>
193 const std::set<std::string> &
199 template <
typename ComputeValueType>
200 const std::set<std::string> &
203 return _supplied_vars;
206 template <
typename ComputeValueType>
210 _depend_uo.insert(uo.
name());
212 _depend_uo.insert(indirect_dependent);
215 template <
typename ComputeValueType>
218 const PostprocessorName & name)
const 220 getUserObjectBaseByName(
name);
223 template <
typename ComputeValueType>
226 const VectorPostprocessorName & name)
const 228 getUserObjectBaseByName(
name);
231 template <
typename ComputeValueType>
237 const auto & var_names = getParam<std::vector<VariableName>>(var_name);
238 _depend_vars.insert(var_names.begin(), var_names.end());
242 template <
typename ComputeValueType>
246 auto var = getVar(var_name, comp);
250 ": Unable to couple time derivative of an auxiliary variable into the auxiliary system.");
255 template <
typename ComputeValueType>
258 unsigned int comp)
const 260 auto var = getVar(var_name, comp);
264 ": Unable to couple time derivative of an auxiliary variable into the auxiliary system.");
274 "Should only be calling setDofValue if there is one dof for the aux var");
285 template <
typename ComputeValueType>
289 if (_coincident_lower_d_calc)
290 _var.insertLower(_aux_sys.solution());
292 _var.insert(_aux_sys.solution());
295 template <
typename ComputeValueType>
303 mooseAssert(!_coincident_lower_d_calc,
304 "Nodal evaluations are point evaluations. We don't have to concern ourselves with " 305 "coincidence of lower-d blocks and higher-d faces because they share nodes");
306 if (_var.isNodalDefined())
309 ComputeValueType
value = computeValue();
311 _var.setNodalValue(
value);
316 _n_local_dofs = _coincident_lower_d_calc ? _var.dofIndicesLower().size() : _var.numberOfDofs();
318 if (_coincident_lower_d_calc)
320 static const std::string lower_error =
"Make sure that the lower-d variable lives on a " 321 "lower-d block that is a superset of the boundary";
322 if (!_current_lower_d_elem)
323 mooseError(
"No lower-dimensional element. ", lower_error);
325 mooseError(
"No degrees of freedom. ", lower_error);
328 if (_n_local_dofs == 1)
330 ComputeValueType
value = 0;
331 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
332 value += _JxW[_qp] * _coord[_qp] * computeValue();
333 value /= (_bnd ? _current_side_volume : _current_elem_volume);
335 setDofValueHelper(
value);
341 if (_coincident_lower_d_calc)
343 _local_sol.resize(1);
344 if constexpr (std::is_same<Real, ComputeValueType>::value)
345 _local_sol(0) =
value;
347 mooseAssert(
false,
"We should not enter the single dof branch with a vector variable");
348 _var.setLowerDofValues(_local_sol);
351 _var.setNodalValue(
value);
356 _local_re.resize(_n_local_dofs);
358 _local_ke.resize(_n_local_dofs, _n_local_dofs);
361 const auto & test = _coincident_lower_d_calc ? _var.phiLower() : _test;
364 for (
unsigned int i = 0; i < test.size(); i++)
365 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
367 ComputeValueType t = _JxW[_qp] * _coord[_qp] * test[i][_qp];
368 _local_re(i) += t * computeValue();
369 for (
unsigned int j = 0; j < test.size(); j++)
370 _local_ke(i, j) += t * test[j][_qp];
373 _local_sol.resize(_n_local_dofs);
375 _local_ke.svd_solve(_local_re, _local_sol);
377 _local_ke.cholesky_solve(_local_re, _local_sol);
379 _coincident_lower_d_calc ? _var.setLowerDofValues(_local_sol) : _var.setDofValues(_local_sol);
392 if (_var.isNodalDefined())
397 _var.setNodalValue(
value);
402 _n_local_dofs = _var.numberOfDofs();
403 if (_n_local_dofs == 1)
406 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
407 value += _JxW[_qp] * _coord[_qp] * computeValue();
408 value /= (_bnd ? _current_side_volume : _current_elem_volume);
412 _var.setNodalValue(
value);
416 _local_re.resize(_n_local_dofs);
417 for (
unsigned int i = 0; i < _local_re.size(); ++i)
418 _local_re(i) = RealEigenVector::Zero(_var.count());
419 _local_ke.resize(_n_local_dofs, _n_local_dofs);
423 for (
unsigned int i = 0; i < _test.size(); i++)
424 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
426 Real t = _JxW[_qp] * _coord[_qp] * _test[i][_qp];
427 _local_re(i) += t * computeValue();
428 for (
unsigned int j = 0; j < _test.size(); j++)
429 _local_ke(i, j) += t * _test[j][_qp];
433 _local_sol.resize(_n_local_dofs);
434 for (
unsigned int i = 0; i < _local_re.size(); ++i)
435 _local_sol(i) = RealEigenVector::Zero(_var.count());
438 for (
unsigned int i = 0; i < _var.count(); ++i)
440 for (
unsigned int j = 0; j < _n_local_dofs; ++j)
441 re(j) = _local_re(j)(i);
444 _local_ke.svd_solve(re, sol);
446 _local_ke.cholesky_solve(re, sol);
448 for (
unsigned int j = 0; j < _n_local_dofs; ++j)
449 _local_sol(j)(i) = sol(j);
452 _var.setDofValues(_local_sol);
457 template <
typename ComputeValueType>
461 if (_sys.solutionStatesInitialized())
462 mooseError(
"The solution states have already been initialized when calling ",
465 "Make sure to call uOld() within the object constructor.");
467 return _nodal ? _var.nodalValueOldArray() : _var.slnOld();
470 template <
typename ComputeValueType>
474 if (_sys.solutionStatesInitialized())
475 mooseError(
"The solution states have already been initialized when calling ",
478 "Make sure to call uOlder() within the object constructor.");
480 return _nodal ? _var.nodalValueOlderArray() : _var.slnOlder();
483 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.
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...
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.
virtual const std::string & name() const
Get the name of the class.
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.
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.
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 ...
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.
Interface for sorting dependent vectors of objects.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
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()
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.