https://mooseframework.inl.gov
SolutionInvalidInterface.h
Go to the documentation of this file.
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 
60 {
61 public:
62  SolutionInvalidInterface(const MooseBase * const moose_base, const InputParameters & params);
63 
64 #ifdef MOOSE_KOKKOS_ENABLED
65 
69  const Moose::Kokkos::FunctorCopy & key);
70 #endif
71 
72  template <typename... Args>
73  void mooseWarning(Args &&... args) const
74  {
75  _si_moose_base.MooseBase::mooseWarning(std::forward<Args>(args)...);
76  flagSolutionWarningMultipleRegistration(_si_moose_base.name() + ": warning");
77  }
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  void mooseDeprecated(Args &&... args) const
88  {
89  _si_moose_base.MooseBase::mooseDeprecated(std::forward<Args>(args)...);
90  flagSolutionWarningMultipleRegistration(_si_moose_base.name() + ": deprecation");
91  }
92 
93  template <typename... Args>
94  void paramWarning(const std::string & param, Args... args) const
95  {
96  _si_moose_base.MooseBase::paramWarning(param, std::forward<Args>(args)...);
97  flagSolutionWarningMultipleRegistration(_si_moose_base.name() + ": warning for parameter '" +
98  param + "'");
99  }
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:
112 
115 };
const FEProblemBase * _si_problem
A pointer to FEProblem base.
Base class for everything in MOOSE with a name and a type.
Definition: MooseBase.h:49
unsigned int InvalidSolutionID
Definition: MooseTypes.h:213
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
InvalidSolutionID registerInvalidSolutionInternal(const std::string &message, const bool warning) const
An interface that allows the marking of invalid solutions during a solve.
void mooseWarning(Args &&... args) const
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
void mooseWarningNonPrefixed(Args &&... args) const
void mooseDeprecated(Args &&... args) const
void flagInvalidSolutionInternal(const InvalidSolutionID invalid_solution_id) const
Set solution invalid mark for the given solution ID.
SolutionInvalidInterface(const MooseBase *const moose_base, const InputParameters &params)
void paramWarning(const std::string &param, Args... args) const
const MooseBase & _si_moose_base
The MooseBase that owns this interface.