ROL
ROL_SerialFunction.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Rapid Optimization Library (ROL) Package
5 // Copyright (2014) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // Questions? Contact lead developers:
37 // Drew Kouri (dpkouri@sandia.gov) and
38 // Denis Ridzal (dridzal@sandia.gov)
39 //
40 // ************************************************************************
41 // @HEADER
42 
43 #pragma once
44 #ifndef ROL_SERIALFUNCION_HPP
45 #define ROL_SERIALFUNCION_HPP
46 
48 #include "ROL_VectorWorkspace.hpp"
49 #include "ROL_TimeStamp.hpp"
50 
56 namespace ROL {
57 
58 template<typename Real>
60 public:
62 
63 private:
65 
66  Ptr<Vector<Real>> u_initial_; // Initial condition
67  Ptr<Vector<Real>> u_zero_; // Zero state vector
68  TimeStampsPtr<Real> timeStampsPtr_; // Set of all time stamps
69  mutable VectorWorkspace<Real> workspace_; // Memory bank for vector clones
70  size_type Nt_; // Number of type steps
71  bool skipInitialCond_ = false;
72 
73 protected:
74 
75  const TimeStamp<Real>& ts( size_type i ) const { return timeStampsPtr_->at(i); }
76  Ptr<Vector<Real>> clone( const Vector<Real>& x ) { return workspace_.clone(x); }
77 
78 public:
79 
80  SerialFunction( const Vector<Real>& u_initial,
81  const TimeStampsPtr<Real>& timeStampsPtr ) :
82  u_initial_(u_initial.clone()),
83  u_zero_(u_initial.clone()),
84  timeStampsPtr_(timeStampsPtr),
85  Nt_(timeStampsPtr->size()) {
86  u_initial_->set(u_initial);
87  u_zero_->zero();
88  }
89 
90  size_type numTimeSteps() const { return Nt_; }
91 
92  const Vector<Real>& getInitialCondition() const { return *u_initial_; }
93  void setInitialCondition( const Vector<Real>& u_initial ) { u_initial_->set(u_initial); }
94 
95  const Vector<Real>& getZeroState() const { return *u_zero_; }
96 
97  bool getSkipInitialCondition() const { return skipInitialCond_; }
98  void setSkipInitialCondition( bool skip ) { skipInitialCond_ = skip; }
99 
100  // Get and set methods for all TimeStamps
102 
103  void setTimeStampsPtr( const TimeStampsPtr<Real>& timeStampsPtr ) {
104  timeStampsPtr_ = timeStampsPtr;
105  Nt_ = timeStampsPtr_->size();
106  }
107 
108  // Get and set methods for individual TimeStamp objects
110  const TimeStamp<Real>& getTimeStamp( size_type i ) const { return timeStampsPtr_->at(i); }
111 
112  void setTimeStamp( size_type i, const TimeStamp<Real>& timeStamp ) {
113  timeStampsPtr_->at(i) = timeStamp;
114  }
115 
116 
117 }; // class SerialFunction
118 
119 
120 } // namespace ROL
121 
122 #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:80
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