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

Private Attributes

MooseObjectParameterName _name
 

Detailed Description

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

Definition at line 180 of file ControllableItem.h.

Constructor & Destructor Documentation

◆ ControllableAlias()

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

Definition at line 76 of file ControllableItem.C.

78 {
79  connect(item, false);
80 }
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 166 of file ControllableItem.h.

167 {
168  return std::all_of(_pairs.begin(),
169  _pairs.end(),
170  [](std::pair<MooseObjectParameterName, libMesh::Parameters::Value *> pair) {
171  libMesh::Parameters::Parameter<T> * param =
172  dynamic_cast<libMesh::Parameters::Parameter<T> *>(pair.second);
173  return param != nullptr;
174  });
175 }
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 22 of file ControllableItem.C.

Referenced by ControllableAlias().

23 {
24  for (const auto & pair : item->_pairs)
25  {
26  if (type_check && type() != pair.second->type())
27  mooseError("The master parameter (",
28  name(),
29  ") has a type '",
30  type(),
31  "' and cannot be connected to the parameter (",
32  pair.first,
33  ") with a different type of '",
34  pair.second->type(),
35  "'.");
36 
37  _pairs.emplace_back(pair.first, pair.second);
38  }
39 }
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 89 of file ControllableItem.C.

90 {
91  // The output stream
92  std::ostringstream oss;
93  oss << ConsoleUtils::indent(indent) << COLOR_GREEN << _name << COLOR_DEFAULT;
94  for (const auto & pair : _pairs)
95  {
96  oss << ConsoleUtils::indent(indent + 2) << COLOR_YELLOW << pair.first << COLOR_DEFAULT << " = ";
97  pair.second->print(oss);
98  oss << " <" << pair.second->type() << ">\n";
99  }
100  return oss.str();
101 }
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 144 of file ControllableItem.h.

145 {
146  std::vector<T> output;
147  output.reserve(_pairs.size());
148  for (const auto & pair : _pairs)
149  {
150  libMesh::Parameters::Parameter<T> * param =
151  dynamic_cast<libMesh::Parameters::Parameter<T> *>(pair.second);
152  if (type_check && param == nullptr)
153  mooseError("Failed to get the '",
154  pair.first,
155  "' parameter the supplied template argument must be of type '",
156  pair.second->type(),
157  "'.");
158  else if (param != nullptr)
159  output.push_back(param->get());
160  }
161  return output;
162 }
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.

◆ isChanged()

bool ControllableItem::isChanged ( )
inlineinherited

Definition at line 101 of file ControllableItem.h.

101 { 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 83 of file ControllableItem.C.

84 {
85  return _name;
86 }
MooseObjectParameterName _name

◆ operator!=()

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

Definition at line 76 of file ControllableItem.h.

76 { 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 77 of file ControllableItem.h.

77 { 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 75 of file ControllableItem.h.

75 { 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 100 of file ControllableItem.h.

100 { _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 122 of file ControllableItem.h.

123 {
124  for (auto & pair : _pairs)
125  {
126  libMesh::Parameters::Parameter<T> * param =
127  dynamic_cast<libMesh::Parameters::Parameter<T> *>(pair.second);
128  if (type_check && param == nullptr)
129  mooseError("Failed to set the '",
130  pair.first,
131  "' parameter the supplied template argument must be of type '",
132  pair.second->type(),
133  "'.");
134  else if (param != nullptr)
135  {
136  param->set() = value;
137  _changed = true;
138  }
139  }
140 }
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 65 of file ControllableItem.C.

Referenced by ControllableItem::connect().

66 {
67  return _pairs[0].second->type();
68 }
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 117 of file ControllableItem.h.

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

◆ _name

MooseObjectParameterName ControllableAlias::_name
private

Definition at line 188 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: