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

The ControllableParameter class is simply a set of ControllableItem objects. More...

#include <ControllableParameter.h>

Public Member Functions

 ControllableParameter ()=default
 
virtual ~ControllableParameter ()=default
 
 ControllableParameter (ControllableParameter &&)=default
 
 ControllableParameter (const ControllableParameter &)=delete
 
ControllableParameteroperator= (const ControllableParameter &)=delete
 
ControllableParameteroperator= (ControllableParameter &&)=delete
 
bool empty ()
 Return true if the container is empty. More...
 
std::string dump () const
 Return a string that lists the parameters stored by this object. 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, bool warn_when_values_difffer=false) const
 Return a copy of the values of the given type. More...
 
template<typename T >
bool check ()
 Check size() and the type of the stored items, i.e., there must be items with the given type. More...
 
void add (ControllableItem *item)
 Adds the supplied item with the other items within this object. More...
 

Private Attributes

std::vector< ControllableItem * > _items
 Storage for the ControllableItems, these are stored as pointers to avoid copies. More...
 

Friends

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

Detailed Description

The ControllableParameter class is simply a set of ControllableItem objects.

This object is what is used from within a Control for setting input parameter values. These objects are made on demand by the Control objects.

This class is needed to allow for multiple parameters to be set with a single interface.

Definition at line 27 of file ControllableParameter.h.

Constructor & Destructor Documentation

◆ ControllableParameter() [1/3]

ControllableParameter::ControllableParameter ( )
default

◆ ~ControllableParameter()

virtual ControllableParameter::~ControllableParameter ( )
virtualdefault

◆ ControllableParameter() [2/3]

ControllableParameter::ControllableParameter ( ControllableParameter &&  )
default

◆ ControllableParameter() [3/3]

ControllableParameter::ControllableParameter ( const ControllableParameter )
delete

Member Function Documentation

◆ add()

void ControllableParameter::add ( ControllableItem item)

Adds the supplied item with the other items within this object.

Definition at line 13 of file ControllableParameter.C.

Referenced by InputParameterWarehouse::getControllableParameter().

14 {
15  _items.push_back(item);
16 }
std::vector< ControllableItem * > _items
Storage for the ControllableItems, these are stored as pointers to avoid copies.

◆ check()

template<typename T >
bool ControllableParameter::check ( )

Check size() and the type of the stored items, i.e., there must be items with the given type.

Definition at line 125 of file ControllableParameter.h.

126 {
127  bool type = std::all_of(
128  _items.begin(), _items.end(), [](ControllableItem * item) { return item->check<T>(); });
129  return type && !empty();
130 }
bool empty()
Return true if the container is empty.
std::vector< ControllableItem * > _items
Storage for the ControllableItems, these are stored as pointers to avoid copies.
MatType type
An intermediate object for building a "controllable item", where an "item" can refer to multiple inpu...

◆ dump()

std::string ControllableParameter::dump ( ) const

Return a string that lists the parameters stored by this object.

This is used by ControlInterface::getControlParamByName for error reporting.

Definition at line 19 of file ControllableParameter.C.

Referenced by get(), and operator<<().

20 {
21  std::ostringstream oss;
22  for (auto item_ptr : _items)
23  oss << item_ptr->dump();
24  return oss.str();
25 }
std::vector< ControllableItem * > _items
Storage for the ControllableItems, these are stored as pointers to avoid copies.

◆ empty()

bool ControllableParameter::empty ( )
inline

Return true if the container is empty.

Definition at line 41 of file ControllableParameter.h.

Referenced by check(), and Control::getControllableParameterByName().

41 { return _items.size() == 0; }
std::vector< ControllableItem * > _items
Storage for the ControllableItems, these are stored as pointers to avoid copies.

◆ get()

template<typename T >
std::vector< T > ControllableParameter::get ( bool  type_check = true,
bool  warn_when_values_difffer = false 
) const

Return a copy of the values of the given type.

Definition at line 92 of file ControllableParameter.h.

Referenced by InputParameterWarehouse::getControllableParameterValues(), and Control::getControllableValueByName().

93 {
94  std::vector<T> output;
95  for (const ControllableItem * const item : _items)
96  {
97  std::vector<T> local = item->get<T>(type_check);
98  output.insert(output.end(), local.begin(), local.end());
99  }
100 
101  // Produce a warning, if the flag is true, when multiple parameters have different values
102  if (warn_when_values_differ && _items.size() > 1)
103  {
104  // The first parameter to test against
105  const T value0 = output[0];
106 
107  // Loop over all other parameter values
108  for (T value : output)
109  {
110  if (value0 != value)
111  {
112  std::ostringstream oss;
113  oss << "The following controlled parameters are being retrieved, but the values differ:\n";
114  oss << dump();
115  mooseWarning(oss.str());
116  }
117  }
118  }
119 
120  return output;
121 }
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:220
std::vector< ControllableItem * > _items
Storage for the ControllableItems, these are stored as pointers to avoid copies.
An intermediate object for building a "controllable item", where an "item" can refer to multiple inpu...
std::string dump() const
Return a string that lists the parameters stored by this object.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

ControllableParameter& ControllableParameter::operator= ( ControllableParameter &&  )
delete

◆ set()

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

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

Parameters
valueThe value to change the parameters to.

Definition at line 84 of file ControllableParameter.h.

Referenced by Control::setControllableValueByName().

85 {
86  for (ControllableItem * item : _items)
87  item->set<T>(value, type_check);
88 }
std::vector< ControllableItem * > _items
Storage for the ControllableItems, these are stored as pointers to avoid copies.
An intermediate object for building a "controllable item", where an "item" can refer to multiple inpu...

Friends And Related Function Documentation

◆ operator<<

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

Allows this to be used with std:: cout.

Definition at line 28 of file ControllableParameter.C.

29 {
30  return stream << obj.dump();
31 }
std::string dump() const
Return a string that lists the parameters stored by this object.

Member Data Documentation

◆ _items

std::vector<ControllableItem *> ControllableParameter::_items
private

Storage for the ControllableItems, these are stored as pointers to avoid copies.

Definition at line 79 of file ControllableParameter.h.

Referenced by add(), check(), dump(), empty(), get(), and set().


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