Rythmos - Transient Integration for Differential Equations  Version of the Day
 All Classes Functions Variables Typedefs Pages
Rythmos_StateAndForwardSensitivityModelEvaluator.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_STATE_AND_FORWARD_SENSITIVITY_MODEL_EVALUATOR_HPP
30 #define RYTHMOS_STATE_AND_FORWARD_SENSITIVITY_MODEL_EVALUATOR_HPP
31 
32 
33 #include "Rythmos_ForwardSensitivityModelEvaluatorBase.hpp"
34 #include "Thyra_ModelEvaluator.hpp" // Interface
35 #include "Thyra_StateFuncModelEvaluatorBase.hpp" // Implementation
36 #include "Thyra_DefaultProductVectorSpace.hpp"
37 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
38 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
39 #include "Thyra_DefaultMultiVectorProductVector.hpp"
40 #include "Thyra_DefaultMultiVectorLinearOpWithSolve.hpp"
41 #include "Teuchos_implicit_cast.hpp"
42 
43 
44 namespace Rythmos {
45 
46 
183 template<class Scalar>
185  : virtual public Thyra::StateFuncModelEvaluatorBase<Scalar>
186 {
187 public:
188 
191 
194 
202  void initializeStructure(
203  const Teuchos::RCP<const ForwardSensitivityModelEvaluatorBase<Scalar> > &sensModel
204  );
205 
206  // 2007/05/30: rabartl: ToDo: Add function to set the nominal values etc.
207 
213  Teuchos::RCP<const Thyra::DefaultProductVector<Scalar> >
215  const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &x_vec,
216  const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &s_bar_vec
217  ) const;
218 
220 
223 
225  int Np() const;
227  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_p_space(int l) const;
229  Teuchos::RCP<const Teuchos::Array<std::string> > get_p_names(int l) const;
231  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_x_space() const;
233  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_f_space() const;
235  Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
237  Teuchos::RCP<Thyra::LinearOpWithSolveBase<Scalar> > create_W() const;
239  Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
240 
242 
243 private:
244 
247 
249  Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
251  void evalModelImpl(
252  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs,
253  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs
254  ) const;
255 
257 
258 private:
259 
260  // /////////////////////////
261  // Private data members
262 
263  Teuchos::RCP<const ForwardSensitivityModelEvaluatorBase<Scalar> > sensModel_;
264 
265  int Np_;
266  Teuchos::RCP<const Thyra::DefaultProductVectorSpace<Scalar> > x_bar_space_;
267  Teuchos::RCP<const Thyra::DefaultProductVectorSpace<Scalar> > f_bar_space_;
268 
269 };
270 
271 
272 // /////////////////////////////////
273 // Implementations
274 
275 
276 // Constructors/Intializers/Accessors
277 
278 
279 template<class Scalar>
281  :Np_(0)
282 {}
283 
284 
285 template<class Scalar>
287  const Teuchos::RCP<const ForwardSensitivityModelEvaluatorBase<Scalar> > &sensModel
288  )
289 {
290 
291  using Teuchos::tuple; using Teuchos::RCP;
292 
293  TEUCHOS_TEST_FOR_EXCEPT( is_null(sensModel) );
294 
295  sensModel_ = sensModel;
296 
297  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
298  stateModel = sensModel_->getStateModel();
299 
300  x_bar_space_ = Thyra::productVectorSpace<Scalar>(
301  tuple<RCP<const Thyra::VectorSpaceBase<Scalar> > >(
302  stateModel->get_x_space(), sensModel_->get_x_space()
303  )
304  );
305 
306  f_bar_space_ = Thyra::productVectorSpace<Scalar>(
307  tuple<RCP<const Thyra::VectorSpaceBase<Scalar> > >(
308  stateModel->get_f_space(), sensModel_->get_f_space()
309  )
310  );
311 
312  Np_ = stateModel->Np();
313 
314 }
315 
316 
317 template<class Scalar>
318 Teuchos::RCP<const Thyra::DefaultProductVector<Scalar> >
320  const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &x_vec,
321  const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &s_bar_vec
322  ) const
323 {
324 
325  using Teuchos::tuple;
326  using Teuchos::RCP;
327  typedef RCP<const Thyra::VectorBase<Scalar> > RCPCV;
328 
329  return Thyra::defaultProductVector<Scalar>(
330  x_bar_space_, tuple<RCPCV>(x_vec,s_bar_vec)
331  );
332 
333 }
334 
335 
336 // Public functions overridden from ModelEvaulator
337 
338 
339 template<class Scalar>
341 {
342  return Np_;
343 }
344 
345 
346 template<class Scalar>
347 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
349 {
350  return sensModel_->getStateModel()->get_p_space(l);
351 }
352 
353 
354 template<class Scalar>
355 Teuchos::RCP<const Teuchos::Array<std::string> >
357 {
358  return sensModel_->getStateModel()->get_p_names(l);
359 }
360 
361 
362 template<class Scalar>
363 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
365 {
366  return x_bar_space_;
367 }
368 
369 
370 template<class Scalar>
371 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
373 {
374  return f_bar_space_;
375 }
376 
377 
378 template<class Scalar>
379 Thyra::ModelEvaluatorBase::InArgs<Scalar>
381 {
382  return this->createInArgs();
383 }
384 
385 
386 template<class Scalar>
387 Teuchos::RCP<Thyra::LinearOpWithSolveBase<Scalar> >
389 {
390  TEUCHOS_TEST_FOR_EXCEPT("ToDo: Implement create_W() when needed!");
391  return Teuchos::null;
392 }
393 
394 
395 template<class Scalar>
396 Thyra::ModelEvaluatorBase::InArgs<Scalar>
398 {
399  typedef Thyra::ModelEvaluatorBase MEB;
400  MEB::InArgs<Scalar>
401  stateModelInArgs = sensModel_->getStateModel()->createInArgs();
402  MEB::InArgsSetup<Scalar> inArgs;
403  inArgs.setModelEvalDescription(this->description());
404  inArgs.set_Np(Np_);
405  inArgs.setSupports( MEB::IN_ARG_x_dot,
406  stateModelInArgs.supports(MEB::IN_ARG_x_dot) );
407  inArgs.setSupports( MEB::IN_ARG_x );
408  inArgs.setSupports( MEB::IN_ARG_t );
409  inArgs.setSupports( MEB::IN_ARG_alpha,
410  stateModelInArgs.supports(MEB::IN_ARG_alpha) );
411  inArgs.setSupports( MEB::IN_ARG_beta,
412  stateModelInArgs.supports(MEB::IN_ARG_beta) );
413  return inArgs;
414 }
415 
416 
417 // Private functions overridden from ModelEvaulatorDefaultBase
418 
419 
420 template<class Scalar>
421 Thyra::ModelEvaluatorBase::OutArgs<Scalar>
423 {
424  typedef Thyra::ModelEvaluatorBase MEB;
425  MEB::OutArgs<Scalar>
426  stateModelOutArgs = sensModel_->getStateModel()->createOutArgs();
427  MEB::OutArgsSetup<Scalar> outArgs;
428  outArgs.setModelEvalDescription(this->description());
429  outArgs.set_Np_Ng(Np_,0);
430  outArgs.setSupports(MEB::OUT_ARG_f);
431  if (stateModelOutArgs.supports(MEB::OUT_ARG_W) ) {
432  outArgs.setSupports(MEB::OUT_ARG_W);
433  outArgs.set_W_properties(stateModelOutArgs.get_W_properties());
434  }
435  return outArgs;
436 }
437 
438 
439 template<class Scalar>
440 void StateAndForwardSensitivityModelEvaluator<Scalar>::evalModelImpl(
441  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &/* inArgs */,
442  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &/* outArgs */
443  ) const
444 {
445  TEUCHOS_TEST_FOR_EXCEPT("ToDo: Implement evalModel(...) when needed!");
446 }
447 
448 
449 } // namespace Rythmos
450 
451 
452 #endif // RYTHMOS_STATE_AND_FORWARD_SENSITIVITY_MODEL_EVALUATOR_HPP
Combined State and Forward sensitivity transient ModelEvaluator subclass.
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int l) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
Teuchos::RCP< Thyra::LinearOpWithSolveBase< Scalar > > create_W() const
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Teuchos::RCP< const Thyra::DefaultProductVector< Scalar > > create_x_bar_vec(const Teuchos::RCP< const Thyra::VectorBase< Scalar > > &x_vec, const Teuchos::RCP< const Thyra::VectorBase< Scalar > > &s_bar_vec) const
Create a wrapped product vector of the form x_bar = [ x; s_bar ].
Forward sensitivity transient ModelEvaluator node interface class.
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
void initializeStructure(const Teuchos::RCP< const ForwardSensitivityModelEvaluatorBase< Scalar > > &sensModel)
Set up the structure of the state and sensitivity equations.