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