https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
ConvergenceIterationTypeEnum Class Reference

Enum for Convergence iteration type, which can have new values registered. More...

#include <ConvergenceIterationTypeEnum.h>

Inheritance diagram for ConvergenceIterationTypeEnum:
[legend]

Public Types

enum class  CompareMode { COMPARE_NAME , COMPARE_ID , COMPARE_BOTH }
 Enum item for controlling comparison in the compareCurrent method. More...
 

Public Member Functions

 ConvergenceIterationTypeEnum ()
 
const MooseEnumItemaddConvergenceIterationType (const std::string &raw_name)
 Add a new Convergence iteration type.
 
 operator int () const
 Cast operators to make this object behave as value_types and std::string these methods can be used so that this class behaves more like a normal value_type enumeration.
 
 operator std::string () const
 
bool operator== (const char *value) const
 Comparison operators for comparing with character constants, MooseEnums or integer values.
 
bool operator== (int value) const
 
bool operator== (unsigned short value) const
 
bool operator== (const MooseEnum &value) const
 
bool operator!= (const char *value) const
 
bool operator!= (int value) const
 
bool operator!= (unsigned short value) const
 
bool operator!= (const MooseEnum &value) const
 
bool compareCurrent (const MooseEnum &other, CompareMode mode=CompareMode::COMPARE_NAME) const
 Method for comparing currently set values between MooseEnum.
 
virtual bool isValid () const override
 IsValid.
 
template<typename T >
getEnum () const
 get the current value cast to the enum type T
 
virtual void deprecate (const std::string &name, const std::string &raw_name="")
 Deprecates various options in the MOOSE enum.
 
std::vector< std::string > getNames () const
 Method for returning a vector of all valid enumeration names for this instance.
 
std::string getRawNames () const
 Method for returning the raw name strings for this instance.
 
std::vector< intgetIDs () const
 Method for returning a vector of ids for this instance.
 
bool isOutOfRangeAllowed () const
 isOutOfRangeAllowed
 
const std::set< MooseEnumItem > & items () const
 Return the complete set of available flags.
 
void addDocumentation (const std::string &name, const std::string &doc)
 Add an item documentation string.
 
const std::map< MooseEnumItem, std::string > & getItemDocumentation () const
 Get the map containing each item's documentation string.
 
int getNextValidID () const
 Compute the next valid ID.
 
MooseEnumBaseoperator+= (const std::string &name)
 Adds an enumeration item from name.
 
MooseEnumBaseoperator+= (const std::initializer_list< std::string > &names)
 Adds enumeration items from a list of names.
 
void assign (const std::string &name, const std::optional< std::string > &context={})
 
void assign (int value)
 
void assign (const MooseEnumItem &item)
 
std::set< MooseEnumItem >::const_iterator find (const MooseEnumItem &other) const
 Locate an item.
 
std::set< MooseEnumItem >::const_iterator find (const std::string &name) const
 
std::set< MooseEnumItem >::const_iterator find (int id) const
 

Protected Member Functions

virtual void checkDeprecated () const override
 Check whether the current value is deprecated when called.
 
void checkDeprecated (const MooseEnumItem &item) const
 Check and warn deprecated values.
 
void addEnumerationNames (const std::string &names)
 Methods to add possible enumeration value to the enum.
 
const MooseEnumItemaddEnumerationName (const std::string &raw_name)
 
const MooseEnumItemaddEnumerationName (const std::string &name, const int &value)
 
const MooseEnumItemaddEnumerationItem (const MooseEnumItem &item)
 

Protected Attributes

std::set< MooseEnumItem_items
 Storage for the assigned items.
 
std::map< MooseEnumItem, MooseEnumItem_deprecated_items
 The map of deprecated names and optional replacements.
 
bool _allow_out_of_range
 Flag to enable enumeration items not previously defined.
 
std::map< MooseEnumItem, std::string > _item_documentation
 The map of items and their respective documentation strings.
 

Private Attributes

MooseEnumItem _current
 The current id.
 

Detailed Description

Enum for Convergence iteration type, which can have new values registered.

Definition at line 17 of file ConvergenceIterationTypeEnum.h.

