www.mooseframework.org
Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Private Member Functions | Private Attributes | List of all members
MeshMetaDataInterface Class Reference

The Interface used to retrieve mesh meta data (attributes) set by the MeshGenerator system. More...

#include <MeshMetaDataInterface.h>

Inheritance diagram for MeshMetaDataInterface:
[legend]

Static Public Attributes

static constexpr auto SYSTEM = "MeshMetaData"
 The system name used when initializing the Restartable interface. More...
 
static constexpr auto NAME = "<empty>"
 The data name used when initializing the Restartable interface for non-MeshGenerator objects. More...
 

Protected Member Functions

 MeshMetaDataInterface (const MooseObject *moose_object)
 Interface for all objects reading MeshMetaData. More...
 
 MeshMetaDataInterface (MooseApp &moose_app)
 This class constructor is used for non-Moose-based objects like interfaces. More...
 
template<typename T >
const T & getMeshProperty (const std::string &data_name, const std::string &prefix)
 Method for retrieving a property with the given type and name exists in the mesh meta-data store. More...
 
template<typename T >
const T & getMeshProperty (const std::string &data_name)
 
bool hasMeshProperty (const std::string &data_name, const std::string &prefix) const
 
template<typename T >
bool hasMeshProperty (const std::string &data_name, const std::string &prefix) const
 
bool hasMeshProperty (const std::string &data_name) const
 
template<typename T >
bool hasMeshProperty (const std::string &data_name) const
 
std::string meshPropertyName (const std::string &data_name) const
 

Static Protected Member Functions

static std::string meshPropertyName (const std::string &data_name, const std::string &prefix)
 

Private Member Functions

virtual std::string meshPropertyPrefix (const std::string &data_name) const
 The default prefix to use for getting/seeing if mesh properties exist. More...
 
const RestartableDataValuegetMeshPropertyInternal (const std::string &data_name, const std::string &prefix) const
 Helper for getting a mesh property. More...
 
template<typename... Args>
void mooseErrorInternal (Args &&... args) const
 Helper for forwarding a mooseError to an object's mooseError if it is available (said error will provide more context: object name and type) More...
 

Private Attributes

MooseApp_meta_data_app
 Reference to the application. More...
 
const MooseObject *const _meta_data_object
 The MooseObject (if any); used for better error handling. More...
 

Detailed Description

The Interface used to retrieve mesh meta data (attributes) set by the MeshGenerator system.

MOOSE objects should avoid retrieving and casting MeshGenerator objects since they are not re-created during a recover operation. This data is read from files early during the simulation setup an d can be used to make decisions about how to setup the rest of the problem.

Definition at line 26 of file MeshMetaDataInterface.h.

Constructor & Destructor Documentation

◆ MeshMetaDataInterface() [1/2]

MeshMetaDataInterface::MeshMetaDataInterface ( const MooseObject moose_object)
protected

Interface for all objects reading MeshMetaData.

The name of the object gets a bogus prefix, which is not intended to be used for storing data. Instead this value is overridden during retrieval.

Definition at line 14 of file MeshMetaDataInterface.C.

15  : _meta_data_app(moose_object->getMooseApp()), _meta_data_object(moose_object)
16 {
17 }
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:45
MooseApp & _meta_data_app
Reference to the application.
const MooseObject *const _meta_data_object
The MooseObject (if any); used for better error handling.

◆ MeshMetaDataInterface() [2/2]

MeshMetaDataInterface::MeshMetaDataInterface ( MooseApp moose_app)
protected

This class constructor is used for non-Moose-based objects like interfaces.

A name for the storage as well as a system name must be passed in along with the thread ID explicitly.

Definition at line 19 of file MeshMetaDataInterface.C.

20  : _meta_data_app(moose_app), _meta_data_object(nullptr)
21 {
22 }
MooseApp & _meta_data_app
Reference to the application.
const MooseObject *const _meta_data_object
The MooseObject (if any); used for better error handling.

Member Function Documentation

◆ getMeshProperty() [1/2]

template<typename T >
const T & MeshMetaDataInterface::getMeshProperty ( const std::string &  data_name,
const std::string &  prefix 
)
protected

Method for retrieving a property with the given type and name exists in the mesh meta-data store.

This method will throw an error if the property does not exist.

Definition at line 134 of file MeshMetaDataInterface.h.

