www.mooseframework.org
ControllableParameter.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef CONTROLLABLEPARAMETER_H
16 #define CONTROLLABLEPARAMETER_H
17 
18 // MOOSE includes
19 #include "InputParameters.h"
20 #include "MooseObjectName.h"
22 
29 template <typename T>
31 {
32 public:
42 
46  std::size_t size() const { return _parameter_values.size(); }
47 
52  void set(const T & value);
53 
57  const std::vector<T *> & get() const;
58 
65  std::string dump();
66 
72  void insert(const MooseObjectParameterName & name, std::shared_ptr<InputParameters> param_object);
73 
74 private:
76  std::vector<T *> _parameter_values;
77 
79  std::multimap<T *, MooseObjectParameterName> _parameter_names;
80 };
81 
82 template <typename T>
84 {
85 }
86 
87 template <typename T>
88 void
90  std::shared_ptr<InputParameters> param_object)
91 {
92  // Get a pointer to the Parameter
93  T * param_ptr = &param_object->template set<T>(name.parameter());
94 
95  // Search for the pointer in the existing multimap
96  typename std::multimap<T *, MooseObjectParameterName>::iterator iter =
97  _parameter_names.find(param_ptr);
98 
99  // If the pointer does not exist, add it
100  if (iter == _parameter_names.end())
101  _parameter_values.push_back(param_ptr);
102 
103  // Update the object names
104  _parameter_names.insert(std::pair<T *, MooseObjectParameterName>(param_ptr, name));
105 }
106 
107 template <typename T>
108 void
110 {
111  typename std::vector<T *>::iterator iter;
112  for (unsigned int i = 0; i < _parameter_values.size(); i++)
113  *_parameter_values[i] = value;
114 }
115 
116 template <typename T>
117 const std::vector<T *> &
119 {
120  return _parameter_values;
121 }
122 
123 template <typename T>
124 std::string
126 {
127  // Count of objects, for printing a number with the parameter
128  unsigned int index = 0;
129 
130  // The output stream
131  std::ostringstream oss;
132 
133  // Loop through each pointer
134  typename std::vector<T *>::iterator iter;
135  for (iter = _parameter_values.begin(); iter != _parameter_values.end(); iter++)
136  {
137  // Get the list of names associated with the parameter
138  std::pair<typename std::multimap<T *, MooseObjectParameterName>::const_iterator,
139  typename std::multimap<T *, MooseObjectParameterName>::const_iterator>
140  range = _parameter_names.equal_range(*iter);
141  typename std::multimap<T *, MooseObjectParameterName>::const_iterator jt;
142 
143  // Print each parameter as a list of possible names
144  oss << "(" << index << ") ";
145  for (jt = range.first; jt != range.second; ++jt)
146  oss << jt->second << " ";
147  oss << "\n";
148  index++;
149  }
150 
151  return oss.str();
152 }
153 
154 #endif // CONTROLLABLEPARAMETER_H
const std::string & parameter() const
Return the parameter name.
std::string dump()
Return a string that lists the parameters stored by this object.
const std::vector< T * > & get() const
Retrieve a copy of the parameter values controlled by this class.
A class for accessing controllable InputParameters.
std::multimap< T *, MooseObjectParameterName > _parameter_names
Map of the possible names associated with the parameters stored for control.
void insert(const MooseObjectParameterName &name, std::shared_ptr< InputParameters > param_object)
Adds a parameter to the container.
std::vector< T * > _parameter_values
Vector of pointers to the parameters stored in this object for control.
ControllableParameter()
Constructor.
void set(const T &value)
Set the value(s) of the controlled parameters stored in this class.
std::size_t size() const
The number of parameters contained in the class.
A class for storing an input parameter name.