Member Enumeration Documentation

◆ CompareMode

enum class MooseEnum::CompareMode
stronginherited

Enum item for controlling comparison in the compareCurrent method.

Enumerator
COMPARE_NAME 
COMPARE_ID 
COMPARE_BOTH 

Definition at line 60 of file MooseEnum.h.

Constructor & Destructor Documentation

◆ ConvergenceIterationTypeEnum()

ConvergenceIterationTypeEnum::ConvergenceIterationTypeEnum ( )
inline

Definition at line 20 of file ConvergenceIterationTypeEnum.h.

20: MooseEnum("") {}
MooseEnum()
Constructor for use by libmesh::Parameters and ReporterMode.
Definition MooseEnum.C:36

Member Function Documentation

◆ addConvergenceIterationType()

const MooseEnumItem & ConvergenceIterationTypeEnum::addConvergenceIterationType ( const std::string &  raw_name)
inline

Add a new Convergence iteration type.

Definition at line 23 of file ConvergenceIterationTypeEnum.h.

24 {
25 return addEnumerationName(raw_name);
26 }
const MooseEnumItem & addEnumerationName(const std::string &raw_name)

Referenced by moose::internal::ConvergenceIterationTypeRegistry::registerType().

◆ addDocumentation()

void MooseEnumBase::addDocumentation ( const std::string &  name,
const std::string &  doc 
)
inherited

Add an item documentation string.

Definition at line 175 of file MooseEnumBase.C.

176{
177 auto it = find(name);
178 if (it == _items.end())
179 mooseError("Item '", name, "' not found in addDocumentation.");
180 _item_documentation[*it] = doc;
181}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
std::set< MooseEnumItem > _items
Storage for the assigned items.
std::set< MooseEnumItem >::const_iterator find(const MooseEnumItem &other) const
Locate an item.
std::map< MooseEnumItem, std::string > _item_documentation
The map of items and their respective documentation strings.

Referenced by MortarConsumerInterface::triangulationParams(), MortarConsumerInterface::validParams(), ReferenceResidualInterface::validParams(), MFEMSamplerBase::validParams(), and PseudoTimestep::validParams().

◆ addEnumerationItem()

const MooseEnumItem & MooseEnumBase::addEnumerationItem ( const MooseEnumItem item)
protectedinherited

Definition at line 117 of file MooseEnumBase.C.

118{
119 const auto & item_it = find(item);
120 if (item_it != _items.end()) // do nothing for identical insertions
121 return *item_it;
122
123 if (find(item.id()) != _items.end())
124 mooseError("The supplied id ",
125 item.id(),
126 " already exists in the enumeration, cannot not add '",
127 item,
128 "'.");
129 if (find(item.name()) != _items.end())
130 mooseError("The name '", item.name(), "' already exists in the enumeration.");
131
132 return *_items.insert(item).first;
133}
const std::string & name() const
const int & id() const
Return the numeric, name, or raw name.

Referenced by ExecFlagEnum::addAvailableFlags(), MooseEnumBase::addEnumerationName(), MultiMooseEnum::addValidName(), MultiMooseEnum::assignValues(), and ReporterProducerEnum::insert().

◆ addEnumerationName() [1/2]

const MooseEnumItem & MooseEnumBase::addEnumerationName ( const std::string &  name,
const int value 
)
protectedinherited

Definition at line 111 of file MooseEnumBase.C.

112{
113 return addEnumerationItem(MooseEnumItem(name, value));
114}
const MooseEnumItem & addEnumerationItem(const MooseEnumItem &item)
Class for containing MooseEnum item information.

◆ addEnumerationName() [2/2]

const MooseEnumItem & MooseEnumBase::addEnumerationName ( const std::string &  raw_name)
protectedinherited

Definition at line 73 of file MooseEnumBase.C.