136 {
137  if (!hasMeshProperty(data_name, prefix))
138  mooseErrorInternal("Failed to get mesh property '", prefix, "/", data_name, "'");
139 
140  auto value = &getMeshPropertyInternal(data_name, prefix);
141  mooseAssert(value->declared(), "Value has not been declared");
142  const RestartableData<T> * T_value = dynamic_cast<const RestartableData<T> *>(value);
143  if (!T_value)
144  mooseErrorInternal("While retrieving mesh property '",
145  prefix,
146  "/",
147  data_name,
148  "' with type '",
149  MooseUtils::prettyCppType<T>(),
150  "',\nthe property exists with different type '",
151  value->type(),
152  "'");
153  return T_value->get();
154 }
void mooseErrorInternal(Args &&... args) const
Helper for forwarding a mooseError to an object&#39;s mooseError if it is available (said error will prov...
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Concrete definition of a parameter value for a specified type.
bool hasMeshProperty(const std::string &data_name, const std::string &prefix) const
const RestartableDataValue & getMeshPropertyInternal(const std::string &data_name, const std::string &prefix) const
Helper for getting a mesh property.

◆ getMeshProperty() [2/2]

template<typename T >
const T& MeshMetaDataInterface::getMeshProperty ( const std::string &  data_name)
inlineprotected

Definition at line 56 of file MeshMetaDataInterface.h.

57  {
58  return getMeshProperty<T>(data_name, meshPropertyPrefix(data_name));
59  }
virtual std::string meshPropertyPrefix(const std::string &data_name) const
The default prefix to use for getting/seeing if mesh properties exist.

◆ getMeshPropertyInternal()

const RestartableDataValue & MeshMetaDataInterface::getMeshPropertyInternal ( const std::string &  data_name,
const std::string &  prefix 
) const
private

Helper for getting a mesh property.

Definition at line 46 of file MeshMetaDataInterface.C.

Referenced by getMeshProperty(), and hasMeshProperty().

48 {
50  meshPropertyName(data_name, prefix), MooseApp::MESH_META_DATA, 0);
51 }
static const RestartableDataMapName MESH_META_DATA
Definition: MooseApp.h:95
static std::string meshPropertyName(const std::string &data_name, const std::string &prefix)
MooseApp & _meta_data_app
Reference to the application.
RestartableDataValue & getRestartableMetaData(const std::string &name, const RestartableDataMapName &metaname, THREAD_ID tid)
Definition: MooseApp.C:1869

◆ hasMeshProperty() [1/4]

bool MeshMetaDataInterface::hasMeshProperty ( const std::string &  data_name,
const std::string &  prefix 
) const
protected
Returns
Whether or not a mesh meta-data exists.

Definition at line 25 of file MeshMetaDataInterface.C.

Referenced by MeshGenerator::declareMeshProperty(), getMeshProperty(), hasMeshProperty(), and MeshGenerator::setMeshProperty().

