https://mooseframework.inl.gov
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
moose::internal::SolutionInvalidityRegistry Class Reference

The place where all sections with solution invalid warnings will be stored. More...

#include <SolutionInvalidityRegistry.h>

Inheritance diagram for moose::internal::SolutionInvalidityRegistry:
[legend]

Public Member Functions

InvalidSolutionID registerInvalidity (const std::string &object_type, const std::string &message, const bool warning)
 Call to register an invalid calculation. More...
 
std::size_t size () const
 
std::size_t id (const SolutionInvalidityName &key) const
 
bool keyExists (const SolutionInvalidityName &key) const
 
bool idExists (const std::size_t id) const
 
const SolutionInvalidityInfoitem (const std::size_t id) const
 

Protected Member Functions

const SolutionInvalidityInfoitemNonLocking (const std::size_t id) const
 
std::size_t registerItem (const SolutionInvalidityName &key, CreateItem &create_item)
 
Registers an item with key key if said key does not exist. More...
 

Protected Attributes

const std::string _name
 The name of this registry; used in error handling. More...
 
std::unordered_map< SolutionInvalidityName, std::size_t, SoltionInvalidityNameHash_key_to_id
 Map of keys to IDs. More...
 
std::deque< SolutionInvalidityInfo_id_to_item
 Vector of IDs to Items. More...
 
std::mutex _key_to_id_mutex
 Mutex for locking access to _key_to_id NOTE: These can be changed to shared_mutexes once we get C++17. More...
 
std::mutex _id_to_item_mutex
 Mutex for locking access to _id_to_item NOTE: These can be changed to shared_mutexes once we get C++17. More...
 

Private Member Functions

 SolutionInvalidityRegistry ()
 

Private Attributes

friend SolutionInvalidity
 This is only here so that SolutionInvalidity can access readSectionInfo. More...
 

Friends

SolutionInvalidityRegistrygetSolutionInvalidityRegistry ()
 So it can be constructed. More...
 

Detailed Description

The place where all sections with solution invalid warnings will be stored.

Definition at line 91 of file SolutionInvalidityRegistry.h.

Constructor & Destructor Documentation

◆ SolutionInvalidityRegistry()

moose::internal::SolutionInvalidityRegistry::SolutionInvalidityRegistry ( )
private

Member Function Documentation

◆ id()

std::size_t GeneralRegistry< SolutionInvalidityName , SolutionInvalidityInfo , SoltionInvalidityNameHash >::id ( const SolutionInvalidityName &  key) const
inherited
Returns
The ID assocated with the key key

Definition at line 97 of file GeneralRegistry.h.

Referenced by registerInvalidity().

