https://mooseframework.inl.gov
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 
18 class MeshGenerator;
19 
27 {
28 public:
30  static constexpr auto SYSTEM = "MeshMetaData";
31 
33  static constexpr auto NAME = "<empty>";
34 
35 protected:
41  MeshMetaDataInterface(const MooseObject * moose_object);
42 
47  MeshMetaDataInterface(MooseApp & moose_app);
48 
49 #ifdef MOOSE_KOKKOS_ENABLED
50 
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 
108 private:
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  {
134  if (_meta_data_object)
135  _meta_data_object->mooseError(std::forward<Args>(args)...);
136  mooseError(std::forward<Args>(args)...);
137  }
138 };
139 
140 template <typename T>
141 const T &
142 MeshMetaDataInterface::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 
164 template <typename T>
165 bool
166 MeshMetaDataInterface::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 }
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...
static constexpr auto NAME
The data name used when initializing the Restartable interface for non-MeshGenerator objects...
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
void mooseErrorInternal(Args &&... args) const
Helper for forwarding a mooseError to an object&#39;s mooseError if it is available (said error will prov...
bool hasMeshProperty(const std::string &data_name) const
Base class for MOOSE-based applications.
Definition: MooseApp.h:108
static std::string meshPropertyName(const std::string &data_name, const std::string &prefix)
MeshMetaDataInterface(const MooseObject *moose_object)
Interface for all objects reading MeshMetaData.
bool hasMeshProperty(const std::string &data_name) const
MooseApp & _meta_data_app
Reference to the application.
const MooseObject *const _meta_data_object
The MooseObject (if any); used for better error handling.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
Concrete definition of a parameter value for a specified type.
static constexpr auto SYSTEM
The system name used when initializing the Restartable interface.
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:281
The Interface used to retrieve mesh meta data (attributes) set by the MeshGenerator system...
const T & getMeshProperty(const std::string &data_name)
virtual std::string meshPropertyPrefix(const std::string &data_name) const
The default prefix to use for getting/seeing if mesh properties exist.
std::string meshPropertyName(const std::string &data_name) const
bool hasMeshProperty(const std::string &data_name, const std::string &prefix) const
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:33
const RestartableDataValue & getMeshPropertyInternal(const std::string &data_name, const std::string &prefix) const
Helper for getting a mesh property.
Abstract definition of a RestartableData value.