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

An intermediate object for building a "controllable item", where an "item" can refer to multiple input parameters with different names. More...

#include <ControllableItem.h>

Inheritance diagram for ControllableItem:
[legend]

Public Member Functions

 ControllableItem (const MooseObjectParameterName &name, libMesh::Parameters::Value *value, const std::set< ExecFlagType > &flags={})
 
virtual ~ControllableItem ()=default
 
 ControllableItem (const ControllableItem &)=default
 
 ControllableItem (ControllableItem &&)=default
 
ControllableItemoperator= (const ControllableItem &)=delete
 
ControllableItemoperator= (ControllableItem &&)=delete
 
void connect (ControllableItem *item, bool type_check=true)
 Connects the supplied item with this item to allow for multiple parameters to be changed by one.
 
template<typename T >
void set (const T &value, bool type_check=true)
 Set the value(s) of the controlled parameters stored in this class.
 
template<typename T >
std::vector< T > get (bool type_check=true) const
 Return a copy of all values for this "item".
 
template<typename T >
bool check () const
 Return true if the template argument is valid for ALL items.
 
virtual const MooseObjectParameterNamename () const
 Return the name of the master parameter.
 
std::string type () const
 Return the type of the master parameter.
 
virtual std::string dump (unsigned int indent=0) const
 Returns a string displaying the parameter name and current value.
 
const std::set< ExecFlagType > & getExecuteOnFlags () const
 Return the execute flag restrictions, an empty set is un-restricted.
 
bool operator== (const ControllableItem &rhs) const
 Use the master name for comparison operators to allow object to work within a set/map.
 
bool operator!= (const ControllableItem &rhs) const
 
bool operator< (const ControllableItem &rhs) const
 
void resetChanged ()
 Methods for ControlOutput::outputChangedControls, these don't have meaning outside of this function.
 
bool isChanged ()
 

Protected Member Functions

 ControllableItem ()
 Constructor for creating an empty item (see ControllableAlias)
 

Protected Attributes

std::vector< std::pair< MooseObjectParameterName, libMesh::Parameters::Value * > > _pairs
 List of names for this item.
 
bool _changed = false
 Flag for ControlOutput, allows output objects to keep track of when a parameter is altered.
 
std::set< ExecFlagType_execute_flags
 Flags to which the control is restricted (if not set it is unrestricted)
 

Friends

std::ostream & operator<< (std::ostream &stream, const ControllableItem &obj)
 Allows this to be used with std:: cout.
 

Detailed Description

An intermediate object for building a "controllable item", where an "item" can refer to multiple input parameters with different names.

The name supplied to the constructor is considered the "master" parameter. The parameter(s) added via the connect method are considered the secondaries.

In general, an ControllableItem will have a one-to-one relationship with an input parameter value, but in some instances it is desirable to connect parameters with different names together. For example, within MOOSE when a material is defined in an input file multiple Material objects are generated automatically. If a parameter is controlled on one of these objects it is necessary to also have the values on the other controlled as well. This example is the driver behind the creation of this intermediate class.

Definition at line 31 of file ControllableItem.h.

Constructor & Destructor Documentation

◆ ControllableItem() [1/4]

ControllableItem::ControllableItem ( const MooseObjectParameterName name,
libMesh::Parameters::Value value,
const std::set< ExecFlagType > &  flags = {} 
)

Definition at line 13 of file ControllableItem.C.

16 : _execute_flags(flags)
17{
18 _pairs.emplace_back(name, value);
19}
std::vector< std::pair< MooseObjectParameterName, libMesh::Parameters::Value * > > _pairs
List of names for this item.
std::set< ExecFlagType > _execute_flags
Flags to which the control is restricted (if not set it is unrestricted)
virtual const MooseObjectParameterName & name() const
Return the name of the master parameter.

◆ ~ControllableItem()

virtual ControllableItem::~ControllableItem ( )
virtualdefault

◆ ControllableItem() [2/4]

ControllableItem::ControllableItem ( const ControllableItem )
default

◆ ControllableItem() [3/4]

ControllableItem::ControllableItem ( ControllableItem &&  )
default

◆ ControllableItem() [4/4]

ControllableItem::ControllableItem ( )
protected

Constructor for creating an empty item (see ControllableAlias)

Definition at line 21 of file ControllableItem.C.

21{}

Member Function Documentation

◆ check()

template<typename T >
bool ControllableItem::check ( ) const

Return true if the template argument is valid for ALL items.

Definition at line 175 of file ControllableItem.h.

176{
177 return std::all_of(_pairs.begin(),
178 _pairs.end(),
179 [](std::pair<MooseObjectParameterName, libMesh::Parameters::Value *> pair)
180 {
181 libMesh::Parameters::Parameter<T> * param =
182 dynamic_cast<libMesh::Parameters::Parameter<T> *>(pair.second);
183 return param != nullptr;
184 });
185}

◆ connect()

void ControllableItem::connect ( ControllableItem item,
bool  type_check = true 
)

Connects the supplied item with this item to allow for multiple parameters to be changed by one.

Definition at line 24 of file ControllableItem.C.

25{
26 for (const auto & pair : item->_pairs)
27 {
28 if (type_check && type() != pair.second->type())
29 mooseError("The master parameter (",
30 name(),
31 ") has a type '",
32 type(),
33 "' and cannot be connected to the parameter (",
34 pair.first,
35 ") with a different type of '",
36 pair.second->type(),
37 "'.");
38
39 _pairs.emplace_back(pair.first, pair.second);
40 }
41}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
std::string type() const
Return the type of the master parameter.

Referenced by ControllableAlias::ControllableAlias().

◆ dump()

std::string ControllableItem::dump ( unsigned int  indent = 0) const
virtual

