10 #ifndef ROL_SIMCONTROLLER_DEF_H
11 #define ROL_SIMCONTROLLER_DEF_H
15 template <
class Real,
class Key>
17 : maxIndex_(0), maxIndex_trial_(0), maxIndex_temp_(0),
18 trial_(false), temp_(false), objUpdated_(false), conUpdated_(false) {
24 template <
class Real,
class Key>
27 for (
auto it = indices_.begin(); it != indices_.end(); ++it) {
28 flags_[it->second] =
false;
33 template <
class Real,
class Key>
41 if (conUpdated_ && objUpdated_) {
47 template <
class Real,
class Key>
55 if (conUpdated_ && objUpdated_) {
61 template <
class Real,
class Key>
81 if (conUpdated_ && objUpdated_) {
88 template <
class Real,
class Key>
108 if (conUpdated_ && objUpdated_) {
115 template <
class Real,
class Key>
119 return isNull(param,indices_trial_);
122 return isNull(param,indices_);
126 return isNull(param,indices_temp_);
131 template <
class Real,
class Key>
135 return isComputed(param,indices_trial_,flags_trial_);
138 return isComputed(param,indices_,flags_);
142 return isComputed(param,indices_temp_,flags_temp_);
147 template <
class Real,
class Key>
151 allocate(x,param,indices_trial_,flags_trial_,vectors_trial_,maxIndex_trial_);
154 allocate(x,param,indices_,flags_,vectors_,maxIndex_);
158 allocate(x,param,indices_temp_,flags_temp_,vectors_temp_,maxIndex_temp_);
162 template <
class Real,
class Key>
166 return get(param,indices_trial_,flags_trial_,vectors_trial_,maxIndex_trial_);
169 return get(param,indices_,flags_,vectors_,maxIndex_);
173 return get(param,indices_temp_,flags_temp_,vectors_temp_,maxIndex_temp_);
178 template <
class Real,
class Key>
182 return set(param,indices_trial_,flags_trial_,vectors_trial_,maxIndex_trial_);
185 return set(param,indices_,flags_,vectors_,maxIndex_);
189 return set(param,indices_temp_,flags_temp_,vectors_temp_,maxIndex_temp_);
194 template <
class Real,
class Key>
199 flag =
get(x,param,indices_trial_,flags_trial_,vectors_trial_,maxIndex_trial_);
202 flag =
get(x,param,indices_,flags_,vectors_,maxIndex_);
206 flag =
get(x,param,indices_temp_,flags_temp_,vectors_temp_,maxIndex_temp_);
211 template <
class Real,
class Key>
215 set(x,param,indices_trial_,flags_trial_,vectors_trial_,maxIndex_trial_);
218 set(x,param,indices_,flags_,vectors_,maxIndex_);
222 set(x,param,indices_temp_,flags_temp_,vectors_temp_,maxIndex_temp_);
226 template <
class Real,
class Key>
228 for (
auto it = indices_.begin(); it != indices_.end(); ++it) {
229 to.
set(*vectors_[it->second],it->first);
233 template <
class Real,
class Key>
235 for (
auto it = indices_trial_.begin(); it != indices_trial_.end(); ++it) {
236 flags_trial_[it->second] =
false;
240 template <
class Real,
class Key>
242 for (
auto it = indices_temp_.begin(); it != indices_temp_.end(); ++it) {
243 flags_temp_[it->second] =
false;
247 template <
class Real,
class Key>
249 const std::map<Key,int> &indices)
const {
250 return (indices.count(param)==0);
253 template <
class Real,
class Key>
255 const std::map<Key,int> &indices,
const std::vector<bool> &flags)
const {
256 if (indices.count(param)>0) {
257 auto it = indices.find(param);
258 return flags[it->second];
263 template <
class Real,
class Key>
265 std::map<Key,int> &indices, std::vector<bool> &flags,
266 std::vector<Ptr<
Vector<Real>>> &vectors,
int &maxIndex)
const {
267 if (isNull(param,indices)) {
268 int index = maxIndex;
269 indices.insert(std::pair<Key,int>(param, index));
270 flags.push_back(
false);
271 vectors.push_back(x.
clone());
276 template <
class Real,
class Key>
278 const std::map<Key,int> &indices,
const std::vector<bool> &flags,
279 const std::vector<Ptr<
Vector<Real>>> &vectors,
const int &maxIndex)
const {
280 int count = indices.count(param);
281 int index = maxIndex;
283 auto it = indices.find(param);
285 return vectors[index];
290 template <
class Real,
class Key>
292 std::map<Key,int> &indices, std::vector<bool> &flags,
293 std::vector<Ptr<
Vector<Real>>> &vectors,
int &maxIndex)
const {
294 ROL_TEST_FOR_EXCEPTION(isNull(param,indices),std::logic_error,
295 ">>> ROL::VectorController::set : Vector has not been allocated!");
296 ROL_TEST_FOR_EXCEPTION(isComputed(param,indices,flags),std::logic_error,
297 ">>> ROL::VectorController::set : Vector is already computed!");
298 int count = indices.count(param);
299 int index = maxIndex;
301 auto it = indices.find(param);
304 return vectors[index];
309 template <
class Real,
class Key>
311 std::map<Key,int> &indices, std::vector<bool> &flags,
312 std::vector<Ptr<
Vector<Real>>> &vectors,
int &maxIndex)
const {
313 int count = indices.count(param);
315 int index = maxIndex;
317 auto it = indices.find(param);
321 x.
set(*vectors[index]);
325 indices.insert(std::pair<Key,int>(param, index));
326 flags.push_back(
false);
327 vectors.push_back(x.
clone());
333 template <
class Real,
class Key>
335 std::map<Key,int> &indices, std::vector<bool> &flags,
336 std::vector<Ptr<
Vector<Real>>> &vectors,
int &maxIndex)
const {
337 int count = indices.count(param);
338 int index = maxIndex;
340 auto it = indices.find(param);
343 vectors[index]->set(x);
346 indices.insert(std::pair<Key,int>(param, index));
347 flags.push_back(
true);
348 vectors.push_back(x.
clone());
349 vectors[index]->set(x);
354 template <
class Real,
class Key>
357 for (
auto it = indices_trial_.begin(); it != indices_trial_.end(); ++it) {
358 set(*vectors_trial_[it->second],it->first,indices_,flags_,vectors_,maxIndex_);
std::map< Key, int > indices_temp_
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
std::vector< bool > flags_
bool isNull(const Key ¶m) const
Check if vector associated with provided key is allocated.
void constraintUpdate(bool flag=true)
Equality constraint update for VectorController storage.
const Ptr< Vector< Real > > set(const Key ¶m)
Set the vector associated with provided key. This assumes the vector data will be changed...
Defines the linear algebra or vector space interface.
std::map< Key, int > indices_
VectorController(void)
Constructor.
void push(VectorController< Real, Key > &to) const
Push the contents of *this into another VectorController.
bool isComputed(const Key ¶m) const
Check if vector has been computed.
void allocate(const Vector< Real > &x, const Key ¶m)
Allocate the vector associated with provided key.
std::map< Key, int > indices_trial_
void objectiveUpdate(bool flag=true)
Objective function update for VectorController storage.
std::vector< Ptr< Vector< Real > > > vectors_trial_
std::vector< Ptr< Vector< Real > > > vectors_temp_
std::vector< bool > flags_temp_
void reset(bool flag=true)
virtual void set(const Vector &x)
Set where .
std::vector< bool > flags_trial_
const Ptr< const Vector< Real > > get(const Key ¶m) const
Return the vector associated with provided key.
std::vector< Ptr< Vector< Real > > > vectors_