https://mooseframework.inl.gov
MooseBase.C
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 #include "MooseBase.h"
11 
12 #include "MooseError.h"
13 #include "InputParameters.h"
14 #include "MooseApp.h"
15 
16 #include "hit/parse.h"
17 
18 MooseBase::MooseBase(const std::string & type,
19  const std::string & name,
20  MooseApp & app,
21  const InputParameters & params)
22  : _app(app), _type(type), _name(name), _params(params)
23 {
24 }
25 
26 std::string
28 {
29  return type() + std::string(" \"") + name() + std::string("\"");
30 }
31 
32 [[noreturn]] void
33 MooseBase::callMooseError(std::string msg, const bool with_prefix) const
34 {
36  const std::string prefix = _app.isUltimateMaster() ? "" : _app.name();
37  if (with_prefix)
38  msg = errorPrefix("error") + msg;
39  moose::internal::mooseErrorRaw(msg, prefix);
40 }
41 
42 std::string
43 MooseBase::errorPrefix(const std::string & error_type) const
44 {
45  std::stringstream oss;
46  if (const auto node = _params.getHitNode())
47  if (!node->isRoot())
48  oss << node->fileLocation() << ":\n";
49  oss << "The following " << error_type << " occurred in the ";
50  if (const auto base_ptr = _params.getBase())
51  oss << *base_ptr;
52  else
53  oss << "object";
54  oss << " '" << name() << "' of type " << type() << ".\n\n";
55  return oss.str();
56 }
std::string name(const ElemQuality q)
const hit::Node * getHitNode(const std::string &param) const
bool isUltimateMaster() const
Whether or not this app is the ultimate master app.
Definition: MooseApp.h:843
std::optional< std::string > getBase() const
Base class for MOOSE-based applications.
Definition: MooseApp.h:96
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
std::string errorPrefix(const std::string &error_type) const
Definition: MooseBase.C:43
const InputParameters & _params
The object&#39;s parameteres.
Definition: MooseBase.h:94
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:51
std::string typeAndName() const
Get the class&#39;s combined type and name; useful in error handling.
Definition: MooseBase.C:27
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
void mooseErrorRaw(std::string msg, const std::string prefix="")
Definition: MooseError.C:53
MooseBase(const std::string &type, const std::string &name, MooseApp &app, const InputParameters &params)
Definition: MooseBase.C:18
void callMooseError(std::string msg, const bool with_prefix) const
Calls moose error with the message msg.
Definition: MooseBase.C:33
void mooseConsole()
Send current output buffer to Console output objects.
OutputWarehouse & getOutputWarehouse()
Get the OutputWarehouse objects.
Definition: MooseApp.C:2414