www.mooseframework.org
Public Member Functions | Protected Attributes | Private Attributes | List of all members
ControllableAlias Class Reference

Allows for aliases to be defined via InputParameterWarehouse::addControllableParameterAlias. More...

#include <ControllableItem.h>

Inheritance diagram for ControllableAlias:
[legend]

Public Member Functions

 ControllableAlias (const MooseObjectParameterName &name, ControllableItem *)
 
virtual const MooseObjectParameterNamename () const override
 Return the name of the master parameter. More...
 
virtual std::string dump (unsigned int indent=0) const override
 Returns a string displaying the parameter name and current value. More...
 
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. More...
 
template<typename T >
void set (const T &value, bool type_check=true)
 Set the value(s) of the controlled parameters stored in this class. More...
 
template<typename T >
std::vector< T > get (bool type_check=true) const
 Return a copy of all values for this "item". More...
 
template<typename T >
bool check () const
 Return true if the template argument is valid for ALL items. More...
 
std::string type () const
 Return the type of the master parameter. More...
 
const std::set< ExecFlagType > & getExecuteOnFlags () const
 Return the execute flag restrictions, an empty set is un-restricted. More...
 
bool operator== (const ControllableItem &rhs) const
 Use the master name for comparison operators to allow object to work within a set/map. More...
 
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. More...
 
bool isChanged ()
 

Protected Attributes

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

Private Attributes

MooseObjectParameterName _name
 

Detailed Description

Allows for aliases to be defined via InputParameterWarehouse::addControllableParameterAlias.

Definition at line 190 of file ControllableItem.h.

Constructor & Destructor Documentation

◆ ControllableAlias()

ControllableAlias::ControllableAlias ( const MooseObjectParameterName name,
ControllableItem item 
)

Definition at line 78 of file ControllableItem.C.

80 {
81  connect(item, false);
82 }
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...
ControllableItem()
Constructor for creating an empty item (see ControllableAlias)
virtual const MooseObjectParameterName & name() const override
Return the name of the master parameter.
MooseObjectParameterName _name

Member Function Documentation

◆ check()

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

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

Definition at line 176 of file ControllableItem.h.

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

◆ connect()

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

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.

Referenced by ControllableAlias().

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:208
virtual const MooseObjectParameterName & name() const
Return the name of the master parameter.
std::vector< std::pair< MooseObjectParameterName, libMesh::Parameters::Value * > > _pairs
List of names for this item.
std::string type() const
Return the type of the master parameter.

◆ dump()

std::string ControllableAlias::dump ( unsigned int  indent = 0) const
overridevirtual

Returns a string displaying the parameter name and current value.

Reimplemented from ControllableItem.

Definition at line 91 of file ControllableItem.C.

92 {
93  // The output stream
94  std::ostringstream oss;
95  oss << ConsoleUtils::indent(indent) << COLOR_GREEN << _name << COLOR_DEFAULT;
96  for (const auto & pair : _pairs)
97  {
98  oss << ConsoleUtils::indent(indent + 2) << COLOR_YELLOW << pair.first << COLOR_DEFAULT << " = ";
99  pair.second->print(oss);
100  oss << " <" << pair.second->type() << ">\n";
101  }
102  return oss.str();
103 }
std::string indent(unsigned int spaces)
Create empty string for indenting.
Definition: ConsoleUtils.C:29
std::vector< std::pair< MooseObjectParameterName, libMesh::Parameters::Value * > > _pairs
List of names for this item.
MooseObjectParameterName _name

◆ get()

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

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

Definition at line 154 of file ControllableItem.h.

155 {
156  std::vector<T> output;
157  output.reserve(_pairs.size());
158  for (const auto & pair : _pairs)
159  {
160  libMesh::Parameters::Parameter<T> * param =
161  dynamic_cast<libMesh::Parameters::Parameter<T> *>(pair.second);
162  if (type_check && param == nullptr)
163  mooseError("Failed to get the '",
164  pair.first,
165  "' parameter the supplied template argument must be of type '",
166  pair.second->type(),
167  "'.");
168  else if (param != nullptr)
169  output.push_back(param->get());
170  }
171  return output;
172 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
std::vector< std::pair< MooseObjectParameterName, libMesh::Parameters::Value * > > _pairs
List of names for this item.

◆ getExecuteOnFlags()

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

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

Definition at line 109 of file ControllableItem.h.

109 { return _execute_flags; }
std::set< ExecFlagType > _execute_flags
Flags to which the control is restricted (if not set it is unrestricted)

◆ isChanged()

bool ControllableItem::isChanged ( )
inlineinherited

Definition at line 103 of file ControllableItem.h.

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

◆ name()

const MooseObjectParameterName & ControllableAlias::name ( ) const
overridevirtual

Return the name of the master parameter.

Reimplemented from ControllableItem.

Definition at line 85 of file ControllableItem.C.

86 {
87  return _name;
88 }
MooseObjectParameterName _name

◆ operator!=()

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

Definition at line 78 of file ControllableItem.h.

78 { return name() != rhs.name(); }
virtual const MooseObjectParameterName & name() const
Return the name of the master parameter.

◆ operator<()

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

Definition at line 79 of file ControllableItem.h.

79 { return name() < rhs.name(); }
virtual const MooseObjectParameterName & name() const
Return the name of the master parameter.

◆ operator==()

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

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

Definition at line 77 of file ControllableItem.h.

77 { return name() == rhs.name(); }
virtual const MooseObjectParameterName & name() const
Return the name of the master parameter.

◆ resetChanged()

void ControllableItem::resetChanged ( )
inlineinherited

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

Definition at line 102 of file ControllableItem.h.

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

◆ set()

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

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 132 of file ControllableItem.h.

133 {
134  for (auto & pair : _pairs)
135  {
136  libMesh::Parameters::Parameter<T> * param =
137  dynamic_cast<libMesh::Parameters::Parameter<T> *>(pair.second);
138  if (type_check && param == nullptr)
139  mooseError("Failed to set the '",
140  pair.first,
141  "' parameter the supplied template argument must be of type '",
142  pair.second->type(),
143  "'.");
144  else if (param != nullptr)
145  {
146  param->set() = value;
147  _changed = true;
148  }
149  }
150 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
std::vector< std::pair< MooseObjectParameterName, libMesh::Parameters::Value * > > _pairs
List of names for this item.
bool _changed
Flag for ControlOutput, allows output objects to keep track of when a parameter is altered...

◆ type()

std::string ControllableItem::type ( ) const
inherited

Return the type of the master parameter.

Definition at line 67 of file ControllableItem.C.

Referenced by ControllableItem::connect().

68 {
69  return _pairs[0].second->type();
70 }
std::vector< std::pair< MooseObjectParameterName, libMesh::Parameters::Value * > > _pairs
List of names for this item.

Member Data Documentation

◆ _changed

bool ControllableItem::_changed = false
protectedinherited

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

Definition at line 124 of file ControllableItem.h.

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

◆ _execute_flags

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

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

Definition at line 127 of file ControllableItem.h.

Referenced by ControllableItem::getExecuteOnFlags().

◆ _name

MooseObjectParameterName ControllableAlias::_name
private

Definition at line 198 of file ControllableItem.h.

Referenced by dump(), and name().

◆ _pairs

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

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