LCOV - code coverage report
Current view: top level - include/kokkos/base - KokkosVariable.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31706 (f8ed4a) with base bb0a08 Lines: 12 12 100.0 %
Date: 2025-11-03 17:23:24 Functions: 8 8 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
      21             : {
      22             : namespace Kokkos
      23             : {
      24             : 
      25             : /**
      26             :  * The Kokkos variable object that carries the coupled variable and tag information
      27             :  */
      28             : class Variable
      29             : {
      30             : public:
      31             :   using CoupleableKey = ::Moose::PassKey<::Coupleable>;
      32             : 
      33             :   /**
      34             :    * Default constructor
      35             :    */
      36        4286 :   Variable() = default;
      37             :   /**
      38             :    * Constructor
      39             :    * Initialize the variable with a MOOSE variable and vector tag ID
      40             :    * @param variable The MOOSE variable
      41             :    * @param tag The vector tag ID
      42             :    */
      43             :   Variable(const MooseVariableBase & variable, const TagID tag) { init(variable, tag); }
      44             :   /**
      45             :    * Constructor
      46             :    * Initialize the variable with a MOOSE variable and vector tag name
      47             :    * @param variable The MOOSE variable
      48             :    * @param tag_name The vector tag name
      49             :    */
      50        5205 :   Variable(const MooseVariableBase & variable, const TagName & tag_name = Moose::SOLUTION_TAG)
      51        5205 :   {
      52        5205 :     init(variable, tag_name);
      53        5205 :   }
      54             :   /**
      55             :    * Initialize the variable with a MOOSE variable and vector tag ID
      56             :    * @param variable The MOOSE variable
      57             :    * @param tag The vector tag ID
      58             :    */
      59             :   void init(const MooseVariableBase & variable, const TagID tag);
      60             :   /**
      61             :    * Initialize the variable with a MOOSE variable and vector tag name
      62             :    * @param variable The MOOSE variable
      63             :    * @param tag_name The vector tag name
      64             :    */
      65             :   void init(const MooseVariableBase & variable, const TagName & tag_name = Moose::SOLUTION_TAG);
      66             :   /**
      67             :    * Initialize the variable with coupled MOOSE variables
      68             :    * @param variables The coupled MOOSE variables
      69             :    * @param tag The vector tag ID
      70             :    */
      71             :   void
      72             :   init(const std::vector<const MooseVariableBase *> & variables, const TagID tag, CoupleableKey);
      73             :   /**
      74             :    * Initialize the variable with coupled default values
      75             :    * @param values The default coupled values
      76             :    */
      77             :   void init(const std::vector<Real> & values, CoupleableKey);
      78             : 
      79             :   /**
      80             :    * Get whether the variable is initialized
      81             :    * @returns Whether the variable is initialized
      82             :    */
      83             :   KOKKOS_FUNCTION bool initialized() const { return _initialized; }
      84             :   /**
      85             :    * Get whether the variable is coupled
      86             :    * @returns Whether the variable is coupled
      87             :    */
      88    51642086 :   KOKKOS_FUNCTION bool coupled() const { return _coupled; }
      89             :   /**
      90             :    * Get whether the variable is nodal
      91             :    * @returns Whether the variable is nodal
      92             :    */
      93         316 :   KOKKOS_FUNCTION bool nodal() const { return _nodal; }
      94             :   /**
      95             :    * Get the number of components
      96             :    * @returns The number of components
      97             :    */
      98             :   KOKKOS_FUNCTION unsigned int components() { return _components; }
      99             :   /**
     100             :    * Get the vector tag ID
     101             :    * @returns The vector tag ID
     102             :    */
     103    58124573 :   KOKKOS_FUNCTION TagID tag() const { return _tag; }
     104             :   /**
     105             :    * Get the variable number of a component
     106             :    * @param comp The variable component
     107             :    * @returns The variable number
     108             :    */
     109    84513258 :   KOKKOS_FUNCTION unsigned int var(unsigned int comp = 0) const { return _var[comp]; }
     110             :   /**
     111             :    * Get the system number of a component
     112             :    * @param comp The variable component
     113             :    * @returns The system number
     114             :    */
     115    84281688 :   KOKKOS_FUNCTION unsigned int sys(unsigned int comp = 0) const { return _sys[comp]; }
     116             :   /**
     117             :    * Get the default value of a component
     118             :    * @param comp The variable component
     119             :    * @returns The default value
     120             :    */
     121       15236 :   KOKKOS_FUNCTION Real value(unsigned int comp = 0) const
     122             :   {
     123             :     KOKKOS_ASSERT(!_coupled);
     124             : 
     125       15236 :     return _default_value[comp];
     126             :   }
     127             : 
     128             : private:
     129             :   /**
     130             :    * Whether the variable is initialized
     131             :    */
     132             :   bool _initialized = false;
     133             :   /**
     134             :    * Whether the variable is coupled
     135             :    */
     136             :   bool _coupled = false;
     137             :   /**
     138             :    * Whether the variable is nodal
     139             :    */
     140             :   bool _nodal = false;
     141             :   /**
     142             :    * Number of components
     143             :    */
     144             :   unsigned int _components = 1;
     145             :   /**
     146             :    * Vector tag ID
     147             :    */
     148             :   TagID _tag = Moose::INVALID_TAG_ID;
     149             :   /**
     150             :    * Variable number of each component
     151             :    */
     152             :   Array<unsigned int> _var;
     153             :   /**
     154             :    * System number of each component
     155             :    */
     156             :   Array<unsigned int> _sys;
     157             :   /**
     158             :    * Default value of each component when the variable is not coupled
     159             :    */
     160             :   Array<Real> _default_value;
     161             : };
     162             : 
     163             : } // namespace Kokkos
     164             : } // namespace Moose

Generated by: LCOV version 1.14