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 _need_vector_tag_u[tag] =
true;
186 if (_sys.hasVector(tag))
187 return _vector_tag_u[tag];
189 mooseError(
"Tag ", tag,
" is not associated with any vector for variable ", _var.name());
192 template <
typename OutputType>
196 if (tag >= _need_vector_tag_dof_u.size())
199 _need_vector_tag_dof_u[tag] =
true;
201 if (_sys.hasVector(tag))
202 return _vector_tags_dof_u[tag];
204 mooseError(
"Tag ", tag,
" is not associated with any vector for variable ", _var.name());
207 template <
typename OutputType>
211 if (tag >= _need_vector_tag_grad.size())
214 _need_vector_tag_grad[tag] =
true;
216 if (_sys.hasVector(tag))
217 return _vector_tag_grad[tag];
219 mooseError(
"Tag ", tag,
" is not associated with any vector for variable ", _var.name());
222 template <
typename OutputType>
226 if (tag >= _matrix_tag_u.size())
228 _need_matrix_tag_u.
resize(tag + 1,
false);
232 _need_matrix_tag_u[tag] =
true;
234 if (_sys.hasMatrix(tag))
235 return _matrix_tag_u[tag];
237 mooseError(
"Tag ", tag,
" is not associated with any matrix for variable ", _var.name());
240 template <
typename OutputType>
247 template <
typename OutputType>
251 if (state > _max_state)
253 _sys.needSolutionState(state);
258 template <
typename OutputType>
259 template <
typename ReturnType,
typename Functor>
268 needSolutionState(cast_int<unsigned int>(state));
279 insertSolutionTag(_old_solution_tag);
280 return functor(_old_solution_tag);
286 insertSolutionTag(_older_solution_tag);
287 return functor(_older_solution_tag);
293 insertSolutionTag(_previous_nl_solution_tag);
294 return functor(_previous_nl_solution_tag);
304 template <
typename OutputType>
309 {
return vectorTagValue(tag_id); };
312 ->stateToTagHelper<FieldVariableValue>(state, functor);
315 template <
typename OutputType>
320 {
return vectorTagGradient(tag_id); };
323 ->stateToTagHelper<FieldVariableGradient>(state, functor);
326 template <
typename OutputType>
330 auto functor = [
this](
TagID tag_id) ->
const DofValues & {
return vectorTagDofValue(tag_id); };
336 template <
typename OutputType>
343 template <
typename OutputType>
350 template <
typename OutputType>
357 template <
typename OutputType>
364 template <
typename OutputType>
368 auto & dof_values = _vector_tags_dof_u[_solution_tag];
369 mooseAssert(
idx < dof_values.size(),
"idx is out of the bounds of degree of freedom values");
371 _has_dof_values =
true;
372 _nodal_value =
value;
375 auto & u = _vector_tag_u[_solution_tag];
376 for (
unsigned int qp = 0; qp < u.size(); qp++)
385 auto & dof_values = _vector_tags_dof_u[_solution_tag];
386 for (decltype(
idx) i = 0; i < dof_values.size(); ++i, ++
idx)
389 _has_dof_values =
true;
390 _nodal_value =
value;
393 template <
typename OutputType>
399 const auto & dof_values = _vector_tags_dof_u[_solution_tag];
400 mooseAssert(dof_values.size() == _dof_indices.size(),
401 "Degree of freedom values size and degree of freedom indices sizes must match.");
402 residual.
insert(&dof_values[0], _dof_indices);
412 const auto & dof_values = _vector_tags_dof_u[_solution_tag];
413 mooseAssert(_dof_indices.size() % _count == 0,
414 "Dof indices should be cleanly divisible by the variable count");
415 const auto n_shapes = _dof_indices.size() / _count;
418 const auto i = indx % n_shapes;
419 const auto j = indx / n_shapes;
420 residual.
set(_dof_indices[indx], dof_values[i](j));
425 template <
typename OutputType>
431 const auto & dof_values = _vector_tags_dof_u[_solution_tag];
432 residual.
add_vector(&dof_values[0], _dof_indices);
442 const auto & dof_values = _vector_tags_dof_u[_solution_tag];
443 mooseAssert(_dof_indices.size() % _count == 0,
444 "Dof indices should be cleanly divisible by the variable count");
445 const auto n_shapes = _dof_indices.size() / _count;
448 const auto i = indx % n_shapes;
449 const auto j = indx / n_shapes;
450 residual.
add(_dof_indices[indx], dof_values[i](j));
455 template <
typename OutputType>
462 vectorTagDofValue(state);
469 return _nodal_value_old;
472 return _nodal_value_older;
475 return _nodal_value_previous_nl;
484 mooseError(
"Nodal values can be requested only on nodal variables, variable '",
489 template <
typename OutputType>
496 vectorTagDofValue(state);
500 return _nodal_value_array;
503 return _nodal_value_old_array;
506 return _nodal_value_older_array;
509 mooseError(
"No current support for PreviousNL for nodal value array");
513 mooseError(
"Nodal values can be requested only on nodal variables, variable '",
518 template <
typename OutputType>
522 bool is_transient = _subproblem.isTransient();
524 auto n = _dof_indices.size();
529 if (_need_u_dot || _need_grad_dot || _need_dof_values_dot)
532 _dof_values_dot.resize(n);
533 _sys.solutionUDot()->get(_dof_indices, &_dof_values_dot[0]);
535 if (_need_u_dotdot || _need_grad_dotdot || _need_dof_values_dotdot)
538 _dof_values_dotdot.resize(n);
539 _sys.solutionUDotDot()->get(_dof_indices, &_dof_values_dotdot[0]);
541 if (_need_u_dot_old || _need_dof_values_dot_old)
544 _dof_values_dot_old.resize(n);
545 _sys.solutionUDotOld()->get(_dof_indices, &_dof_values_dot_old[0]);
547 if (_need_u_dotdot_old || _need_dof_values_dotdot_old)
550 _dof_values_dotdot_old.resize(n);
551 _sys.solutionUDotDotOld()->get(_dof_indices, &_dof_values_dotdot_old[0]);
555 for (
auto tag : _required_vector_tags)
556 if (_need_vector_tag_u[tag] || _need_vector_tag_grad[tag] || _need_vector_tag_dof_u[tag])
558 _subproblem.safeAccessTaggedVectors()) ||
565 if (_sys.hasVector(tag) )
567 auto & vec = _sys.getVector(tag);
568 _vector_tags_dof_u[tag].resize(n);
569 vec.get(_dof_indices, &_vector_tags_dof_u[tag][0]);
573 if (_subproblem.safeAccessTaggedMatrices())
575 auto & active_coupleable_matrix_tags =
576 _subproblem.getActiveFEVariableCoupleableMatrixTags(_tid);
578 for (
auto tag : active_coupleable_matrix_tags)
580 _matrix_tags_dof_u[tag].resize(n);
581 if (_need_matrix_tag_dof_u[tag] || _need_matrix_tag_u[tag])
582 if (_sys.hasMatrix(tag) && _sys.matrixTagActive(tag))
584 mooseAssert(_sys.getMatrix(tag).closed(),
585 "Matrix with tag '" + std::to_string(tag) +
"' should be closed");
586 auto & mat = _sys.getMatrix(tag);
587 for (
unsigned i = 0; i < n; i++)
588 _matrix_tags_dof_u[tag][i] = mat(_dof_indices[i], _dof_indices[i]);
593 if (_need_du_dot_du || _need_dof_du_dot_du)
595 _dof_du_dot_du.resize(n);
596 for (decltype(n) i = 0; i < n; ++i)
597 _dof_du_dot_du[i] = _sys.duDotDu(_var.number());
599 if (_need_du_dotdot_du || _need_dof_du_dotdot_du)
601 _dof_du_dotdot_du.resize(n);
602 for (decltype(n) i = 0; i < n; ++i)
603 _dof_du_dotdot_du[i] = _sys.duDotDotDu();
607 template <
typename OutputType>
610 const unsigned int nshapes,
613 dof_values.
resize(nshapes);
616 dof_values[i].
resize(_count);
618 dof_values[i](j) = sol(_dof_indices[j * nshapes + i]);
626 bool is_transient = _subproblem.isTransient();
628 auto n = _dof_indices.size() / _count;
633 if (_need_u_dot || _need_grad_dot || _need_dof_values_dot)
636 getArrayDofValues(*_sys.solutionUDot(), n, _dof_values_dot);
638 if (_need_u_dotdot || _need_grad_dotdot || _need_dof_values_dotdot)
641 getArrayDofValues(*_sys.solutionUDot(), n, _dof_values_dotdot);
643 if (_need_u_dot_old || _need_dof_values_dot_old)
646 getArrayDofValues(*_sys.solutionUDotOld(), n, _dof_values_dot_old);
648 if (_need_u_dotdot_old || _need_dof_values_dotdot_old)
651 getArrayDofValues(*_sys.solutionUDotDotOld(), n, _dof_values_dotdot_old);
655 for (
auto tag : _required_vector_tags)
657 _subproblem.safeAccessTaggedVectors()) ||
660 if (_sys.hasVector(tag))
662 mooseAssert(_sys.getVector(tag).closed(),
663 "Vector with tag '" + std::to_string(tag) +
"' should be closed");
664 getArrayDofValues(_sys.getVector(tag), n, _vector_tags_dof_u[tag]);
667 if (_subproblem.safeAccessTaggedMatrices())
669 auto & active_coupleable_matrix_tags =
670 _subproblem.getActiveFEVariableCoupleableMatrixTags(_tid);
671 for (
auto tag : active_coupleable_matrix_tags)
673 _matrix_tags_dof_u[tag].resize(n);
674 if (_need_matrix_tag_dof_u[tag] || _need_matrix_tag_u[tag])
675 if (_sys.hasMatrix(tag) && _sys.matrixTagActive(tag))
677 mooseAssert(_sys.getMatrix(tag).closed(),
678 "Matrix with tag '" + std::to_string(tag) +
"' should be closed");
679 auto & mat = _sys.getMatrix(tag);
680 for (
unsigned i = 0; i < n; i++)
681 for (
unsigned j = 0; j < _count; j++)
682 _matrix_tags_dof_u[tag][i](j) = mat(_dof_indices[i] + j, _dof_indices[i] + j);
687 if (_need_du_dot_du || _need_dof_du_dot_du)
689 _dof_du_dot_du.resize(n);
690 for (decltype(n) i = 0; i < n; ++i)
691 _dof_du_dot_du[i] = _sys.duDotDu(_var.number());
693 if (_need_du_dotdot_du || _need_dof_du_dotdot_du)
695 _dof_du_dotdot_du.resize(n);
696 for (decltype(n) i = 0; i < n; ++i)
697 _dof_du_dotdot_du[i] = _sys.duDotDotDu();
701 template <
typename OutputType>
705 if (_subproblem.isTransient())
707 _dof_values_dot.resize(0);
708 _dof_values_dotdot.resize(0);
709 _dof_values_dot_old.resize(0);
710 _dof_values_dotdot_old.resize(0);
711 _dof_du_dot_du.resize(0);
712 _dof_du_dotdot_du.resize(0);
715 for (
auto & dof_values : _vector_tags_dof_u)
716 dof_values.resize(0);
718 _has_dof_values =
false;
721 template <
typename OutputType>
725 bool is_transient = _subproblem.isTransient();
728 auto & dof_values = _vector_tags_dof_u[_solution_tag];
729 _nodal_value = dof_values[0];
730 _nodal_value_array[0] = _nodal_value;
734 if (oldestSolutionStateRequested() >= 1)
736 _nodal_value_old = _vector_tags_dof_u[_old_solution_tag][0];
737 _nodal_value_old_array[0] = _nodal_value_old;
739 if (oldestSolutionStateRequested() >= 2)
741 _nodal_value_older = _vector_tags_dof_u[_older_solution_tag][0];
742 _nodal_value_older_array[0] = _nodal_value_older;
744 if (_need_dof_values_dot)
745 _nodal_value_dot = _dof_values_dot[0];
746 if (_need_dof_values_dotdot)
747 _nodal_value_dotdot = _dof_values_dotdot[0];
748 if (_need_dof_values_dot_old)
749 _nodal_value_dot_old = _dof_values_dot_old[0];
750 if (_need_dof_values_dotdot_old)
751 _nodal_value_dotdot_old = _dof_values_dotdot_old[0];
754 _nodal_value_previous_nl = _vector_tags_dof_u[_previous_nl_solution_tag][0];
761 bool is_transient = _subproblem.isTransient();
763 auto n = _dof_indices.size();
766 auto & dof_values = _vector_tags_dof_u[_solution_tag];
767 for (decltype(n) i = 0; i < n; ++i)
768 _nodal_value(i) = dof_values[i];
769 _nodal_value_array[0] = _nodal_value;
773 if (oldestSolutionStateRequested() >= 1)
775 auto & dof_values_old = _vector_tags_dof_u[_old_solution_tag];
776 for (decltype(n) i = 0; i < n; ++i)
777 _nodal_value_old(i) = dof_values_old[i];
778 _nodal_value_old_array[0] = _nodal_value_old;
780 if (oldestSolutionStateRequested() >= 2)
782 auto & dof_values_older = _vector_tags_dof_u[_older_solution_tag];
783 for (decltype(n) i = 0; i < n; ++i)
784 _nodal_value_older(i) = dof_values_older[i];
785 _nodal_value_older_array[0] = _nodal_value_older;
787 if (_need_dof_values_dot)
788 for (decltype(n) i = 0; i < n; ++i)
789 _nodal_value_dot(i) = _dof_values_dot[i];
790 if (_need_dof_values_dotdot)
791 for (decltype(n) i = 0; i < n; ++i)
792 _nodal_value_dotdot(i) = _dof_values_dotdot[i];
793 if (_need_dof_values_dot_old)
794 for (decltype(n) i = 0; i < n; ++i)
795 _nodal_value_dot_old(i) = _dof_values_dot_old[i];
796 if (_need_dof_values_dotdot_old)
797 for (decltype(n) i = 0; i < n; ++i)
798 _nodal_value_dotdot_old(i) = _dof_values_dotdot_old[i];
802 auto & dof_values_previous_nl = _vector_tags_dof_u[_previous_nl_solution_tag];
803 for (decltype(n) i = 0; i < n; ++i)
804 _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