LCOV - code coverage report
Current view: top level - include/variables - MooseVariableBase.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 16 26 61.5 %
Date: 2025-07-17 01:28:37 Functions: 16 23 69.6 %
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 "MooseObject.h"
      13             : #include "BlockRestrictable.h"
      14             : #include "OutputInterface.h"
      15             : #include "SetupInterface.h"
      16             : #include "MooseTypes.h"
      17             : #include "MooseArray.h"
      18             : #include "MooseError.h"
      19             : 
      20             : #include "libmesh/fe_type.h"
      21             : #include "libmesh/enum_fe_family.h"
      22             : 
      23             : // libMesh forward declarations
      24             : namespace libMesh
      25             : {
      26             : class DofMap;
      27             : class Variable;
      28             : }
      29             : 
      30             : class Assembly;
      31             : class SubProblem;
      32             : class SystemBase;
      33             : class MooseMesh;
      34             : 
      35             : class MooseVariableBase : public MooseObject,
      36             :                           public BlockRestrictable,
      37             :                           public OutputInterface,
      38             :                           public SetupInterface
      39             : {
      40             : public:
      41             :   static InputParameters validParams();
      42             : 
      43             :   MooseVariableBase(const InputParameters & parameters);
      44             : 
      45             :   /// Returns the variable name of a component of an array variable
      46             :   const std::string & arrayVariableComponent(const unsigned int i) const;
      47             : 
      48             :   /**
      49             :    * Get variable number coming from libMesh
      50             :    * @return the libmesh variable number
      51             :    */
      52  7242970098 :   unsigned int number() const { return _var_num; }
      53             : 
      54             :   /**
      55             :    * Get the type of finite element object
      56             :    */
      57     9664330 :   const libMesh::FEType & feType() const { return _fe_type; }
      58             : 
      59             :   /**
      60             :    * Get the system this variable is part of.
      61             :    */
      62  1494810189 :   SystemBase & sys() { return _sys; }
      63             : 
      64             :   /**
      65             :    * Get the system this variable is part of.
      66             :    */
      67       17141 :   const SystemBase & sys() const { return _sys; }
      68             : 
      69             :   /**
      70             :    * Get the variable name
      71             :    */
      72      921087 :   const std::string & name() const override { return _var_name; }
      73             : 
      74             :   /**
      75             :    * Get dual mortar option
      76             :    */
      77      496217 :   bool useDual() const { return _use_dual; }
      78             : 
      79             :   /**
      80             :    * Get all global dofindices for the variable
      81             :    */
      82             :   const std::vector<dof_id_type> & allDofIndices() const;
      83             :   unsigned int totalVarDofs() { return allDofIndices().size(); }
      84             : 
      85             :   /**
      86             :    * Kind of the variable (Nonlinear, Auxiliary, ...)
      87             :    */
      88    29789354 :   Moose::VarKindType kind() const { return _var_kind; }
      89             : 
      90             :   /**
      91             :    * Set the scaling factor for this variable
      92             :    */
      93             :   void scalingFactor(const std::vector<Real> & factor);
      94             : 
      95             :   /**
      96             :    * Get the scaling factor for this variable
      97             :    */
      98    57898522 :   Real scalingFactor() const { return _scaling_factor[0]; }
      99  1240953779 :   const std::vector<Real> & arrayScalingFactor() const { return _scaling_factor; }
     100             : 
     101             :   /**
     102             :    * Get the order of this variable
     103             :    * Note: Order enum can be implicitly converted to unsigned int.
     104             :    */
     105             :   libMesh::Order order() const;
     106             : 
     107             :   /**
     108             :    * Get the number of components
     109             :    * Note: For standard and vector variables, the number is one.
     110             :    */
     111  2455286541 :   unsigned int count() const { return _count; }
     112             : 
     113             :   /**
     114             :    * Is this variable nodal
     115             :    * @return true if it nodal, otherwise false
     116             :    */
     117           0 :   virtual bool isNodal() const { mooseError("Base class cannot determine this"); }
     118             : 
     119             :   /**
     120             :    * Does this variable have DoFs on nodes
     121             :    * @return true if it does, false if not.
     122             :    */
     123           0 :   virtual bool hasDoFsOnNodes() const { mooseError("Base class cannot determine this"); };
     124             : 
     125             :   /**
     126             :    * Return the continuity of this variable
     127             :    */
     128           0 :   virtual libMesh::FEContinuity getContinuity() const
     129             :   {
     130           0 :     mooseError("Base class cannot determine this");
     131             :   };
     132             : 
     133             :   /**
     134             :    * The DofMap associated with the system this variable is in.
     135             :    */
     136     3847116 :   const libMesh::DofMap & dofMap() const { return _dof_map; }
     137             : 
     138           0 :   virtual void getDofIndices(const Elem * /*elem*/,
     139             :                              std::vector<dof_id_type> & /*dof_indices*/) const
     140             :   {
     141           0 :     mooseError("not implemented");
     142             :   };
     143             : 
     144             :   /**
     145             :    * Get local DoF indices
     146             :    */
     147     6154557 :   virtual const std::vector<dof_id_type> & dofIndices() const { return _dof_indices; }
     148             : 
     149             :   /**
     150             :    * Obtain DoF indices of a component with the indices of the 0th component
     151             :    */
     152             :   std::vector<dof_id_type> componentDofIndices(const std::vector<dof_id_type> & dof_indices,
     153             :                                                unsigned int component) const;
     154             : 
     155             :   /**
     156             :    * Get the number of local DoFs
     157             :    */
     158           0 :   virtual unsigned int numberOfDofs() const { return _dof_indices.size(); }
     159             : 
     160             :   /**
     161             :    * Whether or not this variable operates on an eigen kernel
     162             :    */
     163        2679 :   bool eigen() const { return _is_eigen; }
     164             : 
     165             :   /**
     166             :    * Mark this variable as an eigen var or non-eigen var
     167             :    */
     168        1346 :   void eigen(bool eigen) { _is_eigen = eigen; }
     169             : 
     170             :   void initialSetup() override;
     171             : 
     172           0 :   virtual void clearAllDofIndices() { _dof_indices.clear(); }
     173             : 
     174             :   /**
     175             :    * Set the active vector tags
     176             :    * @param vtags Additional vector tags that this variable will need to query at dof indices for,
     177             :    * in addition to our own required solution tags
     178             :    */
     179             :   virtual void setActiveTags(const std::set<TagID> & vtags);
     180             : 
     181             :   /**
     182             :    * @return whether this is an array variable
     183             :    */
     184     1086611 :   virtual bool isArray() const { return !_array_var_component_names.empty(); }
     185             : 
     186             :   /**
     187             :    * @return whether this variable lives on lower dimensional blocks
     188             :    */
     189        1308 :   bool isLowerD() const { return _is_lower_d; }
     190             : 
     191             : protected:
     192             :   /**
     193             :    * @returns whether we should insert derivatives
     194             :    */
     195             :   bool doDerivatives() const;
     196             : 
     197             :   /// System this variable is part of
     198             :   SystemBase & _sys;
     199             : 
     200             :   /// The FEType associated with this variable
     201             :   libMesh::FEType _fe_type;
     202             : 
     203             :   /// variable number (from libMesh)
     204             :   unsigned int _var_num;
     205             : 
     206             :   /// variable number within MOOSE
     207             :   unsigned int _index;
     208             : 
     209             :   /// Whether or not this variable operates on eigen kernels
     210             :   bool _is_eigen;
     211             : 
     212             :   /// Variable type (see MooseTypes.h)
     213             :   Moose::VarKindType _var_kind;
     214             : 
     215             :   /// Problem this variable is part of
     216             :   SubProblem & _subproblem;
     217             : 
     218             :   /// libMesh variable object for this variable
     219             :   const libMesh::Variable & _variable;
     220             : 
     221             :   /// Assembly data
     222             :   Assembly & _assembly;
     223             : 
     224             :   /// DOF map
     225             :   const libMesh::DofMap & _dof_map;
     226             : 
     227             :   /// DOF indices
     228             :   std::vector<dof_id_type> _dof_indices;
     229             : 
     230             :   /// mesh the variable is active in
     231             :   MooseMesh & _mesh;
     232             : 
     233             :   /// Thread ID
     234             :   THREAD_ID _tid;
     235             : 
     236             :   /// Number of variables in the array
     237             :   const unsigned int _count;
     238             : 
     239             :   /// scaling factor for this variable
     240             :   std::vector<Real> _scaling_factor;
     241             : 
     242             :   /// Variable name
     243             :   std::string _var_name;
     244             : 
     245             :   /// If dual mortar approach is used
     246             :   bool _use_dual;
     247             : 
     248             :   /// Whether this variable lives on lower dimensional blocks
     249             :   bool _is_lower_d;
     250             : 
     251             :   /// Array variable names when the variable is an array variable
     252             :   std::vector<std::string> _array_var_component_names;
     253             : };
     254             : 
     255             : inline void
     256           0 : MooseVariableBase::setActiveTags(const std::set<TagID> &)
     257             : {
     258           0 :   mooseError("setActiveTags must be overridden in derived classes.");
     259             : }
     260             : 
     261             : #define usingMooseVariableBaseMembers                                                              \
     262             :   using MooseVariableBase::_sys;                                                                   \
     263             :   using MooseVariableBase::_fe_type;                                                               \
     264             :   using MooseVariableBase::_var_num;                                                               \
     265             :   using MooseVariableBase::_index;                                                                 \
     266             :   using MooseVariableBase::_var_kind;                                                              \
     267             :   using MooseVariableBase::_subproblem;                                                            \
     268             :   using MooseVariableBase::_variable;                                                              \
     269             :   using MooseVariableBase::_assembly;                                                              \
     270             :   using MooseVariableBase::_dof_map;                                                               \
     271             :   using MooseVariableBase::_dof_indices;                                                           \
     272             :   using MooseVariableBase::_mesh;                                                                  \
     273             :   using MooseVariableBase::_tid;                                                                   \
     274             :   using MooseVariableBase::_count;                                                                 \
     275             :   using MooseVariableBase::_scaling_factor;                                                        \
     276             :   using MooseVariableBase::_var_name

Generated by: LCOV version 1.14