LCOV - code coverage report
Current view: top level - include/controllogic - ControlData.h (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #30301 (3b550b) with base 2ad78d Lines: 22 24 91.7 %
Date: 2025-07-30 13:02:48 Functions: 6 9 66.7 %
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 "Restartable.h"
      13             : 
      14             : class ControlDataValue;
      15             : class THMControl;
      16             : 
      17             : /**
      18             :  * Abstract definition of a ControlData value.
      19             :  */
      20             : class ControlDataValue : public Restartable
      21             : {
      22             : public:
      23             :   /**
      24             :    * Constructor
      25             :    * @param moose_app MOOSEApp object this object belong to
      26             :    * @param name The full (unique) name for this piece of data.
      27             :    */
      28       10470 :   ControlDataValue(MooseApp & moose_app, const std::string & name)
      29       10470 :     : Restartable(moose_app, name, "thm::control_logic", 0),
      30       10470 :       _name(name),
      31       10470 :       _declared(false),
      32       20940 :       _control(nullptr)
      33             :   {
      34       10470 :   }
      35             : 
      36             :   /**
      37             :    * Destructor.
      38             :    */
      39       10444 :   virtual ~ControlDataValue() = default;
      40             : 
      41             :   /**
      42             :    * String identifying the type of parameter stored.
      43             :    * Must be reimplemented in derived classes.
      44             :    */
      45             :   virtual std::string type() = 0;
      46             : 
      47             :   /**
      48             :    * The full (unique) name of this particular piece of data.
      49             :    */
      50         138 :   const std::string & name() const { return _name; }
      51             : 
      52             :   /**
      53             :    * Get the pointer to the control object that declared this control data
      54             :    */
      55         429 :   const THMControl * getControl() const { return _control; }
      56             : 
      57             :   /**
      58             :    * Set the pointer to the control object that declared this control data
      59             :    */
      60       10466 :   void setControl(THMControl * ctrl) { _control = ctrl; }
      61             : 
      62             :   /**
      63             :    * Mark the data as declared
      64             :    */
      65       10466 :   void setDeclared() { _declared = true; }
      66             : 
      67             :   /**
      68             :    * Get the declared state
      69             :    */
      70       20912 :   bool getDeclared() { return _declared; }
      71             : 
      72             :   /**
      73             :    * Copy the current value into old (i.e. shift it "back in time")
      74             :    */
      75             :   virtual void copyValuesBack() = 0;
      76             : 
      77             : protected:
      78             :   /// The full (unique) name of this particular piece of data.
      79             :   const std::string _name;
      80             :   /// true if the data was declared by calling declareControlData. All data must be declared up front.
      81             :   bool _declared;
      82             :   /// The control object that declared this control data
      83             :   THMControl * _control;
      84             : };
      85             : 
      86             : /**
      87             :  * Concrete definition of a parameter value
      88             :  * for a specified type.
      89             :  */
      90             : template <typename T>
      91             : class ControlData : public ControlDataValue
      92             : {
      93             : public:
      94             :   /**
      95             :    * Constructor
      96             :    * @param name The full (unique) name for this piece of data.
      97             :    */
      98       10470 :   ControlData(MooseApp & moose_app, std::string name)
      99             :     : ControlDataValue(moose_app, name),
     100       20940 :       _value(declareRestartableData<T>(name)),
     101       20940 :       _value_old(declareRestartableData<T>(name + "_old"))
     102             :   {
     103       10470 :   }
     104             : 
     105             :   /**
     106             :    * @returns a read-only reference to the parameter value.
     107             :    */
     108        1405 :   const T & get() const { return _value; }
     109             : 
     110             :   /**
     111             :    * @returns a read-only reference to the old value.
     112             :    */
     113          97 :   const T & getOld() const { return _value_old; }
     114             : 
     115             :   /**
     116             :    * @returns a writable reference to the parameter value.
     117             :    */
     118       10466 :   T & set() { return _value; }
     119             : 
     120             :   /**
     121             :    * String identifying the type of parameter stored.
     122             :    */
     123             :   virtual std::string type() override;
     124             : 
     125             :   virtual void copyValuesBack() override;
     126             : 
     127             : private:
     128             :   /// Stored value.
     129             :   T & _value;
     130             :   /// Stored old value.
     131             :   T & _value_old;
     132             : };
     133             : 
     134             : // ------------------------------------------------------------
     135             : // ControlData<> class inline methods
     136             : template <typename T>
     137             : inline std::string
     138           0 : ControlData<T>::type()
     139             : {
     140           0 :   return typeid(T).name();
     141             : }
     142             : 
     143             : template <typename T>
     144             : inline void
     145       76219 : ControlData<T>::copyValuesBack()
     146             : {
     147       76219 :   _value_old = _value;
     148       76219 : }

Generated by: LCOV version 1.14