https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MeshMetaDataInterface.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#include "MooseError.h"
13#include "RestartableData.h"
14#include "MooseObject.h"
15
16#include <string>
17
18class MeshGenerator;
19
27{
28public:
30 static constexpr auto SYSTEM = "MeshMetaData";
31
33 static constexpr auto NAME = "<empty>";
34
35protected:
41 MeshMetaDataInterface(const MooseObject * moose_object);
42
48
49#ifdef MOOSE_KOKKOS_ENABLED
54 const Moose::Kokkos::FunctorCopy & key);
55#endif
56
61 template <typename T>
62 const T & getMeshProperty(const std::string & data_name, const std::string & prefix);
63 template <typename T>
64 const T & getMeshProperty(const std::string & data_name)
65 {
66 return getMeshProperty<T>(data_name, meshPropertyPrefix(data_name));
67 }
68
72 bool hasMeshProperty(const std::string & data_name, const std::string & prefix) const;
76 template <typename T>
77 bool hasMeshProperty(const std::string & data_name, const std::string & prefix) const;
78
82 bool hasMeshProperty(const std::string & data_name) const
83 {
84 return hasMeshProperty(data_name, meshPropertyPrefix(data_name));
85 }
89 template <typename T>
90 bool hasMeshProperty(const std::string & data_name) const
91 {
92 return hasMeshProperty<T>(data_name, meshPropertyPrefix(data_name));
93 }
94
98 static std::string meshPropertyName(const std::string & data_name, const std::string & prefix);
99
103 std::string meshPropertyName(const std::string & data_name) const
104 {
105 return meshPropertyName(data_name, meshPropertyPrefix(data_name));
106 }
107
108private:
115 virtual std::string meshPropertyPrefix(const std::string & data_name) const;
116
118 const RestartableDataValue & getMeshPropertyInternal(const std::string & data_name,
119 const std::string & prefix) const;
120
123
126
131 template <typename... Args>
132 [[noreturn]] void mooseErrorInternal(Args &&... args) const
133 {
135 _meta_data_object->mooseError(std::forward<Args>(args)...);
136 mooseError(std::forward<Args>(args)...);
137 }
138};
139
140template <typename T>
141const T &
142MeshMetaDataInterface::getMeshProperty(const std::string & data_name, const std::string & prefix)
143
144{
145 if (!hasMeshProperty(data_name, prefix))
146 mooseErrorInternal("Failed to get mesh property '", prefix, "/", data_name, "'");
147
148 auto value = &getMeshPropertyInternal(data_name, prefix);
149 mooseAssert(value->declared(), "Value has not been declared");
150 const RestartableData<T> * T_value = dynamic_cast<const RestartableData<T> *>(value);
151 if (!T_value)
152 mooseErrorInternal("While retrieving mesh property '",
153 prefix,
154 "/",
155 data_name,
156 "' with type '",
157 MooseUtils::prettyCppType<T>(),
158 "',\nthe property exists with different type '",
159 value->type(),
160 "'");
161 return T_value->get();
162}
163
164template <typename T>
165bool
166MeshMetaDataInterface::hasMeshProperty(const std::string & data_name,
167 const std::string & prefix) const
168{
169 if (!hasMeshProperty(data_name, prefix))
170 return false;
171 const auto & value = getMeshPropertyInternal(data_name, prefix);
172 return dynamic_cast<const RestartableData<T> *>(&value) != nullptr;
173}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
MeshGenerators are objects that can modify or add to an existing mesh.
The Interface used to retrieve mesh meta data (attributes) set by the MeshGenerator system.
bool hasMeshProperty(const std::string &data_name, const std::string &prefix) const
MooseApp & _meta_data_app
Reference to the application.
const MooseObject *const _meta_data_object
The MooseObject (if any); used for better error handling.
static constexpr auto SYSTEM
The system name used when initializing the Restartable interface.
const RestartableDataValue & getMeshPropertyInternal(const std::string &data_name, const std::string &prefix) const
Helper for getting a mesh property.
std::string meshPropertyName(const std::string &data_name) const
void mooseErrorInternal(Args &&... args) const
Helper for forwarding a mooseError to an object's mooseError if it is available (said error will prov...
bool hasMeshProperty(const std::string &data_name) const
const T & getMeshProperty(const std::string &data_name)
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.
static constexpr auto NAME
The data name used when initializing the Restartable interface for non-MeshGenerator objects.
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.
bool hasMeshProperty(const std::string &data_name) const
Base class for MOOSE-based applications.
Definition MooseApp.h:110
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
Abstract definition of a RestartableData value.
Concrete definition of a parameter value for a specified type.
const T & get() const