parameter_multipointer.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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_MULTIPOINTER_H
21 #define LIBMESH_PARAMETER_MULTIPOINTER_H
22 
23 
24 // Local Includes
25 #include "libmesh/libmesh_common.h"
27 
28 // C++ Includes
29 #include <vector>
30 
31 namespace libMesh
32 {
33 
46 template <typename T=Number>
48 {
49 public:
54 
58  ParameterMultiPointer(T * param_ptr) : _ptrs(1, param_ptr) {}
59 
63 #ifdef LIBMESH_ENABLE_DEPRECATED
64  virtual ParameterAccessor<T> &
65  operator= (T * /* new_ptr */) override
66  {
67  libmesh_error();
68  return *this;
69  }
70 #endif
71 
75  virtual void set (const T & new_value) override
76  {
77  libmesh_assert(!_ptrs.empty());
78 #ifndef NDEBUG
79  // Compare other values to the last one we'll change
80  const T & val = *_ptrs.back();
81 #endif
82  for (std::size_t i=0; i != _ptrs.size(); ++i)
83  {
84  // If you're already using inconsistent parameters we can't
85  // help you.
86  libmesh_assert_equal_to(*_ptrs[i], val);
87  *_ptrs[i] = new_value;
88  }
89  }
90 
94  virtual const T & get () const override
95  {
96  libmesh_assert(!_ptrs.empty());
97  T & val = *_ptrs[0];
98 #ifndef NDEBUG
99  // If you're already using inconsistent parameters we can't help
100  // you.
101  for (std::size_t i=1; i < _ptrs.size(); ++i)
102  libmesh_assert_equal_to(*_ptrs[i], val);
103 #endif
104  return val;
105  }
106 
110  virtual std::unique_ptr<ParameterAccessor<T>> clone() const override
111  {
113  pmp->_ptrs = _ptrs;
114 
115  return std::unique_ptr<ParameterAccessor<T>>(pmp);
116  }
117 
118  void push_back (T * new_ptr) { _ptrs.push_back(new_ptr); }
119 
124  std::size_t size() const { return _ptrs.size(); }
125 
126 private:
127  std::vector<T *> _ptrs;
128 };
129 
130 } // namespace libMesh
131 
132 #endif // LIBMESH_PARAMETER_MULTIPOINTER_H
virtual ParameterAccessor< T > & operator=(T *) override
Stores multiple user-provided pointers.
virtual std::unique_ptr< ParameterAccessor< T > > clone() const override
Base class for reading/writing sensitivity parameters.