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 checkExecuteOnType (const ExecFlagType &current) const
 Check the execute flags. 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 14 of file ControllableParameter.C.

Referenced by InputParameterWarehouse::getControllableParameter().

15 {
16  _items.push_back(item);
17 }
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 130 of file ControllableParameter.h.

131 {
132  bool type = std::all_of(
133  _items.begin(), _items.end(), [](ControllableItem * item) { return item->check<T>(); });
134  return type && !empty();
135 }
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...

◆ checkExecuteOnType()

void ControllableParameter::checkExecuteOnType ( const ExecFlagType current) const

Check the execute flags.

Definition at line 29 of file ControllableParameter.C.

Referenced by Control::getControllableParameterByName().

30 {
31  for (const ControllableItem * const item : _items)
32  {
33  const std::set<ExecFlagType> & flags = item->getExecuteOnFlags();
34  if (!flags.empty() && flags.find(current) == flags.end())
35  mooseError("The controllable parameter (",
36  item->name(),
37  ") is not allowed to execute on '",
38  current,
39  "', it is only allowed to execute on '",
40  MooseUtils::join(flags, " "),
41  "'.");
42  }
43 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
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 join(const T &strings, const std::string &delimiter)
Python like join function for strings.
Definition: MooseUtils.C:797

◆ 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 20 of file ControllableParameter.C.

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

21 {
22  std::ostringstream oss;
23  for (auto item_ptr : _items)
24  oss << item_ptr->dump();
25  return oss.str();
26 }
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 97 of file ControllableParameter.h.

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

98 {
99  std::vector<T> output;
100  for (const ControllableItem * const item : _items)
101  {
102  std::vector<T> local = item->get<T>(type_check);
103  output.insert(output.end(), local.begin(), local.end());
104  }
105 
106  // Produce a warning, if the flag is true, when multiple parameters have different values
107  if (warn_when_values_differ && _items.size() > 1)
108  {
109  // The first parameter to test against
110  const T value0 = output[0];
111 
112  // Loop over all other parameter values
113  for (T value : output)
114  {
115  if (value0 != value)
116  {
117  std::ostringstream oss;
118  oss << "The following controlled parameters are being retrieved, but the values differ:\n";
119  oss << dump();
120  mooseWarning(oss.str());
121  }
122  }
123  }
124 
125  return output;
126 }
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 89 of file ControllableParameter.h.

Referenced by Control::setControllableValueByName().

90 {
91  for (ControllableItem * item : _items)
92  item->set<T>(value, type_check);
93 }
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 46 of file ControllableParameter.C.

47 {
48  return stream << obj.dump();
49 }
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 84 of file ControllableParameter.h.

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


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