Skip to content

Commit 93beb11

Browse files
committed
Move solution invalid into a helper class at a higher level that also defines the mooseInfo/Warning/Error
so we no longer need to do "usingSolutionInvalidWarnings" in every user class refs #28181
1 parent 5eee4e5 commit 93beb11

File tree

14 files changed

+450
-436
lines changed

14 files changed

+450
-436
lines changed

framework/include/actions/Action.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "Registry.h"
1616
#include "PerfGraphInterface.h"
1717
#include "MooseObjectParameterName.h"
18-
#include "SolutionInvalidInterface.h"
1918

2019
#include <string>
2120
#include <ostream>
@@ -31,10 +30,7 @@ class Factory;
3130
/**
3231
* Base class for actions.
3332
*/
34-
class Action : public ParallelParamObject,
35-
public MeshMetaDataInterface,
36-
public PerfGraphInterface,
37-
public SolutionInvalidInterface
33+
class Action : public ParallelParamObject, public MeshMetaDataInterface, public PerfGraphInterface
3834
{
3935
public:
4036
/// The name of the parameter that contains the unique action name
@@ -51,9 +47,6 @@ class Action : public ParallelParamObject,
5147
*/
5248
void timedAct();
5349

54-
// To get warnings tracked in the SolutionInvalidityOutput
55-
usingCombinedWarningSolutionWarnings;
56-
5750
private:
5851
/**
5952
* Method for adding a single relationship manager

framework/include/base/MooseBase.h

Lines changed: 74 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "MooseError.h"
1616
#include "MooseObjectName.h"
1717
#include "MooseObjectParameterName.h"
18+
#include "MooseVerbosityHelper.h"
1819

1920
class MooseApp;
2021

@@ -46,7 +47,7 @@ class Node;
4647
* - MooseObject for an object created within a system
4748
* - Action for a class performing a setup task, like creating objects
4849
*/
49-
class MooseBase : public ConsoleStreamInterface
50+
class MooseBase : public ConsoleStreamInterface, public MooseVerbosityHelper
5051
{
5152
public:
5253
/// The name of the parameter that contains the object type
@@ -130,11 +131,6 @@ class MooseBase : public ConsoleStreamInterface
130131
*/
131132
const InputParameters & parameters() const { return _pars; }
132133

133-
/**
134-
* @returns The block-level hit node for this object, if any
135-
*/
136-
const hit::Node * getHitNode() const { return getHitNode(_pars); }
137-
138134
/**
139135
* @returns Whether or not this object has a registered base (set via
140136
* InputParameters::registerBase())
@@ -220,138 +216,6 @@ class MooseBase : public ConsoleStreamInterface
220216
const std::string & object_name,
221217
const std::string & object_parameter) const;
222218

223-
/**
224-
* Emits an error prefixed with the file and line number of the given param (from the input
225-
* file) along with the full parameter path+name followed by the given args as the message.
226-
* If this object's parameters were not created directly by the Parser, then this function falls
227-
* back to the normal behavior of mooseError - only printing a message using the given args.
228-
*/
229-
template <typename... Args>
230-
[[noreturn]] void paramError(const std::string & param, Args... args) const;
231-
232-
/**
233-
* Emits a warning prefixed with the file and line number of the given param (from the input
234-
* file) along with the full parameter path+name followed by the given args as the message.
235-
* If this object's parameters were not created directly by the Parser, then this function falls
236-
* back to the normal behavior of mooseWarning - only printing a message using the given args.
237-
*/
238-
template <typename... Args>
239-
void paramWarning(const std::string & param, Args... args) const;
240-
241-
/**
242-
* Emits an informational message prefixed with the file and line number of the given param
243-
* (from the input file) along with the full parameter path+name followed by the given args as
244-
* the message. If this object's parameters were not created directly by the Parser, then this
245-
* function falls back to the normal behavior of mooseInfo - only printing a message using
246-
* the given args.
247-
*/
248-
template <typename... Args>
249-
void paramInfo(const std::string & param, Args... args) const;
250-
251-
/**
252-
* @returns A prefix to be used in messages that contain the input
253-
* file location associated with this object (if any) and the
254-
* name and type of the object.
255-
*/
256-
std::string messagePrefix(const bool hit_prefix = true) const
257-
{
258-
return messagePrefix(_pars, hit_prefix);
259-
}
260-
261-
/**
262-
* Deprecated message prefix; the error type is no longer used
263-
*/
264-
std::string errorPrefix(const std::string &) const { return messagePrefix(); }
265-
266-
/**
267-
* Emits an error prefixed with object name and type and optionally a file path
268-
* to the top-level block parameter if available.
269-
*/
270-
template <typename... Args>
271-
[[noreturn]] void mooseError(Args &&... args) const
272-
{
273-
callMooseError(argumentsToString(std::forward<Args>(args)...), /* with_prefix = */ true);
274-
}
275-
276-
template <typename... Args>
277-
[[noreturn]] void mooseDocumentedError(const std::string & repo_name,
278-
const unsigned int issue_num,
279-
Args &&... args) const
280-
{
281-
callMooseError(moose::internal::formatMooseDocumentedError(
282-
repo_name, issue_num, argumentsToString(std::forward<Args>(args)...)),
283-
/* with_prefix = */ true);
284-
}
285-
286-
/**
287-
* Emits an error without the prefixing included in mooseError().
288-
*/
289-
template <typename... Args>
290-
[[noreturn]] void mooseErrorNonPrefixed(Args &&... args) const
291-
{
292-
callMooseError(argumentsToString(std::forward<Args>(args)...), /* with_prefix = */ false);
293-
}
294-
295-
/**
296-
* Emits a warning prefixed with object name and type.
297-
*/
298-
template <typename... Args>
299-
void mooseWarning(Args &&... args) const
300-
{
301-
moose::internal::mooseWarningStream(_console, messagePrefix(true), std::forward<Args>(args)...);
302-
}
303-
304-
/**
305-
* Emits a warning without the prefixing included in mooseWarning().
306-
*/
307-
template <typename... Args>
308-
void mooseWarningNonPrefixed(Args &&... args) const
309-
{
310-
moose::internal::mooseWarningStream(_console, std::forward<Args>(args)...);
311-
}
312-
313-
template <typename... Args>
314-
void mooseDeprecated(Args &&... args) const
315-
{
316-
moose::internal::mooseDeprecatedStream(
317-
_console, false, true, messagePrefix(true), std::forward<Args>(args)...);
318-
}
319-
320-
template <typename... Args>
321-
void mooseInfo(Args &&... args) const
322-
{
323-
moose::internal::mooseInfoStream(_console, messagePrefix(true), std::forward<Args>(args)...);
324-
}
325-
326-
/**
327-
* External method for calling moose error with added object context.
328-
* @param msg The message
329-
* @param with_prefix If true, add the prefix from messagePrefix(), which is the object
330-
* information (type, name, etc)
331-
* @param node Optional hit node to add file path context as a prefix
332-
*/
333-
[[noreturn]] void
334-
callMooseError(std::string msg, const bool with_prefix, const hit::Node * node = nullptr) const;
335-
336-
/**
337-
* External method for calling moose error with added object context.
338-
*
339-
* Needed so that objects without the MooseBase context (InputParameters)
340-
* can call errors with context
341-
*
342-
* @param app The app pointer (if available); adds multiapp context and clears the console
343-
* @param params The parameters, needed to obtain object information
344-
* @param msg The message
345-
* @param with_prefix If true, add the prefix from messagePrefix(), which is the object
346-
* information (type, name, etc)
347-
* @param node Optional hit node to add file path context as a prefix
348-
*/
349-
[[noreturn]] static void callMooseError(MooseApp * const app,
350-
const InputParameters & params,
351-
std::string msg,
352-
const bool with_prefix,
353-
const hit::Node * node);
354-
355219
protected:
356220
/// The MOOSE application this is associated with
357221
MooseApp & _app;
@@ -364,23 +228,6 @@ class MooseBase : public ConsoleStreamInterface
364228

365229
/// The object's parameters
366230
const InputParameters & _pars;
367-
368-
private:
369-
/**
370-
* Internal method for getting the message prefix for an object (object type, name, etc).
371-
*
372-
* Needs to be static so that we can call it externally from InputParameters for
373-
* errors that do not have context of the MooseBase
374-
*/
375-
static std::string messagePrefix(const InputParameters & params, const bool hit_prefix);
376-
377-
/**
378-
* Internal method for getting a hit node (if available) given a set of parameters
379-
*
380-
* Needs to be static so that we can call it externally from InputParameters for
381-
* errors that do not have context of the MooseBase
382-
*/
383-
static const hit::Node * getHitNode(const InputParameters & params);
384231
};
385232

386233
template <typename T>
@@ -434,23 +281,89 @@ MooseBase::getCheckedPointerParam(const std::string & name, const std::string &
434281
return _pars.getCheckedPointerParam<T>(name, error_string);
435282
}
436283

284+
// These templates for routines in MooseVerbosityHelper need to be defined here because they require
285+
// the declaration of a MooseBase to be known at compile time.
286+
template <typename... Args>
287+
void
288+
MooseVerbosityHelper::untrackedMooseWarning(Args &&... args) const
289+
{
290+
moose::internal::mooseWarningStream(
291+
_moose_base._console, messagePrefix(true), std::forward<Args>(args)...);
292+
}
293+
294+
template <typename... Args>
295+
void
296+
MooseVerbosityHelper::untrackedMooseWarningNonPrefixed(Args &&... args) const
297+
{
298+
moose::internal::mooseWarningStream(_moose_base._console, std::forward<Args>(args)...);
299+
}
300+
437301
template <typename... Args>
438302
[[noreturn]] void
439-
MooseBase::paramError(const std::string & param, Args... args) const
303+
MooseVerbosityHelper::paramError(const std::string & param, Args... args) const
304+
{
305+
_moose_base.parameters().paramError(param, std::forward<Args>(args)...);
306+
}
307+
308+
template <typename... Args>
309+
void
310+
MooseVerbosityHelper::untrackedParamWarning(const std::string & param, Args... args) const
311+
{
312+
mooseWarning(_moose_base.parameters().paramMessage(param, std::forward<Args>(args)...));
313+
}
314+
315+
template <typename... Args>
316+
void
317+
MooseVerbosityHelper::paramInfo(const std::string & param, Args... args) const
318+
{
319+
mooseInfo(_moose_base.parameters().paramMessage(param, std::forward<Args>(args)...));
320+
}
321+
322+
template <typename... Args>
323+
void
324+
MooseVerbosityHelper::untrackedMooseDeprecated(Args &&... args) const
325+
{
326+
moose::internal::mooseDeprecatedStream(
327+
_moose_base._console, false, true, messagePrefix(true), std::forward<Args>(args)...);
328+
}
329+
330+
template <typename... Args>
331+
void
332+
MooseVerbosityHelper::mooseWarning(Args &&... args) const
333+
{
334+
untrackedMooseWarning(std::forward<Args>(args)...);
335+
flagSolutionWarningMultipleRegistration(_moose_base.name() + ": warning");
336+
}
337+
338+
template <typename... Args>
339+
void
340+
MooseVerbosityHelper::mooseWarningNonPrefixed(Args &&... args) const
341+
{
342+
untrackedMooseWarningNonPrefixed(std::forward<Args>(args)...);
343+
flagSolutionWarningMultipleRegistration(_moose_base.name() + ": warning");
344+
}
345+
346+
template <typename... Args>
347+
void
348+
MooseVerbosityHelper::mooseDeprecated(Args &&... args) const
440349
{
441-
_pars.paramError(param, std::forward<Args>(args)...);
350+
untrackedMooseDeprecated(std::forward<Args>(args)...);
351+
flagSolutionWarningMultipleRegistration(_moose_base.name() + ": deprecation");
442352
}
443353

444354
template <typename... Args>
445355
void
446-
MooseBase::paramWarning(const std::string & param, Args... args) const
356+
MooseVerbosityHelper::mooseInfo(Args &&... args) const
447357
{
448-
mooseWarning(_pars.paramMessage(param, std::forward<Args>(args)...));
358+
moose::internal::mooseInfoStream(
359+
_moose_base._console, messagePrefix(true), std::forward<Args>(args)...);
449360
}
450361

451362
template <typename... Args>
452363
void
453-
MooseBase::paramInfo(const std::string & param, Args... args) const
364+
MooseVerbosityHelper::paramWarning(const std::string & param, Args... args) const
454365
{
455-
mooseInfo(_pars.paramMessage(param, std::forward<Args>(args)...));
366+
untrackedParamWarning(param, std::forward<Args>(args)...);
367+
flagSolutionWarningMultipleRegistration(_moose_base.name() + ": warning for parameter '" + param +
368+
"'");
456369
}

framework/include/base/MooseObject.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "ConsoleStreamInterface.h"
1717
#include "Registry.h"
1818
#include "MooseObjectParameterName.h"
19-
#include "SolutionInvalidInterface.h"
19+
#include "MooseVerbosityHelper.h"
2020

2121
#define usingMooseObjectMembers \
2222
usingMooseBaseMembers; \
@@ -25,9 +25,7 @@
2525
/**
2626
* Every object that can be built by the factory should be derived from this class.
2727
*/
28-
class MooseObject : public ParallelParamObject,
29-
public SolutionInvalidInterface,
30-
public std::enable_shared_from_this<MooseObject>
28+
class MooseObject : public ParallelParamObject, public std::enable_shared_from_this<MooseObject>
3129
{
3230
public:
3331
static InputParameters validParams();
@@ -65,9 +63,6 @@ class MooseObject : public ParallelParamObject,
6563
bool isKokkosObject() const { return parameters().isParamValid(MooseBase::kokkos_object_param); }
6664
#endif
6765

68-
// To get warnings tracked in the SolutionInvalidityOutput
69-
usingCombinedWarningSolutionWarnings;
70-
7166
protected:
7267
/// Reference to the "enable" InputParameters, used by Controls for toggling on/off MooseObjects
7368
const bool & _enabled;

0 commit comments

Comments
 (0)