74{
75 // Make sure the option is not malformed
76 if (raw_name.find_first_of('=') == 0 || raw_name.find_last_of('=') == raw_name.length() - 1)
77 mooseError("You cannot place whitespace around the '=' character in MooseEnumBase");
78
79 // Split on equals sign
80 std::vector<std::string> name_value;
81 MooseUtils::tokenize(MooseUtils::trim(raw_name), name_value, 1, "=");
82
83 // There should be one or two items in the name_value
84 if (name_value.size() < 1 || name_value.size() > 2)
85 mooseError("Invalid option supplied in MooseEnumBase: ", raw_name);
86
87 // Remove un-wanted space around string
88 name_value[0] = MooseUtils::trim(name_value[0]);
89
90 // See if there is a value supplied for this option
91 // strtol allows for proper conversions of both int and hex strings
92 int value;
93 if (name_value.size() == 2)
94 value = std::strtol(name_value[1].c_str(), NULL, 0);
95 else
97
98 return addEnumerationName(name_value[0], value);
99}
int getNextValidID() const
Compute the next valid ID.
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
This function will split the passed in string on a set of delimiters appending the substrings to the ...
std::string trim(const std::string &str, const std::string &white_space=" \t\n\v\f\r")
Standard scripting language trim function.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

Referenced by addConvergenceIterationType(), MooseEnumBase::addEnumerationName(), MooseEnumBase::addEnumerationNames(), MultiMooseEnum::addValidName(), and MooseEnumBase::operator+=().

◆ addEnumerationNames()

void MooseEnumBase::addEnumerationNames ( const std::string &  names)
protectedinherited

Methods to add possible enumeration value to the enum.

The MooseEnum/MultiMooseEnum are not designed to be modified, with respect to the list of possible values. However, this is not the case for the ExecFlagEnum which is a special type of MultiMooseEnum for managing the "execute_on" flags. These methods are used by ExecFlagEnum to allow users to modify the available execute flags for their object.

Definition at line 64 of file MooseEnumBase.C.

65{
66 std::vector<std::string> elements;
67 MooseUtils::tokenize(names, elements, 1, " ");
68 for (const std::string & raw_name : elements)
69 addEnumerationName(raw_name);
70}

Referenced by MooseEnumBase::MooseEnumBase().

◆ assign() [1/3]

void MooseEnum::assign ( const MooseEnumItem item)
inherited

Definition at line 115 of file MooseEnum.C.

116{
117 std::set<MooseEnumItem>::const_iterator iter = find(item);
118 if (iter == _items.end())
119 mooseError("Invalid item \"",
120 item,
121 "\" in MooseEnum. Valid ids are \"",
123 "\".");
124 else
125 _current = *iter;
126
128}
const std::set< MooseEnumItem > & items() const
Return the complete set of available flags.
virtual void checkDeprecated() const override
Check whether the current value is deprecated when called.
Definition MooseEnum.C:205
MooseEnumItem _current
The current id.
Definition MooseEnum.h:167
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:64

◆ assign() [2/3]

void MooseEnum::assign ( const std::string &  name,
const std::optional< std::string > &  context = {} 
)
inherited

Definition at line 60 of file MooseEnum.C.

61{
62 if (MooseUtils::trim(name) == "")
63 {
65 return;
66 }
67
68 // Check if name can be parsed cleanly into an integer
69 int value = 0;
70 bool integer = (std::istringstream(MooseUtils::trim(name)) >> value).eof();
71
72 if (auto iter = find(name); iter != _items.end())
73 _current = *iter;
74 else if (auto subs = find(value); subs != _items.end() && integer)
75 _current = *subs;
76 else
77 {
78 if (!_allow_out_of_range) // Are out of range values allowed?
79 mooseError(context ? (*context + ":\n\n") : std::string(""),
80 "Invalid option \"",
81 name,
82 "\" in MooseEnum. Valid options (not case-sensitive) are \"",
84 "\".");
85
86 _current = MooseEnumItem(name, integer ? value : getNextValidID());
87 _items.insert(_current);
88 }
89
91}
bool _allow_out_of_range
Flag to enable enumeration items not previously defined.
std::string getRawNames() const
Method for returning the raw name strings for this instance.
static const int INVALID_ID
operator std::string() const
Definition MooseEnum.h:96
std::string name(const ElemQuality q)

Referenced by ReporterContextBase::init(), MooseEnum::operator=(), MooseEnum::operator=(), and MooseEnum::operator=().

◆ assign() [3/3]