98 {
99  std::lock_guard<std::mutex> lock(_key_to_id_mutex);
100  const auto it = _key_to_id.find(key);
101  if (it == _key_to_id.end())
102  mooseError(_name, ": Key '", key, "' is not registered");
103  return it->second;
104 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::mutex _key_to_id_mutex
Mutex for locking access to _key_to_id NOTE: These can be changed to shared_mutexes once we get C++17...
const std::string _name
The name of this registry; used in error handling.
std::unordered_map< SolutionInvalidityName, std::size_t, SoltionInvalidityNameHash > _key_to_id
Map of keys to IDs.

◆ idExists()

bool GeneralRegistry< SolutionInvalidityName , SolutionInvalidityInfo , SoltionInvalidityNameHash >::idExists ( const std::size_t  id) const
inherited
Returns
Whether or not the id id is registered

Definition at line 116 of file GeneralRegistry.h.

117 {
118  std::lock_guard<std::mutex> lock(_id_to_item_mutex);
119  return id < _id_to_item.size();
120 }
std::deque< SolutionInvalidityInfo > _id_to_item
Vector of IDs to Items.
std::mutex _id_to_item_mutex
Mutex for locking access to _id_to_item NOTE: These can be changed to shared_mutexes once we get C++1...

◆ item()

Returns
The item associated with the key key (thread safe)

Definition at line 124 of file GeneralRegistry.h.

Referenced by registerInvalidity().

125 {
126  std::lock_guard<std::mutex> lock(_id_to_item_mutex);
127  return itemNonLocking(id);
128 }
std::mutex _id_to_item_mutex
Mutex for locking access to _id_to_item NOTE: These can be changed to shared_mutexes once we get C++1...

◆ itemNonLocking()

const SolutionInvalidityInfo & GeneralRegistry< SolutionInvalidityName , SolutionInvalidityInfo , SoltionInvalidityNameHash >::itemNonLocking ( const std::size_t  id) const
protectedinherited
Returns
The item associated with the key key (not thread safe)

Definition at line 132 of file GeneralRegistry.h.

133 {
134  if (id >= _id_to_item.size())
135  mooseError(_name, ": ID '", id, "' is not registered");
136  return _id_to_item[id];
137 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
const std::string _name
The name of this registry; used in error handling.
std::deque< SolutionInvalidityInfo > _id_to_item
Vector of IDs to Items.

◆ keyExists()

bool GeneralRegistry< SolutionInvalidityName , SolutionInvalidityInfo , SoltionInvalidityNameHash >::keyExists ( const SolutionInvalidityName &  key) const
inherited
Returns
Whether or not the key key is registered

Definition at line 108 of file GeneralRegistry.h.

Referenced by registerInvalidity().

109 {
110  std::lock_guard<std::mutex> lock(_key_to_id_mutex);
111  return _key_to_id.count(key);
112 }
std::mutex _key_to_id_mutex
Mutex for locking access to _key_to_id NOTE: These can be changed to shared_mutexes once we get C++17...
std::unordered_map< SolutionInvalidityName, std::size_t, SoltionInvalidityNameHash > _key_to_id
Map of keys to IDs.

◆ registerInvalidity()

InvalidSolutionID moose::internal::SolutionInvalidityRegistry::registerInvalidity ( const std::string &  object_type,
const std::string &  message,
const bool  warning 
)

Call to register an invalid calculation.

Parameters
object_typeThe type of the object doing the registration
messageThe description of the solution invalid warning
warningWhether or not it is a warning
Returns
The registered ID

Definition at line 33 of file SolutionInvalidityRegistry.C.

Referenced by dataLoad(), SolutionInvalidInterface::registerInvalidSolutionInternal(), and SolutionInvalidity::syncIteration().

36 {
37  const SolutionInvalidityName name(object_type, message);
38  if (keyExists(name))
39  mooseAssert(item(id(name)).warning == warning, "Inconsistent registration for a warning");
40  const auto create_item = [&object_type, &message, &warning](const std::size_t id)
41  { return SolutionInvalidityInfo(object_type, message, id, warning); };
42  return registerItem(name, create_item);
43 }
std::string name(const ElemQuality q)
std::size_t registerItem(const SolutionInvalidityName &key, CreateItem &create_item)
Registers an item with key key if said key does not exist.

◆ registerItem()

std::size_t GeneralRegistry< SolutionInvalidityName , SolutionInvalidityInfo , SoltionInvalidityNameHash >::registerItem ( const SolutionInvalidityName &  key,
CreateItem &  create_item 
)
protectedinherited


Registers an item with key key if said key does not exist.

Parameters
keyThe key
create_itemLambda called to create an item if the key does not exist. Takes a single argument std::size_t which is the

new ID and should return an Item

Returns
The ID of the item

Definition at line 142 of file GeneralRegistry.h.

Referenced by registerInvalidity().

143 {
144  std::lock_guard<std::mutex> lock_key(_key_to_id_mutex);
145 
146  // Is it already registered?
147  const auto it = _key_to_id.find(key);
148  if (it != _key_to_id.end())
149  return it->second;
150 
151  // It's not registered
152  std::lock_guard<std::mutex> lock_id(_id_to_item_mutex);
153  const auto id = _id_to_item.size();
154  _key_to_id.emplace(key, id);
155  _id_to_item.emplace_back(std::move(create_item(id)));
156  return id;
157 }
std::mutex _key_to_id_mutex
Mutex for locking access to _key_to_id NOTE: These can be changed to shared_mutexes once we get C++17...
std::unordered_map< SolutionInvalidityName, std::size_t, SoltionInvalidityNameHash > _key_to_id
Map of keys to IDs.
std::deque< SolutionInvalidityInfo > _id_to_item
Vector of IDs to Items.
std::mutex _id_to_item_mutex
Mutex for locking access to _id_to_item NOTE: These can be changed to shared_mutexes once we get C++1...

◆ size()

Returns
The number of registered items

Definition at line 89 of file GeneralRegistry.h.

90 {
91  std::lock_guard<std::mutex> lock(_id_to_item_mutex);
92  return _id_to_item.size();
93 }
std::deque< SolutionInvalidityInfo > _id_to_item
Vector of IDs to Items.
std::mutex _id_to_item_mutex
Mutex for locking access to _id_to_item NOTE: These can be changed to shared_mutexes once we get C++1...

Friends And Related Function Documentation

◆ getSolutionInvalidityRegistry

SolutionInvalidityRegistry& getSolutionInvalidityRegistry ( )
friend

So it can be constructed.

Definition at line 18 of file SolutionInvalidityRegistry.C.

19 {
20  // In C++11 this is even thread safe! (Lookup "Static Initializers")
21  static SolutionInvalidityRegistry solution_invalid_registry_singleton;
22 
23  return solution_invalid_registry_singleton;
24 }

Member Data Documentation

◆ _id_to_item

Vector of IDs to Items.

Definition at line 72 of file GeneralRegistry.h.

◆ _id_to_item_mutex

std::mutex GeneralRegistry< SolutionInvalidityName , SolutionInvalidityInfo , SoltionInvalidityNameHash >::_id_to_item_mutex
mutableprotectedinherited

Mutex for locking access to _id_to_item NOTE: These can be changed to shared_mutexes once we get C++17.

Definition at line 79 of file GeneralRegistry.h.

◆ _key_to_id

Map of keys to IDs.

Definition at line 70 of file GeneralRegistry.h.

◆ _key_to_id_mutex

std::mutex GeneralRegistry< SolutionInvalidityName , SolutionInvalidityInfo , SoltionInvalidityNameHash >::_key_to_id_mutex
mutableprotectedinherited

Mutex for locking access to _key_to_id NOTE: These can be changed to shared_mutexes once we get C++17.

Definition at line 76 of file GeneralRegistry.h.

◆ _name

const std::string GeneralRegistry< SolutionInvalidityName , SolutionInvalidityInfo , SoltionInvalidityNameHash >::_name
protectedinherited

The name of this registry; used in error handling.

Definition at line 67 of file GeneralRegistry.h.

◆ SolutionInvalidity

friend moose::internal::SolutionInvalidityRegistry::SolutionInvalidity
private

This is only here so that SolutionInvalidity can access readSectionInfo.

Definition at line 114 of file SolutionInvalidityRegistry.h.


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