LCOV - code coverage report
Current view: top level - include/interfaces - SolutionInvalidInterface.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31730 (e8b711) with base e0c998 Lines: 12 12 100.0 %
Date: 2025-10-29 16:49:47 Functions: 61 104 58.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             : // MOOSE includes
      13             : #include "Moose.h"
      14             : #include "SolutionInvalidity.h"
      15             : #include "MooseBase.h"
      16             : 
      17             : // Forward declarations
      18             : class FEProblemBase;
      19             : 
      20             : #define flagInvalidSolution(message)                                                               \
      21             :   do                                                                                               \
      22             :   {                                                                                                \
      23             :     static const auto __invalid_id = this->registerInvalidSolutionInternal(message, false);        \
      24             :     this->flagInvalidSolutionInternal<false>(__invalid_id);                                        \
      25             :   } while (0)
      26             : 
      27             : #define flagSolutionWarning(message)                                                               \
      28             :   do                                                                                               \
      29             :   {                                                                                                \
      30             :     static const auto __invalid_id = this->registerInvalidSolutionInternal(message, true);         \
      31             :     this->flagInvalidSolutionInternal<true>(__invalid_id);                                         \
      32             :   } while (0)
      33             : 
      34             : // This macro is useful when we have different messages but appearing in the same place in the code
      35             : // for example when nesting a solution warning creation under the mooseWarning
      36             : #define flagSolutionWarningMultipleRegistration(message)                                           \
      37             :   do                                                                                               \
      38             :   {                                                                                                \
      39             :     const auto __invalid_id = this->registerInvalidSolutionInternal(message, true);                \
      40             :     this->flagInvalidSolutionInternal<true>(__invalid_id);                                         \
      41             :   } while (0)
      42             : 
      43             : // Every class using this interface must specify either
      44             : // 'usingCombinedWarningSolutionWarnings' or 'usingMooseBaseWarnings'
      45             : #define usingCombinedWarningSolutionWarnings                                                       \
      46             :   using SolutionInvalidInterface::mooseWarning;                                                    \
      47             :   using SolutionInvalidInterface::mooseWarningNonPrefixed;                                         \
      48             :   using SolutionInvalidInterface::mooseDeprecated;                                                 \
      49             :   using SolutionInvalidInterface::paramWarning
      50             : #define usingMooseBaseWarnings                                                                     \
      51             :   using MooseBase::mooseWarning;                                                                   \
      52             :   using MooseBase::mooseWarningNonPrefixed;                                                        \
      53             :   using MooseBase::mooseDeprecated;                                                                \
      54             :   using MooseBase::paramWarning
      55             : 
      56             : /**
      57             :  * An interface that allows the marking of invalid solutions during a solve
      58             :  */
      59             : class SolutionInvalidInterface
      60             : {
      61             : public:
      62             :   SolutionInvalidInterface(const MooseBase * const moose_base, const InputParameters & params);
      63             : 
      64             : #ifdef MOOSE_KOKKOS_ENABLED
      65             :   /**
      66             :    * Special constructor used for Kokkos functor copy during parallel dispatch
      67             :    */
      68             :   SolutionInvalidInterface(const SolutionInvalidInterface & object,
      69             :                            const Moose::Kokkos::FunctorCopy & key);
      70             : #endif
      71             : 
      72             :   template <typename... Args>
      73        2642 :   void mooseWarning(Args &&... args) const
      74             :   {
      75        2642 :     _si_moose_base.MooseBase::mooseWarning(std::forward<Args>(args)...);
      76        2488 :     flagSolutionWarningMultipleRegistration(_si_moose_base.name() + ": warning");
      77        2488 :   }
      78             : 
      79             :   template <typename... Args>
      80             :   void mooseWarningNonPrefixed(Args &&... args) const
      81             :   {
      82             :     _si_moose_base.MooseBase::mooseWarningNonPrefixed(std::forward<Args>(args)...);
      83             :     flagSolutionWarningMultipleRegistration(_si_moose_base.name() + ": warning");
      84             :   }
      85             : 
      86             :   template <typename... Args>
      87        1458 :   void mooseDeprecated(Args &&... args) const
      88             :   {
      89        1458 :     _si_moose_base.MooseBase::mooseDeprecated(std::forward<Args>(args)...);
      90        1458 :     flagSolutionWarningMultipleRegistration(_si_moose_base.name() + ": deprecation");
      91        1458 :   }
      92             : 
      93             :   template <typename... Args>
      94          80 :   void paramWarning(const std::string & param, Args... args) const
      95             :   {
      96          80 :     _si_moose_base.MooseBase::paramWarning(param, std::forward<Args>(args)...);
      97          64 :     flagSolutionWarningMultipleRegistration(_si_moose_base.name() + ": warning for parameter '" +
      98             :                                             param + "'");
      99          64 :   }
     100             : 
     101             : protected:
     102             :   template <bool warning>
     103             :   void flagInvalidSolutionInternal(const InvalidSolutionID invalid_solution_id) const;
     104             : 
     105             :   // Register invalid solution with a message
     106             :   InvalidSolutionID registerInvalidSolutionInternal(const std::string & message,
     107             :                                                     const bool warning) const;
     108             : 
     109             : private:
     110             :   /// The MooseBase that owns this interface
     111             :   const MooseBase & _si_moose_base;
     112             : 
     113             :   /// A pointer to FEProblem base
     114             :   const FEProblemBase * _si_problem;
     115             : };

Generated by: LCOV version 1.14