17 #include "libmesh/dense_vector.h" 30 "matrix_only",
false,
"Whether this object is only doing assembly to matrices (no vectors)");
33 "vector_tags", vtags,
"The tag for the vectors this Kernel should fill");
36 "matrix_tags", mtags,
"The tag for the matrices this Kernel should fill");
38 params.
addParam<std::vector<TagName>>(
"extra_vector_tags",
39 "The extra tags for the vectors this Kernel should fill");
41 params.
addParam<std::vector<TagName>>(
42 "absolute_value_vector_tags",
43 "The tags for the vectors this residual object should fill with the " 44 "absolute value of the residual contribution");
46 params.
addParam<std::vector<TagName>>(
"extra_matrix_tags",
47 "The extra tags for the matrices this Kernel should fill");
50 "absolute_value_vector_tags matrix_only",
51 "Contribution to tagged field data");
57 : _subproblem(*moose_object->parameters().getCheckedPointerParam<
SubProblem *>(
"_subproblem")),
58 _moose_object(*moose_object),
59 _tag_params(_moose_object.parameters())
63 if (!vector_tag_names.isValid())
70 for (
auto & vector_tag_name : vector_tag_names)
75 vector_tag_name.name(),
78 "' is not a residual vector tag");
85 auto & extra_vector_tags =
_tag_params.
get<std::vector<TagName>>(
"extra_vector_tags");
87 for (
auto & vector_tag_name : extra_vector_tags)
95 "' is not a residual vector tag");
101 auto & abs_vector_tags =
_tag_params.
get<std::vector<TagName>>(
"absolute_value_vector_tags");
103 for (
auto & vector_tag_name : abs_vector_tags)
111 "' is not a residual vector tag");
117 if (matrix_tag_names.isValid())
118 for (
auto & matrix_tag_name : matrix_tag_names)
121 auto & extra_matrix_tags =
_tag_params.
get<std::vector<TagName>>(
"extra_matrix_tags");
123 for (
auto & matrix_tag_name : extra_matrix_tags)
130 const auto *
const fe_problem =
133 for (
const auto & conv : fe_problem->getConvergenceObjects())
139 auto create_tags_split =
140 [reference_tag](
const auto & tags,
auto & non_ref_tags,
auto & ref_tags)
142 for (
const auto tag : tags)
143 if (tag == reference_tag)
144 ref_tags.insert(tag);
146 non_ref_tags.insert(tag);
159 #ifdef MOOSE_KOKKOS_ENABLED 162 : _subproblem(object._subproblem),
163 _moose_object(object._moose_object),
164 _tag_params(object._tag_params)
173 mooseError(
"Vector tag ", tag_name,
" does not exist in system");
182 mooseError(
"Matrix tag ", tag_name,
" does not exist in system");
191 mooseError(
"Vector tag ", tag_id,
" does not exist in system");
200 mooseError(
"Matrix tag ", tag_id,
" does not exist in system");
213 const unsigned int ivar,
224 const unsigned int ivar,
225 const std::set<TagID> & vector_tags,
226 const std::set<TagID> & absolute_value_vector_tags)
228 auto prepare = [
this, ivar, &assembly](
auto & re_blocks,
const auto & tags)
231 re_blocks.reserve(tags.size());
232 for (
const auto tag_id : tags)
251 mooseAssert(
_vector_tags.size() >= 1,
"we need at least one active tag");
274 mooseAssert(
_vector_tags.size() >= 1,
"we need at least one active tag");
296 mooseAssert(
_matrix_tags.size() >= 1,
"we need at least one active tag");
310 mooseAssert(!
_matrix_tags.empty(),
"No matrix tags exist");
311 const auto & ij_mat =
313 k.
resize(ij_mat.m(), ij_mat.n());
322 mooseAssert(
_matrix_tags.size() >= 1,
"we need at least one active tag");
338 mooseAssert(
_matrix_tags.size() >= 1,
"we need at least one active tag");
354 mooseAssert(!
_matrix_tags.empty(),
"No matrix tags exist");
357 k.
resize(ij_mat.m(), ij_mat.n());
367 mooseAssert(
_matrix_tags.size() >= 1,
"we need at least one active tag");
415 const unsigned int ivar,
416 const unsigned int jvar,
420 mooseAssert(
_matrix_tags.size() >= 1,
"we need at least one active tag");
425 "Passed-in k must match the blocks we are about to sum into");
432 const unsigned int ivar,
433 const unsigned int jvar,
438 mooseAssert(
_matrix_tags.size() >= 1,
"we need at least one active tag");
444 "Passed-in k must match the blocks we are about to sum into");
488 std::stringstream ss;
490 ss <<
"To further troubleshoot this value in this residual object, add the following lines " 491 "before returning the value in the computeQpResidual() (or similar) method in the " 492 "source file for the class of '" 494 ss <<
" if (!std::isfinite(<return value>))\n";
495 ss <<
" mooseError(\"Found NaN or Inf\");\n\n";
496 ss <<
"Then you can use a breakpoint in a debugger to troubleshoot the origin of the NaN or " virtual TagID getVectorTagID(const TagName &tag_name) const
Get a TagID from a TagName.
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
void accumulateTaggedNonlocalMatrix()
Nonlocal Jacobian blocks will be appended by adding the current nonlocal kernel Jacobian.
std::set< TagID > _ref_abs_vector_tags
A set of either size 1 or 0.
SubProblem & _subproblem
SubProblem that contains tag info.
void addResidualsAndJacobian(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
Add the provided incoming residuals and derivatives for the Jacobian, corresponding to the provided d...
const InputParameters & _tag_params
Parameters from moose object.
void accumulateTaggedLocalResidual()
Local residual blocks will be appended by adding the current local kernel residual.
Keeps track of stuff related to assembling.
const std::vector< dof_id_type > & dof_indices
DenseMatrix< Number > & jacobianBlockNonlocal(unsigned int ivar, unsigned int jvar, LocalDataKey, TagID tag)
Get local Jacobian block from non-local contribution for a pair of variables and a tag...
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
DenseMatrix< Number > & jacobianBlockNeighbor(Moose::DGJacobianType type, unsigned int ivar, unsigned int jvar, LocalDataKey, TagID tag)
Get local Jacobian block of a DG Jacobian type for a pair of variables and a tag. ...
void assignTaggedLocalMatrix()
Local Jacobian blocks will assigned as the current local kernel Jacobian.
const InputParameters & parameters() const
Get the parameters of the object.
void resize(const unsigned int n)
void addResiduals(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
Add the provided incoming residuals corresponding to the provided dof indices.
TagTypeID _type_id
The index for this tag into a vector that contains tags of only its type ordered by ID...
void assignTaggedLocalResidual()
Local residual blocks will assigned as the current local kernel residual.
std::vector< DenseVector< Number > * > _absre_blocks
Residual blocks for absolute value residual tags.
const Real scaling_factor
ResidualTagType
Enumerate whether a (residual) vector tag is to be of a non-reference or reference tag type...
std::vector< DenseVector< Number > * > _re_blocks
Residual blocks Vectors For each Tag.
const DenseVector< ADReal > & residuals
std::set< TagID > _ref_vector_tags
A set of either size 1 or 0.
DenseMatrix< Number > & jacobianBlock(unsigned int ivar, unsigned int jvar, LocalDataKey, TagID tag)
Get local Jacobian block for a pair of variables and a tag.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
DenseMatrix< Number > _local_ke
Holds local Jacobian entries as they are accumulated by this Kernel.
std::set< TagID > _abs_vector_tags
The absolute value residual tag ids.
DenseMatrix< Number > & jacobianBlockMortar(Moose::ConstraintJacobianType type, unsigned int ivar, unsigned int jvar, LocalDataKey, TagID tag)
Returns the jacobian block for the given mortar Jacobian type.
void prepareMatrixTagNeighbor(Assembly &assembly, unsigned int ivar, unsigned int jvar, Moose::DGJacobianType type)
Prepare data for computing element jacobian according to the active tags for DG and interface kernels...
TaggingInterface(const MooseObject *moose_object)
void addJacobian(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
Add the provided residual derivatives into the Jacobian for the provided dof indices.
std::set< TagID > _non_ref_abs_vector_tags
A set to hold absolute value vector tags excluding the reference residual tag.
void prepareMatrixTagNonlocal(Assembly &assembly, unsigned int ivar, unsigned int jvar)
Prepare data for computing nonlocal element jacobian according to the active tags.
const std::string & name() const
Get the name of the class.
Every object that can be built by the factory should be derived from this class.
virtual TagID getMatrixTagID(const TagName &tag_name) const
Get a TagID from a TagName.
std::set< TagID > _matrix_tags
The matrices this Kernel will contribute to.
virtual Moose::VectorTagType vectorTagType(const TagID tag_id) const
DenseVector< Number > & residualBlockLower(unsigned int var_num, LocalDataKey, TagID tag_id)
Get residual block for lower.
TagID referenceVectorTagID(ReferenceVectorTagIDKey) const
Returns the tag ID associated with the reference vector tag ID key.
std::set< TagID > _non_ref_vector_tags
A set to hold vector tags excluding the reference residual tag.
std::set< TagID > _vector_tags
The vector tag ids this Kernel will contribute to.
virtual bool vectorTagExists(const TagID tag_id) const
Check to see if a particular Tag exists.
void accumulateTaggedLocalMatrix()
Local Jacobian blocks will be appended by adding the current local kernel Jacobian.
Utility structure for packaging up all of the residual object's information needed to add into the sy...
void useMatrixTag(const TagName &tag_name, MatrixTagsKey)
Uses a reference residual to define relative convergence criteria.
void prepareVectorTagNeighbor(Assembly &assembly, unsigned int ivar)
Prepare data for computing element residual the according to active tags for DG and interface kernels...
Generic class for solving transient nonlinear problems.
DenseVector< Number > & residualBlockNeighbor(unsigned int var_num, LocalDataKey, TagID tag_id)
Get local neighbor residual block for a variable and a tag.
DenseVector< Number > & residualBlock(unsigned int var_num, LocalDataKey, TagID tag_id)
Get local residual block for a variable and a tag.
void prepareMatrixTagLower(Assembly &assembly, unsigned int ivar, unsigned int jvar, Moose::ConstraintJacobianType type)
Prepare data for computing the jacobian according to the active tags for mortar.
DenseVector< Number > _local_re
Holds local residual entries as they are accumulated by this Kernel.
const MooseObject & _moose_object
Moose objct this tag works on.
void resize(const unsigned int new_m, const unsigned int new_n)
virtual bool checkResidualForNans() const =0
Whether to check residual for NaN/Inf values.
virtual ~TaggingInterface()
void checkForNans() const
Checks _local_re for NaNs/Infs and returns an error if found.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type...
std::vector< DenseMatrix< Number > * > _ke_blocks
Kernel blocks Vectors For each Tag.
void prepareVectorTagLower(Assembly &assembly, unsigned int ivar)
Prepare data for computing the residual according to active tags for mortar constraints.
void prepareVectorTagInternal(Assembly &assembly, unsigned int ivar, const std::set< TagID > &vector_tags, const std::set< TagID > &absolute_value_vector_tags)
Prepare data for computing element residual according to the specified tags Residual blocks for diffe...
void prepareVectorTag(Assembly &assembly, unsigned int ivar)
Prepare data for computing element residual according to active tags.
void prepareMatrixTag(Assembly &assembly, unsigned int ivar, unsigned int jvar)
Prepare data for computing element jacobian according to the active tags.
Storage for all of the information pretaining to a vector tag.
DenseMatrix< Number > _nonlocal_ke
Holds nonlocal Jacobian entries as they are accumulated by this Kernel.
static InputParameters validParams()
virtual const VectorTag & getVectorTag(const TagID tag_id) const
Get a VectorTag from a TagID.
auto index_range(const T &sizable)
Key structure for APIs adding/caching local element residuals/Jacobians.
void useVectorTag(const TagName &tag_name, VectorTagsKey)
virtual bool matrixTagExists(const TagName &tag_name) const
Check to see if a particular Tag exists.