17 template <
typename OutputType>
22 _subproblem(_sys.subproblem()),
24 _dof_map(_sys.dofMap()),
26 _has_dof_values(false),
33 _need_u_dotdot(false),
34 _need_u_dot_old(false),
35 _need_u_dotdot_old(false),
36 _need_du_dot_du(false),
37 _need_du_dotdot_du(false),
38 _need_grad_dot(false),
39 _need_grad_dotdot(false),
40 _need_dof_values_dot(false),
41 _need_dof_values_dotdot(false),
42 _need_dof_values_dot_old(false),
43 _need_dof_values_dotdot_old(false),
44 _need_dof_du_dot_du(false),
45 _need_dof_du_dotdot_du(false),
53 const auto max_future_num_vector_tags = num_vector_tags + 2;
83 template <
typename OutputType>
87 auto num_matrix_tags = _subproblem.numMatrixTags();
89 _matrix_tags_dof_u.resize(num_matrix_tags);
90 _need_matrix_tag_dof_u.resize(num_matrix_tags,
false);
92 _need_matrix_tag_u.resize(num_matrix_tags,
false);
93 _matrix_tag_u.resize(num_matrix_tags);
96 template <
typename OutputType>
102 if (tag >= _need_vector_tag_dof_u.size())
105 _need_vector_tag_dof_u[tag] =
true;
107 if (_sys.hasVector(tag))
108 return _vector_tags_dof_u[tag];
111 "Tag ", tag,
" is not associated with any vector for nodal variable ", _var.name());
114 mooseError(
"Nodal values can be requested only on nodal variables, variable '",
119 template <
typename OutputType>
125 if (tag >= _matrix_tags_dof_u.size())
127 _need_matrix_tag_dof_u.
resize(tag + 1,
false);
131 _need_matrix_tag_dof_u[tag] =
true;
133 if (_sys.hasMatrix(tag))
134 return _matrix_tags_dof_u[tag];
137 "Tag ", tag,
" is not associated with any matrix for nodal variable ", _var.name());
140 mooseError(
"Nodal values can be requested only on nodal variables, variable '",
145 template <
typename OutputType>
149 mooseAssert(_need_vector_tag_dof_u.size() == _need_vector_tag_u.size() &&
150 _need_vector_tag_dof_u.size() == _need_vector_tag_grad.size() &&
151 _need_vector_tag_dof_u.size() == _vector_tags_dof_u.size() &&
152 _need_vector_tag_dof_u.size() == _vector_tag_u.size() &&
153 _need_vector_tag_dof_u.size() == _vector_tag_grad.size(),
154 "These sizes should be in sync.");
156 auto check_capacity = [tag](
const auto & vector_to_check)
158 if (tag + 1 > vector_to_check.capacity())
159 mooseError(
"New size greater than tag capacity. This will cause reallocation which will " 160 "invalidate any stored references.");
162 check_capacity(_need_vector_tag_dof_u);
163 check_capacity(_need_vector_tag_u);
164 check_capacity(_need_vector_tag_grad);
165 check_capacity(_vector_tags_dof_u);
166 check_capacity(_vector_tag_u);
167 check_capacity(_vector_tag_grad);
169 _need_vector_tag_dof_u.resize(tag + 1,
false);
170 _need_vector_tag_u.resize(tag + 1,
false);
171 _need_vector_tag_grad.resize(tag + 1,
false);
172 _vector_tags_dof_u.resize(tag + 1);
173 _vector_tag_u.resize(tag + 1);
174 _vector_tag_grad.resize(tag + 1);
177 template <
typename OutputType>
181 if (tag >= _need_vector_tag_u.size())
184 _var.requireQpComputations();
186 _need_vector_tag_u[tag] =
true;
188 if (_sys.hasVector(tag))
189 return _vector_tag_u[tag];
191 mooseError(
"Tag ", tag,
" is not associated with any vector for variable ", _var.name());
194 template <
typename OutputType>
198 if (tag >= _need_vector_tag_dof_u.size())
201 _var.requireQpComputations();
203 _need_vector_tag_dof_u[tag] =
true;
205 if (_sys.hasVector(tag))
206 return _vector_tags_dof_u[tag];
208 mooseError(
"Tag ", tag,
" is not associated with any vector for variable ", _var.name());
211 template <
typename OutputType>
215 if (tag >= _need_vector_tag_grad.size())
218 _var.requireQpComputations();
220 _need_vector_tag_grad[tag] =
true;
222 if (_sys.hasVector(tag))
223 return _vector_tag_grad[tag];
225 mooseError(
"Tag ", tag,
" is not associated with any vector for variable ", _var.name());
228 template <
typename OutputType>
232 if (tag >= _matrix_tag_u.size())
234 _need_matrix_tag_u.
resize(tag + 1,
false);
238 _var.requireQpComputations();
240 _need_matrix_tag_u[tag] =
true;
242 if (_sys.hasMatrix(tag))
243 return _matrix_tag_u[tag];
245 mooseError(
"Tag ", tag,
" is not associated with any matrix for variable ", _var.name());
248 template <
typename OutputType>
255 template <
typename OutputType>
259 if (state > _max_state)
261 _sys.needSolutionState(state);
266 template <
typename OutputType>
267 template <
typename ReturnType,
typename Functor>
276 needSolutionState(cast_int<unsigned int>(state));
287 insertSolutionTag(_old_solution_tag);
288 return functor(_old_solution_tag);
294 insertSolutionTag(_older_solution_tag);
295 return functor(_older_solution_tag);
301 insertSolutionTag(_previous_nl_solution_tag);
302 return functor(_previous_nl_solution_tag);
312 template <
typename OutputType>
317 {
return vectorTagValue(tag_id); };
319 _var.requireQpComputations();
322 ->stateToTagHelper<FieldVariableValue>(state, functor);
325 template <
typename OutputType>
330 {
return vectorTagGradient(tag_id); };
332 _var.requireQpComputations();
335 ->stateToTagHelper<FieldVariableGradient>(state, functor);
338 template <
typename OutputType>
342 auto functor = [
this](
TagID tag_id) ->
const DofValues & {
return vectorTagDofValue(tag_id); };
344 _var.requireQpComputations();
350 template <
typename OutputType>
357 template <
typename OutputType>
364 template <
typename OutputType>
371 template <
typename OutputType>
378 template <
typename OutputType>
382 auto & dof_values = _vector_tags_dof_u[_solution_tag];
383 mooseAssert(
idx < dof_values.size(),
"idx is out of the bounds of degree of freedom values");
385 _has_dof_values =
true;
386 _nodal_value =
value;
389 auto & u = _vector_tag_u[_solution_tag];
390 for (
unsigned int qp = 0; qp < u.size(); qp++)
399 auto & dof_values = _vector_tags_dof_u[_solution_tag];
400 for (decltype(
idx) i = 0; i < dof_values.size(); ++i, ++
idx)
403 _has_dof_values =
true;
404 _nodal_value =
value;
407 template <
typename OutputType>
413 const auto & dof_values = _vector_tags_dof_u[_solution_tag];
414 mooseAssert(dof_values.size() == _dof_indices.size(),
415 "Degree of freedom values size and degree of freedom indices sizes must match.");
416 residual.
insert(&dof_values[0], _dof_indices);
426 const auto & dof_values = _vector_tags_dof_u[_solution_tag];
427 mooseAssert(_dof_indices.size() % _count == 0,
428 "Dof indices should be cleanly divisible by the variable count");
429 const auto n_shapes = _dof_indices.size() / _count;
432 const auto i = indx % n_shapes;
433 const auto j = indx / n_shapes;
434 residual.
set(_dof_indices[indx], dof_values[i](j));
439 template <
typename OutputType>
445 const auto & dof_values = _vector_tags_dof_u[_solution_tag];
446 residual.
add_vector(&dof_values[0], _dof_indices);
456 const auto & dof_values = _vector_tags_dof_u[_solution_tag];
457 mooseAssert(_dof_indices.size() % _count == 0,
458 "Dof indices should be cleanly divisible by the variable count");
459 const auto n_shapes = _dof_indices.size() / _count;
462 const auto i = indx % n_shapes;
463 const auto j = indx / n_shapes;
464 residual.
add(_dof_indices[indx], dof_values[i](j));
469 template <
typename OutputType>
476 vectorTagDofValue(state);
483 return _nodal_value_old;
486 return _nodal_value_older;
489 return _nodal_value_previous_nl;
498 mooseError(
"Nodal values can be requested only on nodal variables, variable '",
503 template <
typename OutputType>
510 vectorTagDofValue(state);
514 return _nodal_value_array;
517 return _nodal_value_old_array;
520 return _nodal_value_older_array;
523 mooseError(
"No current support for PreviousNL for nodal value array");
527 mooseError(
"Nodal values can be requested only on nodal variables, variable '",
532 template <
typename OutputType>
536 bool is_transient = _subproblem.isTransient();
538 auto n = _dof_indices.size();
543 if (_need_u_dot || _need_grad_dot || _need_dof_values_dot)
546 _dof_values_dot.resize(n);
547 _sys.solutionUDot()->get(_dof_indices, &_dof_values_dot[0]);
549 if (_need_u_dotdot || _need_grad_dotdot || _need_dof_values_dotdot)
552 _dof_values_dotdot.resize(n);
553 _sys.solutionUDotDot()->get(_dof_indices, &_dof_values_dotdot[0]);
555 if (_need_u_dot_old || _need_dof_values_dot_old)
558 _dof_values_dot_old.resize(n);
559 _sys.solutionUDotOld()->get(_dof_indices, &_dof_values_dot_old[0]);
561 if (_need_u_dotdot_old || _need_dof_values_dotdot_old)
564 _dof_values_dotdot_old.resize(n);
565 _sys.solutionUDotDotOld()->get(_dof_indices, &_dof_values_dotdot_old[0]);
569 for (
auto tag : _required_vector_tags)
570 if (_need_vector_tag_u[tag] || _need_vector_tag_grad[tag] || _need_vector_tag_dof_u[tag])
572 _subproblem.safeAccessTaggedVectors()) ||
579 if (_sys.hasVector(tag) )
581 auto & vec = _sys.getVector(tag);
582 _vector_tags_dof_u[tag].resize(n);
583 vec.get(_dof_indices, &_vector_tags_dof_u[tag][0]);
587 if (_subproblem.safeAccessTaggedMatrices())
589 auto & active_coupleable_matrix_tags =
590 _subproblem.getActiveFEVariableCoupleableMatrixTags(_tid);
592 for (
auto tag : active_coupleable_matrix_tags)
594 _matrix_tags_dof_u[tag].resize(n);
595 if (_need_matrix_tag_dof_u[tag] || _need_matrix_tag_u[tag])
596 if (_sys.hasMatrix(tag) && _sys.matrixTagActive(tag))
598 mooseAssert(_sys.getMatrix(tag).closed(),
599 "Matrix with tag '" + std::to_string(tag) +
"' should be closed");
600 auto & mat = _sys.getMatrix(tag);
601 for (
unsigned i = 0; i < n; i++)
602 _matrix_tags_dof_u[tag][i] = mat(_dof_indices[i], _dof_indices[i]);
607 if (_need_du_dot_du || _need_dof_du_dot_du)
609 _dof_du_dot_du.resize(n);
610 for (decltype(n) i = 0; i < n; ++i)
611 _dof_du_dot_du[i] = _sys.duDotDu(_var.number());
613 if (_need_du_dotdot_du || _need_dof_du_dotdot_du)
615 _dof_du_dotdot_du.resize(n);
616 for (decltype(n) i = 0; i < n; ++i)
617 _dof_du_dotdot_du[i] = _sys.duDotDotDu();
621 template <
typename OutputType>
624 const unsigned int nshapes,
627 dof_values.
resize(nshapes);
630 dof_values[i].
resize(_count);
632 dof_values[i](j) = sol(_dof_indices[j * nshapes + i]);
640 bool is_transient = _subproblem.isTransient();
642 auto n = _dof_indices.size() / _count;
647 if (_need_u_dot || _need_grad_dot || _need_dof_values_dot)
650 getArrayDofValues(*_sys.solutionUDot(), n, _dof_values_dot);
652 if (_need_u_dotdot || _need_grad_dotdot || _need_dof_values_dotdot)
655 getArrayDofValues(*_sys.solutionUDot(), n, _dof_values_dotdot);
657 if (_need_u_dot_old || _need_dof_values_dot_old)
660 getArrayDofValues(*_sys.solutionUDotOld(), n, _dof_values_dot_old);
662 if (_need_u_dotdot_old || _need_dof_values_dotdot_old)
665 getArrayDofValues(*_sys.solutionUDotDotOld(), n, _dof_values_dotdot_old);
669 for (
auto tag : _required_vector_tags)
671 _subproblem.safeAccessTaggedVectors()) ||
674 if (_sys.hasVector(tag))
676 mooseAssert(_sys.getVector(tag).closed(),
677 "Vector with tag '" + std::to_string(tag) +
"' should be closed");
678 getArrayDofValues(_sys.getVector(tag), n, _vector_tags_dof_u[tag]);
681 if (_subproblem.safeAccessTaggedMatrices())
683 auto & active_coupleable_matrix_tags =
684 _subproblem.getActiveFEVariableCoupleableMatrixTags(_tid);
685 for (
auto tag : active_coupleable_matrix_tags)
687 _matrix_tags_dof_u[tag].resize(n);
688 if (_need_matrix_tag_dof_u[tag] || _need_matrix_tag_u[tag])
689 if (_sys.hasMatrix(tag) && _sys.matrixTagActive(tag))
691 mooseAssert(_sys.getMatrix(tag).closed(),
692 "Matrix with tag '" + std::to_string(tag) +
"' should be closed");
693 auto & mat = _sys.getMatrix(tag);
694 for (
unsigned i = 0; i < n; i++)
695 for (
unsigned j = 0; j < _count; j++)
696 _matrix_tags_dof_u[tag][i](j) = mat(_dof_indices[i] + j, _dof_indices[i] + j);
701 if (_need_du_dot_du || _need_dof_du_dot_du)
703 _dof_du_dot_du.resize(n);
704 for (decltype(n) i = 0; i < n; ++i)
705 _dof_du_dot_du[i] = _sys.duDotDu(_var.number());
707 if (_need_du_dotdot_du || _need_dof_du_dotdot_du)
709 _dof_du_dotdot_du.resize(n);
710 for (decltype(n) i = 0; i < n; ++i)
711 _dof_du_dotdot_du[i] = _sys.duDotDotDu();
715 template <
typename OutputType>
719 if (_subproblem.isTransient())
721 _dof_values_dot.resize(0);
722 _dof_values_dotdot.resize(0);
723 _dof_values_dot_old.resize(0);
724 _dof_values_dotdot_old.resize(0);
725 _dof_du_dot_du.resize(0);
726 _dof_du_dotdot_du.resize(0);
729 for (
auto & dof_values : _vector_tags_dof_u)
730 dof_values.resize(0);
732 _has_dof_values =
false;
735 template <
typename OutputType>
739 bool is_transient = _subproblem.isTransient();
742 auto & dof_values = _vector_tags_dof_u[_solution_tag];
743 _nodal_value = dof_values[0];
744 _nodal_value_array[0] = _nodal_value;
748 if (oldestSolutionStateRequested() >= 1)
750 _nodal_value_old = _vector_tags_dof_u[_old_solution_tag][0];
751 _nodal_value_old_array[0] = _nodal_value_old;
753 if (oldestSolutionStateRequested() >= 2)
755 _nodal_value_older = _vector_tags_dof_u[_older_solution_tag][0];
756 _nodal_value_older_array[0] = _nodal_value_older;
758 if (_need_dof_values_dot)
759 _nodal_value_dot = _dof_values_dot[0];
760 if (_need_dof_values_dotdot)
761 _nodal_value_dotdot = _dof_values_dotdot[0];
762 if (_need_dof_values_dot_old)
763 _nodal_value_dot_old = _dof_values_dot_old[0];
764 if (_need_dof_values_dotdot_old)
765 _nodal_value_dotdot_old = _dof_values_dotdot_old[0];
768 _nodal_value_previous_nl = _vector_tags_dof_u[_previous_nl_solution_tag][0];
775 bool is_transient = _subproblem.isTransient();
777 auto n = _dof_indices.size();
780 auto & dof_values = _vector_tags_dof_u[_solution_tag];
781 for (decltype(n) i = 0; i < n; ++i)
782 _nodal_value(i) = dof_values[i];
783 _nodal_value_array[0] = _nodal_value;
787 if (oldestSolutionStateRequested() >= 1)
789 auto & dof_values_old = _vector_tags_dof_u[_old_solution_tag];
790 for (decltype(n) i = 0; i < n; ++i)
791 _nodal_value_old(i) = dof_values_old[i];
792 _nodal_value_old_array[0] = _nodal_value_old;
794 if (oldestSolutionStateRequested() >= 2)
796 auto & dof_values_older = _vector_tags_dof_u[_older_solution_tag];
797 for (decltype(n) i = 0; i < n; ++i)
798 _nodal_value_older(i) = dof_values_older[i];
799 _nodal_value_older_array[0] = _nodal_value_older;
801 if (_need_dof_values_dot)
802 for (decltype(n) i = 0; i < n; ++i)
803 _nodal_value_dot(i) = _dof_values_dot[i];
804 if (_need_dof_values_dotdot)
805 for (decltype(n) i = 0; i < n; ++i)
806 _nodal_value_dotdot(i) = _dof_values_dotdot[i];
807 if (_need_dof_values_dot_old)
808 for (decltype(n) i = 0; i < n; ++i)
809 _nodal_value_dot_old(i) = _dof_values_dot_old[i];
810 if (_need_dof_values_dotdot_old)
811 for (decltype(n) i = 0; i < n; ++i)
812 _nodal_value_dotdot_old(i) = _dof_values_dotdot_old[i];
816 auto & dof_values_previous_nl = _vector_tags_dof_u[_previous_nl_solution_tag];
817 for (decltype(n) i = 0; i < n; ++i)
818 _nodal_value_previous_nl(i) = dof_values_previous_nl[i];
virtual TagID getVectorTagID(const TagName &tag_name) const
Get a TagID from a TagName.
virtual void insert(const Number *v, const std::vector< numeric_index_type > &dof_indices)
void resizeVectorTagData(TagID tag)
resize the vector tag need flags and data containers to accomodate this tag index ...
const FieldVariableValue & matrixTagValue(TagID tag) const
Class for stuff related to variables.
const ReturnType & stateToTagHelper(Moose::SolutionState state, Functor functor)
Helper method that converts a SolutionState argument into a corresponding tag ID, potentially request...
void sizeMatrixTagData()
size matrix tag data
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
const FieldVariableGradient & vectorTagGradient(TagID tag) const
const TagName OLDER_SOLUTION_TAG
virtual void add_vector(const Number *v, const std::vector< numeric_index_type > &dof_indices)
const DofValues & nodalVectorTagValue(TagID tag) const
const MooseArray< OutputType > & nodalValueArray(Moose::SolutionState state) const
std::vector< bool > _need_vector_tag_u
void getArrayDofValues(const libMesh::NumericVector< libMesh::Number > &sol, unsigned int n, MooseArray< RealEigenVector > &dof_values) const
const SubProblem & _subproblem
The subproblem which we can query for information related to tagged vectors and matrices.
Base class for a system (of equations)
std::vector< bool > _need_vector_tag_grad
const DofValues & vectorTagDofValue(TagID tag) const
std::vector< bool > _need_vector_tag_dof_u
void add(libMesh::NumericVector< libMesh::Number > &residual)
Add the current local DOF values to the input vector.
void setNodalValue(const OutputType &value, unsigned int idx=0)
Set nodal value.
void insert(libMesh::NumericVector< libMesh::Number > &residual)
Set the current local DOF values to the input vector.
const FieldVariableGradient & gradSln(Moose::SolutionState state) const
Local solution gradient getter.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
FunctorEnvelope< T > Functor
const TagName OLD_SOLUTION_TAG
MooseArray< OutputType > _nodal_value_array
Nodal values as MooseArrays for use with AuxKernels.
const OutputType & nodalValue(Moose::SolutionState state) const
const DofValues & nodalMatrixTagValue(TagID tag) const
void insertSolutionTag(TagID tag_id)
insert a solution tag into our tag containers
std::vector< DofValues > _vector_tags_dof_u
MooseVariableDataBase(const MooseVariableField< OutputType > &var, SystemBase &sys, THREAD_ID tid)
const DofValues & dofValuesOlder() const
MooseArray< OutputType > _nodal_value_old_array
const FieldVariableValue & vectorTagValue(TagID tag) const
void fetchDofValues()
Helper methods for assigning dof values from their corresponding solution values. ...
const TagID INVALID_TAG_ID
const DofValues & dofValuesPreviousNL() const
std::vector< FieldVariableGradient > _vector_tag_grad
IntRange< T > make_range(T beg, T end)
void resize(unsigned int size)
Change the number of elements the array can store.
virtual unsigned int numVectorTags(const Moose::VectorTagType type=Moose::VECTOR_TAG_ANY) const
The total number of tags, which can be limited to the tag type.
const FieldVariableValue & sln(Moose::SolutionState state) const
Local solution getter.
const TagName SOLUTION_TAG
MooseArray< OutputType > _nodal_value_older_array
virtual void set(const numeric_index_type i, const Number value)=0
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
void needSolutionState(unsigned int state)
Request that we have at least state number of older solution states/vectors.
std::vector< FieldVariableValue > _vector_tag_u
virtual void add(const numeric_index_type i, const Number value)=0
const DofValues & dofValuesOld() const
const TagName PREVIOUS_NL_SOLUTION_TAG
auto index_range(const T &sizable)
unsigned int oldestSolutionStateRequested() const
The oldest solution state that is requested for this variable (0 = current, 1 = old, 2 = older, etc).
const DofValues & dofValues() const