void MooseEnum::assign ( int  value)
inherited

Definition at line 94 of file MooseEnum.C.

95{
96 if (value == MooseEnumItem::INVALID_ID)
97 {
99 return;
100 }
101
102 if (auto iter = find(value); iter != _items.end())
103 _current = *iter;
104 else
105 mooseError("Invalid id \"",
106 value,
107 "\" in MooseEnum. Valid ids are \"",
109 "\".");
110
112}
std::vector< int > getIDs() const
Method for returning a vector of ids for this instance.

◆ checkDeprecated() [1/2]

void MooseEnum::checkDeprecated ( ) const
overrideprotectedvirtualinherited

Check whether the current value is deprecated when called.

Implements MooseEnumBase.

Definition at line 205 of file MooseEnum.C.

206{
208}
virtual void checkDeprecated() const =0
Method that must be implemented to check derived class values against the _deprecated_names.

Referenced by MooseEnum::assign(), MooseEnum::assign(), and MooseEnum::assign().

◆ checkDeprecated() [2/2]

void MooseEnumBase::checkDeprecated ( const MooseEnumItem item) const
protectedinherited

Check and warn deprecated values.

Definition at line 136 of file MooseEnumBase.C.

137{
138 std::map<MooseEnumItem, MooseEnumItem>::const_iterator it = _deprecated_items.find(item);
139 if (it != _deprecated_items.end())
140 {
141 if (it->second.name().empty())
142 mooseWarning(item.name() + " is deprecated");
143 else
144 mooseWarning(item.name() + " is deprecated, consider using " + it->second.name());
145 }
146}
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition MooseError.h:345
std::map< MooseEnumItem, MooseEnumItem > _deprecated_items
The map of deprecated names and optional replacements.

◆ compareCurrent()

bool MooseEnum::compareCurrent ( const MooseEnum other,
CompareMode  mode = CompareMode::COMPARE_NAME 
) const
inherited

Method for comparing currently set values between MooseEnum.

Definition at line 174 of file MooseEnum.C.

175{
176 switch (mode)
177 {
179 return (_current.id() == other._current.id()) && (_current.name() == other._current.name());
181 return _current.name() == other._current.name();
183 return _current.id() == other._current.id();
184 }
185 return false;
186}

◆ deprecate()

void MooseEnumBase::deprecate ( const std::string &  name,
const std::string &  raw_name = "" 
)
virtualinherited

Deprecates various options in the MOOSE enum.

For each deprecated option, you may supply an optional new option that will be used in a message telling the user which new option replaces the old one.

Definition at line 45 of file MooseEnumBase.C.

46{
47 std::set<MooseEnumItem>::const_iterator deprecated = find(name);
48 if (deprecated == _items.end())
49 mooseError("Cannot deprecate the enum item ", name, ", is not an available value.");
50
51 std::set<MooseEnumItem>::const_iterator replaced = find(raw_name);
52 if (replaced == _items.end())
53 mooseError("Cannot deprecate the enum item ",
54 name,
55 ", since the replaced item ",
56 raw_name,
57 " it is not an available value.");
58
59 _deprecated_items.emplace(std::make_pair(*deprecated, *replaced));
61}

◆ find() [1/3]

std::set< MooseEnumItem >::const_iterator MooseEnumBase::find ( const MooseEnumItem other) const
inherited

◆ find() [2/3]

std::set< MooseEnumItem >::const_iterator MooseEnumBase::find ( const std::string &  name) const
inherited

Definition at line 190 of file MooseEnumBase.C.

191{
192 std::string upper = MooseUtils::toUpper(name);
193 return std::find_if(_items.begin(),
194 _items.end(),
195 [&upper](MooseEnumItem const & item) { return item.name() == upper; });
196}

◆ find() [3/3]

std::set< MooseEnumItem >::const_iterator MooseEnumBase::find ( int  id) const
inherited

Definition at line 199 of file MooseEnumBase.C.

200{
201 return std::find_if(
202 _items.begin(), _items.end(), [&id](MooseEnumItem const & item) { return item.id() == id; });
203}

◆ getEnum()

template<typename T >
T MooseEnum::getEnum ( ) const
inherited

