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
ROL::TimeStampsPtr
Ptr< std::vector< TimeStamp< Real > >> TimeStampsPtr
Definition: ROL_TimeStamp.hpp:66
ROL::SerialFunction::getTimeStamp
TimeStamp< Real > & getTimeStamp(size_type i)
Definition: ROL_SerialFunction.hpp:109
ROL::SerialFunction::clone
Ptr< Vector< Real > > clone(const Vector< Real > &x)
Definition: ROL_SerialFunction.hpp:76
ROL::TimeStamp
Contains local time step information.
Definition: ROL_TimeStamp.hpp:70
ROL::PartitionedVector
Defines the linear algebra of vector space on a generic partitioned vector.
Definition: ROL_PartitionedVector.hpp:60
ROL::SerialFunction::u_initial_
Ptr< Vector< Real > > u_initial_
Definition: ROL_SerialFunction.hpp:66
ROL::SerialFunction::timeStampsPtr_
TimeStampsPtr< Real > timeStampsPtr_
Definition: ROL_SerialFunction.hpp:68
ROL::SerialFunction::ts
const TimeStamp< Real > & ts(size_type i) const
Definition: ROL_SerialFunction.hpp:75
ROL::SerialFunction::setSkipInitialCondition
void setSkipInitialCondition(bool skip)
Definition: ROL_SerialFunction.hpp:98
ROL::SerialFunction::SerialFunction
SerialFunction(const Vector< Real > &u_initial, const TimeStampsPtr< Real > &timeStampsPtr)
Definition: ROL_SerialFunction.hpp:80
ROL::SerialFunction::getInitialCondition
const Vector< Real > & getInitialCondition() const
Definition: ROL_SerialFunction.hpp:92
ROL::SerialFunction::u_zero_
Ptr< Vector< Real > > u_zero_
Definition: ROL_SerialFunction.hpp:67
ROL::SerialFunction::setTimeStampsPtr
void setTimeStampsPtr(const TimeStampsPtr< Real > &timeStampsPtr)
Definition: ROL_SerialFunction.hpp:103
ROL::SerialFunction::setInitialCondition
void setInitialCondition(const Vector< Real > &u_initial)
Definition: ROL_SerialFunction.hpp:93
ROL::SerialFunction::getSkipInitialCondition
bool getSkipInitialCondition() const
Definition: ROL_SerialFunction.hpp:97
ROL::SerialFunction::size_type
typename std::vector< Real >::size_type size_type
Definition: ROL_SerialFunction.hpp:61
ROL::Vector
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:84
ROL::SerialFunction::getTimeStampsPtr
TimeStampsPtr< Real > getTimeStampsPtr() const
Definition: ROL_SerialFunction.hpp:101
ROL::SerialFunction::numTimeSteps
size_type numTimeSteps() const
Definition: ROL_SerialFunction.hpp:90
ROL::SerialFunction::skipInitialCond_
bool skipInitialCond_
Definition: ROL_SerialFunction.hpp:71
ROL
Definition: ROL_ElementwiseVector.hpp:61
ROL::SerialFunction
Provides behavior common to SerialObjective as SerialConstaint.
Definition: ROL_SerialFunction.hpp:59
ROL_TimeStamp.hpp
ROL_VectorWorkspace.hpp
size_type
typename PV< Real >::size_type size_type
Definition: ROL_Objective_SerialSimOpt.hpp:91
ROL::SerialFunction::getTimeStamp
const TimeStamp< Real > & getTimeStamp(size_type i) const
Definition: ROL_SerialFunction.hpp:110
ROL::SerialFunction::workspace_
VectorWorkspace< Real > workspace_
Definition: ROL_SerialFunction.hpp:69
ROL::SerialFunction::Nt_
size_type Nt_
Definition: ROL_SerialFunction.hpp:70
ROL::SerialFunction::setTimeStamp
void setTimeStamp(size_type i, const TimeStamp< Real > &timeStamp)
Definition: ROL_SerialFunction.hpp:112
ROL_PartitionedVector.hpp
ROL::SerialFunction::getZeroState
const Vector< Real > & getZeroState() const
Definition: ROL_SerialFunction.hpp:95
ROL::details::VectorWorkspace
Definition: ROL_VectorWorkspace.hpp:101