Rythmos - Transient Integration for Differential Equations  Version of the Day
 All Classes Functions Variables Typedefs Pages
Rythmos_ForwardResponseSensitivityComputerObserver.hpp
1 //@HEADER
2 // ***********************************************************************
3 //
4 // Rythmos Package
5 // Copyright (2006) 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 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
25 //
26 // ***********************************************************************
27 //@HEADER
28 
29 #ifndef RYTHMOS_FORWARD_RESPONSE_SENSITIVITY_COMPUTER_OBSERVER_HPP
30 #define RYTHMOS_FORWARD_RESPONSE_SENSITIVITY_COMPUTER_OBSERVER_HPP
31 
32 
33 #include "Rythmos_IntegrationObserverBase.hpp"
34 #include "Rythmos_ForwardResponseSensitivityComputer.hpp"
35 #include "Rythmos_ResponseAndFwdSensPoint.hpp"
36 #include "Rythmos_extractStateAndSens.hpp"
37 
38 
39 namespace Rythmos {
40 
41 
47 template<class Scalar>
49  : public IntegrationObserverBase<Scalar>
50 {
51 public:
52 
55 
58 
60  void initialize(
61  const RCP<const Thyra::ModelEvaluator<Scalar> > &responseFunc,
62  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &basePoint,
63  const int p_index,
64  const int g_index
65  );
66 
68  const Array<ResponseAndFwdSensPoint<Scalar> >& responseAndFwdSensPoints() const;
69 
71 
74 
76  virtual RCP<IntegrationObserverBase<Scalar> >
78 
80  virtual void resetIntegrationObserver(
81  const TimeRange<Scalar> &integrationTimeDomain
82  );
83 
85  virtual void observeCompletedTimeStep(
86  const StepperBase<Scalar> &stepper,
87  const StepControlInfo<Scalar> &stepCtrlInfo,
88  const int timeStepIter
89  );
90 
92 
93 private:
94 
95  ForwardResponseSensitivityComputer<Scalar> forwardResponseSensitivityComputer_;
96  Array<ResponseAndFwdSensPoint<Scalar> > responseAndFwdSensPoints_;
97 
98  RCP<Thyra::VectorBase<Scalar> > g_hat_;
99  RCP<Thyra::MultiVectorBase<Scalar> > D_g_hat_D_p_;
100 
101 };
102 
103 
108 template<class Scalar>
109 RCP<ForwardResponseSensitivityComputerObserver<Scalar> >
111 {
112  RCP<ForwardResponseSensitivityComputerObserver<Scalar> >
114  return frsco;
115 }
116 
117 
122 template<class Scalar>
123 RCP<ForwardResponseSensitivityComputerObserver<Scalar> >
125  const RCP<const Thyra::ModelEvaluator<Scalar> > &responseFunc,
126  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &basePoint,
127  const int p_index,
128  const int g_index
129  )
130 {
131  RCP<ForwardResponseSensitivityComputerObserver<Scalar> >
132  frsco = Rythmos::forwardResponseSensitivityComputerObserver<Scalar>();
133  frsco->initialize(responseFunc,basePoint,p_index,g_index);
134  return frsco;
135 }
136 
137 
138 //
139 // Implementations
140 //
141 
142 
143 // Constructors/Initializers/Accessors
144 
145 
146 template<class Scalar>
148 {}
149 
150 
151 template<class Scalar>
153  const RCP<const Thyra::ModelEvaluator<Scalar> > &responseFunc,
154  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &basePoint,
155  const int p_index,
156  const int g_index
157  )
158 {
159  forwardResponseSensitivityComputer_.setResponseFunction(
160  responseFunc, basePoint, p_index, g_index );
161  g_hat_ = forwardResponseSensitivityComputer_.create_g_hat();
162  D_g_hat_D_p_ = forwardResponseSensitivityComputer_.create_D_g_hat_D_p();
163 }
164 
165 
166 template<class Scalar>
167 const Array<ResponseAndFwdSensPoint<Scalar> >&
169 {
170  return responseAndFwdSensPoints_;
171 }
172 
173 
174 // Overridden from IntegrationObserverBase
175 
176 
177 template<class Scalar>
178 RCP<IntegrationObserverBase<Scalar> >
180 {
181  TEUCHOS_TEST_FOR_EXCEPT(true);
182  return Teuchos::null;
183 }
184 
185 
186 template<class Scalar>
188  const TimeRange<Scalar> &integrationTimeDomain
189  )
190 {
191  responseAndFwdSensPoints_.clear();
192 }
193 
194 
195 template<class Scalar>
197  const StepperBase<Scalar> &stepper,
198  const StepControlInfo<Scalar> &stepCtrlInfo,
199  const int timeStepIter
200  )
201 {
202 
203  using Teuchos::OSTab;
204  using Teuchos::includesVerbLevel;
205 
206  // Setup the output info
207 
208  const RCP<FancyOStream> out = this->getOStream();
209  const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
210 
211  const bool trace =
212  ( !is_null(out) && includesVerbLevel(verbLevel,Teuchos::VERB_LOW) );
213 
214  forwardResponseSensitivityComputer_.setOStream(out);
215  forwardResponseSensitivityComputer_.setVerbLevel(verbLevel);
216 
217  OSTab tab(out);
218 
219  if (trace)
220  *out << "\nEntering ForwardResponseSensitivityComputerObserver<Scalar>::observeCompletedTimeStep(...) ...\n";
221 
222  // A) Get x_bar and x_dot_bar for this time step
223 
224  const Scalar t = stepper.getStepStatus().time;
225 
226  RCP<const Thyra::VectorBase<Scalar> > x_bar, x_bar_dot;
227 
228  get_x_and_x_dot( stepper, t, &x_bar, &x_bar_dot );
229 
230  RCP<const Thyra::VectorBase<Scalar> > x;
231  RCP<const Thyra::MultiVectorBase<Scalar> > S;
232  RCP<const Thyra::VectorBase<Scalar> > x_dot;
233  RCP<const Thyra::MultiVectorBase<Scalar> > S_dot;
234 
235  extractStateAndSens( x_bar, x_bar_dot, &x, &S, &x_dot, &S_dot );
236 
237  // B) Compute and assemble the response and reduced sensitivity
238 
239  forwardResponseSensitivityComputer_.computeResponseAndSensitivity(
240  x_dot.get(), S_dot.get(), *x, *S, t, &*g_hat_, &*D_g_hat_D_p_
241  );
242 
243  // C) Store this point
244 
245  responseAndFwdSensPoints_.push_back(
247  t, g_hat_->clone_v(), D_g_hat_D_p_->clone_mv()
248  )
249  );
250 
251  if (trace)
252  *out << "\nEntering ForwardResponseSensitivityComputerObserver<Scalar>::observeCompletedTimeStep(...) ...\n";
253 
254 }
255 
256 
257 } // namespace Rythmos
258 
259 
260 #endif //RYTHMOS_FORWARD_RESPONSE_SENSITIVITY_COMPUTER_OBSERVER_HPP
Base class for defining stepper functionality.
virtual void resetIntegrationObserver(const TimeRange< Scalar > &integrationTimeDomain)
Observer class that computes sensitivities at the end of each time step.
Simple struct to aggregate integration/stepper control information.
virtual const StepStatus< Scalar > getStepStatus() const =0
Get current stepper status after a step has been taken.
Simple class to combine a response and it&#39;s forward sensitivity at a time point.
const Array< ResponseAndFwdSensPoint< Scalar > > & responseAndFwdSensPoints() const
virtual void observeCompletedTimeStep(const StepperBase< Scalar > &stepper, const StepControlInfo< Scalar > &stepCtrlInfo, const int timeStepIter)
RCP< ForwardResponseSensitivityComputerObserver< Scalar > > forwardResponseSensitivityComputerObserver(const RCP< const Thyra::ModelEvaluator< Scalar > > &responseFunc, const Thyra::ModelEvaluatorBase::InArgs< Scalar > &basePoint, const int p_index, const int g_index)
Non-member constructor.
Base class for strategy objects that observe and time integration by observing the stepper object...
void initialize(const RCP< const Thyra::ModelEvaluator< Scalar > > &responseFunc, const Thyra::ModelEvaluatorBase::InArgs< Scalar > &basePoint, const int p_index, const int g_index)
RCP< ForwardResponseSensitivityComputerObserver< Scalar > > forwardResponseSensitivityComputerObserver()
Non-member constructor.
Concrete utility class for computing (assembling) forward transient response sensitivities.
virtual RCP< IntegrationObserverBase< Scalar > > cloneIntegrationObserver() const