get the current value cast to the enum type T

Definition at line 172 of file MooseEnum.h.

173{
174#ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS
175 static_assert(std::is_enum<T>::value == true,
176 "The type requested from MooseEnum::getEnum must be an enum type!\n\n");
177#endif
178 return static_cast<T>(_current.id());
179}

Referenced by CSG::CSGRegion::getRegionType().

◆ getIDs()

std::vector< int > MooseEnumBase::getIDs ( ) const
inherited

Method for returning a vector of ids for this instance.

Returns
a vector of ints containing the possible ids for this enumeration

Definition at line 165 of file MooseEnumBase.C.

166{
167 std::vector<int> out;
168 out.reserve(_items.size());
169 for (const auto & item : _items)
170 out.push_back(item.id());
171 return out;
172}
OStreamProxy out(std::cout)

Referenced by MooseEnum::assign().

◆ getItemDocumentation()

const std::map< MooseEnumItem, std::string > & MooseEnumBase::getItemDocumentation ( ) const
inherited

Get the map containing each item's documentation string.

Definition at line 184 of file MooseEnumBase.C.

185{
186 return _item_documentation;
187}

◆ getNames()

std::vector< std::string > MooseEnumBase::getNames ( ) const
inherited

Method for returning a vector of all valid enumeration names for this instance.

Returns
a vector of names

Definition at line 149 of file MooseEnumBase.C.

150{
151 std::vector<std::string> out;
152 out.reserve(_items.size());
153 for (const auto & item : _items)
154 out.push_back(item.name());
155 return out;
156}

Referenced by Moose::PetscSupport::dontAddCommonKSPOptions(), and Moose::PetscSupport::dontAddCommonSNESOptions().

◆ getNextValidID()

int MooseEnumBase::getNextValidID ( ) const
inherited

Compute the next valid ID.

Definition at line 102 of file MooseEnumBase.C.

103{
104 int value = -1; // Use -1 so if no values exist the first will be zero
105 for (const auto & item : _items)
106 value = std::max(value, item.id());
107 return ++value;
108}
auto max(const L &left, const R &right)

Referenced by MooseEnumBase::addEnumerationName(), MultiMooseEnum::addValidName(), MooseEnum::assign(), MultiMooseEnum::assignValues(), and moose::internal::ExecFlagRegistry::registerFlag().

◆ getRawNames()

std::string MooseEnumBase::getRawNames ( ) const
inherited

Method for returning the raw name strings for this instance.

Returns
a space separated list of names

Definition at line 159 of file MooseEnumBase.C.

160{
161 return Moose::stringify(_items, " ");
162}

Referenced by MooseEnum::assign(), MultiMooseEnum::assignValues(), AdvancedOutput::enableOutputTypes(), MooseEnum::operator==(), PiecewiseConstant::validParams(), and ComparisonPostprocessor::validParams().

◆ isOutOfRangeAllowed()

bool MooseEnumBase::isOutOfRangeAllowed ( ) const
inlineinherited

isOutOfRangeAllowed

Returns
- a Boolean indicating whether enum names out of range are allowed

Definition at line 88 of file MooseEnumBase.h.

88{ return _allow_out_of_range; }

◆ isValid()

virtual bool MooseEnum::isValid ( ) const
inlineoverridevirtualinherited

IsValid.

Returns
- a Boolean indicating whether this Enumeration has been set

Implements MooseEnumBase.

Definition at line 139 of file MooseEnum.h.

◆ items()

const std::set< MooseEnumItem > & MooseEnumBase::items ( ) const
inlineinherited

◆ operator int()

MooseEnum::operator int ( ) const
inlineinherited

Cast operators to make this object behave as value_types and std::string these methods can be used so that this class behaves more like a normal value_type enumeration.

Definition at line 95 of file MooseEnum.h.

95{ return _current.id(); }

◆ operator std::string()

MooseEnum::operator std::string ( ) const
inlineinherited

Definition at line 96 of file MooseEnum.h.

96{ return _current.rawName(); }
const std::string & rawName() const

◆ operator!=() [1/4]

bool MooseEnum::operator!= ( const char *  value) const
inherited

