LCOV - code coverage report
Current view: top level - include/variables - MooseVariableDependencyInterface.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 12 12 100.0 %
Date: 2025-07-17 01:28:37 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14