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;
91 template <
typename OutputType>
97 if (tag >= _need_vector_tag_dof_u.size())
100 _need_vector_tag_dof_u[tag] =
true;
102 if (_sys.hasVector(tag))
103 return _vector_tags_dof_u[tag];
106 "Tag ", tag,
" is not associated with any vector for nodal variable ", _var.name());
109 mooseError(
"Nodal values can be requested only on nodal variables, variable '",
114 template <
typename OutputType>
120 if (tag >= _matrix_tags_dof_u.size())
122 _need_matrix_tag_dof_u.
resize(tag + 1,
false);
126 _need_matrix_tag_dof_u[tag] =
true;
128 if (_sys.hasMatrix(tag))
129 return _matrix_tags_dof_u[tag];
132 "Tag ", tag,
" is not associated with any matrix for nodal variable ", _var.name());
135 mooseError(
"Nodal values can be requested only on nodal variables, variable '",
140 template <
typename OutputType>
144 mooseAssert(_need_vector_tag_dof_u.size() == _need_vector_tag_u.size() &&
145 _need_vector_tag_dof_u.size() == _need_vector_tag_grad.size() &&
146 _need_vector_tag_dof_u.size() == _vector_tags_dof_u.size() &&
147 _need_vector_tag_dof_u.size() == _vector_tag_u.size() &&
148 _need_vector_tag_dof_u.size() == _vector_tag_grad.size(),
149 "These sizes should be in sync.");
151 auto check_capacity = [tag](
const auto & vector_to_check)
153 if (tag + 1 > vector_to_check.capacity())
154 mooseError(
"New size greater than tag capacity. This will cause reallocation which will " 155 "invalidate any stored references.");
157 check_capacity(_need_vector_tag_dof_u);
158 check_capacity(_need_vector_tag_u);
159 check_capacity(_need_vector_tag_grad);
160 check_capacity(_vector_tags_dof_u);
161 check_capacity(_vector_tag_u);
162 check_capacity(_vector_tag_grad);
164 _need_vector_tag_dof_u.resize(tag + 1,
false);
165 _need_vector_tag_u.resize(tag + 1,
false);
166 _need_vector_tag_grad.resize(tag + 1,
false);
167 _vector_tags_dof_u.resize(tag + 1);
168 _vector_tag_u.resize(tag + 1);
169 _vector_tag_grad.resize(tag + 1);
172 template <
typename OutputType>
176 if (tag >= _need_vector_tag_u.size())
179 _need_vector_tag_u[tag] =
true;
181 if (_sys.hasVector(tag))
182 return _vector_tag_u[tag];
184 mooseError(
"Tag ", tag,
" is not associated with any vector for variable ", _var.name());
187 template <
typename OutputType>
191 if (tag >= _need_vector_tag_dof_u.size())
194 _need_vector_tag_dof_u[tag] =
true;
196 if (_sys.hasVector(tag))
197 return _vector_tags_dof_u[tag];
199 mooseError(
"Tag ", tag,
" is not associated with any vector for variable ", _var.name());
202 template <
typename OutputType>
206 if (tag >= _need_vector_tag_grad.size())
209 _need_vector_tag_grad[tag] =
true;
211 if (_sys.hasVector(tag))
212 return _vector_tag_grad[tag];
214 mooseError(
"Tag ", tag,
" is not associated with any vector for variable ", _var.name());
217 template <
typename OutputType>
221 if (tag >= _matrix_tag_u.size())
223 _need_matrix_tag_u.
resize(tag + 1,
false);
227 _need_matrix_tag_u[tag] =
true;
229 if (_sys.hasMatrix(tag))
230 return _matrix_tag_u[tag];
232 mooseError(
"Tag ", tag,
" is not associated with any matrix for variable ", _var.name());
235 template <
typename OutputType>
242 template <
typename OutputType>
246 if (state > _max_state)
248 _sys.needSolutionState(state);
253 template <
typename OutputType>
254 template <
typename ReturnType,
typename Functor>
263 needSolutionState(cast_int<unsigned int>(state));
274 insertSolutionTag(_old_solution_tag);
275 return functor(_old_solution_tag);
281 insertSolutionTag(_older_solution_tag);
282 return functor(_older_solution_tag);
288 insertSolutionTag(_previous_nl_solution_tag);
289 return functor(_previous_nl_solution_tag);
299 template <
typename OutputType>
304 {
return vectorTagValue(tag_id); };
307 ->stateToTagHelper<FieldVariableValue>(state, functor);
310 template <
typename OutputType>
315 {
return vectorTagGradient(tag_id); };
318 ->stateToTagHelper<FieldVariableGradient>(state, functor);
321 template <
typename OutputType>
325 auto functor = [
this](
TagID tag_id) ->
const DoFValue & {
return vectorTagDofValue(tag_id); };
331 template <
typename OutputType>
338 template <
typename OutputType>
345 template <
typename OutputType>
352 template <
typename OutputType>
359 template <
typename OutputType>
363 auto & dof_values = _vector_tags_dof_u[_solution_tag];
364 mooseAssert(
idx < dof_values.size(),
"idx is out of the bounds of degree of freedom values");
366 _has_dof_values =
true;
367 _nodal_value =
value;
370 auto & u = _vector_tag_u[_solution_tag];
371 for (
unsigned int qp = 0; qp < u.size(); qp++)
380 auto & dof_values = _vector_tags_dof_u[_solution_tag];
381 for (decltype(
idx) i = 0; i < dof_values.size(); ++i, ++
idx)
384 _has_dof_values =
true;
385 _nodal_value =
value;
388 template <
typename OutputType>
394 auto & dof_values = _vector_tags_dof_u[_solution_tag];
395 mooseAssert(dof_values.size() == _dof_indices.size(),
396 "Degree of freedom values size and degree of freedom indices sizes must match.");
397 residual.
insert(&dof_values[0], _dof_indices);
407 auto & dof_values = _vector_tags_dof_u[_solution_tag];
410 for (
unsigned int i = 0; i < _dof_indices.size(); ++i)
411 for (
unsigned int j = 0; j < _count; ++j)
412 residual.
set(_dof_indices[i] + j, dof_values[i](j));
417 for (
unsigned int j = 0; j < _count; ++j)
419 for (
unsigned int i = 0; i < _dof_indices.size(); ++i)
420 residual.
set(_dof_indices[i] + n, dof_values[i](j));
421 n += _dof_indices.size();
427 template <
typename OutputType>
433 auto & dof_values = _vector_tags_dof_u[_solution_tag];
434 residual.
add_vector(&dof_values[0], _dof_indices);
444 auto & dof_values = _vector_tags_dof_u[_solution_tag];
447 for (
unsigned int i = 0; i < _dof_indices.size(); ++i)
448 for (
unsigned int j = 0; j < _count; ++j)
449 residual.
add(_dof_indices[i] + j, dof_values[i](j));
454 for (
unsigned int j = 0; j < _count; ++j)
456 for (
unsigned int i = 0; i < _dof_indices.size(); ++i)
457 residual.
add(_dof_indices[i] + n, dof_values[i](j));
458 n += _dof_indices.size();
464 template <
typename OutputType>
471 vectorTagDofValue(state);
478 return _nodal_value_old;
481 return _nodal_value_older;
484 return _nodal_value_previous_nl;
493 mooseError(
"Nodal values can be requested only on nodal variables, variable '",
498 template <
typename OutputType>
505 vectorTagDofValue(state);
509 return _nodal_value_array;
512 return _nodal_value_old_array;
515 return _nodal_value_older_array;
518 mooseError(
"No current support for PreviousNL for nodal value array");
522 mooseError(
"Nodal values can be requested only on nodal variables, variable '",
527 template <
typename OutputType>
531 bool is_transient = _subproblem.isTransient();
533 auto n = _dof_indices.size();
538 if (_need_u_dot || _need_grad_dot || _need_dof_values_dot)
541 _dof_values_dot.resize(n);
542 _sys.solutionUDot()->get(_dof_indices, &_dof_values_dot[0]);
544 if (_need_u_dotdot || _need_grad_dotdot || _need_dof_values_dotdot)
547 _dof_values_dotdot.resize(n);
548 _sys.solutionUDotDot()->get(_dof_indices, &_dof_values_dotdot[0]);
550 if (_need_u_dot_old || _need_dof_values_dot_old)
553 _dof_values_dot_old.resize(n);
554 _sys.solutionUDotOld()->get(_dof_indices, &_dof_values_dot_old[0]);
556 if (_need_u_dotdot_old || _need_dof_values_dotdot_old)
559 _dof_values_dotdot_old.resize(n);
560 _sys.solutionUDotDotOld()->get(_dof_indices, &_dof_values_dotdot_old[0]);
564 for (
auto tag : _required_vector_tags)
565 if (_need_vector_tag_u[tag] || _need_vector_tag_grad[tag] || _need_vector_tag_dof_u[tag])
567 _subproblem.safeAccessTaggedVectors()) ||
573 if (_sys.hasVector(tag) )
575 auto & vec = _sys.getVector(tag);
576 _vector_tags_dof_u[tag].resize(n);
577 vec.get(_dof_indices, &_vector_tags_dof_u[tag][0]);
581 if (_subproblem.safeAccessTaggedMatrices())
583 auto & active_coupleable_matrix_tags =
584 _subproblem.getActiveFEVariableCoupleableMatrixTags(_tid);
586 for (
auto tag : active_coupleable_matrix_tags)
588 _matrix_tags_dof_u[tag].resize(n);
589 if (_need_matrix_tag_dof_u[tag] || _need_matrix_tag_u[tag])
590 if (_sys.hasMatrix(tag) && _sys.matrixTagActive(tag) && _sys.getMatrix(tag).closed())
592 auto & mat = _sys.getMatrix(tag);
593 for (
unsigned i = 0; i < n; i++)
595 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
596 _matrix_tags_dof_u[tag][i] = mat(_dof_indices[i], _dof_indices[i]);
602 if (_need_du_dot_du || _need_dof_du_dot_du)
604 _dof_du_dot_du.resize(n);
605 for (decltype(n) i = 0; i < n; ++i)
606 _dof_du_dot_du[i] = _sys.duDotDu(_var.number());
608 if (_need_du_dotdot_du || _need_dof_du_dotdot_du)
610 _dof_du_dotdot_du.resize(n);
611 for (decltype(n) i = 0; i < n; ++i)
612 _dof_du_dotdot_du[i] = _sys.duDotDotDu();
616 template <
typename OutputType>
625 for (
unsigned int i = 0; i < n; ++i)
627 dof_values[i].
resize(_count);
628 auto dof = _dof_indices[i];
629 for (
unsigned int j = 0; j < _count; ++j)
630 dof_values[i](j) = sol(dof++);
635 for (
unsigned int i = 0; i < n; ++i)
637 dof_values[i].
resize(_count);
638 auto dof = _dof_indices[i];
639 for (
unsigned int j = 0; j < _count; ++j)
641 dof_values[i](j) = sol(dof);
652 bool is_transient = _subproblem.isTransient();
654 auto n = _dof_indices.size();
659 if (_need_u_dot || _need_grad_dot || _need_dof_values_dot)
662 getArrayDoFValues(*_sys.solutionUDot(), n, _dof_values_dot);
664 if (_need_u_dotdot || _need_grad_dotdot || _need_dof_values_dotdot)
667 getArrayDoFValues(*_sys.solutionUDot(), n, _dof_values_dotdot);
669 if (_need_u_dot_old || _need_dof_values_dot_old)
672 getArrayDoFValues(*_sys.solutionUDotOld(), n, _dof_values_dot_old);
674 if (_need_u_dotdot_old || _need_dof_values_dotdot_old)
677 getArrayDoFValues(*_sys.solutionUDotDotOld(), n, _dof_values_dotdot_old);
681 for (
auto tag : _required_vector_tags)
683 _subproblem.safeAccessTaggedVectors()) ||
686 if (_sys.hasVector(tag) && _sys.getVector(tag).closed())
687 getArrayDoFValues(_sys.getVector(tag), n, _vector_tags_dof_u[tag]);
689 if (_subproblem.safeAccessTaggedMatrices())
691 auto & active_coupleable_matrix_tags =
692 _subproblem.getActiveFEVariableCoupleableMatrixTags(_tid);
693 for (
auto tag : active_coupleable_matrix_tags)
695 _matrix_tags_dof_u[tag].resize(n);
696 if (_need_matrix_tag_dof_u[tag] || _need_matrix_tag_u[tag])
697 if (_sys.hasMatrix(tag) && _sys.matrixTagActive(tag) && _sys.getMatrix(tag).closed())
699 auto & mat = _sys.getMatrix(tag);
700 for (
unsigned i = 0; i < n; i++)
702 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
703 for (
unsigned j = 0; j < _count; j++)
704 _matrix_tags_dof_u[tag][i](j) = mat(_dof_indices[i] + j, _dof_indices[i] + j);
710 if (_need_du_dot_du || _need_dof_du_dot_du)
712 _dof_du_dot_du.resize(n);
713 for (decltype(n) i = 0; i < n; ++i)
714 _dof_du_dot_du[i] = _sys.duDotDu(_var.number());
716 if (_need_du_dotdot_du || _need_dof_du_dotdot_du)
718 _dof_du_dotdot_du.resize(n);
719 for (decltype(n) i = 0; i < n; ++i)
720 _dof_du_dotdot_du[i] = _sys.duDotDotDu();
724 template <
typename OutputType>
728 if (_subproblem.isTransient())
730 _dof_values_dot.resize(0);
731 _dof_values_dotdot.resize(0);
732 _dof_values_dot_old.resize(0);
733 _dof_values_dotdot_old.resize(0);
734 _dof_du_dot_du.resize(0);
735 _dof_du_dotdot_du.resize(0);
738 for (
auto & dof_values : _vector_tags_dof_u)
739 dof_values.resize(0);
741 _has_dof_values =
false;
744 template <
typename OutputType>
748 bool is_transient = _subproblem.isTransient();
752 auto & dof_values = _vector_tags_dof_u[_solution_tag];
753 _nodal_value = dof_values[0];
754 _nodal_value_array[0] = _nodal_value;
758 if (oldestSolutionStateRequested() >= 1)
760 _nodal_value_old = _vector_tags_dof_u[_old_solution_tag][0];
761 _nodal_value_old_array[0] = _nodal_value_old;
763 if (oldestSolutionStateRequested() >= 2)
765 _nodal_value_older = _vector_tags_dof_u[_older_solution_tag][0];
766 _nodal_value_older_array[0] = _nodal_value_older;
768 if (_need_dof_values_dot)
769 _nodal_value_dot = _dof_values_dot[0];
770 if (_need_dof_values_dotdot)
771 _nodal_value_dotdot = _dof_values_dotdot[0];
772 if (_need_dof_values_dot_old)
773 _nodal_value_dot_old = _dof_values_dot_old[0];
774 if (_need_dof_values_dotdot_old)
775 _nodal_value_dotdot_old = _dof_values_dotdot_old[0];
778 _nodal_value_previous_nl = _vector_tags_dof_u[_previous_nl_solution_tag][0];
785 bool is_transient = _subproblem.isTransient();
787 auto n = _dof_indices.size();
790 auto & dof_values = _vector_tags_dof_u[_solution_tag];
791 for (decltype(n) i = 0; i < n; ++i)
792 _nodal_value(i) = dof_values[i];
793 _nodal_value_array[0] = _nodal_value;
797 if (oldestSolutionStateRequested() >= 1)
799 auto & dof_values_old = _vector_tags_dof_u[_old_solution_tag];
800 for (decltype(n) i = 0; i < n; ++i)
801 _nodal_value_old(i) = dof_values_old[i];
802 _nodal_value_old_array[0] = _nodal_value_old;
804 if (oldestSolutionStateRequested() >= 2)
806 auto & dof_values_older = _vector_tags_dof_u[_older_solution_tag];
807 for (decltype(n) i = 0; i < n; ++i)
808 _nodal_value_older(i) = dof_values_older[i];
809 _nodal_value_older_array[0] = _nodal_value_older;
811 if (_need_dof_values_dot)
812 for (decltype(n) i = 0; i < n; ++i)
813 _nodal_value_dot(i) = _dof_values_dot[i];
814 if (_need_dof_values_dotdot)
815 for (decltype(n) i = 0; i < n; ++i)
816 _nodal_value_dotdot(i) = _dof_values_dotdot[i];
817 if (_need_dof_values_dot_old)
818 for (decltype(n) i = 0; i < n; ++i)
819 _nodal_value_dot_old(i) = _dof_values_dot_old[i];
820 if (_need_dof_values_dotdot_old)
821 for (decltype(n) i = 0; i < n; ++i)
822 _nodal_value_dotdot_old(i) = _dof_values_dotdot_old[i];
826 auto & dof_values_previous_nl = _vector_tags_dof_u[_previous_nl_solution_tag];
827 for (decltype(n) i = 0; i < n; ++i)
828 _nodal_value_previous_nl(i) = dof_values_previous_nl[i];
virtual TagID getVectorTagID(const TagName &tag_name) const
Get a TagID from a TagName.
std::vector< DoFValue > _matrix_tags_dof_u
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
std::vector< FieldVariableValue > _matrix_tag_u
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 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)
void fetchDoFValues()
Helper methods for assigning dof values from their corresponding solution values. ...
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)
const DoFValue & nodalVectorTagValue(TagID tag) const
std::vector< bool > _need_vector_tag_grad
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.
const DoFValue & dofValues() const
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.
std::vector< DoFValue > _vector_tags_dof_u
const OutputType & nodalValue(Moose::SolutionState state) const
void insertSolutionTag(TagID tag_id)
insert a solution tag into our tag containers
MooseVariableDataBase(const MooseVariableField< OutputType > &var, SystemBase &sys, THREAD_ID tid)
const DoFValue & dofValuesOlder() const
MooseArray< OutputType > _nodal_value_old_array
std::vector< bool > _need_matrix_tag_u
virtual unsigned int numMatrixTags() const
The total number of tags.
const FieldVariableValue & vectorTagValue(TagID tag) const
const DoFValue & dofValuesPreviousNL() const
std::vector< bool > _need_matrix_tag_dof_u
const TagID INVALID_TAG_ID
const DoFValue & nodalMatrixTagValue(TagID tag) const
std::vector< FieldVariableGradient > _vector_tag_grad
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 DoFValue & dofValuesOld() const
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 TagName PREVIOUS_NL_SOLUTION_TAG
unsigned int oldestSolutionStateRequested() const
The oldest solution state that is requested for this variable (0 = current, 1 = old, 2 = older, etc).
const DoFValue & vectorTagDofValue(TagID tag) const