Definition at line 144 of file MooseEnum.C.

145{
146 return !(*this == name);
147}

◆ operator!=() [2/4]

bool MooseEnum::operator!= ( const MooseEnum value) const
inherited

Definition at line 197 of file MooseEnum.C.

198{
199 mooseDeprecated("This method will be removed because the meaning is not well defined, please use "
200 "the 'compareCurrent' method instead.");
201 return value._current.name() != _current.name();
202}
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition MooseError.h:363

◆ operator!=() [3/4]

bool MooseEnum::operator!= ( int  value) const
inherited

Definition at line 156 of file MooseEnum.C.

157{
158 return value != _current;
159}

◆ operator!=() [4/4]

bool MooseEnum::operator!= ( unsigned short  value) const
inherited

Definition at line 168 of file MooseEnum.C.

169{
170 return value != _current;
171}

◆ operator+=() [1/2]

MooseEnumBase & MooseEnumBase::operator+= ( const std::initializer_list< std::string > &  names)
inherited

Adds enumeration items from a list of names.

Definition at line 224 of file MooseEnumBase.C.

225{
226 for (const auto & name : names)
227 *this += name;
228 return *this;
229}

◆ operator+=() [2/2]

MooseEnumBase & MooseEnumBase::operator+= ( const std::string &  name)
inherited

Adds an enumeration item from name.

Definition at line 216 of file MooseEnumBase.C.

217{
218 addEnumerationName(name);
220 return *this;
221}

Referenced by MultiMooseEnum::operator+=(), and MultiMooseEnum::operator+=().

◆ operator==() [1/4]

bool MooseEnum::operator== ( const char *  value) const
inherited

Comparison operators for comparing with character constants, MooseEnums or integer values.

Parameters
value- RHS value to compare against
Returns
bool - the truth value for the comparison

Definition at line 131 of file MooseEnum.C.

132{
133 std::string upper(MooseUtils::toUpper(name));
134
135 mooseAssert(_allow_out_of_range || find(upper) != _items.end(),
136 "Invalid string comparison \"" + upper +
137 "\" in MooseEnum. Valid options (not case-sensitive) are \"" + getRawNames() +
138 "\".");
139
140 return _current == upper;
141}

◆ operator==() [2/4]

bool MooseEnum::operator== ( const MooseEnum value) const
inherited

Definition at line 189 of file MooseEnum.C.

190{
191 mooseDeprecated("This method will be removed because the meaning is not well defined, please use "
192 "the 'compareCurrent' method instead.");
193 return value._current.name() == _current.name();
194}

◆ operator==() [3/4]

bool MooseEnum::operator== ( int  value) const
inherited

Definition at line 150 of file MooseEnum.C.

151{
152 return value == _current;
153}

◆ operator==() [4/4]

bool MooseEnum::operator== ( unsigned short  value) const
inherited

Definition at line 162 of file MooseEnum.C.

163{
164 return value == _current;
165}

Member Data Documentation

◆ _allow_out_of_range

bool MooseEnumBase::_allow_out_of_range
protectedinherited

Flag to enable enumeration items not previously defined.

Definition at line 163 of file MooseEnumBase.h.

Referenced by MooseEnum::assign(), MultiMooseEnum::assignValues(), MooseEnumBase::isOutOfRangeAllowed(), and MooseEnum::operator==().

◆ _current

MooseEnumItem MooseEnum::_current
privateinherited

◆ _deprecated_items

std::map<MooseEnumItem, MooseEnumItem> MooseEnumBase::_deprecated_items
protectedinherited

The map of deprecated names and optional replacements.

Definition at line 160 of file MooseEnumBase.h.

Referenced by MooseEnumBase::checkDeprecated(), and MooseEnumBase::deprecate().

◆ _item_documentation

std::map<MooseEnumItem, std::string> MooseEnumBase::_item_documentation
protectedinherited

The map of items and their respective documentation strings.

Definition at line 166 of file MooseEnumBase.h.

Referenced by MooseEnumBase::addDocumentation(), and MooseEnumBase::getItemDocumentation().

◆ _items

std::set<MooseEnumItem> MooseEnumBase::_items
protectedinherited

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