LCOV - code coverage report
Current view: top level - include/kokkos/base - KokkosVariable.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 17 17 100.0 %
Date: 2026-05-29 20:35:17 Functions: 12 12 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://www.mooseframework.org
       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 "KokkosTypes.h"
      13             : 
      14             : #include "MooseTypes.h"
      15             : #include "MooseVariableBase.h"
      16             : #include "MoosePassKey.h"
      17             : 
      18             : class Coupleable;
      19             : 
      20             : namespace Moose::Kokkos
      21             : {
      22             : 
      23             : /**
      24             :  * The Kokkos variable object that carries the coupled variable and tag information
      25             :  */
      26             : class Variable
      27             : {
      28             : public:
      29             :   using CoupleableKey = ::Moose::PassKey<::Coupleable>;
      30             : 
      31             :   /**
      32             :    * Default constructor
      33             :    */
      34       20529 :   Variable() = default;
      35             :   /**
      36             :    * Constructor
      37             :    * Initialize the variable with a MOOSE variable and vector tag ID
      38             :    * @param variable The MOOSE variable
      39             :    * @param tag The vector tag ID
      40             :    */
      41             :   Variable(const MooseVariableFieldBase & variable, const TagID tag) { init(variable, tag); }
      42             :   /**
      43             :    * Constructor
      44             :    * Initialize the variable with a MOOSE variable and vector tag name
      45             :    * @param variable The MOOSE variable
      46             :    * @param tag_name The vector tag name
      47             :    */
      48       12502 :   Variable(const MooseVariableFieldBase & variable, const TagName & tag_name = Moose::SOLUTION_TAG)
      49       12502 :   {
      50       12502 :     init(variable, tag_name);
      51       12502 :   }
      52             :   /**
      53             :    * Constructor
      54             :    * Initialize the variable with multiple MOOSE variables and vector tag ID
      55             :    * @param variables The MOOSE variables
      56             :    * @param tag The vector tag ID
      57             :    */
      58             :   ///@{
      59             :   Variable(const std::vector<const MooseVariableFieldBase *> & variables, const TagID tag)
      60             :   {
      61             :     init(variables, tag);
      62             :   }
      63             :   Variable(const std::vector<MooseVariableFieldBase *> & variables, const TagID tag)
      64             :   {
      65             :     init(variables, tag);
      66             :   }
      67             :   ///@}
      68             :   /**
      69             :    * Constructor
      70             :    * Initialize the variable with multiple MOOSE variables and vector tag name
      71             :    * @param variables The MOOSE variables
      72             :    * @param tag The vector tag ID
      73             :    */
      74             :   ///@{
      75             :   Variable(const std::vector<const MooseVariableFieldBase *> & variables,
      76             :            const TagName & tag_name = Moose::SOLUTION_TAG)
      77             :   {
      78             :     init(variables, tag_name);
      79             :   }
      80             :   Variable(const std::vector<MooseVariableFieldBase *> & variables,
      81             :            const TagName & tag_name = Moose::SOLUTION_TAG)
      82             :   {
      83             :     init(variables, tag_name);
      84             :   }
      85             :   ///@}
      86             :   /**
      87             :    * Initialize the variable with a MOOSE variable and vector tag ID
      88             :    * @param variable The MOOSE variable
      89             :    * @param tag The vector tag ID
      90             :    */
      91             :   void init(const MooseVariableFieldBase & variable, const TagID tag);
      92             :   /**
      93             :    * Initialize the variable with a MOOSE variable and vector tag name
      94             :    * @param variable The MOOSE variable
      95             :    * @param tag_name The vector tag name
      96             :    */
      97             :   void init(const MooseVariableFieldBase & variable,
      98             :             const TagName & tag_name = Moose::SOLUTION_TAG);
      99             :   /**
     100             :    * Initialize the variable with multiple MOOSE variables and vector tag ID
     101             :    * @param variables The MOOSE variables
     102             :    * @param tag The vector tag ID
     103             :    */
     104             :   ///@{
     105             :   void init(const std::vector<const MooseVariableFieldBase *> & variables, const TagID tag);
     106             :   void init(const std::vector<MooseVariableFieldBase *> & variables, const TagID tag);
     107             :   ///@}
     108             :   /**
     109             :    * Initialize the variable with multiple MOOSE variables and vector tag name
     110             :    * @param variables The MOOSE variables
     111             :    * @param tag_name The vector tag name
     112             :    */
     113             :   ///@{
     114             :   void init(const std::vector<const MooseVariableFieldBase *> & variables,
     115             :             const TagName & tag_name = Moose::SOLUTION_TAG);
     116             :   void init(const std::vector<MooseVariableFieldBase *> & variables,
     117             :             const TagName & tag_name = Moose::SOLUTION_TAG);
     118             :   ///@}
     119             :   /**
     120             :    * Initialize the variable with coupled default values
     121             :    * @param values The default coupled values
     122             :    */
     123             :   void init(const std::vector<Real> & values, CoupleableKey);
     124             : 
     125             :   /**
     126             :    * Get the MOOSE variable of a component
     127             :    * @param comp The variable component
     128             :    * @returns The MOOSE variable
     129             :    */
     130        7209 :   const MooseVariableFieldBase * mooseVar(unsigned int comp = 0)
     131             :   {
     132        7209 :     return _moose_var.size() ? _moose_var[comp] : nullptr;
     133             :   }
     134             : 
     135             :   /**
     136             :    * Get whether the variable is initialized
     137             :    * @returns Whether the variable is initialized
     138             :    */
     139             :   KOKKOS_FUNCTION bool initialized() const { return _initialized; }
     140             :   /**
     141             :    * Get whether the variable is coupled
     142             :    * @returns Whether the variable is coupled
     143             :    */
     144    87963508 :   KOKKOS_FUNCTION bool coupled() const { return _coupled; }
     145             :   /**
     146             :    * Get whether the variable is nodal
     147             :    * @returns Whether the variable is nodal
     148             :    */
     149      153796 :   KOKKOS_FUNCTION bool nodal() const { return _nodal; }
     150             :   /**
     151             :    * Get whether the tag is time derivative
     152             :    * @returns Whether the tag is time derivative
     153             :    */
     154       75464 :   KOKKOS_FUNCTION bool dot() const { return _dot; }
     155             :   /**
     156             :    * Get whether the tag is old/older value
     157             :    * @returns Whether the tag is old/older value
     158             :    */
     159       68255 :   KOKKOS_FUNCTION bool old() const { return _old; }
     160             :   /**
     161             :    * Get the number of components
     162             :    * @returns The number of components
     163             :    */
     164      226392 :   KOKKOS_FUNCTION unsigned int components() { return _components; }
     165             :   /**
     166             :    * Get the vector tag ID
     167             :    * @returns The vector tag ID
     168             :    */
     169   109001914 :   KOKKOS_FUNCTION TagID tag() const { return _tag; }
     170             :   /**
     171             :    * Get the variable number of a component
     172             :    * @param comp The variable component
     173             :    * @returns The variable number
     174             :    */
     175   167951370 :   KOKKOS_FUNCTION unsigned int var(unsigned int comp = 0) const { return _var[comp]; }
     176             :   /**
     177             :    * Get the system number of a component
     178             :    * @param comp The variable component
     179             :    * @returns The system number
     180             :    */
     181   196376844 :   KOKKOS_FUNCTION unsigned int sys(unsigned int comp = 0) const { return _sys[comp]; }
     182             :   /**
     183             :    * Get the default value of a component
     184             :    * @param comp The variable component
     185             :    * @returns The default value
     186             :    */
     187       31268 :   KOKKOS_FUNCTION Real value(unsigned int comp = 0) const
     188             :   {
     189             :     KOKKOS_ASSERT(!_coupled);
     190             : 
     191       31268 :     return _default_value[comp];
     192             :   }
     193             : 
     194             : private:
     195             :   /**
     196             :    * Whether the variable is initialized
     197             :    */
     198             :   bool _initialized = false;
     199             :   /**
     200             :    * Whether the variable is coupled
     201             :    */
     202             :   bool _coupled = false;
     203             :   /**
     204             :    * Whether the variable is nodal
     205             :    */
     206             :   bool _nodal = false;
     207             :   /**
     208             :    * Whether the tag is time derivative
     209             :    */
     210             :   bool _dot = false;
     211             :   /**
     212             :    * Whether the tag is old/older value
     213             :    */
     214             :   bool _old = false;
     215             :   /**
     216             :    * Number of components
     217             :    */
     218             :   unsigned int _components = 1;
     219             :   /**
     220             :    * Vector tag ID
     221             :    */
     222             :   TagID _tag = Moose::INVALID_TAG_ID;
     223             :   /**
     224             :    * MOOSE variable of each component
     225             :    */
     226             :   Array<const MooseVariableFieldBase *> _moose_var;
     227             :   /**
     228             :    * Variable number of each component
     229             :    */
     230             :   Array<unsigned int> _var;
     231             :   /**
     232             :    * System number of each component
     233             :    */
     234             :   Array<unsigned int> _sys;
     235             :   /**
     236             :    * Default value of each component when the variable is not coupled
     237             :    */
     238             :   Array<Real> _default_value;
     239             : };
     240             : 
     241             : } // namespace Moose::Kokkos

Generated by: LCOV version 1.14