www.mooseframework.org
TaggingInterface.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 #include "TaggingInterface.h"
11 #include "Conversion.h"
12 #include "FEProblem.h"
13 #include "Assembly.h"
14 
15 #include "libmesh/dense_vector.h"
16 
17 template <>
20 {
22 
23  // These are the default names for tags, but users will be able to add their own
24  MultiMooseEnum vtags("nontime time", "nontime", true);
25  MultiMooseEnum mtags("nontime system", "system", true);
26 
27  params.addParam<MultiMooseEnum>(
28  "vector_tags", vtags, "The tag for the vectors this Kernel should fill");
29 
30  params.addParam<MultiMooseEnum>(
31  "matrix_tags", mtags, "The tag for the matrices this Kernel should fill");
32 
33  params.addParam<std::vector<TagName>>("extra_vector_tags",
34  "The extra tags for the vectors this Kernel should fill");
35 
36  params.addParam<std::vector<TagName>>("extra_matrix_tags",
37  "The extra tags for the matrices this Kernel should fill");
38 
39  params.addParamNamesToGroup("vector_tags matrix_tags extra_vector_tags extra_matrix_tags",
40  "Tagging");
41 
42  return params;
43 }
44 
46  : _moose_object(*moose_object),
47  _tag_params(_moose_object.parameters()),
48  _subproblem(*_tag_params.getCheckedPointerParam<SubProblem *>("_subproblem"))
49 {
50  auto & vector_tag_names = _tag_params.get<MultiMooseEnum>("vector_tags");
51 
52  if (!vector_tag_names.isValid())
53  mooseError("MUST provide at least one vector_tag for Kernel: ", _moose_object.name());
54 
55  for (auto & vector_tag_name : vector_tag_names)
56  _vector_tags.insert(_subproblem.getVectorTagID(vector_tag_name.name()));
57 
58  // Add extra vector tags. These tags should be created in the System already, otherwise
59  // we can not add the extra tags
60  auto & extra_vector_tags = _tag_params.get<std::vector<TagName>>("extra_vector_tags");
61 
62  for (auto & vector_tag_name : extra_vector_tags)
63  _vector_tags.insert(_subproblem.getVectorTagID(vector_tag_name));
64 
65  auto & matrix_tag_names = _tag_params.get<MultiMooseEnum>("matrix_tags");
66 
67  if (!matrix_tag_names.isValid())
68  mooseError("MUST provide at least one matrix_tag for Kernel: ", _moose_object.name());
69 
70  for (auto & matrix_tag_name : matrix_tag_names)
71  _matrix_tags.insert(_subproblem.getMatrixTagID(matrix_tag_name.name()));
72 
73  auto & extra_matrix_tags = _tag_params.get<std::vector<TagName>>("extra_matrix_tags");
74 
75  for (auto & matrix_tag_name : extra_matrix_tags)
76  _matrix_tags.insert(_subproblem.getMatrixTagID(matrix_tag_name));
77 
78  _re_blocks.resize(_vector_tags.size());
79  _ke_blocks.resize(_matrix_tags.size());
80 }
81 
82 void
83 TaggingInterface::useVectorTag(const TagName & tag_name)
84 {
85  if (!_subproblem.vectorTagExists(tag_name))
86  mooseError("Vector tag ", tag_name, " does not exsit in system");
87 
88  _vector_tags.insert(_subproblem.getVectorTagID(tag_name));
89 }
90 
91 void
92 TaggingInterface::useMatrixTag(const TagName & tag_name)
93 {
94  if (!_subproblem.matrixTagExists(tag_name))
95  mooseError("Matrix tag ", tag_name, " does not exsit in system");
96 
97  _matrix_tags.insert(_subproblem.getMatrixTagID(tag_name));
98 }
99 
100 void
102 {
103  if (!_subproblem.vectorTagExists(tag_id))
104  mooseError("Vector tag ", tag_id, " does not exsit in system");
105 
106  _vector_tags.insert(tag_id);
107 }
108 
109 void
111 {
112  if (!_subproblem.matrixTagExists(tag_id))
113  mooseError("Matrix tag ", tag_id, " does not exsit in system");
114 
115  _matrix_tags.insert(tag_id);
116 }
117 
118 void
119 TaggingInterface::prepareVectorTag(Assembly & assembly, unsigned int ivar)
120 {
121  _re_blocks.resize(_vector_tags.size());
122  mooseAssert(_vector_tags.size() >= 1, "we need at least one active tag");
123  auto vector_tag = _vector_tags.begin();
124  for (MooseIndex(_vector_tags) i = 0; i < _vector_tags.size(); i++, ++vector_tag)
125  _re_blocks[i] = &assembly.residualBlock(ivar, *vector_tag);
126 
127  _local_re.resize(_re_blocks[0]->size());
128  _local_re.zero();
129 }
130 
131 void
133 {
134  _re_blocks.resize(_vector_tags.size());
135  mooseAssert(_vector_tags.size() >= 1, "we need at least one active tag");
136  auto vector_tag = _vector_tags.begin();
137  for (MooseIndex(_vector_tags) i = 0; i < _vector_tags.size(); i++, ++vector_tag)
138  _re_blocks[i] = &assembly.residualBlockNeighbor(ivar, *vector_tag);
139 
140  _local_re.resize(_re_blocks[0]->size());
141  _local_re.zero();
142 }
143 
144 void
145 TaggingInterface::prepareVectorTagLower(Assembly & assembly, unsigned int ivar)
146 {
147  _re_blocks.resize(_vector_tags.size());
148  mooseAssert(_vector_tags.size() >= 1, "we need at least one active tag");
149  auto vector_tag = _vector_tags.begin();
150  for (MooseIndex(_vector_tags) i = 0; i < _vector_tags.size(); i++, ++vector_tag)
151  _re_blocks[i] = &assembly.residualBlockLower(ivar, *vector_tag);
152 
153  _local_re.resize(_re_blocks[0]->size());
154  _local_re.zero();
155 }
156 
157 void
158 TaggingInterface::prepareMatrixTag(Assembly & assembly, unsigned int ivar, unsigned int jvar)
159 {
160  _ke_blocks.resize(_matrix_tags.size());
161  mooseAssert(_matrix_tags.size() >= 1, "we need at least one active tag");
162  auto mat_vector = _matrix_tags.begin();
163  for (MooseIndex(_matrix_tags) i = 0; i < _matrix_tags.size(); i++, ++mat_vector)
164  _ke_blocks[i] = &assembly.jacobianBlock(ivar, jvar, *mat_vector);
165 
166  _local_ke.resize(_ke_blocks[0]->m(), _ke_blocks[0]->n());
167  _local_ke.zero();
168 }
169 
170 void
172  unsigned int ivar,
173  unsigned int jvar,
175 {
176  _ke_blocks.resize(_matrix_tags.size());
177  mooseAssert(_matrix_tags.size() >= 1, "we need at least one active tag");
178  auto mat_vector = _matrix_tags.begin();
179  for (MooseIndex(_matrix_tags) i = 0; i < _matrix_tags.size(); i++, ++mat_vector)
180  _ke_blocks[i] = &assembly.jacobianBlockNeighbor(type, ivar, jvar, *mat_vector);
181 
182  _local_ke.resize(_ke_blocks[0]->m(), _ke_blocks[0]->n());
183  _local_ke.zero();
184 }
185 
186 void
188  unsigned int ivar,
189  unsigned int jvar,
191 {
192  _ke_blocks.resize(_matrix_tags.size());
193  mooseAssert(_matrix_tags.size() >= 1, "we need at least one active tag");
194  auto mat_vector = _matrix_tags.begin();
195  for (MooseIndex(_matrix_tags) i = 0; i < _matrix_tags.size(); i++, ++mat_vector)
196  _ke_blocks[i] = &assembly.jacobianBlockLower(type, ivar, jvar, *mat_vector);
197 
198  _local_ke.resize(_ke_blocks[0]->m(), _ke_blocks[0]->n());
199  _local_ke.zero();
200 }
201 
202 void
204 {
205  for (auto & re : _re_blocks)
206  *re += _local_re;
207 }
208 
209 void
211 {
212  for (auto & re : _re_blocks)
213  *re = _local_re;
214 }
215 
216 void
218 {
219  for (auto & ke : _ke_blocks)
220  *ke += _local_ke;
221 }
222 
223 void
225 {
226  for (auto & ke : _ke_blocks)
227  *ke = _local_ke;
228 }
229 
virtual TagID getVectorTagID(const TagName &tag_name)
Get a TagID from a TagName.
Definition: SubProblem.C:91
SubProblem & _subproblem
SubProblem that contains tag info.
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.
Definition: Assembly.h:62
DenseVector< Number > & residualBlockNeighbor(unsigned int var_num, TagID tag_id=0)
Definition: Assembly.h:725
unsigned int TagID
Definition: MooseTypes.h:162
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
void assignTaggedLocalMatrix()
Local Jacobian blocks will assigned as the current local kernel Jacobian.
DenseMatrix< Number > & jacobianBlock(unsigned int ivar, unsigned int jvar, TagID tag=0)
Definition: Assembly.C:2019
void assignTaggedLocalResidual()
Local residual blocks will assigned as the current local kernel residual.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::vector< DenseVector< Number > * > _re_blocks
Residual blocks Vectors For each Tag.
void useMatrixTag(const TagName &tag_name)
DenseMatrix< Number > _local_ke
Holds residual entries as they are accumulated by this Kernel.
InputParameters emptyInputParameters()
DenseVector< Number > & residualBlockLower(unsigned int var_num, TagID tag_id=0)
Definition: Assembly.h:730
virtual bool matrixTagExists(const TagName &tag_name)
Check to see if a particular Tag exists.
Definition: SubProblem.C:129
void prepareMatrixTagNeighbor(Assembly &assembly, unsigned int ivar, unsigned int jvar, Moose::DGJacobianType type)
Prepare data for computing element jacobian according to the ative tags for DG and interface kernels...
TaggingInterface(const MooseObject *moose_object)
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:42
PetscInt m
std::set< TagID > _matrix_tags
The matrices this Kernel will contribute to.
DenseMatrix< Number > & jacobianBlockLower(Moose::ConstraintJacobianType type, unsigned int ivar, unsigned int jvar, TagID tag=0)
Returns the jacobian block for the given mortar Jacobian type.
Definition: Assembly.C:2072
InputParameters validParams< TaggingInterface >()
std::set< TagID > _vector_tags
The vectors this Kernel will contribute to.
void useVectorTag(const TagName &tag_name)
virtual bool vectorTagExists(TagID tag)
Check to see if a particular Tag exists.
Definition: SubProblem.h:112
void accumulateTaggedLocalMatrix()
Local Jacobian blocks will be appended by adding the current local kernel Jacobian.
DGJacobianType
Definition: MooseTypes.h:515
MatType type
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.
Definition: SubProblem.h:59
PetscInt n
ConstraintJacobianType
Definition: MooseTypes.h:543
virtual TagID getMatrixTagID(const TagName &tag_name)
Get a TagID from a TagName.
Definition: SubProblem.C:143
void prepareMatrixTagLower(Assembly &assembly, unsigned int ivar, unsigned int jvar, Moose::ConstraintJacobianType type)
Prepare data for computing the jacobian according to the ative tags for mortar.
DenseVector< Number > _local_re
Holds residual entries as they are accumulated by this Kernel.
const MooseObject & _moose_object
Moose objct this tag works on.
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
virtual ~TaggingInterface()
DenseMatrix< Number > & jacobianBlockNeighbor(Moose::DGJacobianType type, unsigned int ivar, unsigned int jvar, TagID tag=0)
Definition: Assembly.C:2033
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
DenseVector< Number > & residualBlock(unsigned int var_num, TagID tag_id=0)
Definition: Assembly.h:720
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 prepareVectorTag(Assembly &assembly, unsigned int ivar)
Prepare data for computing element residual the according to active tags.
void prepareMatrixTag(Assembly &assembly, unsigned int ivar, unsigned int jvar)
Prepare data for computing element jacobian according to the ative tags.
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...