Line data Source code
1 : //* This file is part of the MOOSE framework
2 : //* https://mooseframework.inl.gov
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 : #pragma once
11 :
12 : #include "DenseMatrix.h"
13 : #include "MooseTypes.h"
14 : #include "MultiMooseEnum.h"
15 : #include "Assembly.h"
16 : #include "MooseVariableFE.h"
17 : #include "SystemBase.h"
18 :
19 : #include "libmesh/dense_vector.h"
20 : #include "metaphysicl/raw_type.h"
21 :
22 : #include <vector>
23 :
24 : // Forward declarations
25 : class InputParameters;
26 : class MooseObject;
27 : class SubProblem;
28 : class Assembly;
29 :
30 : #ifdef MOOSE_KOKKOS_ENABLED
31 : namespace Moose::Kokkos
32 : {
33 : class ResidualObject;
34 : class System;
35 : }
36 : #endif
37 :
38 : template <typename T>
39 : InputParameters validParams();
40 :
41 : /**
42 : * Utility structure for packaging up all of the residual object's information needed to add into
43 : * the system residual and Jacobian in the context of automatic differentiation. The necessary
44 : * information includes the vector of residuals and Jacobians represented by dual numbers, the
45 : * vector of degrees of freedom (this should be the same length as the vector of dual numbers), and
46 : * a scaling factor that will multiply the dual numbers before their addition into the global
47 : * residual and Jacobian
48 : */
49 : struct ADResidualsPacket
50 : {
51 : const DenseVector<ADReal> & residuals;
52 : const std::vector<dof_id_type> & dof_indices;
53 : const Real scaling_factor;
54 : };
55 :
56 : class TaggingInterface
57 : {
58 : public:
59 : TaggingInterface(const MooseObject * moose_object);
60 :
61 : #ifdef MOOSE_KOKKOS_ENABLED
62 : /**
63 : * Special constructor used for Kokkos functor copy during parallel dispatch
64 : */
65 : TaggingInterface(const TaggingInterface & object, const Moose::Kokkos::FunctorCopy & key);
66 : #endif
67 :
68 : virtual ~TaggingInterface();
69 :
70 : static InputParameters validParams();
71 :
72 : /**
73 : * Class that is used as a parameter to some of our vector tag APIs that allows only
74 : * blessed framework classes to call them
75 : */
76 : class VectorTagsKey
77 : {
78 : friend class AttribVectorTags;
79 : friend class NonlinearEigenSystem;
80 : friend class LinearSystemContributionObject;
81 : template <typename>
82 : friend class MooseObjectTagWarehouse;
83 : #ifdef MOOSE_KOKKOS_ENABLED
84 : friend class Moose::Kokkos::ResidualObject;
85 : friend class Moose::Kokkos::System;
86 : #endif
87 :
88 697338 : VectorTagsKey() {}
89 : VectorTagsKey(const VectorTagsKey &) {}
90 : };
91 :
92 : /**
93 : * Class that is used as a parameter to some of our matrix tag APIs that allows only
94 : * blessed framework classes to call them
95 : */
96 : class MatrixTagsKey
97 : {
98 : friend class AttribMatrixTags;
99 : friend class NonlinearEigenSystem;
100 : friend class LinearSystemContributionObject;
101 : template <typename>
102 : friend class MooseObjectTagWarehouse;
103 : #ifdef MOOSE_KOKKOS_ENABLED
104 : friend class Moose::Kokkos::ResidualObject;
105 : friend class Moose::Kokkos::System;
106 : #endif
107 :
108 665316 : MatrixTagsKey() {}
109 : MatrixTagsKey(const MatrixTagsKey &) {}
110 : };
111 :
112 : /**
113 : * Enumerate whether a (residual) vector tag is to be of a non-reference or reference tag type
114 : */
115 : enum class ResidualTagType
116 : {
117 : NonReference,
118 : Reference
119 : };
120 :
121 : void useVectorTag(const TagName & tag_name, VectorTagsKey);
122 :
123 : void useMatrixTag(const TagName & tag_name, MatrixTagsKey);
124 :
125 : void useVectorTag(TagID tag_id, VectorTagsKey);
126 :
127 : void useMatrixTag(TagID tag_id, MatrixTagsKey);
128 :
129 : bool isVectorTagged() { return _vector_tags.size() > 0; }
130 :
131 : bool isMatrixTagged() { return _matrix_tags.size() > 0; }
132 :
133 433642117 : bool hasVectorTags() const { return !_vector_tags.empty(); }
134 :
135 694164 : const std::set<TagID> & getVectorTags(VectorTagsKey) const { return _vector_tags; }
136 :
137 660196 : const std::set<TagID> & getMatrixTags(MatrixTagsKey) const { return _matrix_tags; }
138 :
139 : protected:
140 : /**
141 : * Prepare data for computing element residual according to active tags.
142 : * Residual blocks for different tags will be extracted from Assembly.
143 : * A local residual will be zeroed. It should be called
144 : * right before the local element vector is computed.
145 : */
146 : void prepareVectorTag(Assembly & assembly, unsigned int ivar);
147 :
148 : /**
149 : * Prepare vector tags in a reference residual problem context
150 : * @param Assembly The assembly object that we obtain the local residual blocks from
151 : * @param ivar The variable which we are retrieving the local residual blocks for
152 : * @param ref_problem A pointer to a reference residual problem. This can be a nullptr
153 : * @param tag_type What type of tags to prepare
154 : */
155 : void prepareVectorTag(Assembly & assembly, unsigned int ivar, ResidualTagType tag_type);
156 :
157 : /**
158 : * Prepare data for computing element residual the according to active tags
159 : * for DG and interface kernels.
160 : * Residual blocks for different tags will be extracted from Assembly.
161 : * A local residual will be zeroed. It should be called
162 : * right before the local element vector is computed.
163 : */
164 : void prepareVectorTagNeighbor(Assembly & assembly, unsigned int ivar);
165 :
166 : /**
167 : * Prepare data for computing the residual according to active tags for mortar constraints.
168 : * Residual blocks for different tags will be extracted from Assembly. A local residual will be
169 : * zeroed. It should be called right before the local element vector is computed.
170 : */
171 : void prepareVectorTagLower(Assembly & assembly, unsigned int ivar);
172 :
173 : /**
174 : * Prepare data for computing element jacobian according to the active tags.
175 : * Jacobian blocks for different tags will be extracted from Assembly.
176 : * A local Jacobian will be zeroed. It should be called
177 : * right before the local element matrix is computed.
178 : */
179 : void prepareMatrixTag(Assembly & assembly, unsigned int ivar, unsigned int jvar);
180 :
181 : void prepareMatrixTag(Assembly & assembly,
182 : unsigned int ivar,
183 : unsigned int jvar,
184 : DenseMatrix<Number> & k) const;
185 :
186 : /**
187 : * Prepare data for computing nonlocal element jacobian according to the active tags.
188 : * Jacobian blocks for different tags will be extracted from Assembly.
189 : * A nonlocal Jacobian will be zeroed. It should be called
190 : * right before the nonlocal element matrix is computed.
191 : */
192 : void prepareMatrixTagNonlocal(Assembly & assembly, unsigned int ivar, unsigned int jvar);
193 :
194 : /**
195 : * Prepare data for computing element jacobian according to the active tags
196 : * for DG and interface kernels.
197 : * Jacobian blocks for different tags will be extracted from Assembly.
198 : * A local Jacobian will be zeroed. It should be called
199 : * right before the local element matrix is computed.
200 : */
201 : void prepareMatrixTagNeighbor(Assembly & assembly,
202 : unsigned int ivar,
203 : unsigned int jvar,
204 : Moose::DGJacobianType type);
205 :
206 : void prepareMatrixTagNeighbor(Assembly & assembly,
207 : unsigned int ivar,
208 : unsigned int jvar,
209 : Moose::DGJacobianType type,
210 : DenseMatrix<Number> & k) const;
211 :
212 : /**
213 : * Prepare data for computing the jacobian according to the active tags for mortar. Jacobian
214 : * blocks for different tags will be extracted from Assembly. A local Jacobian will be zeroed. It
215 : * should be called right before the local element matrix is computed.
216 : */
217 : void prepareMatrixTagLower(Assembly & assembly,
218 : unsigned int ivar,
219 : unsigned int jvar,
220 : Moose::ConstraintJacobianType type);
221 :
222 : /**
223 : * Local residual blocks will be appended by adding the current local kernel residual.
224 : * It should be called after the local element vector has been computed.
225 : */
226 : void accumulateTaggedLocalResidual();
227 :
228 : /**
229 : * Local residual blocks will assigned as the current local kernel residual.
230 : * It should be called after the local element vector has been computed.
231 : */
232 : void assignTaggedLocalResidual();
233 :
234 : /**
235 : * Local Jacobian blocks will be appended by adding the current local kernel Jacobian.
236 : * It should be called after the local element matrix has been computed.
237 : */
238 : void accumulateTaggedLocalMatrix();
239 :
240 : void accumulateTaggedLocalMatrix(Assembly & assembly,
241 : unsigned int ivar,
242 : unsigned int jvar,
243 : const DenseMatrix<Number> & k);
244 :
245 : void accumulateTaggedLocalMatrix(Assembly & assembly,
246 : unsigned int ivar,
247 : unsigned int jvar,
248 : Moose::DGJacobianType type,
249 : const DenseMatrix<Number> & k);
250 :
251 : /**
252 : * Nonlocal Jacobian blocks will be appended by adding the current nonlocal kernel Jacobian.
253 : * It should be called after the nonlocal element matrix has been computed.
254 : */
255 : void accumulateTaggedNonlocalMatrix();
256 :
257 : /**
258 : * Local Jacobian blocks will assigned as the current local kernel Jacobian.
259 : * It should be called after the local element matrix has been computed.
260 : */
261 : void assignTaggedLocalMatrix();
262 :
263 : /**
264 : * Add the provided incoming residuals corresponding to the provided dof indices
265 : */
266 : template <typename Residuals, typename Indices>
267 : void addResiduals(Assembly & assembly,
268 : const Residuals & residuals,
269 : const Indices & dof_indices,
270 : Real scaling_factor);
271 :
272 : template <typename Residuals, typename Indices>
273 : void addResiduals(Assembly & assembly,
274 : const Residuals & residuals,
275 : const Indices & dof_indices,
276 : const std::vector<Real> & scaling_factors);
277 :
278 : /**
279 : * Add the provided incoming residuals corresponding to the provided dof indices
280 : */
281 : template <typename T, typename Indices>
282 : void addResiduals(Assembly & assembly,
283 : const DenseVector<T> & residuals,
284 : const Indices & dof_indices,
285 : Real scaling_factor);
286 :
287 : /**
288 : * Add the provided incoming residuals and derivatives for the Jacobian, corresponding to the
289 : * provided dof indices
290 : */
291 : template <typename Residuals, typename Indices>
292 : void addResidualsAndJacobian(Assembly & assembly,
293 : const Residuals & residuals,
294 : const Indices & dof_indices,
295 : Real scaling_factor);
296 :
297 : /**
298 : * Add the provided residual derivatives into the Jacobian for the provided dof indices
299 : */
300 : template <typename Residuals, typename Indices>
301 : void addJacobian(Assembly & assembly,
302 : const Residuals & residuals,
303 : const Indices & dof_indices,
304 : Real scaling_factor);
305 :
306 : /**
307 : * Add the provided residual derivatives into the Jacobian for the provided dof indices. This
308 : * overload is meant for array variables because it takes an array of scaling factors
309 : */
310 : template <typename Residuals, typename Indices>
311 : void addJacobian(Assembly & assembly,
312 : const Residuals & residuals,
313 : const Indices & dof_indices,
314 : const std::vector<Real> & scaling_factors);
315 :
316 : /**
317 : * Add the provided incoming residuals corresponding to the provided dof indices
318 : */
319 : void addResiduals(Assembly & assembly, const ADResidualsPacket & packet);
320 :
321 : /**
322 : * Add the provided incoming residuals and derivatives for the Jacobian, corresponding to the
323 : * provided dof indices
324 : */
325 : void addResidualsAndJacobian(Assembly & assembly, const ADResidualsPacket & packet);
326 :
327 : /**
328 : * Add the provided residual derivatives into the Jacobian for the provided dof indices
329 : */
330 : void addJacobian(Assembly & assembly, const ADResidualsPacket & packet);
331 :
332 : /**
333 : * Add the provided incoming residuals corresponding to the provided dof indices. This API should
334 : * only be used if the caller knows that no libMesh-level constraints (hanging nodes or periodic
335 : * boundary conditions) apply to the provided dof indices
336 : */
337 : template <typename Residuals, typename Indices>
338 : void addResidualsWithoutConstraints(Assembly & assembly,
339 : const Residuals & residuals,
340 : const Indices & dof_indices,
341 : Real scaling_factor);
342 :
343 : /**
344 : * Add the provided incoming residuals and derivatives for the Jacobian, corresponding to the
345 : * provided dof indices. This API should only be used if the caller knows that no libMesh-level
346 : * constraints (hanging nodes or periodic boundary conditions) apply to the provided dof indices
347 : */
348 : template <typename Residuals, typename Indices>
349 : void addResidualsAndJacobianWithoutConstraints(Assembly & assembly,
350 : const Residuals & residuals,
351 : const Indices & dof_indices,
352 : Real scaling_factor);
353 :
354 : /**
355 : * Add the provided residual derivatives into the Jacobian for the provided dof indices. This API
356 : * should only be used if the caller knows that no libMesh-level constraints (hanging nodes or
357 : * periodic boundary conditions) apply to the provided dof indices
358 : */
359 : template <typename Residuals, typename Indices>
360 : void addJacobianWithoutConstraints(Assembly & assembly,
361 : const Residuals & residuals,
362 : const Indices & dof_indices,
363 : Real scaling_factor);
364 :
365 : /**
366 : * Add into a single Jacobian element
367 : */
368 : void addJacobianElement(Assembly & assembly,
369 : Real value,
370 : dof_id_type row_index,
371 : dof_id_type column_index,
372 : Real scaling_factor);
373 :
374 : /**
375 : * Add a local Jacobian matrix
376 : */
377 : void addJacobian(Assembly & assembly,
378 : DenseMatrix<Real> & local_k,
379 : const std::vector<dof_id_type> & row_indices,
380 : const std::vector<dof_id_type> & column_indices,
381 : Real scaling_factor);
382 :
383 : /**
384 : * Set residual using the variables' insertion API
385 : */
386 : template <typename T>
387 : void setResidual(SystemBase & sys, const T & residual, MooseVariableFE<T> & var);
388 :
389 : /**
390 : * Set residual at a specified degree of freedom index
391 : */
392 : void setResidual(SystemBase & sys, Real residual, dof_id_type dof_index);
393 :
394 : /**
395 : * Set residuals using the provided functor
396 : */
397 : template <typename SetResidualFunctor>
398 : void setResidual(SystemBase & sys, SetResidualFunctor set_residual_functor);
399 :
400 : /// SubProblem that contains tag info
401 : SubProblem & _subproblem;
402 :
403 : /// Holds local residual entries as they are accumulated by this Kernel
404 : DenseVector<Number> _local_re;
405 :
406 : /// Holds local Jacobian entries as they are accumulated by this Kernel
407 : DenseMatrix<Number> _local_ke;
408 :
409 : /// Holds nonlocal Jacobian entries as they are accumulated by this Kernel
410 : DenseMatrix<Number> _nonlocal_ke;
411 :
412 : private:
413 : /**
414 : * Prepare data for computing element residual according to the specified tags
415 : * Residual blocks for different tags will be extracted from Assembly.
416 : * A local residual will be zeroed. It should be called
417 : * right before the local element vector is computed.
418 : */
419 : void prepareVectorTagInternal(Assembly & assembly,
420 : unsigned int ivar,
421 : const std::set<TagID> & vector_tags,
422 : const std::set<TagID> & absolute_value_vector_tags);
423 :
424 : #ifndef NDEBUG
425 : /**
426 : * Checks \c _local_re for NaNs/Infs and returns an error if found
427 : */
428 : void checkForNans() const;
429 : #endif
430 :
431 : /// The vector tag ids this Kernel will contribute to
432 : std::set<TagID> _vector_tags;
433 :
434 : /// The absolute value residual tag ids
435 : std::set<TagID> _abs_vector_tags;
436 :
437 : /// The matrices this Kernel will contribute to
438 : std::set<TagID> _matrix_tags;
439 :
440 : /// A set to hold vector tags excluding the reference residual tag. If there is no reference
441 : /// residual problem, this container is the same as \p _vector_tags;
442 : std::set<TagID> _non_ref_vector_tags;
443 :
444 : /// A set to hold absolute value vector tags excluding the reference residual tag. If there is no
445 : /// reference residual problem, this container is the same as \p _abs_vector_tags;
446 : std::set<TagID> _non_ref_abs_vector_tags;
447 :
448 : /// A set of either size 1 or 0. If we have a reference residual problem and \p _vector_tags holds
449 : /// the reference vector tag, then this set holds the reference vector tags, otherwise it holds
450 : /// nothing
451 : std::set<TagID> _ref_vector_tags;
452 :
453 : /// A set of either size 1 or 0. If we have a reference residual problem and \p _abs_vector_tags
454 : /// holds the reference vector tag, then this set holds the reference vector tags, otherwise it
455 : /// holds nothing
456 : std::set<TagID> _ref_abs_vector_tags;
457 :
458 : /// Moose objct this tag works on
459 : const MooseObject & _moose_object;
460 :
461 : /// Parameters from moose object
462 : const InputParameters & _tag_params;
463 :
464 : /// Residual blocks Vectors For each Tag
465 : std::vector<DenseVector<Number> *> _re_blocks;
466 :
467 : /// Residual blocks for absolute value residual tags
468 : std::vector<DenseVector<Number> *> _absre_blocks;
469 :
470 : /// Kernel blocks Vectors For each Tag
471 : std::vector<DenseMatrix<Number> *> _ke_blocks;
472 :
473 : /// A container to hold absolute values of residuals passed into \p addResiduals. We maintain
474 : /// this data member to avoid constant dynamic heap allocations
475 : std::vector<Real> _absolute_residuals;
476 :
477 : friend class NonlinearSystemBase;
478 : };
479 :
480 : #define usingTaggingInterfaceMembers \
481 : using TaggingInterface::_subproblem; \
482 : using TaggingInterface::accumulateTaggedLocalResidual; \
483 : using TaggingInterface::accumulateTaggedLocalMatrix; \
484 : using TaggingInterface::prepareVectorTag; \
485 : using TaggingInterface::prepareMatrixTag; \
486 : using TaggingInterface::prepareVectorTagNeighbor; \
487 : using TaggingInterface::_local_re; \
488 : using TaggingInterface::prepareVectorTagLower; \
489 : using TaggingInterface::prepareMatrixTagNeighbor; \
490 : using TaggingInterface::prepareMatrixTagLower; \
491 : using TaggingInterface::_local_ke
492 :
493 : template <typename Residuals, typename Indices>
494 : void
495 27183393 : TaggingInterface::addResiduals(Assembly & assembly,
496 : const Residuals & residuals,
497 : const Indices & dof_indices,
498 : const Real scaling_factor)
499 : {
500 27183393 : assembly.cacheResiduals(
501 27183393 : residuals, dof_indices, scaling_factor, Assembly::LocalDataKey{}, _vector_tags);
502 27183393 : if (!_abs_vector_tags.empty())
503 : {
504 14580 : _absolute_residuals.resize(residuals.size());
505 43740 : for (const auto i : index_range(residuals))
506 29160 : _absolute_residuals[i] = std::abs(MetaPhysicL::raw_value(residuals[i]));
507 :
508 14580 : assembly.cacheResiduals(_absolute_residuals,
509 : dof_indices,
510 : scaling_factor,
511 14580 : Assembly::LocalDataKey{},
512 14580 : _abs_vector_tags);
513 : }
514 27183393 : }
515 :
516 : template <typename Residuals, typename Indices>
517 : void
518 2544 : TaggingInterface::addResiduals(Assembly & assembly,
519 : const Residuals & residuals,
520 : const Indices & dof_indices,
521 : const std::vector<Real> & scaling_factors)
522 : {
523 2544 : const auto count = scaling_factors.size();
524 : mooseAssert(dof_indices.size() % count == 0,
525 : "The number of dof indices should be divided cleanly by the variable count");
526 2544 : const auto nshapes = dof_indices.size() / count;
527 :
528 7632 : for (const auto j : make_range(count))
529 : // The Residuals type may not offer operator[] (e.g. eigen vectors) but more commonly it
530 : // should offer data()
531 10176 : addResiduals(assembly,
532 5088 : Moose::makeSpan(residuals, j * nshapes, nshapes),
533 10176 : Moose::makeSpan(dof_indices, j * nshapes, nshapes),
534 : scaling_factors[j]);
535 2544 : }
536 :
537 : template <typename T, typename Indices>
538 : void
539 3183086 : TaggingInterface::addResiduals(Assembly & assembly,
540 : const DenseVector<T> & residuals,
541 : const Indices & dof_indices,
542 : const Real scaling_factor)
543 : {
544 3183086 : addResiduals(assembly, residuals.get_values(), dof_indices, scaling_factor);
545 3183086 : }
546 :
547 : template <typename Residuals, typename Indices>
548 : void
549 159970 : TaggingInterface::addResidualsWithoutConstraints(Assembly & assembly,
550 : const Residuals & residuals,
551 : const Indices & dof_indices,
552 : const Real scaling_factor)
553 : {
554 159970 : assembly.cacheResidualsWithoutConstraints(
555 159970 : residuals, dof_indices, scaling_factor, Assembly::LocalDataKey{}, _vector_tags);
556 159970 : if (!_abs_vector_tags.empty())
557 : {
558 192 : _absolute_residuals.resize(residuals.size());
559 832 : for (const auto i : index_range(residuals))
560 640 : _absolute_residuals[i] = std::abs(MetaPhysicL::raw_value(residuals[i]));
561 :
562 192 : assembly.cacheResidualsWithoutConstraints(_absolute_residuals,
563 : dof_indices,
564 : scaling_factor,
565 192 : Assembly::LocalDataKey{},
566 192 : _abs_vector_tags);
567 : }
568 159970 : }
569 :
570 : template <typename Residuals, typename Indices>
571 : void
572 9218709 : TaggingInterface::addResidualsAndJacobian(Assembly & assembly,
573 : const Residuals & residuals,
574 : const Indices & dof_indices,
575 : Real scaling_factor)
576 : {
577 9218709 : addResiduals(assembly, residuals, dof_indices, scaling_factor);
578 9218709 : addJacobian(assembly, residuals, dof_indices, scaling_factor);
579 9218709 : }
580 :
581 : template <typename Residuals, typename Indices>
582 : void
583 14361836 : TaggingInterface::addJacobian(Assembly & assembly,
584 : const Residuals & residuals,
585 : const Indices & dof_indices,
586 : Real scaling_factor)
587 : {
588 14361836 : assembly.cacheJacobian(
589 14361836 : residuals, dof_indices, scaling_factor, Assembly::LocalDataKey{}, _matrix_tags);
590 14361836 : }
591 :
592 : template <typename Residuals, typename Indices>
593 : void
594 1431 : TaggingInterface::addJacobian(Assembly & assembly,
595 : const Residuals & residuals,
596 : const Indices & dof_indices,
597 : const std::vector<Real> & scaling_factors)
598 : {
599 1431 : const auto count = scaling_factors.size();
600 : mooseAssert(dof_indices.size() % count == 0,
601 : "The number of dof indices should be divided cleanly by the variable count");
602 1431 : const auto nshapes = dof_indices.size() / count;
603 :
604 4293 : for (const auto j : make_range(count))
605 : // The Residuals type may not offer operator[] (e.g. eigen vectors) but more commonly it
606 : // should offer data()
607 5724 : addJacobian(assembly,
608 2862 : Moose::makeSpan(residuals, j * nshapes, nshapes),
609 5724 : Moose::makeSpan(dof_indices, j * nshapes, nshapes),
610 : scaling_factors[j]);
611 1431 : }
612 :
613 : template <typename Residuals, typename Indices>
614 : void
615 159970 : TaggingInterface::addResidualsAndJacobianWithoutConstraints(Assembly & assembly,
616 : const Residuals & residuals,
617 : const Indices & dof_indices,
618 : Real scaling_factor)
619 : {
620 159970 : addResidualsWithoutConstraints(assembly, residuals, dof_indices, scaling_factor);
621 159970 : addJacobianWithoutConstraints(assembly, residuals, dof_indices, scaling_factor);
622 159970 : }
623 :
624 : template <typename Residuals, typename Indices>
625 : void
626 159970 : TaggingInterface::addJacobianWithoutConstraints(Assembly & assembly,
627 : const Residuals & residuals,
628 : const Indices & dof_indices,
629 : Real scaling_factor)
630 : {
631 159970 : assembly.cacheJacobianWithoutConstraints(
632 159970 : residuals, dof_indices, scaling_factor, Assembly::LocalDataKey{}, _matrix_tags);
633 159970 : }
634 :
635 : inline void
636 8888444 : TaggingInterface::addJacobianElement(Assembly & assembly,
637 : const Real value,
638 : const dof_id_type row_index,
639 : const dof_id_type column_index,
640 : const Real scaling_factor)
641 : {
642 8888444 : assembly.cacheJacobian(
643 8888444 : row_index, column_index, value * scaling_factor, Assembly::LocalDataKey{}, _matrix_tags);
644 8888444 : }
645 :
646 : inline void
647 2952433 : TaggingInterface::addJacobian(Assembly & assembly,
648 : DenseMatrix<Real> & local_k,
649 : const std::vector<dof_id_type> & row_indices,
650 : const std::vector<dof_id_type> & column_indices,
651 : const Real scaling_factor)
652 : {
653 5904866 : for (const auto matrix_tag : _matrix_tags)
654 2952433 : assembly.cacheJacobianBlock(
655 5904866 : local_k, row_indices, column_indices, scaling_factor, Assembly::LocalDataKey{}, matrix_tag);
656 2952433 : }
657 :
658 : template <typename T>
659 : void
660 55761951 : TaggingInterface::setResidual(SystemBase & sys, const T & residual, MooseVariableFE<T> & var)
661 : {
662 112286218 : for (const auto tag_id : _vector_tags)
663 56524267 : if (sys.hasVector(tag_id))
664 55804929 : var.insertNodalValue(sys.getVector(tag_id), residual);
665 55761951 : }
666 :
667 : inline void
668 858564 : TaggingInterface::setResidual(SystemBase & sys, const Real residual, const dof_id_type dof_index)
669 : {
670 1717128 : for (const auto tag_id : _vector_tags)
671 858564 : if (sys.hasVector(tag_id))
672 858564 : sys.getVector(tag_id).set(dof_index, residual);
673 858564 : }
674 :
675 : template <typename SetResidualFunctor>
676 : void
677 : TaggingInterface::setResidual(SystemBase & sys, const SetResidualFunctor set_residual_functor)
678 : {
679 : for (const auto tag_id : _vector_tags)
680 : if (sys.hasVector(tag_id))
681 : set_residual_functor(sys.getVector(tag_id));
682 : }
|