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 "MooseTypes.h" 13 : 14 : #include "libmesh/id_types.h" 15 : 16 : #include <set> 17 : #include <vector> 18 : #include <algorithm> 19 : 20 : class MooseObject; 21 : class MooseVariableFieldBase; 22 : namespace libMesh 23 : { 24 : class DofObject; 25 : } 26 : 27 : class MooseVariableDependencyInterface 28 : { 29 : public: 30 : // Must be a pointer in order to disambiguate with default copy constructor 31 : MooseVariableDependencyInterface(const MooseObject *); 32 : 33 : #ifdef MOOSE_KOKKOS_ENABLED 34 : /** 35 : * Special constructor used for Kokkos functor copy during parallel dispatch 36 : */ 37 : MooseVariableDependencyInterface(const MooseVariableDependencyInterface &, 38 : const Moose::Kokkos::FunctorCopy & key); 39 : #endif 40 : 41 : /** 42 : * Retrieve the set of MooseVariableFieldBase that _this_ object depends on. 43 : * @return The MooseVariableFieldBase that MUST be reinited before evaluating this object 44 : */ 45 18707859 : const std::set<MooseVariableFieldBase *> & getMooseVariableDependencies() const 46 : { 47 18707859 : return _moose_variable_dependencies; 48 : } 49 : 50 : /** 51 : * Check whether all of the variable dependencies have degree of freedom indices on the supplied 52 : * degree of freedom object 53 : * @param dof_object The degree of freedom object (an element or node) that we want to check for 54 : * existence of variable degrees of freedom on 55 : * @param vars_to_omit Variables that we can omit from checking 56 : * @return Any variables that do not have degrees of freedom on the supplied degree of freedom 57 : * object 58 : */ 59 : template <typename DofObjectType> 60 : std::set<MooseVariableFieldBase *> 61 : checkAllVariables(const DofObjectType & dof_object, 62 : const std::set<MooseVariableFieldBase *> & vars_to_omit = {}); 63 : 64 : /** 65 : * Check whether all of the supplied variables have degree of freedom indices on the supplied 66 : * degree of freedom object 67 : * @param dof_object The degree of freedom object (an element or node) that we want to check for 68 : * existence of variable degrees of freedom on 69 : * @param vars_to_check the variables to check 70 : * @return Any variables that do not have degrees of freedom on the supplied degree of freedom 71 : * object 72 : */ 73 : template <typename DofObjectType> 74 : std::set<MooseVariableFieldBase *> 75 : checkVariables(const DofObjectType & dof_object, 76 : const std::set<MooseVariableFieldBase *> & vars_to_check); 77 : 78 : /** 79 : * Call this function to add the passed in MooseVariableFieldBase as a variable that _this_ object 80 : * depends on. 81 : */ 82 413384 : void addMooseVariableDependency(MooseVariableFieldBase * var) 83 : { 84 413384 : _moose_variable_dependencies.insert(var); 85 413384 : } 86 : void addMooseVariableDependency(const std::vector<MooseVariableFieldBase *> & vars) 87 : { 88 : _moose_variable_dependencies.insert(vars.begin(), vars.end()); 89 : } 90 : 91 : private: 92 : std::set<MooseVariableFieldBase *> _moose_variable_dependencies; 93 : 94 : /// A container for holding dof indices in order to avoid constant memory reallocation 95 : std::vector<libMesh::dof_id_type> _dof_indices; 96 : }; 97 : 98 : template <typename DofObjectType> 99 : std::set<MooseVariableFieldBase *> 100 1327211 : MooseVariableDependencyInterface::checkAllVariables( 101 : const DofObjectType & dof_object, const std::set<MooseVariableFieldBase *> & vars_to_omit) 102 : { 103 1327211 : if (vars_to_omit.empty()) 104 322327 : return checkVariables(dof_object, _moose_variable_dependencies); 105 : 106 1004884 : std::set<MooseVariableFieldBase *> vars_to_check; 107 1004884 : std::set_difference(_moose_variable_dependencies.begin(), 108 : _moose_variable_dependencies.end(), 109 : vars_to_omit.begin(), 110 : vars_to_omit.end(), 111 : std::inserter(vars_to_check, vars_to_check.begin())); 112 1004884 : return checkVariables(dof_object, vars_to_check); 113 1004884 : }