LCOV - code coverage report
Current view: top level - include/interfaces - ScalarCoupleable.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 99787a Lines: 6 6 100.0 %
Date: 2025-10-14 20:01:24 Functions: 3 3 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 "Moose.h"
      13             : 
      14             : // MOOSE includes
      15             : #include "MooseVariableBase.h"
      16             : 
      17             : // C++ includes
      18             : #include <unordered_map>
      19             : #include <string>
      20             : #include <vector>
      21             : 
      22             : // Forward declarations
      23             : class FEProblemBase;
      24             : class InputParameters;
      25             : class MooseObject;
      26             : class MooseVariableScalar;
      27             : 
      28             : /**
      29             :  * Interface for objects that needs scalar coupling capabilities
      30             :  *
      31             :  */
      32             : class ScalarCoupleable
      33             : {
      34             : public:
      35             :   /**
      36             :    * Constructing the object
      37             :    * @param parameters Parameters that come from constructing the object
      38             :    */
      39             :   ScalarCoupleable(const MooseObject * moose_object);
      40             : 
      41             : #ifdef MOOSE_KOKKOS_ENABLED
      42             :   /**
      43             :    * Special constructor used for Kokkos functor copy during parallel dispatch
      44             :    */
      45             :   ScalarCoupleable(const ScalarCoupleable & object, const Moose::Kokkos::FunctorCopy & key);
      46             : #endif
      47             : 
      48             :   /**
      49             :    * Get the list of coupled scalar variables
      50             :    * @return The list of coupled variables
      51             :    */
      52     9654466 :   const std::vector<MooseVariableScalar *> & getCoupledMooseScalarVars()
      53             :   {
      54     9654466 :     return _coupled_moose_scalar_vars;
      55             :   }
      56             : 
      57       19880 :   const std::set<TagID> & getScalarVariableCoupleableVectorTags() const
      58             :   {
      59       19880 :     return _sc_coupleable_vector_tags;
      60             :   }
      61             : 
      62       19880 :   const std::set<TagID> & getScalarVariableCoupleableMatrixTags() const
      63             :   {
      64       19880 :     return _sc_coupleable_matrix_tags;
      65             :   }
      66             : 
      67             : protected:
      68             :   /**
      69             :    * Returns true if a variables has been coupled_as name.
      70             :    * @param var_name The of the coupled variable
      71             :    * @param i By default 0, in general the index to test in a vector of MooseVariable pointers.
      72             :    */
      73             :   bool isCoupledScalar(const std::string & var_name, unsigned int i = 0) const;
      74             : 
      75             :   /**
      76             :    * Return the number of components to the coupled scalar variable
      77             :    * @param var_name The of the coupled variable
      78             :    */
      79             :   unsigned int coupledScalarComponents(const std::string & var_name) const;
      80             : 
      81             :   /**
      82             :    * Returns the index for a scalar coupled variable by name
      83             :    * @param var_name Name of coupled variable
      84             :    * @param comp Component number for vector of coupled variables
      85             :    * @return Index of coupled variable
      86             :    */
      87             :   unsigned int coupledScalar(const std::string & var_name, unsigned int comp = 0) const;
      88             : 
      89             :   /**
      90             :    * Returns the order for a scalar coupled variable by name
      91             :    * @param var_name Name of coupled variable
      92             :    * @param comp Component number for vector of coupled variables
      93             :    * @return Order of coupled variable
      94             :    */
      95             :   libMesh::Order coupledScalarOrder(const std::string & var_name, unsigned int comp = 0) const;
      96             : 
      97             :   /**
      98             :    * Returns value of a scalar coupled variable
      99             :    * @param var_name Name of coupled variable
     100             :    * @param comp Component number for vector of coupled variables
     101             :    * @return Reference to a VariableValue for the coupled variable
     102             :    */
     103             :   const VariableValue & coupledScalarValue(const std::string & var_name,
     104             :                                            unsigned int comp = 0) const;
     105             : 
     106             :   /**
     107             :    * Returns AD value of a scalar coupled variable
     108             :    * @param var_name Name of coupled variable
     109             :    * @param comp Component number for vector of coupled variables
     110             :    * @return Reference to a ADVariableValue for the coupled variable
     111             :    */
     112             :   const ADVariableValue & adCoupledScalarValue(const std::string & var_name,
     113             :                                                unsigned int comp = 0) const;
     114             : 
     115             :   /**
     116             :    * Returns value of a coupled scalar variable for use in templated automatic differentiation
     117             :    * classes
     118             :    * @param var_name Name of coupled scalar variable
     119             :    * @param comp Component number for vector of coupled scalar variables
     120             :    * @return Reference to a GenericVariableValue for the coupled scalar variable
     121             :    */
     122             :   template <bool is_ad>
     123             :   const GenericVariableValue<is_ad> & coupledGenericScalarValue(const std::string & var_name,
     124             :                                                                 unsigned int comp = 0) const;
     125             : 
     126             :   /**
     127             :    * Returns value of a scalar coupled variable
     128             :    * @param var_name Name of coupled variable
     129             :    * @param tag Tag ID of coupled vector ;
     130             :    * @param comp Component number for vector of coupled variables
     131             :    * @return Reference to a VariableValue for the coupled variable
     132             :    */
     133             :   const VariableValue &
     134             :   coupledVectorTagScalarValue(const std::string & var_name, TagID tag, unsigned int comp = 0) const;
     135             : 
     136             :   /**
     137             :    * Returns value of a scalar coupled variable
     138             :    * @param var_name Name of coupled variable
     139             :    * @param tag Tag ID of coupled matrix;
     140             :    * @param comp Component number for vector of coupled variables
     141             :    * @return Reference to a VariableValue for the coupled variable
     142             :    */
     143             :   const VariableValue &
     144             :   coupledMatrixTagScalarValue(const std::string & var_name, TagID tag, unsigned int comp = 0) const;
     145             : 
     146             :   /**
     147             :    * Returns the old (previous time step) value of a scalar coupled variable
     148             :    * @param var_name Name of coupled variable
     149             :    * @param comp Component number for vector of coupled variables
     150             :    * @return Reference to a old VariableValue for the coupled variable
     151             :    */
     152             :   const VariableValue & coupledScalarValueOld(const std::string & var_name,
     153             :                                               unsigned int comp = 0) const;
     154             : 
     155             :   /**
     156             :    * Returns the older (two time steps previous) value of a scalar coupled variable
     157             :    * @param var_name Name of coupled variable
     158             :    * @param comp Component number for vector of coupled variables
     159             :    * @return Reference to a older VariableValue for the coupled variable
     160             :    */
     161             :   const VariableValue & coupledScalarValueOlder(const std::string & var_name,
     162             :                                                 unsigned int comp = 0) const;
     163             :   /**
     164             :    * Returns the time derivative of a scalar coupled variable
     165             :    * @param var_name Name of coupled variable
     166             :    * @param comp Component number for vector of coupled variables
     167             :    * @return Reference to a time derivative VariableValue for the coupled variable
     168             :    */
     169             :   const VariableValue & coupledScalarDot(const std::string & var_name, unsigned int comp = 0) const;
     170             : 
     171             :   /**
     172             :    * Returns the time derivative of a scalar coupled variable, including its dependence on the
     173             :    * nonlinear degrees of freedom through automatic differentiation
     174             :    * @param var_name Name of coupled variable
     175             :    * @param comp Component number for vector of coupled variables
     176             :    * @return Reference to the time derivative at quadrature points for the coupled variable,
     177             :    * including automatic differentiation information
     178             :    */
     179             :   const ADVariableValue & adCoupledScalarDot(const std::string & var_name,
     180             :                                              unsigned int comp = 0) const;
     181             : 
     182             :   /**
     183             :    * Returns the second time derivative of a scalar coupled variable
     184             :    * @param var_name Name of coupled variable
     185             :    * @param comp Component number for vector of coupled variables
     186             :    * @return Reference to a time derivative VariableValue for the coupled variable
     187             :    */
     188             :   const VariableValue & coupledScalarDotDot(const std::string & var_name,
     189             :                                             unsigned int comp = 0) const;
     190             : 
     191             :   /**
     192             :    * Returns the old time derivative of a scalar coupled variable
     193             :    * @param var_name Name of coupled variable
     194             :    * @param comp Component number for vector of coupled variables
     195             :    * @return Reference to a time derivative VariableValue for the coupled variable
     196             :    */
     197             :   const VariableValue & coupledScalarDotOld(const std::string & var_name,
     198             :                                             unsigned int comp = 0) const;
     199             : 
     200             :   /**
     201             :    * Returns the old second time derivative of a scalar coupled variable
     202             :    * @param var_name Name of coupled variable
     203             :    * @param comp Component number for vector of coupled variables
     204             :    * @return Reference to a time derivative VariableValue for the coupled variable
     205             :    */
     206             :   const VariableValue & coupledScalarDotDotOld(const std::string & var_name,
     207             :                                                unsigned int comp = 0) const;
     208             : 
     209             :   /**
     210             :    * Time derivative of a scalar coupled variable with respect to the coefficients
     211             :    * @param var_name Name of coupled variable
     212             :    * @param comp Component number for vector of coupled variables
     213             :    * @return Reference to a VariableValue containing the time derivative of the coupled variable
     214             :    * with respect to the coefficients
     215             :    */
     216             :   const VariableValue & coupledScalarDotDu(const std::string & var_name,
     217             :                                            unsigned int comp = 0) const;
     218             : 
     219             :   /**
     220             :    * Second time derivative of a scalar coupled variable with respect to the coefficients
     221             :    * @param var_name Name of coupled variable
     222             :    * @param comp Component number for vector of coupled variables
     223             :    * @return Reference to a VariableValue containing the time derivative of the coupled variable
     224             :    * with respect to the coefficients
     225             :    */
     226             :   const VariableValue & coupledScalarDotDotDu(const std::string & var_name,
     227             :                                               unsigned int comp = 0) const;
     228             : 
     229             :   /**
     230             :    * Extract pointer to a scalar coupled variable
     231             :    * @param var_name Name of parameter desired
     232             :    * @param comp Component number of multiple coupled variables
     233             :    * @return Pointer to the desired variable
     234             :    */
     235             :   const MooseVariableScalar * getScalarVar(const std::string & var_name, unsigned int comp) const;
     236             : 
     237             : protected:
     238             :   // Reference to FEProblemBase
     239             :   FEProblemBase & _sc_fe_problem;
     240             : 
     241             :   /// Thread ID of the thread using this object
     242             :   const THREAD_ID _sc_tid;
     243             : 
     244             :   /// Scalar zero
     245             :   const Real & _real_zero;
     246             : 
     247             :   /// Zero value of a scalar variable
     248             :   const VariableValue & _scalar_zero;
     249             : 
     250             :   /// Zero point
     251             :   const Point & _point_zero;
     252             : 
     253             : private:
     254             :   /**
     255             :    * Helper method to return (and insert if necessary) the default value
     256             :    * for an uncoupled variable.
     257             :    * @param var_name the name of the variable for which to retrieve a default value
     258             :    * @return VariableValue * a pointer to the associated VariableValue.
     259             :    */
     260             :   const VariableValue * getDefaultValue(const std::string & var_name) const;
     261             : 
     262             :   /**
     263             :    * Helper method to return (and insert if necessary) the AD default value
     264             :    * for an uncoupled variable.
     265             :    * @param var_name the name of the variable for which to retrieve a default value
     266             :    * @return ADVariableValue * a pointer to the associated ADVariableValue.
     267             :    */
     268             :   const ADVariableValue * getADDefaultValue(const std::string & var_name) const;
     269             : 
     270             :   /**
     271             :    * Check that the right kind of variable is being coupled in
     272             :    *
     273             :    * @param var_name The name of the coupled variable
     274             :    */
     275             :   void checkVar(const std::string & var_name) const;
     276             : 
     277             :   /**
     278             :    * Checks to make sure that the current Executioner has set "_is_transient" when old/older values
     279             :    * are coupled in.
     280             :    * @param name the name of the variable
     281             :    * @param fn_name The name of the function that called this method - used in the error message
     282             :    */
     283             :   void validateExecutionerType(const std::string & name, const std::string & fn_name) const;
     284             : 
     285             :   // Reference to the interface's input parameters
     286             :   const InputParameters & _sc_parameters;
     287             : 
     288             :   /// The name of the object this interface is part of
     289             :   const std::string & _sc_name;
     290             : 
     291             :   /// True if implicit value is required
     292             :   const bool _sc_is_implicit;
     293             : 
     294             :   /// Coupled vars whose values we provide
     295             :   std::unordered_map<std::string, std::vector<MooseVariableScalar *>> _coupled_scalar_vars;
     296             : 
     297             :   /// Will hold the default value for optional coupled scalar variables.
     298             :   mutable std::unordered_map<std::string, std::unique_ptr<VariableValue>> _default_value;
     299             : 
     300             :   /// Will hold the default AD value for optional coupled scalar variables.
     301             :   mutable std::unordered_map<std::string, std::unique_ptr<ADVariableValue>> _dual_default_value;
     302             : 
     303             :   /// Vector of coupled variables
     304             :   std::vector<MooseVariableScalar *> _coupled_moose_scalar_vars;
     305             : 
     306             :   /// Field variables coupled into this object (for error checking)
     307             :   std::unordered_map<std::string, std::vector<MooseVariableFieldBase *>> _sc_coupled_vars;
     308             : 
     309             :   /// The scalar coupleable vector tags
     310             :   mutable std::set<TagID> _sc_coupleable_vector_tags;
     311             :   /// The scalar coupleable matrix tags
     312             :   mutable std::set<TagID> _sc_coupleable_matrix_tags;
     313             : };

Generated by: LCOV version 1.14