libMesh
parameter_multiaccessor.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_PARAMETER_MULTIACCESSOR_H
21 #define LIBMESH_PARAMETER_MULTIACCESSOR_H
22 
23 
24 // Local Includes
25 #include "libmesh/libmesh_common.h"
26 #include "libmesh/parameter_accessor.h"
27 
28 // C++ Includes
29 #include <vector>
30 
31 namespace libMesh
32 {
33 
46 template <typename T=Number>
48 {
49 public:
54 
58  ParameterMultiAccessor(const ParameterAccessor<T> & param_accessor) :
59  _accessors(1, param_accessor.clone()) {}
60 
61  /*
62  * Destructor: delete our clones of sub-accessors
63  */
65  for (std::size_t i=0; i != _accessors.size(); ++i)
66  delete _accessors[i];
67  }
68 
72 #ifdef LIBMESH_ENABLE_DEPRECATED
73  virtual ParameterAccessor<T> &
74  operator= (T * /* new_ptr */) libmesh_override
75  {
76  libmesh_error();
77  return *this;
78  }
79 #endif
80 
84  virtual void set (const T & new_value) libmesh_override
85  {
86  libmesh_assert(!_accessors.empty());
87 #ifndef NDEBUG
88  // Compare other values to the last one we'll change
89  const T & val = _accessors.back()->get();
90 #endif
91  for (std::size_t i=0; i != _accessors.size(); ++i)
92  {
93  // If you're already using inconsistent parameters we can't
94  // help you.
95  libmesh_assert_equal_to(_accessors[i]->get(), val);
96  _accessors[i]->set(new_value);
97  }
98  }
99 
103  virtual const T & get () const libmesh_override
104  {
105  libmesh_assert(!_accessors.empty());
106  const T & val = _accessors[0]->get();
107 #ifndef NDEBUG
108  // If you're already using inconsistent parameters we can't help
109  // you.
110  for (std::size_t i=1; i < _accessors.size(); ++i)
111  libmesh_assert_equal_to(_accessors[i]->get(), val);
112 #endif
113  return val;
114  }
115 
119  virtual UniquePtr<ParameterAccessor<T>> clone() const libmesh_override
120  {
122  for (std::size_t i=0; i != _accessors.size(); ++i)
123  pmp->_accessors.push_back(_accessors[i]->clone().release());
124 
125  return UniquePtr<ParameterAccessor<T>>(pmp);
126  }
127 
128 
129  void push_back (const ParameterAccessor<T> & new_accessor) {
130  _accessors.push_back(new_accessor.clone().release());
131  }
132 
138  std::size_t size() const { return _accessors.size(); }
139 
140 private:
141  std::vector<ParameterAccessor<T> *> _accessors;
142 };
143 
144 } // namespace libMesh
145 
146 #endif // LIBMESH_PARAMETER_MULTIACCESSOR_H
virtual UniquePtr< ParameterAccessor< T > > clone() const libmesh_override
ParameterMultiAccessor(const ParameterAccessor< T > &param_accessor)
Constructor: take the first sub-accessor for the parameter.
The libMesh namespace provides an interface to certain functionality in the library.
libmesh_assert(j)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
void push_back(const ParameterAccessor< T > &new_accessor)
ParameterMultiAccessor()
Constructor: no parameters attached yet.
std::vector< ParameterAccessor< T > * > _accessors
Accessor object allowing reading and modification of the independent variables in a parameter sensiti...
virtual UniquePtr< ParameterAccessor< T > > clone() const =0
virtual ParameterAccessor< T > & operator=(T *) libmesh_override
A simple reseater won&#39;t work with a multi-accessor.
Accessor object allowing reading and modification of the independent variables in a parameter sensiti...