Returns a string displaying the parameter name and current value.

Reimplemented in ControllableAlias.

Definition at line 44 of file ControllableItem.C.

45{
46
47 // Count of objects, for printing a number with the parameter
48 unsigned int index = 0;
49
50 std::ostringstream oss;
51 for (const auto & pair : _pairs)
52 {
53 if (index == 0) // master parameter
54 oss << ConsoleUtils::indent(indent) << COLOR_GREEN << pair.first << COLOR_DEFAULT << " = ";
55 else // secondary parameters
56 oss << ConsoleUtils::indent(indent + 2) << COLOR_YELLOW << pair.first << COLOR_DEFAULT
57 << " = ";
58
59 pair.second->print(oss);
60 oss << " <" << pair.second->type() << ">" << '\n';
61 index++;
62 }
63 return oss.str();
64}
std::string indent(unsigned int spaces)
Create empty string for indenting.

◆ get()

template<typename T >
std::vector< T > ControllableItem::get ( bool  type_check = true) const

Return a copy of all values for this "item".

Definition at line 153 of file ControllableItem.h.

154{
155 std::vector<T> output;
156 output.reserve(_pairs.size());
157 for (const auto & pair : _pairs)
158 {
160 dynamic_cast<libMesh::Parameters::Parameter<T> *>(pair.second);
161 if (type_check && param == nullptr)
162 mooseError("Failed to get the '",
163 pair.first,
164 "' parameter the supplied template argument must be of type '",
165 pair.second->type(),
166 "'.");
167 else if (param != nullptr)
168 output.push_back(param->get());
169 }
170 return output;
171}

◆ getExecuteOnFlags()

const std::set< ExecFlagType > & ControllableItem::getExecuteOnFlags ( ) const
inline

Return the execute flag restrictions, an empty set is un-restricted.

Definition at line 108 of file ControllableItem.h.

108{ return _execute_flags; }

◆ isChanged()

bool ControllableItem::isChanged ( )
inline

Definition at line 102 of file ControllableItem.h.

102{ return _changed; }
bool _changed
Flag for ControlOutput, allows output objects to keep track of when a parameter is altered.

◆ name()

const MooseObjectParameterName & ControllableItem::name ( ) const
virtual

Return the name of the master parameter.

Reimplemented in ControllableAlias.

Definition at line 73 of file ControllableItem.C.

74{
75 return _pairs[0].first;
76}

Referenced by connect(), ControllableItem(), operator!=(), operator<(), and operator==().

◆ operator!=()

bool ControllableItem::operator!= ( const ControllableItem rhs) const
inline

Definition at line 77 of file ControllableItem.h.

77{ return name() != rhs.name(); }

◆ operator<()

bool ControllableItem::operator< ( const ControllableItem rhs) const
inline

Definition at line 78 of file ControllableItem.h.

78{ return name() < rhs.name(); }

◆ operator=() [1/2]

ControllableItem & ControllableItem::operator= ( const ControllableItem )
delete

◆ operator=() [2/2]

ControllableItem & ControllableItem::operator= ( ControllableItem &&  )
delete

◆ operator==()

bool ControllableItem::operator== ( const ControllableItem rhs) const
inline

Use the master name for comparison operators to allow object to work within a set/map.

Definition at line 76 of file ControllableItem.h.

76{ return name() == rhs.name(); }

◆ resetChanged()

void ControllableItem::resetChanged ( )
inline

Methods for ControlOutput::outputChangedControls, these don't have meaning outside of this function.

Definition at line 101 of file ControllableItem.h.

101{ _changed = false; }

◆ set()

template<typename T >
void ControllableItem::set ( const T &  value,
bool  type_check = true 
)

Set the value(s) of the controlled parameters stored in this class.

The 'skip_type_check' flag allows this object to work with ControllableParameter that can store values of varying types.

Definition at line 131 of file ControllableItem.h.

132{
133 for (auto & pair : _pairs)
134 {
136 dynamic_cast<libMesh::Parameters::Parameter<T> *>(pair.second);
137 if (type_check && param == nullptr)
138 mooseError("Failed to set the '",
139 pair.first,
140 "' parameter the supplied template argument must be of type '",
141 pair.second->type(),
142 "'.");
143 else if (param != nullptr)
144 {
145 param->set() = value;
146 _changed = true;
147 }
148 }
149}
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ type()

std::string ControllableItem::type ( ) const

Return the type of the master parameter.

Definition at line 67 of file ControllableItem.C.

68{
69 return _pairs[0].second->type();
70}

Referenced by connect().

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  stream,
const ControllableItem obj 
)
friend

Allows this to be used with std:: cout.

Definition at line 105 of file ControllableItem.C.

107{
108 return stream << obj.dump();
109}
virtual std::string dump(unsigned int indent=0) const
Returns a string displaying the parameter name and current value.

Member Data Documentation

◆ _changed

bool ControllableItem::_changed = false
protected

Flag for ControlOutput, allows output objects to keep track of when a parameter is altered.

Definition at line 123 of file ControllableItem.h.

Referenced by isChanged(), resetChanged(), and set().

◆ _execute_flags

std::set<ExecFlagType> ControllableItem::_execute_flags
protected

Flags to which the control is restricted (if not set it is unrestricted)

Definition at line 126 of file ControllableItem.h.

Referenced by getExecuteOnFlags().

◆ _pairs

std::vector<std::pair<MooseObjectParameterName, libMesh::Parameters::Value *> > ControllableItem::_pairs
protected

List of names for this item.

Definition at line 120 of file ControllableItem.h.

Referenced by check(), connect(), ControllableItem(), dump(), ControllableAlias::dump(), get(), name(), set(), and type().


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