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 26 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 129 of file ControllableParameter.h.

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

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:299
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.h:130

◆ 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 40 of file ControllableParameter.h.

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

40 { 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 96 of file ControllableParameter.h.

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

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

Referenced by Control::setControllableValueByName().

89 {
90  for (ControllableItem * item : _items)
91  item->set<T>(value, type_check);
92 }
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
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 83 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: