45 #ifndef ROL_SIMCONTROLLER_DEF_H
46 #define ROL_SIMCONTROLLER_DEF_H
50 template <
class Real,
class Key>
52 : maxIndex_(0), maxIndex_trial_(0), maxIndex_temp_(0),
53 trial_(false), temp_(false), objUpdated_(false), conUpdated_(false) {
59 template <
class Real,
class Key>
62 for (
auto it = indices_.begin(); it != indices_.end(); ++it) {
63 flags_[it->second] =
false;
68 template <
class Real,
class Key>
76 if (conUpdated_ && objUpdated_) {
82 template <
class Real,
class Key>
90 if (conUpdated_ && objUpdated_) {
96 template <
class Real,
class Key>
116 if (conUpdated_ && objUpdated_) {
123 template <
class Real,
class Key>
143 if (conUpdated_ && objUpdated_) {
150 template <
class Real,
class Key>
154 return isNull(param,indices_trial_);
157 return isNull(param,indices_);
161 return isNull(param,indices_temp_);
166 template <
class Real,
class Key>
170 return isComputed(param,indices_trial_,flags_trial_);
173 return isComputed(param,indices_,flags_);
177 return isComputed(param,indices_temp_,flags_temp_);
182 template <
class Real,
class Key>
186 allocate(x,param,indices_trial_,flags_trial_,vectors_trial_,maxIndex_trial_);
189 allocate(x,param,indices_,flags_,vectors_,maxIndex_);
193 allocate(x,param,indices_temp_,flags_temp_,vectors_temp_,maxIndex_temp_);
197 template <
class Real,
class Key>
201 return get(param,indices_trial_,flags_trial_,vectors_trial_,maxIndex_trial_);
204 return get(param,indices_,flags_,vectors_,maxIndex_);
208 return get(param,indices_temp_,flags_temp_,vectors_temp_,maxIndex_temp_);
213 template <
class Real,
class Key>
217 return set(param,indices_trial_,flags_trial_,vectors_trial_,maxIndex_trial_);
220 return set(param,indices_,flags_,vectors_,maxIndex_);
224 return set(param,indices_temp_,flags_temp_,vectors_temp_,maxIndex_temp_);
229 template <
class Real,
class Key>
234 flag =
get(x,param,indices_trial_,flags_trial_,vectors_trial_,maxIndex_trial_);
237 flag =
get(x,param,indices_,flags_,vectors_,maxIndex_);
241 flag =
get(x,param,indices_temp_,flags_temp_,vectors_temp_,maxIndex_temp_);
246 template <
class Real,
class Key>
250 set(x,param,indices_trial_,flags_trial_,vectors_trial_,maxIndex_trial_);
253 set(x,param,indices_,flags_,vectors_,maxIndex_);
257 set(x,param,indices_temp_,flags_temp_,vectors_temp_,maxIndex_temp_);
261 template <
class Real,
class Key>
263 for (
auto it = indices_.begin(); it != indices_.end(); ++it) {
264 to.
set(*vectors_[it->second],it->first);
268 template <
class Real,
class Key>
270 for (
auto it = indices_trial_.begin(); it != indices_trial_.end(); ++it) {
271 flags_trial_[it->second] =
false;
275 template <
class Real,
class Key>
277 for (
auto it = indices_temp_.begin(); it != indices_temp_.end(); ++it) {
278 flags_temp_[it->second] =
false;
282 template <
class Real,
class Key>
284 const std::map<Key,int> &indices)
const {
285 return (indices.count(param)==0);
288 template <
class Real,
class Key>
290 const std::map<Key,int> &indices,
const std::vector<bool> &flags)
const {
291 if (indices.count(param)>0) {
292 auto it = indices.find(param);
293 return flags[it->second];
298 template <
class Real,
class Key>
300 std::map<Key,int> &indices, std::vector<bool> &flags,
301 std::vector<Ptr<
Vector<Real>>> &vectors,
int &maxIndex)
const {
302 if (isNull(param,indices)) {
303 int index = maxIndex;
304 indices.insert(std::pair<Key,int>(param, index));
305 flags.push_back(
false);
306 vectors.push_back(x.
clone());
311 template <
class Real,
class Key>
313 const std::map<Key,int> &indices,
const std::vector<bool> &flags,
314 const std::vector<Ptr<
Vector<Real>>> &vectors,
const int &maxIndex)
const {
315 int count = indices.count(param);
316 int index = maxIndex;
318 auto it = indices.find(param);
320 return vectors[index];
325 template <
class Real,
class Key>
327 std::map<Key,int> &indices, std::vector<bool> &flags,
328 std::vector<Ptr<
Vector<Real>>> &vectors,
int &maxIndex)
const {
329 ROL_TEST_FOR_EXCEPTION(isNull(param,indices),std::logic_error,
330 ">>> ROL::VectorController::set : Vector has not been allocated!");
331 ROL_TEST_FOR_EXCEPTION(isComputed(param,indices,flags),std::logic_error,
332 ">>> ROL::VectorController::set : Vector is already computed!");
333 int count = indices.count(param);
334 int index = maxIndex;
336 auto it = indices.find(param);
339 return vectors[index];
344 template <
class Real,
class Key>
346 std::map<Key,int> &indices, std::vector<bool> &flags,
347 std::vector<Ptr<
Vector<Real>>> &vectors,
int &maxIndex)
const {
348 int count = indices.count(param);
350 int index = maxIndex;
352 auto it = indices.find(param);
356 x.
set(*vectors[index]);
360 indices.insert(std::pair<Key,int>(param, index));
361 flags.push_back(
false);
362 vectors.push_back(x.
clone());
368 template <
class Real,
class Key>
370 std::map<Key,int> &indices, std::vector<bool> &flags,
371 std::vector<Ptr<
Vector<Real>>> &vectors,
int &maxIndex)
const {
372 int count = indices.count(param);
373 int index = maxIndex;
375 auto it = indices.find(param);
378 vectors[index]->set(x);
381 indices.insert(std::pair<Key,int>(param, index));
382 flags.push_back(
true);
383 vectors.push_back(x.
clone());
384 vectors[index]->set(x);
389 template <
class Real,
class Key>
392 for (
auto it = indices_trial_.begin(); it != indices_trial_.end(); ++it) {
393 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_