https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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.
 
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.
 

Protected Attributes

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.
 
std::deque< SolutionInvalidityInfo_id_to_item
 Vector of IDs to Items.
 
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::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.
 

Private Member Functions

 SolutionInvalidityRegistry ()
 

Private Attributes

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

Friends

SolutionInvalidityRegistrygetSolutionInvalidityRegistry ()
 So it can be constructed.
 

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 32 of file GeneralRegistry.h.

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:311
std::unordered_map< SolutionInvalidityName, std::size_t, SoltionInvalidityNameHash > _key_to_id
Map of keys to IDs.
const std::string _name
The name of this registry; used in error handling.
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...

◆ 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 41 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::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 46 of file GeneralRegistry.h.

125{
126 std::lock_guard<std::mutex> lock(_id_to_item_mutex);
127 return itemNonLocking(id);
128}

◆ 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 52 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}

◆ keyExists()

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

Definition at line 37 of file GeneralRegistry.h.

109{
110 std::lock_guard<std::mutex> lock(_key_to_id_mutex);
111 return _key_to_id.count(key);
112}

◆ 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.

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::size_t registerItem(const SolutionInvalidityName &key, CreateItem &create_item)
Registers an item with key key if said key does not exist.
std::string name(const ElemQuality q)

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

◆ 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 64 of file GeneralRegistry.h.

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}

◆ size()

Returns
The number of registered items

Definition at line 27 of file GeneralRegistry.h.

90{
91 std::lock_guard<std::mutex> lock(_id_to_item_mutex);
92 return _id_to_item.size();
93}

Friends And Related Symbol 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: