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");
81 template <
typename ComputeValueType>
86 parameters.getCheckedPointerParam<
SystemBase *>(
"_sys")
88 parameters.
get<AuxVariableName>(
"variable"))
108 *parameters.getCheckedPointerParam<
FEProblemBase *>(
"_fe_problem_base"),
110 mooseVariableBase()->isNodal()),
117 _check_boundary_restricted(getParam<bool>(
"check_boundary_restricted")),
118 _subproblem(*getCheckedPointerParam<
SubProblem *>(
"_subproblem")),
119 _sys(*getCheckedPointerParam<
SystemBase *>(
"_sys")),
120 _nl_sys(*getCheckedPointerParam<
SystemBase *>(
"_nl_sys")),
123 _var(_aux_sys.getActualFieldVariable<ComputeValueType>(
124 _tid, parameters.
get<AuxVariableName>(
"variable"))),
125 _nodal(_var.isNodal()),
126 _u(_nodal ? _var.nodalValueArray() : _var.sln()),
128 _assembly(_subproblem.assembly(_tid, 0)),
130 _mesh(_subproblem.
mesh()),
132 _test(_bnd ? _var.phiFace() : _var.phi()),
133 _q_point(_bnd ? _assembly.qPointsFace() : _assembly.qPoints()),
134 _qrule(_bnd ? _assembly.qRuleFace() : _assembly.qRule()),
135 _JxW(_bnd ? _assembly.JxWFace() : _assembly.JxW()),
136 _coord(_assembly.coordTransformation()),
138 _current_elem(_assembly.elem()),
139 _current_side(_assembly.side()),
140 _current_elem_volume(_assembly.elemVolume()),
141 _current_side_volume(_assembly.sideElemVolume()),
143 _current_node(_assembly.node()),
144 _current_boundary_id(_assembly.currentBoundaryID()),
145 _solution(_aux_sys.solution()),
147 _current_lower_d_elem(_assembly.lowerDElem()),
148 _coincident_lower_d_calc(_bnd && !isNodal() && _var.isLowerD())
158 auto boundaries =
_mesh.
getMesh().get_boundary_info().build_side_list();
159 std::set<dof_id_type> elements;
160 for (
const auto & t : boundaries)
164 const auto eid = std::get<0>(t);
165 const auto stat = elements.insert(eid);
168 "Boundary restricted auxiliary kernel '",
170 "' has element (id=",
172 ") connected with more than one boundary sides.\nTo skip this error check, " 173 "set 'check_boundary_restricted = false'.\nRefer to the AuxKernel " 174 "documentation on boundary restricted aux kernels for understanding this error.");
191 template <
typename ComputeValueType>
192 const std::set<std::string> &
198 template <
typename ComputeValueType>
199 const std::set<std::string> &
202 return _supplied_vars;
205 template <
typename ComputeValueType>
209 _depend_uo.insert(uo.
name());
211 _depend_uo.insert(indirect_dependent);
214 template <
typename ComputeValueType>
217 const PostprocessorName & name)
const 219 getUserObjectBaseByName(
name);
222 template <
typename ComputeValueType>
225 const VectorPostprocessorName & name)
const 227 getUserObjectBaseByName(
name);
230 template <
typename ComputeValueType>
236 const auto & var_names = getParam<std::vector<VariableName>>(var_name);
237 _depend_vars.insert(var_names.begin(), var_names.end());
241 template <
typename ComputeValueType>
245 auto var = getVar(var_name, comp);
249 ": Unable to couple time derivative of an auxiliary variable into the auxiliary system.");
254 template <
typename ComputeValueType>
257 unsigned int comp)
const 259 auto var = getVar(var_name, comp);
263 ": Unable to couple time derivative of an auxiliary variable into the auxiliary system.");
273 "Should only be calling setDofValue if there is one dof for the aux var");
284 template <
typename ComputeValueType>
288 if (_coincident_lower_d_calc)
289 _var.insertLower(_aux_sys.solution());
291 _var.insert(_aux_sys.solution());
294 template <
typename ComputeValueType>
302 mooseAssert(!_coincident_lower_d_calc,
303 "Nodal evaluations are point evaluations. We don't have to concern ourselves with " 304 "coincidence of lower-d blocks and higher-d faces because they share nodes");
305 if (_var.isNodalDefined())
308 ComputeValueType
value = computeValue();
310 _var.setNodalValue(
value);
315 _n_local_dofs = _coincident_lower_d_calc ? _var.dofIndicesLower().size() : _var.numberOfDofs();
317 if (_coincident_lower_d_calc)
319 static const std::string lower_error =
"Make sure that the lower-d variable lives on a " 320 "lower-d block that is a superset of the boundary";
321 if (!_current_lower_d_elem)
322 mooseError(
"No lower-dimensional element. ", lower_error);
324 mooseError(
"No degrees of freedom. ", lower_error);
327 if (_n_local_dofs == 1)
329 ComputeValueType
value = 0;
330 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
331 value += _JxW[_qp] * _coord[_qp] * computeValue();
332 value /= (_bnd ? _current_side_volume : _current_elem_volume);
334 setDofValueHelper(
value);
340 if (_coincident_lower_d_calc)
342 _local_sol.resize(1);
343 if constexpr (std::is_same<Real, ComputeValueType>::value)
344 _local_sol(0) =
value;
346 mooseAssert(
false,
"We should not enter the single dof branch with a vector variable");
347 _var.setLowerDofValues(_local_sol);
350 _var.setNodalValue(
value);
355 _local_re.resize(_n_local_dofs);
357 _local_ke.resize(_n_local_dofs, _n_local_dofs);
360 const auto & test = _coincident_lower_d_calc ? _var.phiLower() : _test;
363 for (
unsigned int i = 0; i < test.size(); i++)
364 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
366 ComputeValueType t = _JxW[_qp] * _coord[_qp] * test[i][_qp];
367 _local_re(i) += t * computeValue();
368 for (
unsigned int j = 0; j < test.size(); j++)
369 _local_ke(i, j) += t * test[j][_qp];
372 _local_sol.resize(_n_local_dofs);
374 _local_ke.svd_solve(_local_re, _local_sol);
376 _local_ke.cholesky_solve(_local_re, _local_sol);
378 _coincident_lower_d_calc ? _var.setLowerDofValues(_local_sol) : _var.setDofValues(_local_sol);
391 if (_var.isNodalDefined())
396 _var.setNodalValue(
value);
401 _n_local_dofs = _var.numberOfDofs();
402 if (_n_local_dofs == 1)
405 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
406 value += _JxW[_qp] * _coord[_qp] * computeValue();
407 value /= (_bnd ? _current_side_volume : _current_elem_volume);
411 _var.setNodalValue(
value);
415 _local_re.resize(_n_local_dofs);
416 for (
unsigned int i = 0; i < _local_re.size(); ++i)
417 _local_re(i) = RealEigenVector::Zero(_var.count());
418 _local_ke.resize(_n_local_dofs, _n_local_dofs);
422 for (
unsigned int i = 0; i < _test.size(); i++)
423 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
425 Real t = _JxW[_qp] * _coord[_qp] * _test[i][_qp];
426 _local_re(i) += t * computeValue();
427 for (
unsigned int j = 0; j < _test.size(); j++)
428 _local_ke(i, j) += t * _test[j][_qp];
432 _local_sol.resize(_n_local_dofs);
433 for (
unsigned int i = 0; i < _local_re.size(); ++i)
434 _local_sol(i) = RealEigenVector::Zero(_var.count());
437 for (
unsigned int i = 0; i < _var.count(); ++i)
439 for (
unsigned int j = 0; j < _n_local_dofs; ++j)
440 re(j) = _local_re(j)(i);
443 _local_ke.svd_solve(re, sol);
445 _local_ke.cholesky_solve(re, sol);
447 for (
unsigned int j = 0; j < _n_local_dofs; ++j)
448 _local_sol(j)(i) = sol(j);
451 _var.setDofValues(_local_sol);
456 template <
typename ComputeValueType>
460 if (_sys.solutionStatesInitialized())
461 mooseError(
"The solution states have already been initialized when calling ",
464 "Make sure to call uOld() within the object constructor.");
466 return _nodal ? _var.nodalValueOldArray() : _var.slnOld();
469 template <
typename ComputeValueType>
473 if (_sys.solutionStatesInitialized())
474 mooseError(
"The solution states have already been initialized when calling ",
477 "Make sure to call uOlder() within the object constructor.");
479 return _nodal ? _var.nodalValueOlderArray() : _var.slnOlder();
482 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.
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.
const FEType & feType() const
Get the type of finite element object.
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.