ROL
ROL_SerialFunction.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #pragma once
11 #ifndef ROL_SERIALFUNCION_HPP
12 #define ROL_SERIALFUNCION_HPP
13 
15 #include "ROL_VectorWorkspace.hpp"
16 #include "ROL_TimeStamp.hpp"
17 
23 namespace ROL {
24 
25 template<typename Real>
27 public:
29 
30 private:
32 
33  Ptr<Vector<Real>> u_initial_; // Initial condition
34  Ptr<Vector<Real>> u_zero_; // Zero state vector
35  TimeStampsPtr<Real> timeStampsPtr_; // Set of all time stamps
36  mutable VectorWorkspace<Real> workspace_; // Memory bank for vector clones
37  size_type Nt_; // Number of type steps
38  bool skipInitialCond_ = false;
39 
40 protected:
41 
42  const TimeStamp<Real>& ts( size_type i ) const { return timeStampsPtr_->at(i); }
43  Ptr<Vector<Real>> clone( const Vector<Real>& x ) { return workspace_.clone(x); }
44 
45 public:
46 
47  SerialFunction( const Vector<Real>& u_initial,
48  const TimeStampsPtr<Real>& timeStampsPtr ) :
49  u_initial_(u_initial.clone()),
50  u_zero_(u_initial.clone()),
51  timeStampsPtr_(timeStampsPtr),
52  Nt_(timeStampsPtr->size()) {
53  u_initial_->set(u_initial);
54  u_zero_->zero();
55  }
56 
57  size_type numTimeSteps() const { return Nt_; }
58 
59  const Vector<Real>& getInitialCondition() const { return *u_initial_; }
60  void setInitialCondition( const Vector<Real>& u_initial ) { u_initial_->set(u_initial); }
61 
62  const Vector<Real>& getZeroState() const { return *u_zero_; }
63 
64  bool getSkipInitialCondition() const { return skipInitialCond_; }
65  void setSkipInitialCondition( bool skip ) { skipInitialCond_ = skip; }
66 
67  // Get and set methods for all TimeStamps
69 
70  void setTimeStampsPtr( const TimeStampsPtr<Real>& timeStampsPtr ) {
71  timeStampsPtr_ = timeStampsPtr;
72  Nt_ = timeStampsPtr_->size();
73  }
74 
75  // Get and set methods for individual TimeStamp objects
77  const TimeStamp<Real>& getTimeStamp( size_type i ) const { return timeStampsPtr_->at(i); }
78 
79  void setTimeStamp( size_type i, const TimeStamp<Real>& timeStamp ) {
80  timeStampsPtr_->at(i) = timeStamp;
81  }
82 
83 
84 }; // class SerialFunction
85 
86 
87 } // namespace ROL
88 
89 #endif // ROL_SERIALFUNCION_HPP
VectorWorkspace< Real > workspace_
const Vector< Real > & getInitialCondition() const
typename PV< Real >::size_type size_type
const Vector< Real > & getZeroState() const
Defines the linear algebra of vector space on a generic partitioned vector.
size_type numTimeSteps() const
Ptr< Vector< Real > > u_zero_
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
void setInitialCondition(const Vector< Real > &u_initial)
const TimeStamp< Real > & getTimeStamp(size_type i) const
void setTimeStampsPtr(const TimeStampsPtr< Real > &timeStampsPtr)
typename std::vector< Real >::size_type size_type
Ptr< Vector< Real > > clone(const Vector< Real > &x)
TimeStamp< Real > & getTimeStamp(size_type i)
Ptr< Vector< Real > > u_initial_
bool getSkipInitialCondition() const
Provides behavior common to SerialObjective as SerialConstaint.
Ptr< std::vector< TimeStamp< Real >>> TimeStampsPtr
void setSkipInitialCondition(bool skip)
TimeStampsPtr< Real > timeStampsPtr_
SerialFunction(const Vector< Real > &u_initial, const TimeStampsPtr< Real > &timeStampsPtr)
void setTimeStamp(size_type i, const TimeStamp< Real > &timeStamp)
const TimeStamp< Real > & ts(size_type i) const
TimeStampsPtr< Real > getTimeStampsPtr() const