27 {
28  return _meta_data_app.hasRestartableMetaData(meshPropertyName(data_name, prefix),
30 }
bool hasRestartableMetaData(const std::string &name, const RestartableDataMapName &metaname) const
Definition: MooseApp.C:1859
static const RestartableDataMapName MESH_META_DATA
Definition: MooseApp.h:95
static std::string meshPropertyName(const std::string &data_name, const std::string &prefix)
MooseApp & _meta_data_app
Reference to the application.

◆ hasMeshProperty() [2/4]

template<typename T >
bool MeshMetaDataInterface::hasMeshProperty ( const std::string &  data_name,
const std::string &  prefix 
) const
protected
Returns
Whether or not a mesh meta-data exists with the given type.

Definition at line 158 of file MeshMetaDataInterface.h.

160 {
161  if (!hasMeshProperty(data_name, prefix))
162  return false;
163  const auto & value = getMeshPropertyInternal(data_name, prefix);
164  return dynamic_cast<const RestartableData<T> *>(&value) != nullptr;
165 }
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Concrete definition of a parameter value for a specified type.
bool hasMeshProperty(const std::string &data_name, const std::string &prefix) const
const RestartableDataValue & getMeshPropertyInternal(const std::string &data_name, const std::string &prefix) const
Helper for getting a mesh property.

◆ hasMeshProperty() [3/4]

bool MeshMetaDataInterface::hasMeshProperty ( const std::string &  data_name) const
inlineprotected
Returns
Whether or not a mesh meta-data exists with the default prefix.

Definition at line 74 of file MeshMetaDataInterface.h.

75  {
76  return hasMeshProperty(data_name, meshPropertyPrefix(data_name));
77  }
virtual std::string meshPropertyPrefix(const std::string &data_name) const
The default prefix to use for getting/seeing if mesh properties exist.
bool hasMeshProperty(const std::string &data_name, const std::string &prefix) const

◆ hasMeshProperty() [4/4]

template<typename T >
bool MeshMetaDataInterface::hasMeshProperty ( const std::string &  data_name) const
inlineprotected
Returns
Whether or not a mesh meta-data exists with the default prefix and the given type.

Definition at line 82 of file MeshMetaDataInterface.h.

83  {
84  return hasMeshProperty<T>(data_name, meshPropertyPrefix(data_name));
85  }
virtual std::string meshPropertyPrefix(const std::string &data_name) const
The default prefix to use for getting/seeing if mesh properties exist.

◆ meshPropertyName() [1/2]

std::string MeshMetaDataInterface::meshPropertyName ( const std::string &  data_name,
const std::string &  prefix 
)
staticprotected
Returns
The full name for mesh property data.

Definition at line 33 of file MeshMetaDataInterface.C.

Referenced by MeshGenerator::declareMeshProperty(), getMeshPropertyInternal(), hasMeshProperty(), meshPropertyName(), and MeshGenerator::setMeshPropertyHelper().

34 {
35  return std::string(SYSTEM) + "/" + prefix + "/" + data_name;
36 }
static constexpr auto SYSTEM
The system name used when initializing the Restartable interface.

◆ meshPropertyName() [2/2]

std::string MeshMetaDataInterface::meshPropertyName ( const std::string &  data_name) const
inlineprotected
Returns
The default mesh property name for mesh property data

Definition at line 95 of file MeshMetaDataInterface.h.

96  {
97  return meshPropertyName(data_name, meshPropertyPrefix(data_name));
98  }
static std::string meshPropertyName(const std::string &data_name, const std::string &prefix)
virtual std::string meshPropertyPrefix(const std::string &data_name) const
The default prefix to use for getting/seeing if mesh properties exist.

◆ meshPropertyPrefix()

std::string MeshMetaDataInterface::meshPropertyPrefix ( const std::string &  data_name) const
privatevirtual

The default prefix to use for getting/seeing if mesh properties exist.

For now, this is not supported except in MeshGenerators. In the future, we will automate looking for mesh properties.

Reimplemented in MeshGenerator.

Definition at line 39 of file MeshMetaDataInterface.C.

Referenced by getMeshProperty(), hasMeshProperty(), and meshPropertyName().

40 {
41  mooseError("This object does not support obtaining a mesh property without a prefix.\n\nThis "
42  "capability is upcoming.");
43 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299

◆ mooseErrorInternal()

template<typename... Args>
void MeshMetaDataInterface::mooseErrorInternal ( Args &&...  args) const
inlineprivate

Helper for forwarding a mooseError to an object's mooseError if it is available (said error will provide more context: object name and type)

Definition at line 124 of file MeshMetaDataInterface.h.

Referenced by getMeshProperty().

125  {
126  if (_meta_data_object)
127  _meta_data_object->mooseError(std::forward<Args>(args)...);
128  mooseError(std::forward<Args>(args)...);
129  }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
const MooseObject *const _meta_data_object
The MooseObject (if any); used for better error handling.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.

Member Data Documentation

◆ _meta_data_app

MooseApp& MeshMetaDataInterface::_meta_data_app
private

Reference to the application.

Definition at line 114 of file MeshMetaDataInterface.h.

Referenced by getMeshPropertyInternal(), and hasMeshProperty().

◆ _meta_data_object

const MooseObject* const MeshMetaDataInterface::_meta_data_object
private

The MooseObject (if any); used for better error handling.

Definition at line 117 of file MeshMetaDataInterface.h.

Referenced by mooseErrorInternal().

◆ NAME

constexpr auto MeshMetaDataInterface::NAME = "<empty>"
static

The data name used when initializing the Restartable interface for non-MeshGenerator objects.

Definition at line 33 of file MeshMetaDataInterface.h.

◆ SYSTEM

constexpr auto MeshMetaDataInterface::SYSTEM = "MeshMetaData"
static

The system name used when initializing the Restartable interface.

Definition at line 30 of file MeshMetaDataInterface.h.

Referenced by meshPropertyName().


The documentation for this class was generated from the following files: