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 15563915 : const std::set<MooseVariableFieldBase *> & getMooseVariableDependencies() const 46 : { 47 15563915 : 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 : * node 67 : * @param node The 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 : virtual std::set<MooseVariableFieldBase *> 74 : checkVariables(const libMesh::Node & node, 75 : const std::set<MooseVariableFieldBase *> & vars_to_check); 76 : 77 : /** 78 : * Check whether all of the supplied variables have degree of freedom indices on the supplied 79 : * element 80 : * @param element The element that we want to check for 81 : * existence of variable degrees of freedom on 82 : * @param vars_to_check the variables to check 83 : * @return Any variables that do not have degrees of freedom on the supplied degree of freedom 84 : * object 85 : */ 86 : std::set<MooseVariableFieldBase *> 87 : checkVariables(const libMesh::Elem & element, 88 : const std::set<MooseVariableFieldBase *> & vars_to_check); 89 : 90 : /** 91 : * Call this function to add the passed in MooseVariableFieldBase as a variable that _this_ object 92 : * depends on. 93 : */ 94 386624 : void addMooseVariableDependency(MooseVariableFieldBase * var) 95 : { 96 386624 : _moose_variable_dependencies.insert(var); 97 386624 : } 98 : void addMooseVariableDependency(const std::vector<MooseVariableFieldBase *> & vars) 99 : { 100 : _moose_variable_dependencies.insert(vars.begin(), vars.end()); 101 : } 102 : 103 : private: 104 : /// Helper method for checking variables for dof indices. Returns the subset of variables of \p 105 : /// vars_to_check that do \emph not have dof indices on the provided \p dof_object 106 : template <typename DofObjectType> 107 : std::set<MooseVariableFieldBase *> 108 : checkVariablesHelper(const DofObjectType & dof_object, 109 : const std::set<MooseVariableFieldBase *> & vars_to_check); 110 : 111 : std::set<MooseVariableFieldBase *> _moose_variable_dependencies; 112 : 113 : /// A container for holding dof indices in order to avoid constant memory reallocation 114 : std::vector<libMesh::dof_id_type> _dof_indices; 115 : }; 116 : 117 : template <typename DofObjectType> 118 : std::set<MooseVariableFieldBase *> 119 1231712 : MooseVariableDependencyInterface::checkAllVariables( 120 : const DofObjectType & dof_object, const std::set<MooseVariableFieldBase *> & vars_to_omit) 121 : { 122 1231712 : if (vars_to_omit.empty()) 123 268277 : return checkVariables(dof_object, _moose_variable_dependencies); 124 : 125 963435 : std::set<MooseVariableFieldBase *> vars_to_check; 126 963435 : std::set_difference(_moose_variable_dependencies.begin(), 127 : _moose_variable_dependencies.end(), 128 : vars_to_omit.begin(), 129 : vars_to_omit.end(), 130 : std::inserter(vars_to_check, vars_to_check.begin())); 131 963435 : return checkVariables(dof_object, vars_to_check); 132 963435 : } 133 : 134 : inline std::set<MooseVariableFieldBase *> 135 978070 : MooseVariableDependencyInterface::checkVariables( 136 : const libMesh::Node & node, const std::set<MooseVariableFieldBase *> & vars_to_check) 137 : { 138 978070 : return checkVariablesHelper(node, vars_to_check); 139 : } 140 : 141 : inline std::set<MooseVariableFieldBase *> 142 256450 : MooseVariableDependencyInterface::checkVariables( 143 : const libMesh::Elem & element, const std::set<MooseVariableFieldBase *> & vars_to_check) 144 : { 145 256450 : return checkVariablesHelper(element, vars_to_check); 146 : }